2014-05-18 11:20:45 +00:00
|
|
|
#!/bin/bash
|
2014-09-16 21:22:03 +00:00
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
2014-05-18 11:20:45 +00:00
|
|
|
|
2014-11-16 20:13:20 +00:00
|
|
|
# Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 19:43:32 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License as published by the Free
|
|
|
|
# Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
# more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-06-01 20:50:14 +00:00
|
|
|
|
2014-05-18 11:20:45 +00:00
|
|
|
iterations=${1:-5}
|
|
|
|
|
2014-07-11 09:31:16 +00:00
|
|
|
id1=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU
|
|
|
|
id2=JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU
|
2014-05-18 11:20:45 +00:00
|
|
|
|
|
|
|
go build json.go
|
|
|
|
|
|
|
|
start() {
|
|
|
|
echo "Starting..."
|
2014-10-15 13:05:25 +00:00
|
|
|
STTRACE=model,scanner STPROFILER=":9091" ../bin/syncthing -home "f1" > 1.out 2>&1 &
|
|
|
|
STTRACE=model,scanner STPROFILER=":9092" ../bin/syncthing -home "f2" > 2.out 2>&1 &
|
2014-07-11 09:31:16 +00:00
|
|
|
sleep 1
|
2014-05-18 11:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
echo "Stopping..."
|
|
|
|
for i in 1 2 ; do
|
2014-09-16 21:26:52 +00:00
|
|
|
curl -s -o /dev/null -HX-API-Key:abc123 -X POST "http://127.0.0.1:808$i/rest/shutdown"
|
2014-05-18 11:20:45 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
echo "Setting up dirs..."
|
|
|
|
mkdir -p s1
|
|
|
|
pushd s1 >/dev/null
|
2014-09-16 21:22:03 +00:00
|
|
|
rm -r */*[02468] 2>/dev/null || true
|
2014-05-18 11:20:45 +00:00
|
|
|
rm -rf *2
|
2014-07-11 09:31:16 +00:00
|
|
|
for ((i = 0; i < 500; i++)) ; do
|
|
|
|
mkdir -p "$RANDOM/$RANDOM"
|
2014-05-18 11:20:45 +00:00
|
|
|
done
|
2014-07-11 09:31:16 +00:00
|
|
|
for ((i = 0; i < 500; i++)) ; do
|
|
|
|
d="$RANDOM/$RANDOM"
|
|
|
|
mkdir -p "$d"
|
|
|
|
touch "$d/foo"
|
|
|
|
done
|
|
|
|
../md5r -d | grep -v ' . ' > ../dirs-1
|
2014-05-18 11:20:45 +00:00
|
|
|
popd >/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
testConvergence() {
|
|
|
|
while true ; do
|
|
|
|
sleep 5
|
2014-09-02 10:04:54 +00:00
|
|
|
s1comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8082/rest/debug/peerCompletion" | ./json "$id1")
|
|
|
|
s2comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8081/rest/debug/peerCompletion" | ./json "$id2")
|
2014-05-18 11:20:45 +00:00
|
|
|
s1comp=${s1comp:-0}
|
|
|
|
s2comp=${s2comp:-0}
|
|
|
|
tot=$(($s1comp + $s2comp))
|
|
|
|
echo $tot / 200
|
|
|
|
if [[ $tot == 200 ]] ; then
|
2014-09-28 11:00:38 +00:00
|
|
|
# when fixing up directories, a device will announce completion
|
2014-05-19 20:31:28 +00:00
|
|
|
# slightly before it's actually complete. this is arguably a bug,
|
|
|
|
# but we let it slide for the moment as long as it gets there
|
|
|
|
# eventually.
|
|
|
|
sleep 5
|
2014-05-18 11:20:45 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Verifying..."
|
|
|
|
|
|
|
|
pushd s2 >/dev/null
|
2014-07-11 09:31:16 +00:00
|
|
|
../md5r -d | grep -v ' . ' | grep -v .stversions > ../dirs-2
|
2014-05-18 11:20:45 +00:00
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
if ! cmp dirs-1 dirs-2 ; then
|
2014-09-28 11:00:38 +00:00
|
|
|
echo Folders differ
|
2014-05-18 11:20:45 +00:00
|
|
|
stop
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-09-16 21:22:03 +00:00
|
|
|
chmod -R +w s? s??-? || true
|
2014-05-18 11:20:45 +00:00
|
|
|
rm -rf s? s??-?
|
2014-07-11 09:31:16 +00:00
|
|
|
rm -rf f?/*.idx.gz f?/index
|
2014-05-18 11:20:45 +00:00
|
|
|
|
|
|
|
setup
|
|
|
|
start
|
|
|
|
|
2014-07-11 09:31:16 +00:00
|
|
|
for ((j = 0; j < iterations; j++)) ; do
|
2014-05-18 11:20:45 +00:00
|
|
|
echo "#$j..."
|
|
|
|
testConvergence
|
|
|
|
setup
|
|
|
|
echo "Waiting..."
|
|
|
|
sleep 30
|
|
|
|
done
|
|
|
|
|
|
|
|
stop
|