test-folders.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. # Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved.
  5. # Use of this source code is governed by an MIT-style license that can be
  6. # found in the LICENSE file.
  7. iterations=${1:-5}
  8. id1=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU
  9. id2=JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU
  10. go build json.go
  11. start() {
  12. echo "Starting..."
  13. STTRACE=model,scanner STPROFILER=":9091" syncthing -home "f1" > 1.out 2>&1 &
  14. STTRACE=model,scanner STPROFILER=":9092" syncthing -home "f2" > 2.out 2>&1 &
  15. sleep 1
  16. }
  17. stop() {
  18. echo "Stopping..."
  19. for i in 1 2 ; do
  20. curl -s -o /dev/null -HX-API-Key:abc123 -X POST "http://127.0.0.1:808$i/rest/shutdown"
  21. done
  22. }
  23. setup() {
  24. echo "Setting up dirs..."
  25. mkdir -p s1
  26. pushd s1 >/dev/null
  27. rm -r */*[02468] 2>/dev/null || true
  28. rm -rf *2
  29. for ((i = 0; i < 500; i++)) ; do
  30. mkdir -p "$RANDOM/$RANDOM"
  31. done
  32. for ((i = 0; i < 500; i++)) ; do
  33. d="$RANDOM/$RANDOM"
  34. mkdir -p "$d"
  35. touch "$d/foo"
  36. done
  37. ../md5r -d | grep -v ' . ' > ../dirs-1
  38. popd >/dev/null
  39. }
  40. testConvergence() {
  41. while true ; do
  42. sleep 5
  43. s1comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8082/rest/debug/peerCompletion" | ./json "$id1")
  44. s2comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8081/rest/debug/peerCompletion" | ./json "$id2")
  45. s1comp=${s1comp:-0}
  46. s2comp=${s2comp:-0}
  47. tot=$(($s1comp + $s2comp))
  48. echo $tot / 200
  49. if [[ $tot == 200 ]] ; then
  50. # when fixing up directories, a node will announce completion
  51. # slightly before it's actually complete. this is arguably a bug,
  52. # but we let it slide for the moment as long as it gets there
  53. # eventually.
  54. sleep 5
  55. break
  56. fi
  57. done
  58. echo "Verifying..."
  59. pushd s2 >/dev/null
  60. ../md5r -d | grep -v ' . ' | grep -v .stversions > ../dirs-2
  61. popd >/dev/null
  62. if ! cmp dirs-1 dirs-2 ; then
  63. echo Repos differ
  64. stop
  65. exit 1
  66. fi
  67. }
  68. chmod -R +w s? s??-? || true
  69. rm -rf s? s??-?
  70. rm -rf f?/*.idx.gz f?/index
  71. setup
  72. start
  73. for ((j = 0; j < iterations; j++)) ; do
  74. echo "#$j..."
  75. testConvergence
  76. setup
  77. echo "Waiting..."
  78. sleep 30
  79. done
  80. stop