test.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/bash
  2. export STNORESTART=1
  3. iterations=${1:-5}
  4. id1=I6KAH7666SLLL5PFXSOAUFJCDZYAOMLEKCP2GB3BV5RQST3PSROA
  5. id2=JMFJCXBGZDE4BOCJE3VF65GYZNAIVJRET3J6HMRAUQIGJOFKNHMQ
  6. id3=373HSRPQLPNLIJYKZVQFP4PKZ6R2ZE6K3YD442UJHBGBQGWWXAHA
  7. go build genfiles.go
  8. go build md5r.go
  9. go build json.go
  10. start() {
  11. echo "Starting..."
  12. for i in 1 2 3 4 ; do
  13. STPROFILER=":909$i" syncthing -home "h$i" &
  14. done
  15. }
  16. testConvergence() {
  17. while true ; do
  18. sleep 5
  19. s1comp=$(curl -s "http://localhost:8082/rest/connections" | ./json "$id1/Completion")
  20. s2comp=$(curl -s "http://localhost:8083/rest/connections" | ./json "$id2/Completion")
  21. s3comp=$(curl -s "http://localhost:8081/rest/connections" | ./json "$id3/Completion")
  22. s1comp=${s1comp:-0}
  23. s2comp=${s2comp:-0}
  24. s3comp=${s3comp:-0}
  25. tot=$(($s1comp + $s2comp + $s3comp))
  26. echo $tot / 300
  27. if [[ $tot == 300 ]] ; then
  28. break
  29. fi
  30. done
  31. echo "Verifying..."
  32. cat md5-? | sort | uniq > md5-tot
  33. cat md5-12-? | sort | uniq > md5-12-tot
  34. cat md5-23-? | sort | uniq > md5-23-tot
  35. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  36. pushd "s$i" >/dev/null
  37. ../md5r -l | sort > ../md5-$i
  38. popd >/dev/null
  39. done
  40. ok=0
  41. for i in 1 2 3 ; do
  42. if ! cmp "md5-$i" md5-tot >/dev/null ; then
  43. echo "Fail: instance $i unconverged for default"
  44. else
  45. ok=$(($ok + 1))
  46. echo "OK: instance $i converged for default"
  47. fi
  48. done
  49. for i in 12-1 12-2 ; do
  50. if ! cmp "md5-$i" md5-12-tot >/dev/null ; then
  51. echo "Fail: instance $i unconverged for s12"
  52. else
  53. ok=$(($ok + 1))
  54. echo "OK: instance $i converged for s12"
  55. fi
  56. done
  57. for i in 23-2 23-3 ; do
  58. if ! cmp "md5-$i" md5-23-tot >/dev/null ; then
  59. echo "Fail: instance $i unconverged for s23"
  60. else
  61. ok=$(($ok + 1))
  62. echo "OK: instance $i converged for s23"
  63. fi
  64. done
  65. if [[ $ok != 7 ]] ; then
  66. pkill syncthing
  67. exit 1
  68. fi
  69. }
  70. alterFiles() {
  71. pkill -STOP syncthing
  72. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  73. pushd "s$i" >/dev/null
  74. nfiles=$(find . -type f | wc -l)
  75. if [[ $nfiles > 2000 ]] ; then
  76. todelete=$(( $nfiles - 2000 ))
  77. echo "Deleting $todelete files..."
  78. find . -type f \
  79. | grep -v large \
  80. | sort -k 1.16 \
  81. | head -n "$todelete" \
  82. | xargs rm -f
  83. fi
  84. ../genfiles -maxexp 22 -files 600
  85. echo " $i: append to large file"
  86. dd if=/dev/urandom bs=1024k count=4 >> large-$i 2>/dev/null
  87. ../md5r -l > ../md5-tmp
  88. (grep -v large ../md5-tmp ; grep "large-$i" ../md5-tmp) | grep -v '/.syncthing.' > ../md5-$i
  89. popd >/dev/null
  90. done
  91. pkill -CONT syncthing
  92. }
  93. echo "Setting up files..."
  94. for i in 1 2 3 12-1 12-2 23-2 23-3; do
  95. rm -f h$i/*.idx.gz
  96. rm -rf "s$i"
  97. mkdir "s$i"
  98. pushd "s$i" >/dev/null
  99. echo " $i: random nonoverlapping"
  100. ../genfiles -maxexp 22 -files 600
  101. echo " $i: empty file"
  102. touch "empty-$i"
  103. echo " $i: large file"
  104. dd if=/dev/urandom of=large-$i bs=1024k count=55 2>/dev/null
  105. popd >/dev/null
  106. done
  107. echo "MD5-summing..."
  108. for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
  109. pushd "s$i" >/dev/null
  110. ../md5r -l > ../md5-$i
  111. popd >/dev/null
  112. done
  113. start
  114. testConvergence
  115. for ((t = 1; t <= $iterations; t++)) ; do
  116. echo "Add and remove random files ($t / $iterations)..."
  117. alterFiles
  118. echo "Waiting..."
  119. sleep 30
  120. testConvergence
  121. done
  122. pkill syncthing