2016-09-11 12:32:33 -07:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
export TMROOT=$HOME/.tendermint_persist
|
|
|
|
|
2017-02-20 15:51:00 -08:00
|
|
|
rm -rf "$TMROOT"
|
2016-09-11 12:32:33 -07:00
|
|
|
tendermint init
|
|
|
|
|
2017-02-20 15:41:29 -08:00
|
|
|
TM_CMD="tendermint node --log_level=debug" # &> tendermint_${name}.log"
|
|
|
|
DUMMY_CMD="dummy --persist $TMROOT/dummy" # &> dummy_${name}.log"
|
|
|
|
|
|
|
|
|
2016-09-11 12:32:33 -07:00
|
|
|
function start_procs(){
|
|
|
|
name=$1
|
|
|
|
indexToFail=$2
|
|
|
|
echo "Starting persistent dummy and tendermint"
|
2017-02-20 15:41:29 -08:00
|
|
|
if [[ "$CIRCLECI" == true ]]; then
|
|
|
|
$DUMMY_CMD &
|
|
|
|
else
|
|
|
|
$DUMMY_CMD &> "dummy_${name}.log" &
|
|
|
|
fi
|
2016-09-11 12:32:33 -07:00
|
|
|
PID_DUMMY=$!
|
|
|
|
if [[ "$indexToFail" == "" ]]; then
|
|
|
|
# run in background, dont fail
|
2017-02-20 15:41:29 -08:00
|
|
|
if [[ "$CIRCLECI" == true ]]; then
|
|
|
|
$TM_CMD &
|
|
|
|
else
|
|
|
|
$TM_CMD &> "tendermint_${name}.log" &
|
|
|
|
fi
|
2016-09-11 12:32:33 -07:00
|
|
|
PID_TENDERMINT=$!
|
|
|
|
else
|
|
|
|
# run in foreground, fail
|
2017-02-20 15:41:29 -08:00
|
|
|
if [[ "$CIRCLECI" == true ]]; then
|
|
|
|
FAIL_TEST_INDEX=$indexToFail $TM_CMD
|
|
|
|
else
|
|
|
|
FAIL_TEST_INDEX=$indexToFail $TM_CMD &> "tendermint_${name}.log"
|
|
|
|
fi
|
2016-09-11 12:32:33 -07:00
|
|
|
PID_TENDERMINT=$!
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function kill_procs(){
|
2017-02-20 15:51:00 -08:00
|
|
|
kill -9 "$PID_DUMMY" "$PID_TENDERMINT"
|
|
|
|
wait "$PID_DUMMY"
|
|
|
|
wait "$PID_TENDERMINT"
|
2016-09-11 12:32:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
failsStart=0
|
2017-02-20 15:51:00 -08:00
|
|
|
fails=$(grep -r "fail.Fail" --include \*.go . | wc -l)
|
|
|
|
failsEnd=$((fails-1))
|
2016-09-11 12:32:33 -07:00
|
|
|
|
2017-02-20 15:51:00 -08:00
|
|
|
for failIndex in $(seq $failsStart $failsEnd); do
|
2016-09-11 12:32:33 -07:00
|
|
|
echo ""
|
|
|
|
echo "* Test FailIndex $failIndex"
|
|
|
|
# test failure at failIndex
|
|
|
|
|
2017-02-20 22:28:58 -08:00
|
|
|
bash ./test/utils/txs.sh "localhost:46657" &
|
2017-02-20 15:51:00 -08:00
|
|
|
start_procs 1 "$failIndex"
|
2016-09-11 12:32:33 -07:00
|
|
|
|
|
|
|
# tendermint should fail when it hits the fail index
|
2017-02-20 15:51:00 -08:00
|
|
|
kill -9 "$PID_DUMMY"
|
|
|
|
wait "$PID_DUMMY"
|
2017-02-21 11:14:08 -08:00
|
|
|
wait "$PID_TENDERMINT"
|
2016-09-11 12:32:33 -07:00
|
|
|
|
|
|
|
start_procs 2
|
|
|
|
|
|
|
|
# wait for node to handshake and make a new block
|
|
|
|
addr="localhost:46657"
|
2017-02-20 15:51:00 -08:00
|
|
|
curl -s "$addr/status" > /dev/null
|
2016-09-11 12:32:33 -07:00
|
|
|
ERR=$?
|
|
|
|
i=0
|
|
|
|
while [ "$ERR" != 0 ]; do
|
|
|
|
sleep 1
|
2017-02-20 15:51:00 -08:00
|
|
|
curl -s "$addr/status" > /dev/null
|
2016-09-11 12:32:33 -07:00
|
|
|
ERR=$?
|
2017-02-20 15:51:00 -08:00
|
|
|
i=$((i + 1))
|
2016-09-11 12:32:33 -07:00
|
|
|
if [[ $i == 10 ]]; then
|
|
|
|
echo "Timed out waiting for tendermint to start"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# wait for a new block
|
2017-02-20 15:51:00 -08:00
|
|
|
h1=$(curl -s $addr/status | jq .result[1].latest_block_height)
|
2016-09-11 12:32:33 -07:00
|
|
|
h2=$h1
|
|
|
|
while [ "$h2" == "$h1" ]; do
|
|
|
|
sleep 1
|
2017-02-20 15:51:00 -08:00
|
|
|
h2=$(curl -s $addr/status | jq .result[1].latest_block_height)
|
2016-09-11 12:32:33 -07:00
|
|
|
done
|
|
|
|
|
|
|
|
kill_procs
|
|
|
|
|
|
|
|
echo "* Passed Test for FailIndex $failIndex"
|
|
|
|
echo ""
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Passed Test: Persistence"
|