test-merge.sh 3.8 KB

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