From 2abcde03ada676baa85107f51fbe26e96fef32f9 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 6 Dec 2016 22:08:05 -0500 Subject: [PATCH] tests: cleanup and fix scripts --- test/app/counter_test.sh | 68 +++++++++++++++++--------------------- test/app/test.sh | 10 +++--- test/p2p/fast_sync/test.sh | 54 +++++++++++------------------- test/p2p/test.sh | 20 +---------- test/persist/test.sh | 2 ++ 5 files changed, 58 insertions(+), 96 deletions(-) diff --git a/test/app/counter_test.sh b/test/app/counter_test.sh index 80b9b27b..24f4fb61 100644 --- a/test/app/counter_test.sh +++ b/test/app/counter_test.sh @@ -1,4 +1,9 @@ #! /bin/bash + +if [[ "$GRPC_BROADCAST_TX" == "" ]]; then + GRPC_BROADCAST_TX="" +fi + set -u ##################### @@ -25,34 +30,40 @@ function sendTx() { TX=$1 if [[ "$GRPC_BROADCAST_TX" == "" ]]; then RESPONSE=`curl -s localhost:46657/broadcast_tx_commit?tx=\"$TX\"` - CODE=`echo $RESPONSE | jq .result[1].code` ERROR=`echo $RESPONSE | jq .error` ERROR=$(echo "$ERROR" | tr -d '"') # remove surrounding quotes + + RESPONSE=`echo $RESPONSE | jq .result[1]` else if [ ! -f grpc_client ]; then go build -o grpc_client grpc_client.go fi RESPONSE=`./grpc_client $TX` - echo $RESPONSE | jq . &> /dev/null - IS_JSON=$? - if [[ "$IS_JSON" != "0" ]]; then - ERROR="$RESPONSE" - else - ERROR="" # reset - fi - APPEND_TX_RESPONSE=`echo $RESPONSE | jq .append_tx` - APPEND_TX_CODE=`getCode "$APPEND_TX_RESPONSE"` - CHECK_TX_RESPONSE=`echo $RESPONSE | jq .check_tx` - CHECK_TX_CODE=`getCode "$CHECK_TX_RESPONSE"` + ERROR="" + fi - echo "-------" - echo "TX $TX" - echo "RESPONSE $RESPONSE" - echo "CHECK_TX_RESPONSE $CHECK_TX_RESPONSE" - echo "APPEND_TX_RESPONSE $APPEND_TX_RESPONSE" - echo "CHECK_TX_CODE $CHECK_TX_CODE" - echo "APPEND_TX_CODE $APPEND_TX_CODE" - echo "----" + echo "RESPONSE" + echo $RESPONSE + + echo $RESPONSE | jq . &> /dev/null + IS_JSON=$? + if [[ "$IS_JSON" != "0" ]]; then + ERROR="$RESPONSE" + fi + APPEND_TX_RESPONSE=`echo $RESPONSE | jq .append_tx` + APPEND_TX_CODE=`getCode "$APPEND_TX_RESPONSE"` + CHECK_TX_RESPONSE=`echo $RESPONSE | jq .check_tx` + CHECK_TX_CODE=`getCode "$CHECK_TX_RESPONSE"` + + echo "-------" + echo "TX $TX" + echo "RESPONSE $RESPONSE" + echo "ERROR $ERROR" + echo "----" + + if [[ "$ERROR" != "" ]]; then + echo "Unexpected error sending tx ($TX): $ERROR" + exit 1 fi } @@ -66,10 +77,6 @@ if [[ $APPEND_TX_CODE != 0 ]]; then exit 1 fi -if [[ "$GRPC_BROADCAST_TX" == "" && "$ERROR" != "" ]]; then - echo "Unexpected error. Tx $TX should have been included in a block. $ERROR" - exit 1 -fi echo "... sending tx. expect error" @@ -80,11 +87,6 @@ if [[ "$CHECK_TX_CODE" == 0 ]]; then echo "Got zero exit code for $TX. Expected tx to be rejected by mempool. $RESPONSE" exit 1 fi -if [[ "$GRPC_BROADCAST_TX" == "" && "$ERROR" == "" ]]; then - echo "Expected to get an error - tx $TX should have been rejected from mempool" - echo "$RESPONSE" - exit 1 -fi echo "... sending tx. expect no error" @@ -96,10 +98,6 @@ if [[ $APPEND_TX_CODE != 0 ]]; then echo "Got non-zero exit code for $TX. $RESPONSE" exit 1 fi -if [[ "$GRPC_BROADCAST_TX" == "" && "$ERROR" != "" ]]; then - echo "Unexpected error. Tx $TX should have been accepted in block. $ERROR" - exit 1 -fi echo "... sending tx. expect no error, but invalid" @@ -114,9 +112,5 @@ if [[ $APPEND_TX_CODE == 0 ]]; then echo "Got zero exit code for $TX. Should have been bad nonce. $RESPONSE" exit 1 fi -if [[ "$GRPC_BROADCAST_TX" == "" && "$ERROR" != "" ]]; then - echo "Unexpected error. Tx $TX should have been included in a block. $ERROR" - exit 1 -fi echo "Passed Test: $TESTNAME" diff --git a/test/app/test.sh b/test/app/test.sh index 4830c2b1..bcc55c93 100644 --- a/test/app/test.sh +++ b/test/app/test.sh @@ -13,7 +13,7 @@ export TMROOT=$HOME/.tendermint_app function dummy_over_socket(){ rm -rf $TMROOT tendermint init - echo "Starting dummy and tendermint" + echo "Starting dummy_over_socket" dummy > /dev/null & pid_dummy=$! tendermint node > tendermint.log & @@ -30,7 +30,7 @@ function dummy_over_socket(){ function dummy_over_socket_reorder(){ rm -rf $TMROOT tendermint init - echo "Starting tendermint and dummy" + echo "Starting dummy_over_socket_reorder (ie. start tendermint first)" tendermint node > tendermint.log & pid_tendermint=$! sleep 2 @@ -48,7 +48,7 @@ function dummy_over_socket_reorder(){ function counter_over_socket() { rm -rf $TMROOT tendermint init - echo "Starting counter and tendermint" + echo "Starting counter_over_socket" counter --serial > /dev/null & pid_counter=$! tendermint node > tendermint.log & @@ -64,7 +64,7 @@ function counter_over_socket() { function counter_over_grpc() { rm -rf $TMROOT tendermint init - echo "Starting counter and tendermint" + echo "Starting counter_over_grpc" counter --serial --tmsp grpc > /dev/null & pid_counter=$! tendermint node --tmsp grpc > tendermint.log & @@ -80,7 +80,7 @@ function counter_over_grpc() { function counter_over_grpc_grpc() { rm -rf $TMROOT tendermint init - echo "Starting counter and tendermint" + echo "Starting counter_over_grpc_grpc (ie. with grpc broadcast_tx)" counter --serial --tmsp grpc > /dev/null & pid_counter=$! sleep 1 diff --git a/test/p2p/fast_sync/test.sh b/test/p2p/fast_sync/test.sh index 7a5453f0..43c5d041 100644 --- a/test/p2p/fast_sync/test.sh +++ b/test/p2p/fast_sync/test.sh @@ -1,44 +1,28 @@ #! /bin/bash set -eu -set -o pipefail -############################################################### -# for each peer: -# kill peer -# bring it back online via fast sync -# check app hash -############################################################### +DOCKER_IMAGE=$1 +NETWORK_NAME=$2 +COUNT=$3 +N=$4 -ID=$1 +echo "Testing fasysync on node $COUNT" -addr=$(test/p2p/ip.sh $ID):46657 -peerID=$(( $(($ID % 4)) + 1 )) # 1->2 ... 3->4 ... 4->1 -peer_addr=$(test/p2p/ip.sh $peerID):46657 +# kill peer +set +e # circle sigh :( +docker rm -vf local_testnet_$COUNT +set -e -# get another peer's height -h1=`curl -s $peer_addr/status | jq .result[1].latest_block_height` - -# get another peer's state -root1=`curl -s $peer_addr/status | jq .result[1].latest_app_hash` - -echo "Other peer is on height $h1 with state $root1" -echo "Waiting for peer $ID to catch up" - -# wait for it to sync to past its previous height -set +e -set +o pipefail -h2="0" -while [[ "$h2" -lt "$(($h1+3))" ]]; do - sleep 1 - h2=`curl -s $addr/status | jq .result[1].latest_block_height` - echo "... $h2" +# restart peer - should have an empty blockchain +SEEDS="$(test/p2p/ip.sh 1):46656" +for j in `seq 2 $N`; do + SEEDS="$SEEDS,$(test/p2p/ip.sh $j):46656" done +bash test/p2p/peer.sh $DOCKER_IMAGE $NETWORK_NAME $COUNT $SEEDS -# check the app hash -root2=`curl -s $addr/status | jq .result[1].latest_app_hash` +bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME fs_$COUNT "test/p2p/fast_sync/restart_peer.sh $COUNT" + +echo "" +echo "PASS" +echo "" -if [[ "$root1" != "$root2" ]]; then - echo "App hash after fast sync does not match. Got $root2; expected $root1" - exit 1 -fi -echo "... fast sync successful" diff --git a/test/p2p/test.sh b/test/p2p/test.sh index 4d021a4e..9ca50737 100644 --- a/test/p2p/test.sh +++ b/test/p2p/test.sh @@ -16,23 +16,5 @@ bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME ab test/p2p/atomic_broadcast # run it on each of them N=4 for i in `seq 1 $N`; do - echo "Testing fasysync on node $i" - - # kill peer - set +e # circle sigh :( - docker rm -vf local_testnet_$i - set -e - - # restart peer - should have an empty blockchain - SEEDS="$(test/p2p/ip.sh 1):46656" - for j in `seq 2 $N`; do - SEEDS="$SEEDS,$(test/p2p/ip.sh $j):46656" - done - bash test/p2p/peer.sh $DOCKER_IMAGE $NETWORK_NAME $i $SEEDS - - bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME fs_$i "test/p2p/fast_sync/test.sh $i" + bash test/p2p/fast_sync/test.sh $DOCKER_IMAGE $NETWORK_NAME $i $N done -echo "" -echo "PASS" -echo "" - diff --git a/test/persist/test.sh b/test/persist/test.sh index 5c1e1241..1a94a093 100644 --- a/test/persist/test.sh +++ b/test/persist/test.sh @@ -37,6 +37,7 @@ function send_txs(){ start_procs 1 send_txs kill_procs + start_procs 2 # wait for node to handshake and make a new block @@ -64,5 +65,6 @@ while [ "$h2" == "$h1" ]; do done kill_procs +sleep 2 echo "Passed Test: Persistence"