test-folders.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. go build json.go
  9. start() {
  10. echo "Starting..."
  11. STTRACE=model,scanner STPROFILER=":9091" syncthing -home "f1" > 1.out 2>&1 &
  12. STTRACE=model,scanner STPROFILER=":9092" syncthing -home "f2" > 2.out 2>&1 &
  13. sleep 1
  14. }
  15. stop() {
  16. echo "Stopping..."
  17. for i in 1 2 ; do
  18. curl -HX-API-Key:abc123 -X POST "http://127.0.0.1:808$i/rest/shutdown"
  19. done
  20. }
  21. setup() {
  22. echo "Setting up dirs..."
  23. mkdir -p s1
  24. pushd s1 >/dev/null
  25. rm -r */*[02468] 2>/dev/null
  26. rm -rf *2
  27. for ((i = 0; i < 500; i++)) ; do
  28. mkdir -p "$RANDOM/$RANDOM"
  29. done
  30. for ((i = 0; i < 500; i++)) ; do
  31. d="$RANDOM/$RANDOM"
  32. mkdir -p "$d"
  33. touch "$d/foo"
  34. done
  35. ../md5r -d | grep -v ' . ' > ../dirs-1
  36. popd >/dev/null
  37. }
  38. testConvergence() {
  39. while true ; do
  40. sleep 5
  41. s1comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8082/rest/debug/peerCompletion" | ./json "$id1")
  42. s2comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8081/rest/debug/peerCompletion" | ./json "$id2")
  43. s1comp=${s1comp:-0}
  44. s2comp=${s2comp:-0}
  45. tot=$(($s1comp + $s2comp))
  46. echo $tot / 200
  47. if [[ $tot == 200 ]] ; then
  48. # when fixing up directories, a node will announce completion
  49. # slightly before it's actually complete. this is arguably a bug,
  50. # but we let it slide for the moment as long as it gets there
  51. # eventually.
  52. sleep 5
  53. break
  54. fi
  55. done
  56. echo "Verifying..."
  57. pushd s2 >/dev/null
  58. ../md5r -d | grep -v ' . ' | grep -v .stversions > ../dirs-2
  59. popd >/dev/null
  60. if ! cmp dirs-1 dirs-2 ; then
  61. echo Repos differ
  62. stop
  63. exit 1
  64. fi
  65. }
  66. chmod -R +w s? s??-?
  67. rm -rf s? s??-?
  68. rm -rf f?/*.idx.gz f?/index
  69. setup
  70. start
  71. for ((j = 0; j < iterations; j++)) ; do
  72. echo "#$j..."
  73. testConvergence
  74. setup
  75. echo "Waiting..."
  76. sleep 30
  77. done
  78. stop