test-folders.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. # Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  5. #
  6. # This program is free software: you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by the Free
  8. # Software Foundation, either version 3 of the License, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but WITHOUT
  12. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. # more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program. If not, see <http://www.gnu.org/licenses/>.
  18. iterations=${1:-5}
  19. id1=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU
  20. id2=JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU
  21. go build json.go
  22. start() {
  23. echo "Starting..."
  24. STTRACE=model,scanner STPROFILER=":9091" syncthing -home "f1" > 1.out 2>&1 &
  25. STTRACE=model,scanner STPROFILER=":9092" syncthing -home "f2" > 2.out 2>&1 &
  26. sleep 1
  27. }
  28. stop() {
  29. echo "Stopping..."
  30. for i in 1 2 ; do
  31. curl -s -o /dev/null -HX-API-Key:abc123 -X POST "http://127.0.0.1:808$i/rest/shutdown"
  32. done
  33. }
  34. setup() {
  35. echo "Setting up dirs..."
  36. mkdir -p s1
  37. pushd s1 >/dev/null
  38. rm -r */*[02468] 2>/dev/null || true
  39. rm -rf *2
  40. for ((i = 0; i < 500; i++)) ; do
  41. mkdir -p "$RANDOM/$RANDOM"
  42. done
  43. for ((i = 0; i < 500; i++)) ; do
  44. d="$RANDOM/$RANDOM"
  45. mkdir -p "$d"
  46. touch "$d/foo"
  47. done
  48. ../md5r -d | grep -v ' . ' > ../dirs-1
  49. popd >/dev/null
  50. }
  51. testConvergence() {
  52. while true ; do
  53. sleep 5
  54. s1comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8082/rest/debug/peerCompletion" | ./json "$id1")
  55. s2comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8081/rest/debug/peerCompletion" | ./json "$id2")
  56. s1comp=${s1comp:-0}
  57. s2comp=${s2comp:-0}
  58. tot=$(($s1comp + $s2comp))
  59. echo $tot / 200
  60. if [[ $tot == 200 ]] ; then
  61. # when fixing up directories, a device will announce completion
  62. # slightly before it's actually complete. this is arguably a bug,
  63. # but we let it slide for the moment as long as it gets there
  64. # eventually.
  65. sleep 5
  66. break
  67. fi
  68. done
  69. echo "Verifying..."
  70. pushd s2 >/dev/null
  71. ../md5r -d | grep -v ' . ' | grep -v .stversions > ../dirs-2
  72. popd >/dev/null
  73. if ! cmp dirs-1 dirs-2 ; then
  74. echo Folders differ
  75. stop
  76. exit 1
  77. fi
  78. }
  79. chmod -R +w s? s??-? || true
  80. rm -rf s? s??-?
  81. rm -rf f?/*.idx.gz f?/index
  82. setup
  83. start
  84. for ((j = 0; j < iterations; j++)) ; do
  85. echo "#$j..."
  86. testConvergence
  87. setup
  88. echo "Waiting..."
  89. sleep 30
  90. done
  91. stop