test-delupd.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. # Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  5. #
  6. # This program is free software: you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by the Free
  8. # Software Foundation, either version 3 of the License, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but WITHOUT
  12. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. # more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program. If not, see <http://www.gnu.org/licenses/>.
  18. iterations=${1:-5}
  19. id1=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU
  20. id2=JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU
  21. id3=373HSRP-QLPNLIE-JYKZVQF-P4PKZ63-R2ZE6K3-YD442U2-JHBGBQG-WWXAHAU
  22. go build genfiles.go
  23. go build md5r.go
  24. go build json.go
  25. start() {
  26. echo "Starting..."
  27. for i in 1 2 3 ; do
  28. STTRACE=model,scanner STPROFILER=":909$i" ../bin/syncthing -home "h$i" > "$i.out" 2>&1 &
  29. done
  30. }
  31. stop() {
  32. for i in 1 2 3 ; do
  33. curl -s -o /dev/null -HX-API-Key:abc123 -X POST "http://127.0.0.1:808$i/rest/shutdown"
  34. done
  35. exit $1
  36. }
  37. testConvergence() {
  38. while true ; do
  39. sleep 5
  40. s1comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8082/rest/debug/peerCompletion" | ./json "$id1")
  41. s2comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8083/rest/debug/peerCompletion" | ./json "$id2")
  42. s3comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8081/rest/debug/peerCompletion" | ./json "$id3")
  43. s1comp=${s1comp:-0}
  44. s2comp=${s2comp:-0}
  45. s3comp=${s3comp:-0}
  46. tot=$(($s1comp + $s2comp + $s3comp))
  47. echo $tot / 300
  48. if [[ $tot == 300 ]] ; then
  49. break
  50. fi
  51. done
  52. echo "Verifying..."
  53. cp md5-1 md5-tot
  54. cp md5-12-2 md5-12-tot
  55. cp md5-23-3 md5-23-tot
  56. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  57. pushd "s$i" >/dev/null
  58. ../md5r -l | sort | grep -v .stversions | grep -v .stfolder > ../md5-$i
  59. popd >/dev/null
  60. done
  61. ok=0
  62. for i in 1 2 3 ; do
  63. if ! cmp "md5-$i" md5-tot >/dev/null ; then
  64. echo "Fail: instance $i unconverged for default"
  65. else
  66. ok=$(($ok + 1))
  67. echo "OK: instance $i converged for default"
  68. fi
  69. done
  70. for i in 12-1 12-2 ; do
  71. if ! cmp "md5-$i" md5-12-tot >/dev/null ; then
  72. echo "Fail: instance $i unconverged for s12"
  73. else
  74. ok=$(($ok + 1))
  75. echo "OK: instance $i converged for s12"
  76. fi
  77. done
  78. for i in 23-2 23-3 ; do
  79. if ! cmp "md5-$i" md5-23-tot >/dev/null ; then
  80. echo "Fail: instance $i unconverged for s23"
  81. else
  82. ok=$(($ok + 1))
  83. echo "OK: instance $i converged for s23"
  84. fi
  85. done
  86. if [[ $ok != 7 ]] ; then
  87. stop 1
  88. fi
  89. }
  90. alterFiles() {
  91. pkill -STOP syncthing
  92. for i in 1 12-2 23-3 ; do
  93. # Delete some files
  94. pushd "s$i" >/dev/null
  95. chmod 755 ro-test
  96. nfiles=$(find . -type f | wc -l)
  97. if [[ $nfiles -ge 300 ]] ; then
  98. todelete=$(( $nfiles - 300 ))
  99. echo " $i: deleting $todelete files..."
  100. set +o pipefail
  101. find . -type f \
  102. | grep -v timechanged \
  103. | sort -k 1.16 \
  104. | head -n "$todelete" \
  105. | xargs rm -f
  106. set -o pipefail
  107. fi
  108. # Create some new files and alter existing ones
  109. echo " $i: random nonoverlapping"
  110. ../genfiles -maxexp 22 -files 200
  111. echo " $i: new files in ro directory"
  112. uuidgen > ro-test/$(uuidgen)
  113. chmod 500 ro-test
  114. touch "timechanged-$i"
  115. ../md5r -l | sort | grep -v .stversions | grep -v .stfolder > ../md5-$i
  116. popd >/dev/null
  117. done
  118. pkill -CONT syncthing
  119. echo "Restarting instance 2"
  120. curl -s -o /dev/null -HX-API-Key:abc123 -X POST "http://127.0.0.1:8082/rest/restart"
  121. }
  122. rm -rf h?/*.idx.gz h?/index
  123. chmod -R u+w s? s??-? || true
  124. rm -rf s? s??-?
  125. mkdir s1 s2 s3 s12-1 s12-2 s23-2 s23-3
  126. echo "Setting up files..."
  127. for i in 1 12-2 23-3; do
  128. pushd "s$i" >/dev/null
  129. echo " $i: random nonoverlapping"
  130. ../genfiles -maxexp 22 -files 400
  131. echo " $i: ro directory"
  132. mkdir ro-test
  133. uuidgen > ro-test/$(uuidgen)
  134. chmod 500 ro-test
  135. dd if=/dev/urandom of="timechanged-$i" bs=1024k count=1
  136. popd >/dev/null
  137. done
  138. echo "MD5-summing..."
  139. for i in 1 12-2 23-3 ; do
  140. pushd "s$i" >/dev/null
  141. ../md5r -l | sort > ../md5-$i
  142. popd >/dev/null
  143. done
  144. start
  145. testConvergence
  146. for ((t = 1; t <= $iterations; t++)) ; do
  147. echo "Add and remove random files ($t / $iterations)..."
  148. alterFiles
  149. echo "Waiting..."
  150. sleep 30
  151. testConvergence
  152. done
  153. stop 0