folders.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. iterations=${1:-5}
  3. id1=I6KAH7666SLLL5PFXSOAUFJCDZYAOMLEKCP2GB3BV5RQST3PSROA
  4. id2=JMFJCXBGZDE4BOCJE3VF65GYZNAIVJRET3J6HMRAUQIGJOFKNHMQ
  5. go build json.go
  6. start() {
  7. echo "Starting..."
  8. STTRACE=model,scanner STPROFILER=":9091" syncthing -home "f1" > 1.out 2>&1 &
  9. STTRACE=model,scanner STPROFILER=":9092" syncthing -home "f2" > 2.out 2>&1 &
  10. }
  11. stop() {
  12. echo "Stopping..."
  13. for i in 1 2 ; do
  14. curl -X POST "http://localhost:808$i/rest/shutdown"
  15. done
  16. }
  17. setup() {
  18. echo "Setting up dirs..."
  19. mkdir -p s1
  20. pushd s1 >/dev/null
  21. rmdir */*[02468] 2>/dev/null
  22. rm -rf *2
  23. for ((i = 0; i < 1000; i++)) ; do
  24. mkdir -p $RANDOM/$RANDOM
  25. done
  26. popd >/dev/null
  27. }
  28. testConvergence() {
  29. while true ; do
  30. sleep 5
  31. s1comp=$(curl -s "http://localhost:8082/rest/connections" | ./json "$id1/Completion")
  32. s2comp=$(curl -s "http://localhost:8081/rest/connections" | ./json "$id2/Completion")
  33. s1comp=${s1comp:-0}
  34. s2comp=${s2comp:-0}
  35. tot=$(($s1comp + $s2comp))
  36. echo $tot / 200
  37. if [[ $tot == 200 ]] ; then
  38. # when fixing up directories, a node will announce completion
  39. # slightly before it's actually complete. this is arguably a bug,
  40. # but we let it slide for the moment as long as it gets there
  41. # eventually.
  42. sleep 5
  43. break
  44. fi
  45. done
  46. echo "Verifying..."
  47. pushd s1 >/dev/null
  48. ../md5r -d | grep -v ' . ' > ../dirs-1
  49. popd >/dev/null
  50. pushd s2 >/dev/null
  51. ../md5r -d | grep -v ' . ' > ../dirs-2
  52. popd >/dev/null
  53. if ! cmp dirs-1 dirs-2 ; then
  54. echo Repos differ
  55. stop
  56. exit 1
  57. fi
  58. }
  59. rm -rf s? s??-?
  60. rm -f f?/*.idx.gz
  61. setup
  62. start
  63. for ((j = 0; j < 10; j++)) ; do
  64. echo "#$j..."
  65. testConvergence
  66. setup
  67. echo "Waiting..."
  68. sleep 30
  69. done
  70. stop