syncthing/test/test-delupd.sh

166 lines
3.8 KiB
Bash
Raw Normal View History

2014-03-14 02:39:37 -07:00
#!/bin/bash
2014-09-16 14:22:03 -07:00
set -euo pipefail
IFS=$'\n\t'
2014-03-14 02:39:37 -07:00
2014-06-01 13:50:14 -07: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.
iterations=${1:-5}
2014-03-23 00:53:24 -07: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 02:39:37 -07:00
go build genfiles.go
go build md5r.go
go build json.go
start() {
2014-03-14 02:39:37 -07:00
echo "Starting..."
2014-07-11 02:31:16 -07:00
for i in 1 2 3 ; do
STTRACE=model,scanner STPROFILER=":909$i" syncthing -home "h$i" > "$i.out" 2>&1 &
2014-03-14 02:39:37 -07:00
done
2014-06-22 08:26:31 -07:00
}
stop() {
2014-07-11 02:31:16 -07:00
for i in 1 2 3 ; do
2014-09-16 14:26:52 -07:00
curl -s -o /dev/null -HX-API-Key:abc123 -X POST "http://127.0.0.1:808$i/rest/shutdown"
2014-06-22 08:26:31 -07:00
done
exit $1
}
2014-03-14 02:39:37 -07:00
testConvergence() {
2014-03-14 02:39:37 -07:00
while true ; do
sleep 5
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 02:39:37 -07: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-07-11 02:31:16 -07:00
cp md5-1 md5-tot
cp md5-12-2 md5-12-tot
cp md5-23-3 md5-23-tot
2014-03-14 02:39:37 -07:00
for i in 1 2 3 12-1 12-2 23-2 23-3; do
2014-03-14 02:39:37 -07:00
pushd "s$i" >/dev/null
2014-07-11 02:31:16 -07:00
../md5r -l | sort | grep -v .stversions > ../md5-$i
2014-03-14 02:39:37 -07:00
popd >/dev/null
2014-03-23 00:53:24 -07:00
done
ok=0
for i in 1 2 3 ; do
2014-03-14 02:39:37 -07:00
if ! cmp "md5-$i" md5-tot >/dev/null ; then
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 02:39:37 -07:00
else
2014-03-23 00:53:24 -07:00
ok=$(($ok + 1))
echo "OK: instance $i converged for s12"
2014-03-14 02:39:37 -07:00
fi
done
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 08:26:31 -07:00
stop 1
2014-03-23 00:53:24 -07:00
fi
2014-03-14 02:39:37 -07:00
}
alterFiles() {
pkill -STOP syncthing
2014-07-11 02:31:16 -07:00
for i in 1 12-2 23-3 ; do
# Delete some files
pushd "s$i" >/dev/null
chmod 755 ro-test
nfiles=$(find . -type f | wc -l)
2014-07-11 02:31:16 -07:00
if [[ $nfiles -ge 300 ]] ; then
todelete=$(( $nfiles - 300 ))
echo " $i: deleting $todelete files..."
2014-09-16 14:26:52 -07:00
set +o pipefail
find . -type f \
| grep -v timechanged \
| sort -k 1.16 \
| head -n "$todelete" \
| xargs rm -f
2014-09-16 14:26:52 -07:00
set -o pipefail
fi
2014-07-11 02:31:16 -07:00
# Create some new files and alter existing ones
echo " $i: random nonoverlapping"
../genfiles -maxexp 22 -files 200
echo " $i: new files in ro directory"
uuidgen > ro-test/$(uuidgen)
chmod 500 ro-test
touch "timechanged-$i"
2014-07-11 02:31:16 -07:00
../md5r -l | sort | grep -v .stversions > ../md5-$i
popd >/dev/null
done
2014-07-11 02:31:16 -07:00
pkill -CONT syncthing
echo "Restarting instance 2"
2014-09-16 14:26:52 -07:00
curl -s -o /dev/null -HX-API-Key:abc123 -X POST "http://127.0.0.1:8082/rest/restart"
}
2014-07-06 05:46:48 -07:00
rm -rf h?/*.idx.gz h?/index
2014-09-16 14:22:03 -07:00
chmod -R u+w s? s??-? || true
2014-07-11 02:31:16 -07:00
rm -rf s? s??-?
mkdir s1 s2 s3 s12-1 s12-2 s23-2 s23-3
2014-06-06 12:40:04 -07:00
2014-03-14 02:39:37 -07:00
echo "Setting up files..."
2014-07-11 02:31:16 -07:00
for i in 1 12-2 23-3; do
2014-03-14 02:39:37 -07:00
pushd "s$i" >/dev/null
echo " $i: random nonoverlapping"
2014-07-11 02:31:16 -07:00
../genfiles -maxexp 22 -files 400
echo " $i: ro directory"
mkdir ro-test
uuidgen > ro-test/$(uuidgen)
chmod 500 ro-test
dd if=/dev/urandom of="timechanged-$i" bs=1024k count=1
2014-03-14 02:39:37 -07:00
popd >/dev/null
done
echo "MD5-summing..."
2014-07-11 02:31:16 -07:00
for i in 1 12-2 23-3 ; do
2014-03-14 02:39:37 -07:00
pushd "s$i" >/dev/null
2014-07-11 02:31:16 -07:00
../md5r -l | sort > ../md5-$i
2014-03-14 02:39:37 -07:00
popd >/dev/null
done
start
2014-03-14 02:39:37 -07:00
testConvergence
for ((t = 1; t <= $iterations; t++)) ; do
echo "Add and remove random files ($t / $iterations)..."
alterFiles
2014-03-14 02:39:37 -07:00
echo "Waiting..."
sleep 30
2014-03-23 00:53:24 -07:00
testConvergence
done
2014-03-14 02:39:37 -07:00
2014-06-22 08:26:31 -07:00
stop 0