test-merge.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 4 ; do
  28. STTRACE=files,model,puller,versioner STPROFILER=":909$i" ../bin/syncthing -home "h$i" > "$i.out" 2>&1 &
  29. done
  30. }
  31. stop() {
  32. for i in 1 2 3 4 ; 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. clean() {
  38. if [[ $(uname -s) == "Linux" ]] ; then
  39. grep -v .stversions | grep -v .stfolder | grep -v utf8-nfd
  40. else
  41. grep -v .stversions | grep -v .stfolder
  42. fi
  43. }
  44. testConvergence() {
  45. while true ; do
  46. sleep 5
  47. s1comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8082/rest/debug/peerCompletion" | ./json "$id1")
  48. s2comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8083/rest/debug/peerCompletion" | ./json "$id2")
  49. s3comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8081/rest/debug/peerCompletion" | ./json "$id3")
  50. s1comp=${s1comp:-0}
  51. s2comp=${s2comp:-0}
  52. s3comp=${s3comp:-0}
  53. tot=$(($s1comp + $s2comp + $s3comp))
  54. echo $tot / 300
  55. if [[ $tot == 300 ]] ; then
  56. break
  57. fi
  58. done
  59. echo "Verifying..."
  60. cat md5-? | sort | clean | uniq > md5-tot
  61. cat md5-12-? | sort | clean | uniq > md5-12-tot
  62. cat md5-23-? | sort | clean | uniq > md5-23-tot
  63. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  64. pushd "s$i" >/dev/null
  65. ../md5r -l | sort | clean > ../md5-$i
  66. popd >/dev/null
  67. done
  68. ok=0
  69. for i in 1 2 3 ; do
  70. if ! cmp "md5-$i" md5-tot >/dev/null ; then
  71. echo "Fail: instance $i unconverged for default"
  72. else
  73. ok=$(($ok + 1))
  74. echo "OK: instance $i converged for default"
  75. fi
  76. done
  77. for i in 12-1 12-2 ; do
  78. if ! cmp "md5-$i" md5-12-tot >/dev/null ; then
  79. echo "Fail: instance $i unconverged for s12"
  80. else
  81. ok=$(($ok + 1))
  82. echo "OK: instance $i converged for s12"
  83. fi
  84. done
  85. for i in 23-2 23-3 ; do
  86. if ! cmp "md5-$i" md5-23-tot >/dev/null ; then
  87. echo "Fail: instance $i unconverged for s23"
  88. else
  89. ok=$(($ok + 1))
  90. echo "OK: instance $i converged for s23"
  91. fi
  92. done
  93. if [[ $ok != 7 ]] ; then
  94. stop 1
  95. fi
  96. }
  97. alterFiles() {
  98. pkill -STOP syncthing
  99. # Create some new files and alter existing ones
  100. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  101. pushd "s$i" >/dev/null
  102. echo " $i: random nonoverlapping"
  103. ../genfiles -maxexp 22 -files 200 -src ../genfiles
  104. echo " $i: append to large file"
  105. dd if=large-$i bs=1024k count=4 >> large-$i 2>/dev/null
  106. ../md5r -l > ../md5-tmp
  107. (grep -v large ../md5-tmp ; grep "large-$i" ../md5-tmp) | grep -v '/.syncthing.' > ../md5-$i
  108. popd >/dev/null
  109. done
  110. pkill -CONT syncthing
  111. }
  112. rm -rf h?/*.idx.gz h?/index
  113. chmod -R +w s? s??-? s4d || true
  114. rm -rf s? s??-? s4d
  115. echo "Setting up files..."
  116. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  117. mkdir "s$i"
  118. pushd "s$i" >/dev/null
  119. echo " $i: random nonoverlapping"
  120. ../genfiles -maxexp 22 -files 200 -src ../genfiles
  121. echo " $i: empty file"
  122. touch "empty-$i"
  123. echo " $i: large file"
  124. dd if=/dev/urandom of=large-$i bs=1024k count=15 2>/dev/null
  125. echo " $i: weird encodings"
  126. echo somedata > "$(echo -e utf8-nfc-\\xc3\\xad)-$i"
  127. echo somedata > "$(echo -e utf8-nfd-i\\xcc\\x81)-$i"
  128. echo somedata > "$(echo -e cp850-\\xa1)-$i"
  129. touch "empty-$i"
  130. popd >/dev/null
  131. done
  132. mkdir s4d
  133. echo somerandomdata > s4d/extrafile
  134. echo "MD5-summing..."
  135. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  136. pushd "s$i" >/dev/null
  137. ../md5r -l > ../md5-$i
  138. popd >/dev/null
  139. done
  140. start
  141. testConvergence
  142. for ((t = 1; t <= $iterations; t++)) ; do
  143. echo "Add and alter random files ($t / $iterations)..."
  144. alterFiles
  145. echo "Waiting..."
  146. sleep 30
  147. testConvergence
  148. done
  149. stop 0