tendermint/test/p2p/basic/test.sh

75 lines
1.8 KiB
Bash
Raw Normal View History

2016-12-12 13:00:21 -08:00
#! /bin/bash
set -u
N=$1
###################################################################
# wait for all peers to come online
# for each peer:
# wait to have N-1 peers
# wait to be at height > 1
###################################################################
2017-12-29 08:02:41 -08:00
# wait 60s per step per peer
MAX_SLEEP=60
2016-12-12 13:00:21 -08:00
# wait for everyone to come online
echo "Waiting for nodes to come online"
for i in `seq 1 $N`; do
addr=$(test/p2p/ip.sh $i):26657
2016-12-12 13:00:21 -08:00
curl -s $addr/status > /dev/null
ERR=$?
2017-12-29 08:02:41 -08:00
COUNT=0
2016-12-12 13:00:21 -08:00
while [ "$ERR" != 0 ]; do
2017-12-29 08:02:41 -08:00
sleep 1
2016-12-12 13:00:21 -08:00
curl -s $addr/status > /dev/null
ERR=$?
2017-12-29 08:02:41 -08:00
COUNT=$((COUNT+1))
if [ "$COUNT" -gt "$MAX_SLEEP" ]; then
echo "Waited too long for node $i to come online"
exit 1
fi
2016-12-12 13:00:21 -08:00
done
echo "... node $i is up"
done
echo ""
# wait for each of them to sync up
for i in `seq 1 $N`; do
addr=$(test/p2p/ip.sh $i):26657
2016-12-12 13:00:21 -08:00
N_1=$(($N - 1))
# - assert everyone has N-1 other peers
2017-04-28 19:31:30 -07:00
N_PEERS=`curl -s $addr/net_info | jq '.result.peers | length'`
2017-12-29 08:02:41 -08:00
COUNT=0
2016-12-12 13:00:21 -08:00
while [ "$N_PEERS" != $N_1 ]; do
echo "Waiting for node $i to connect to all peers ..."
sleep 1
2017-04-28 19:31:30 -07:00
N_PEERS=`curl -s $addr/net_info | jq '.result.peers | length'`
2017-12-29 08:02:41 -08:00
COUNT=$((COUNT+1))
if [ "$COUNT" -gt "$MAX_SLEEP" ]; then
echo "Waited too long for node $i to connect to all peers"
exit 1
fi
2016-12-12 13:00:21 -08:00
done
# - assert block height is greater than 1
BLOCK_HEIGHT=`curl -s $addr/status | jq .result.sync_info.latest_block_height`
2017-12-29 08:02:41 -08:00
COUNT=0
2016-12-12 13:00:21 -08:00
while [ "$BLOCK_HEIGHT" -le 1 ]; do
echo "Waiting for node $i to commit a block ..."
sleep 1
BLOCK_HEIGHT=`curl -s $addr/status | jq .result.sync_info.latest_block_height`
2017-12-29 08:02:41 -08:00
COUNT=$((COUNT+1))
if [ "$COUNT" -gt "$MAX_SLEEP" ]; then
echo "Waited too long for node $i to commit a block"
exit 1
fi
2016-12-12 13:00:21 -08:00
done
echo "Node $i is connected to all peers and at block $BLOCK_HEIGHT"
done
echo ""
echo "PASS"
echo ""