syncthing/integration/test-folders.sh

93 lines
2.0 KiB
Bash
Raw Normal View History

2014-05-18 13:20:45 +02:00
#!/bin/bash
2014-06-01 22:50:14 +02:00
# Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved.
# Use of this source code is governed by an MIT-style license that can be
# found in the LICENSE file.
2014-05-18 13:20:45 +02:00
iterations=${1:-5}
2014-07-11 11:31:16 +02:00
id1=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU
id2=JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU
2014-05-18 13:20:45 +02:00
go build json.go
start() {
echo "Starting..."
STTRACE=model,scanner STPROFILER=":9091" syncthing -home "f1" > 1.out 2>&1 &
STTRACE=model,scanner STPROFILER=":9092" syncthing -home "f2" > 2.out 2>&1 &
2014-07-11 11:31:16 +02:00
sleep 1
2014-05-18 13:20:45 +02:00
}
stop() {
echo "Stopping..."
for i in 1 2 ; do
2014-06-05 11:48:22 +02:00
curl -HX-API-Key:abc123 -X POST "http://localhost:808$i/rest/shutdown"
2014-05-18 13:20:45 +02:00
done
}
setup() {
echo "Setting up dirs..."
mkdir -p s1
pushd s1 >/dev/null
2014-07-11 11:31:16 +02:00
rm -r */*[02468] 2>/dev/null
2014-05-18 13:20:45 +02:00
rm -rf *2
2014-07-11 11:31:16 +02:00
for ((i = 0; i < 500; i++)) ; do
mkdir -p "$RANDOM/$RANDOM"
2014-05-18 13:20:45 +02:00
done
2014-07-11 11:31:16 +02: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 13:20:45 +02:00
popd >/dev/null
}
testConvergence() {
while true ; do
sleep 5
2014-06-05 11:48:22 +02:00
s1comp=$(curl -HX-API-Key:abc123 -s "http://localhost:8082/rest/connections" | ./json "$id1/Completion")
s2comp=$(curl -HX-API-Key:abc123 -s "http://localhost:8081/rest/connections" | ./json "$id2/Completion")
2014-05-18 13:20:45 +02:00
s1comp=${s1comp:-0}
s2comp=${s2comp:-0}
tot=$(($s1comp + $s2comp))
echo $tot / 200
if [[ $tot == 200 ]] ; then
# when fixing up directories, a node will announce completion
# 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 13:20:45 +02:00
break
fi
done
echo "Verifying..."
pushd s2 >/dev/null
2014-07-11 11:31:16 +02:00
../md5r -d | grep -v ' . ' | grep -v .stversions > ../dirs-2
2014-05-18 13:20:45 +02:00
popd >/dev/null
if ! cmp dirs-1 dirs-2 ; then
echo Repos differ
stop
exit 1
fi
}
rm -rf s? s??-?
2014-07-11 11:31:16 +02:00
rm -rf f?/*.idx.gz f?/index
2014-05-18 13:20:45 +02:00
setup
start
2014-07-11 11:31:16 +02:00
for ((j = 0; j < iterations; j++)) ; do
2014-05-18 13:20:45 +02:00
echo "#$j..."
testConvergence
setup
echo "Waiting..."
sleep 30
done
stop