test-reconnect.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. id1=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU
  6. id2=JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU
  7. go build json.go
  8. go build md5r.go
  9. go build genfiles.go
  10. start() {
  11. echo "Starting..."
  12. STTRACE=model,scanner STPROFILER=":9091" syncthing -home "f1" > 1.out 2>&1 &
  13. STTRACE=model,scanner STPROFILER=":9092" syncthing -home "f2" > 2.out 2>&1 &
  14. sleep 1
  15. }
  16. stop() {
  17. echo "Stopping..."
  18. for i in 1 2 ; do
  19. curl -HX-API-Key:abc123 -X POST "http://localhost:808$i/rest/shutdown"
  20. done
  21. sleep 1
  22. }
  23. setup() {
  24. echo "Setting up..."
  25. rm -rf s? s??-?
  26. rm -rf f?/*.idx.gz f?/index
  27. mkdir -p s1
  28. pushd s1 >/dev/null
  29. ../genfiles
  30. ../md5r > ../md5-1
  31. popd >/dev/null
  32. }
  33. testConvergence() {
  34. torestart="$1"
  35. prevcomp=0
  36. while true ; do
  37. sleep 5
  38. comp=$(curl -HX-API-Key:abc123 -s "http://localhost:8081/rest/debug/peerCompletion" | ./json "$id2")
  39. comp=${comp:-0}
  40. echo $comp / 100
  41. if [[ $comp == 100 ]] ; then
  42. echo Done
  43. break
  44. fi
  45. # Restart if the destination has made some progress
  46. if [[ $comp -gt $prevcomp ]] ; then
  47. prevcomp=$comp
  48. curl -HX-API-Key:abc123 -X POST "http://localhost:$torestart/rest/restart"
  49. fi
  50. done
  51. echo "Verifying..."
  52. pushd s2 >/dev/null
  53. ../md5r | grep -v .stversions > ../md5-2
  54. popd >/dev/null
  55. if ! cmp md5-1 md5-2 ; then
  56. echo Repos differ
  57. stop
  58. exit 1
  59. fi
  60. }
  61. echo Testing reconnects during pull where the source node restarts
  62. setup
  63. start
  64. testConvergence 8081
  65. stop
  66. echo Testing reconnects during pull where the destination node restarts
  67. setup
  68. start
  69. testConvergence 8082
  70. stop
  71. exit 0