2014-03-14 09:39:37 +00:00
|
|
|
#!/bin/bash
|
2014-09-16 21:22:03 +00:00
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
2014-03-14 09:39:37 +00:00
|
|
|
|
2014-06-01 20:50:14 +00: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-04-14 11:45:47 +00:00
|
|
|
iterations=${1:-5}
|
2014-03-23 07:53:24 +00:00
|
|
|
|
2014-06-29 23:42:03 +00:00
|
|
|
id1=I6KAH76-66SLLLB-5PFXSOA-UFJCDZC-YAOMLEK-CP2GB32-BV5RQST-3PSROAU
|
|
|
|
id2=JMFJCXB-GZDE4BN-OCJE3VF-65GYZNU-AIVJRET-3J6HMRQ-AUQIGJO-FKNHMQU
|
|
|
|
id3=373HSRP-QLPNLIE-JYKZVQF-P4PKZ63-R2ZE6K3-YD442U2-JHBGBQG-WWXAHAU
|
2014-03-14 09:39:37 +00:00
|
|
|
|
|
|
|
go build genfiles.go
|
|
|
|
go build md5r.go
|
|
|
|
go build json.go
|
|
|
|
|
2014-04-14 11:45:47 +00:00
|
|
|
start() {
|
2014-03-14 09:39:37 +00:00
|
|
|
echo "Starting..."
|
2014-05-11 17:30:29 +00:00
|
|
|
for i in 1 2 3 4 ; do
|
2014-07-11 09:31:16 +00:00
|
|
|
STTRACE=files,model,puller,versioner STPROFILER=":909$i" syncthing -home "h$i" > "$i.out" 2>&1 &
|
2014-03-14 09:39:37 +00:00
|
|
|
done
|
2014-06-22 15:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
for i in 1 2 3 4 ; 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-06-22 15:26:31 +00:00
|
|
|
done
|
|
|
|
exit $1
|
2014-04-14 11:45:47 +00:00
|
|
|
}
|
2014-03-14 09:39:37 +00:00
|
|
|
|
2014-06-11 15:51:31 +00:00
|
|
|
clean() {
|
|
|
|
if [[ $(uname -s) == "Linux" ]] ; then
|
2014-07-11 09:31:16 +00:00
|
|
|
grep -v .stversions | grep -v utf8-nfd
|
2014-06-11 15:51:31 +00:00
|
|
|
else
|
2014-07-11 09:31:16 +00:00
|
|
|
grep -v .stversions
|
2014-06-11 15:51:31 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-14 11:45:47 +00:00
|
|
|
testConvergence() {
|
2014-03-14 09:39:37 +00:00
|
|
|
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:8083/rest/debug/peerCompletion" | ./json "$id2")
|
|
|
|
s3comp=$(curl -HX-API-Key:abc123 -s "http://127.0.0.1:8081/rest/debug/peerCompletion" | ./json "$id3")
|
2014-03-14 09:39:37 +00:00
|
|
|
s1comp=${s1comp:-0}
|
|
|
|
s2comp=${s2comp:-0}
|
|
|
|
s3comp=${s3comp:-0}
|
|
|
|
tot=$(($s1comp + $s2comp + $s3comp))
|
|
|
|
echo $tot / 300
|
|
|
|
if [[ $tot == 300 ]] ; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Verifying..."
|
2014-06-11 15:51:31 +00:00
|
|
|
cat md5-? | sort | clean | uniq > md5-tot
|
|
|
|
cat md5-12-? | sort | clean | uniq > md5-12-tot
|
|
|
|
cat md5-23-? | sort | clean | uniq > md5-23-tot
|
2014-03-14 09:39:37 +00:00
|
|
|
|
2014-03-29 17:53:48 +00:00
|
|
|
for i in 1 2 3 12-1 12-2 23-2 23-3; do
|
2014-03-14 09:39:37 +00:00
|
|
|
pushd "s$i" >/dev/null
|
2014-06-11 15:51:31 +00:00
|
|
|
../md5r -l | sort | clean > ../md5-$i
|
2014-03-14 09:39:37 +00:00
|
|
|
popd >/dev/null
|
2014-03-23 07:53:24 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
ok=0
|
|
|
|
for i in 1 2 3 ; do
|
2014-03-14 09:39:37 +00:00
|
|
|
if ! cmp "md5-$i" md5-tot >/dev/null ; then
|
2014-03-29 17:53:48 +00:00
|
|
|
echo "Fail: instance $i unconverged for default"
|
|
|
|
else
|
|
|
|
ok=$(($ok + 1))
|
|
|
|
echo "OK: instance $i converged for default"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
for i in 12-1 12-2 ; do
|
|
|
|
if ! cmp "md5-$i" md5-12-tot >/dev/null ; then
|
|
|
|
echo "Fail: instance $i unconverged for s12"
|
2014-03-14 09:39:37 +00:00
|
|
|
else
|
2014-03-23 07:53:24 +00:00
|
|
|
ok=$(($ok + 1))
|
2014-03-29 17:53:48 +00:00
|
|
|
echo "OK: instance $i converged for s12"
|
2014-03-14 09:39:37 +00:00
|
|
|
fi
|
|
|
|
done
|
2014-03-29 17:53:48 +00:00
|
|
|
for i in 23-2 23-3 ; do
|
|
|
|
if ! cmp "md5-$i" md5-23-tot >/dev/null ; then
|
|
|
|
echo "Fail: instance $i unconverged for s23"
|
|
|
|
else
|
|
|
|
ok=$(($ok + 1))
|
|
|
|
echo "OK: instance $i converged for s23"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ $ok != 7 ]] ; then
|
2014-06-22 15:26:31 +00:00
|
|
|
stop 1
|
2014-03-23 07:53:24 +00:00
|
|
|
fi
|
2014-03-14 09:39:37 +00:00
|
|
|
}
|
|
|
|
|
2014-04-14 11:45:47 +00:00
|
|
|
alterFiles() {
|
|
|
|
pkill -STOP syncthing
|
2014-07-11 09:31:16 +00:00
|
|
|
|
|
|
|
# Create some new files and alter existing ones
|
2014-04-14 11:45:47 +00:00
|
|
|
for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
|
|
|
|
pushd "s$i" >/dev/null
|
|
|
|
|
2014-07-11 09:31:16 +00:00
|
|
|
echo " $i: random nonoverlapping"
|
|
|
|
../genfiles -maxexp 22 -files 200
|
2014-04-14 11:45:47 +00:00
|
|
|
echo " $i: append to large file"
|
2014-07-11 09:31:16 +00:00
|
|
|
dd if=large-$i bs=1024k count=4 >> large-$i 2>/dev/null
|
2014-04-14 11:45:47 +00:00
|
|
|
../md5r -l > ../md5-tmp
|
|
|
|
(grep -v large ../md5-tmp ; grep "large-$i" ../md5-tmp) | grep -v '/.syncthing.' > ../md5-$i
|
|
|
|
popd >/dev/null
|
|
|
|
done
|
2014-07-11 09:31:16 +00:00
|
|
|
|
2014-04-14 11:45:47 +00:00
|
|
|
pkill -CONT syncthing
|
|
|
|
}
|
|
|
|
|
2014-07-06 12:46:48 +00:00
|
|
|
rm -rf h?/*.idx.gz h?/index
|
2014-09-16 21:22:03 +00:00
|
|
|
chmod -R +w s? s??-? s4d || true
|
2014-06-06 19:40:04 +00:00
|
|
|
rm -rf s? s??-? s4d
|
|
|
|
|
2014-03-14 09:39:37 +00:00
|
|
|
echo "Setting up files..."
|
2014-03-29 17:53:48 +00:00
|
|
|
for i in 1 2 3 12-1 12-2 23-2 23-3; do
|
2014-03-14 09:39:37 +00:00
|
|
|
mkdir "s$i"
|
|
|
|
pushd "s$i" >/dev/null
|
|
|
|
echo " $i: random nonoverlapping"
|
2014-07-11 09:31:16 +00:00
|
|
|
../genfiles -maxexp 22 -files 200
|
2014-03-14 09:39:37 +00:00
|
|
|
echo " $i: empty file"
|
|
|
|
touch "empty-$i"
|
2014-03-23 07:43:18 +00:00
|
|
|
echo " $i: large file"
|
2014-07-11 09:31:16 +00:00
|
|
|
dd if=/dev/urandom of=large-$i bs=1024k count=15 2>/dev/null
|
2014-06-05 09:48:22 +00:00
|
|
|
echo " $i: weird encodings"
|
|
|
|
echo somedata > "$(echo -e utf8-nfc-\\xc3\\xad)-$i"
|
|
|
|
echo somedata > "$(echo -e utf8-nfd-i\\xcc\\x81)-$i"
|
|
|
|
echo somedata > "$(echo -e cp850-\\xa1)-$i"
|
|
|
|
touch "empty-$i"
|
2014-03-14 09:39:37 +00:00
|
|
|
popd >/dev/null
|
|
|
|
done
|
|
|
|
|
2014-06-06 19:40:04 +00:00
|
|
|
mkdir s4d
|
|
|
|
echo somerandomdata > s4d/extrafile
|
|
|
|
|
2014-03-14 09:39:37 +00:00
|
|
|
echo "MD5-summing..."
|
2014-03-29 17:53:48 +00:00
|
|
|
for i in 1 2 3 12-1 12-2 23-2 23-3 ; do
|
2014-03-14 09:39:37 +00:00
|
|
|
pushd "s$i" >/dev/null
|
|
|
|
../md5r -l > ../md5-$i
|
|
|
|
popd >/dev/null
|
|
|
|
done
|
|
|
|
|
2014-04-14 11:45:47 +00:00
|
|
|
start
|
2014-03-14 09:39:37 +00:00
|
|
|
testConvergence
|
|
|
|
|
2014-04-14 11:45:47 +00:00
|
|
|
for ((t = 1; t <= $iterations; t++)) ; do
|
2014-07-11 09:31:16 +00:00
|
|
|
echo "Add and alter random files ($t / $iterations)..."
|
2014-04-14 11:45:47 +00:00
|
|
|
alterFiles
|
2014-03-14 09:39:37 +00:00
|
|
|
|
2014-04-14 11:45:47 +00:00
|
|
|
echo "Waiting..."
|
|
|
|
sleep 30
|
2014-03-23 07:53:24 +00:00
|
|
|
testConvergence
|
|
|
|
done
|
2014-03-14 09:39:37 +00:00
|
|
|
|
2014-06-22 15:26:31 +00:00
|
|
|
stop 0
|