test.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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=I6KAH7666SLLL5PFXSOAUFJCDZYAOMLEKCP2GB3BV5RQST3PSROA
  7. id2=JMFJCXBGZDE4BOCJE3VF65GYZNAIVJRET3J6HMRAUQIGJOFKNHMQ
  8. id3=373HSRPQLPNLIJYKZVQFP4PKZ6R2ZE6K3YD442UJHBGBQGWWXAHA
  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. STPROFILER=":909$i" syncthing -home "h$i" > "$i.out" 2>&1 &
  16. done
  17. }
  18. clean() {
  19. if [[ $(uname -s) == "Linux" ]] ; then
  20. grep -v utf8-nfd
  21. else
  22. cat
  23. fi
  24. }
  25. testConvergence() {
  26. while true ; do
  27. sleep 5
  28. s1comp=$(curl -HX-API-Key:abc123 -s "http://localhost:8082/rest/connections" | ./json "$id1/Completion")
  29. s2comp=$(curl -HX-API-Key:abc123 -s "http://localhost:8083/rest/connections" | ./json "$id2/Completion")
  30. s3comp=$(curl -HX-API-Key:abc123 -s "http://localhost:8081/rest/connections" | ./json "$id3/Completion")
  31. s1comp=${s1comp:-0}
  32. s2comp=${s2comp:-0}
  33. s3comp=${s3comp:-0}
  34. tot=$(($s1comp + $s2comp + $s3comp))
  35. echo $tot / 300
  36. if [[ $tot == 300 ]] ; then
  37. break
  38. fi
  39. done
  40. echo "Verifying..."
  41. cat md5-? | sort | clean | uniq > md5-tot
  42. cat md5-12-? | sort | clean | uniq > md5-12-tot
  43. cat md5-23-? | sort | clean | uniq > md5-23-tot
  44. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  45. pushd "s$i" >/dev/null
  46. ../md5r -l | sort | clean > ../md5-$i
  47. popd >/dev/null
  48. done
  49. ok=0
  50. for i in 1 2 3 ; do
  51. if ! cmp "md5-$i" md5-tot >/dev/null ; then
  52. echo "Fail: instance $i unconverged for default"
  53. else
  54. ok=$(($ok + 1))
  55. echo "OK: instance $i converged for default"
  56. fi
  57. done
  58. for i in 12-1 12-2 ; do
  59. if ! cmp "md5-$i" md5-12-tot >/dev/null ; then
  60. echo "Fail: instance $i unconverged for s12"
  61. else
  62. ok=$(($ok + 1))
  63. echo "OK: instance $i converged for s12"
  64. fi
  65. done
  66. for i in 23-2 23-3 ; do
  67. if ! cmp "md5-$i" md5-23-tot >/dev/null ; then
  68. echo "Fail: instance $i unconverged for s23"
  69. else
  70. ok=$(($ok + 1))
  71. echo "OK: instance $i converged for s23"
  72. fi
  73. done
  74. if [[ $ok != 7 ]] ; then
  75. pkill syncthing
  76. exit 1
  77. fi
  78. }
  79. alterFiles() {
  80. pkill -STOP syncthing
  81. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  82. pushd "s$i" >/dev/null
  83. nfiles=$(find . -type f | wc -l)
  84. if [[ $nfiles > 2000 ]] ; then
  85. todelete=$(( $nfiles - 2000 ))
  86. echo "Deleting $todelete files..."
  87. find . -type f \
  88. | grep -v large \
  89. | sort -k 1.16 \
  90. | head -n "$todelete" \
  91. | xargs rm -f
  92. fi
  93. ../genfiles -maxexp 22 -files 600
  94. echo " $i: append to large file"
  95. dd if=/dev/urandom bs=1024k count=4 >> large-$i 2>/dev/null
  96. ../md5r -l > ../md5-tmp
  97. (grep -v large ../md5-tmp ; grep "large-$i" ../md5-tmp) | grep -v '/.syncthing.' > ../md5-$i
  98. popd >/dev/null
  99. done
  100. pkill -CONT syncthing
  101. }
  102. rm -f h?/*.idx.gz
  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 600
  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=55 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 remove random files ($t / $iterations)..."
  133. alterFiles
  134. echo "Waiting..."
  135. sleep 30
  136. testConvergence
  137. done
  138. for i in 1 2 3 4 ; do
  139. curl -HX-API-Key:abc123 -X POST "http://localhost:808$i/rest/shutdown"
  140. done