test-merge.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/bin/bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. # Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved.
  5. # Use of this source code is governed by an MIT-style license that can be
  6. # found in the LICENSE file.
  7. iterations=${1:-5}
  8. id1=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU
  9. id2=JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU
  10. id3=373HSRP-QLPNLIE-JYKZVQF-P4PKZ63-R2ZE6K3-YD442U2-JHBGBQG-WWXAHAU
  11. go build genfiles.go
  12. go build md5r.go
  13. go build json.go
  14. start() {
  15. echo "Starting..."
  16. for i in 1 2 3 4 ; do
  17. STTRACE=files,model,puller,versioner STPROFILER=":909$i" syncthing -home "h$i" > "$i.out" 2>&1 &
  18. done
  19. }
  20. stop() {
  21. for i in 1 2 3 4 ; do
  22. curl -s -o /dev/null -HX-API-Key:abc123 -X POST "http://127.0.0.1:808$i/rest/shutdown"
  23. done
  24. exit $1
  25. }
  26. clean() {
  27. if [[ $(uname -s) == "Linux" ]] ; then
  28. grep -v .stversions | grep -v utf8-nfd
  29. else
  30. grep -v .stversions
  31. fi
  32. }
  33. testConvergence() {
  34. while true ; do
  35. sleep 5
  36. s1comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8082/rest/debug/peerCompletion" | ./json "$id1")
  37. s2comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8083/rest/debug/peerCompletion" | ./json "$id2")
  38. s3comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8081/rest/debug/peerCompletion" | ./json "$id3")
  39. s1comp=${s1comp:-0}
  40. s2comp=${s2comp:-0}
  41. s3comp=${s3comp:-0}
  42. tot=$(($s1comp + $s2comp + $s3comp))
  43. echo $tot / 300
  44. if [[ $tot == 300 ]] ; then
  45. break
  46. fi
  47. done
  48. echo "Verifying..."
  49. cat md5-? | sort | clean | uniq > md5-tot
  50. cat md5-12-? | sort | clean | uniq > md5-12-tot
  51. cat md5-23-? | sort | clean | uniq > md5-23-tot
  52. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  53. pushd "s$i" >/dev/null
  54. ../md5r -l | sort | clean > ../md5-$i
  55. popd >/dev/null
  56. done
  57. ok=0
  58. for i in 1 2 3 ; do
  59. if ! cmp "md5-$i" md5-tot >/dev/null ; then
  60. echo "Fail: instance $i unconverged for default"
  61. else
  62. ok=$(($ok + 1))
  63. echo "OK: instance $i converged for default"
  64. fi
  65. done
  66. for i in 12-1 12-2 ; do
  67. if ! cmp "md5-$i" md5-12-tot >/dev/null ; then
  68. echo "Fail: instance $i unconverged for s12"
  69. else
  70. ok=$(($ok + 1))
  71. echo "OK: instance $i converged for s12"
  72. fi
  73. done
  74. for i in 23-2 23-3 ; do
  75. if ! cmp "md5-$i" md5-23-tot >/dev/null ; then
  76. echo "Fail: instance $i unconverged for s23"
  77. else
  78. ok=$(($ok + 1))
  79. echo "OK: instance $i converged for s23"
  80. fi
  81. done
  82. if [[ $ok != 7 ]] ; then
  83. stop 1
  84. fi
  85. }
  86. alterFiles() {
  87. pkill -STOP syncthing
  88. # Create some new files and alter existing ones
  89. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  90. pushd "s$i" >/dev/null
  91. echo " $i: random nonoverlapping"
  92. ../genfiles -maxexp 22 -files 200
  93. echo " $i: append to large file"
  94. dd if=large-$i bs=1024k count=4 >> large-$i 2>/dev/null
  95. ../md5r -l > ../md5-tmp
  96. (grep -v large ../md5-tmp ; grep "large-$i" ../md5-tmp) | grep -v '/.syncthing.' > ../md5-$i
  97. popd >/dev/null
  98. done
  99. pkill -CONT syncthing
  100. }
  101. rm -rf h?/*.idx.gz h?/index
  102. chmod -R +w s? s??-? s4d || true
  103. rm -rf s? s??-? s4d
  104. echo "Setting up files..."
  105. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  106. mkdir "s$i"
  107. pushd "s$i" >/dev/null
  108. echo " $i: random nonoverlapping"
  109. ../genfiles -maxexp 22 -files 200
  110. echo " $i: empty file"
  111. touch "empty-$i"
  112. echo " $i: large file"
  113. dd if=/dev/urandom of=large-$i bs=1024k count=15 2>/dev/null
  114. echo " $i: weird encodings"
  115. echo somedata > "$(echo -e utf8-nfc-\\xc3\\xad)-$i"
  116. echo somedata > "$(echo -e utf8-nfd-i\\xcc\\x81)-$i"
  117. echo somedata > "$(echo -e cp850-\\xa1)-$i"
  118. touch "empty-$i"
  119. popd >/dev/null
  120. done
  121. mkdir s4d
  122. echo somerandomdata > s4d/extrafile
  123. echo "MD5-summing..."
  124. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  125. pushd "s$i" >/dev/null
  126. ../md5r -l > ../md5-$i
  127. popd >/dev/null
  128. done
  129. start
  130. testConvergence
  131. for ((t = 1; t <= $iterations; t++)) ; do
  132. echo "Add and alter random files ($t / $iterations)..."
  133. alterFiles
  134. echo "Waiting..."
  135. sleep 30
  136. testConvergence
  137. done
  138. stop 0