test-delupd.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/bin/bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. # Copyright (C) 2014 The Syncthing Authors.
  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. | grep -v .stfolder \
  104. | sort -k 1.16 \
  105. | head -n "$todelete" \
  106. | xargs rm -f
  107. set -o pipefail
  108. fi
  109. # Create some new files and alter existing ones
  110. echo " $i: random nonoverlapping"
  111. ../genfiles -maxexp 22 -files 200 -src ../genfiles
  112. echo " $i: new files in ro directory"
  113. uuidgen > ro-test/$(uuidgen)
  114. chmod 500 ro-test
  115. touch "timechanged-$i"
  116. ../md5r -l | sort | grep -v .stversions | grep -v .stfolder > ../md5-$i
  117. popd >/dev/null
  118. done
  119. pkill -CONT syncthing
  120. echo "Restarting instance 2"
  121. curl -s -o /dev/null -HX-API-Key:abc123 -X POST "http://127.0.0.1:8082/rest/restart"
  122. }
  123. rm -rf h?/*.idx.gz h?/index
  124. chmod -R u+w s? s??-? || true
  125. rm -rf s? s??-?
  126. mkdir s1 s2 s3 s12-1 s12-2 s23-2 s23-3
  127. echo "Setting up files..."
  128. for i in 1 12-2 23-3; do
  129. pushd "s$i" >/dev/null
  130. echo " $i: random nonoverlapping"
  131. ../genfiles -maxexp 22 -files 400 -src ../genfiles
  132. echo " $i: ro directory"
  133. mkdir ro-test
  134. uuidgen > ro-test/$(uuidgen)
  135. chmod 500 ro-test
  136. dd if=/dev/urandom of="timechanged-$i" bs=1024k count=1
  137. popd >/dev/null
  138. done
  139. echo "MD5-summing..."
  140. for i in 1 12-2 23-3 ; do
  141. pushd "s$i" >/dev/null
  142. ../md5r -l | grep -v .stfolder | sort > ../md5-$i
  143. popd >/dev/null
  144. done
  145. start
  146. testConvergence
  147. for ((t = 1; t <= $iterations; t++)) ; do
  148. echo "Add and remove random files ($t / $iterations)..."
  149. alterFiles
  150. echo "Waiting..."
  151. sleep 30
  152. testConvergence
  153. done
  154. stop 0