test.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. go build http.go
  13. start() {
  14. echo "Starting..."
  15. for i in 1 2 3 4 ; do
  16. STTRACE=files,model,puller STPROFILER=":909$i" syncthing -home "h$i" > "$i.out" 2>&1 &
  17. done
  18. # Test REST API
  19. sleep 2
  20. curl -s -o /dev/null http://testuser:testpass@localhost:8081/index.html
  21. curl -s -o /dev/null http://localhost:8082/index.html
  22. sleep 1
  23. ./http -target localhost:8081 -user testuser -pass testpass -csrf h1/csrftokens.txt || stop 1
  24. ./http -target localhost:8081 -api abc123 || stop 1
  25. ./http -target localhost:8082 -csrf h2/csrftokens.txt || stop 1
  26. ./http -target localhost:8082 -api abc123 || stop 1
  27. }
  28. stop() {
  29. for i in 1 2 3 4 ; do
  30. curl -HX-API-Key:abc123 -X POST "http://localhost:808$i/rest/shutdown"
  31. done
  32. exit $1
  33. }
  34. clean() {
  35. if [[ $(uname -s) == "Linux" ]] ; then
  36. grep -v utf8-nfd
  37. else
  38. cat
  39. fi
  40. }
  41. testConvergence() {
  42. while true ; do
  43. sleep 5
  44. s1comp=$(curl -HX-API-Key:abc123 -s "http://localhost:8082/rest/connections" | ./json "$id1/Completion")
  45. s2comp=$(curl -HX-API-Key:abc123 -s "http://localhost:8083/rest/connections" | ./json "$id2/Completion")
  46. s3comp=$(curl -HX-API-Key:abc123 -s "http://localhost:8081/rest/connections" | ./json "$id3/Completion")
  47. s1comp=${s1comp:-0}
  48. s2comp=${s2comp:-0}
  49. s3comp=${s3comp:-0}
  50. tot=$(($s1comp + $s2comp + $s3comp))
  51. echo $tot / 300
  52. if [[ $tot == 300 ]] ; then
  53. break
  54. fi
  55. done
  56. echo "Verifying..."
  57. cat md5-? | sort | clean | uniq > md5-tot
  58. cat md5-12-? | sort | clean | uniq > md5-12-tot
  59. cat md5-23-? | sort | clean | uniq > md5-23-tot
  60. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  61. pushd "s$i" >/dev/null
  62. ../md5r -l | sort | clean > ../md5-$i
  63. popd >/dev/null
  64. done
  65. ok=0
  66. for i in 1 2 3 ; do
  67. if ! cmp "md5-$i" md5-tot >/dev/null ; then
  68. echo "Fail: instance $i unconverged for default"
  69. else
  70. ok=$(($ok + 1))
  71. echo "OK: instance $i converged for default"
  72. fi
  73. done
  74. for i in 12-1 12-2 ; do
  75. if ! cmp "md5-$i" md5-12-tot >/dev/null ; then
  76. echo "Fail: instance $i unconverged for s12"
  77. else
  78. ok=$(($ok + 1))
  79. echo "OK: instance $i converged for s12"
  80. fi
  81. done
  82. for i in 23-2 23-3 ; do
  83. if ! cmp "md5-$i" md5-23-tot >/dev/null ; then
  84. echo "Fail: instance $i unconverged for s23"
  85. else
  86. ok=$(($ok + 1))
  87. echo "OK: instance $i converged for s23"
  88. fi
  89. done
  90. if [[ $ok != 7 ]] ; then
  91. stop 1
  92. fi
  93. }
  94. alterFiles() {
  95. pkill -STOP syncthing
  96. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  97. pushd "s$i" >/dev/null
  98. nfiles=$(find . -type f | wc -l)
  99. if [[ $nfiles > 2000 ]] ; then
  100. todelete=$(( $nfiles - 2000 ))
  101. echo "Deleting $todelete files..."
  102. find . -type f \
  103. | grep -v large \
  104. | sort -k 1.16 \
  105. | head -n "$todelete" \
  106. | xargs rm -f
  107. fi
  108. ../genfiles -maxexp 22 -files 600
  109. echo " $i: append to large file"
  110. dd if=/dev/urandom bs=1024k count=4 >> large-$i 2>/dev/null
  111. ../md5r -l > ../md5-tmp
  112. (grep -v large ../md5-tmp ; grep "large-$i" ../md5-tmp) | grep -v '/.syncthing.' > ../md5-$i
  113. popd >/dev/null
  114. done
  115. pkill -CONT syncthing
  116. }
  117. rm -rf h?/*.idx.gz h?/index
  118. rm -rf s? s??-? s4d
  119. echo "Setting up files..."
  120. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  121. mkdir "s$i"
  122. pushd "s$i" >/dev/null
  123. echo " $i: random nonoverlapping"
  124. ../genfiles -maxexp 22 -files 600
  125. echo " $i: empty file"
  126. touch "empty-$i"
  127. echo " $i: large file"
  128. dd if=/dev/urandom of=large-$i bs=1024k count=55 2>/dev/null
  129. echo " $i: weird encodings"
  130. echo somedata > "$(echo -e utf8-nfc-\\xc3\\xad)-$i"
  131. echo somedata > "$(echo -e utf8-nfd-i\\xcc\\x81)-$i"
  132. echo somedata > "$(echo -e cp850-\\xa1)-$i"
  133. touch "empty-$i"
  134. popd >/dev/null
  135. done
  136. mkdir s4d
  137. echo somerandomdata > s4d/extrafile
  138. echo "MD5-summing..."
  139. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  140. pushd "s$i" >/dev/null
  141. ../md5r -l > ../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