test.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/bash
  2. iterations=${1:-5}
  3. id1=I6KAH7666SLLL5PFXSOAUFJCDZYAOMLEKCP2GB3BV5RQST3PSROA
  4. id2=JMFJCXBGZDE4BOCJE3VF65GYZNAIVJRET3J6HMRAUQIGJOFKNHMQ
  5. id3=373HSRPQLPNLIJYKZVQFP4PKZ6R2ZE6K3YD442UJHBGBQGWWXAHA
  6. go build genfiles.go
  7. go build md5r.go
  8. go build json.go
  9. start() {
  10. echo "Starting..."
  11. for i in 1 2 3 4 ; do
  12. STPROFILER=":909$i" syncthing -home "h$i" > "$i.out" 2>&1 &
  13. done
  14. }
  15. testConvergence() {
  16. while true ; do
  17. sleep 5
  18. s1comp=$(curl -s "http://localhost:8082/rest/connections" | ./json "$id1/Completion")
  19. s2comp=$(curl -s "http://localhost:8083/rest/connections" | ./json "$id2/Completion")
  20. s3comp=$(curl -s "http://localhost:8081/rest/connections" | ./json "$id3/Completion")
  21. s1comp=${s1comp:-0}
  22. s2comp=${s2comp:-0}
  23. s3comp=${s3comp:-0}
  24. tot=$(($s1comp + $s2comp + $s3comp))
  25. echo $tot / 300
  26. if [[ $tot == 300 ]] ; then
  27. break
  28. fi
  29. done
  30. echo "Verifying..."
  31. cat md5-? | sort | uniq > md5-tot
  32. cat md5-12-? | sort | uniq > md5-12-tot
  33. cat md5-23-? | sort | uniq > md5-23-tot
  34. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  35. pushd "s$i" >/dev/null
  36. ../md5r -l | sort > ../md5-$i
  37. popd >/dev/null
  38. done
  39. ok=0
  40. for i in 1 2 3 ; do
  41. if ! cmp "md5-$i" md5-tot >/dev/null ; then
  42. echo "Fail: instance $i unconverged for default"
  43. else
  44. ok=$(($ok + 1))
  45. echo "OK: instance $i converged for default"
  46. fi
  47. done
  48. for i in 12-1 12-2 ; do
  49. if ! cmp "md5-$i" md5-12-tot >/dev/null ; then
  50. echo "Fail: instance $i unconverged for s12"
  51. else
  52. ok=$(($ok + 1))
  53. echo "OK: instance $i converged for s12"
  54. fi
  55. done
  56. for i in 23-2 23-3 ; do
  57. if ! cmp "md5-$i" md5-23-tot >/dev/null ; then
  58. echo "Fail: instance $i unconverged for s23"
  59. else
  60. ok=$(($ok + 1))
  61. echo "OK: instance $i converged for s23"
  62. fi
  63. done
  64. if [[ $ok != 7 ]] ; then
  65. pkill syncthing
  66. exit 1
  67. fi
  68. }
  69. alterFiles() {
  70. pkill -STOP syncthing
  71. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  72. pushd "s$i" >/dev/null
  73. nfiles=$(find . -type f | wc -l)
  74. if [[ $nfiles > 2000 ]] ; then
  75. todelete=$(( $nfiles - 2000 ))
  76. echo "Deleting $todelete files..."
  77. find . -type f \
  78. | grep -v large \
  79. | sort -k 1.16 \
  80. | head -n "$todelete" \
  81. | xargs rm -f
  82. fi
  83. ../genfiles -maxexp 22 -files 600
  84. echo " $i: append to large file"
  85. dd if=/dev/urandom bs=1024k count=4 >> large-$i 2>/dev/null
  86. ../md5r -l > ../md5-tmp
  87. (grep -v large ../md5-tmp ; grep "large-$i" ../md5-tmp) | grep -v '/.syncthing.' > ../md5-$i
  88. popd >/dev/null
  89. done
  90. pkill -CONT syncthing
  91. }
  92. echo "Setting up files..."
  93. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  94. rm -f h$i/*.idx.gz
  95. rm -rf "s$i"
  96. mkdir "s$i"
  97. pushd "s$i" >/dev/null
  98. echo " $i: random nonoverlapping"
  99. ../genfiles -maxexp 22 -files 600
  100. echo " $i: empty file"
  101. touch "empty-$i"
  102. echo " $i: large file"
  103. dd if=/dev/urandom of=large-$i bs=1024k count=55 2>/dev/null
  104. popd >/dev/null
  105. done
  106. echo "MD5-summing..."
  107. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  108. pushd "s$i" >/dev/null
  109. ../md5r -l > ../md5-$i
  110. popd >/dev/null
  111. done
  112. start
  113. testConvergence
  114. for ((t = 1; t <= $iterations; t++)) ; do
  115. echo "Add and remove random files ($t / $iterations)..."
  116. alterFiles
  117. echo "Waiting..."
  118. sleep 30
  119. testConvergence
  120. done
  121. for i in 1 2 3 4 ; do
  122. curl -X POST "http://localhost:808$i/rest/shutdown"
  123. done