test-folders.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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://localhost: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://localhost:8082/rest/debug/peerCompletion" | ./json "$id1")
  42. s2comp=$(curl -HX-API-Key:abc123 -s "http://localhost: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. rm -rf s? s??-?
  67. rm -rf f?/*.idx.gz f?/index
  68. setup
  69. start
  70. for ((j = 0; j < iterations; j++)) ; do
  71. echo "#$j..."
  72. testConvergence
  73. setup
  74. echo "Waiting..."
  75. sleep 30
  76. done
  77. stop