From 163fe1731b9ad3cbcd532a23d103fcbf8e31cea5 Mon Sep 17 00:00:00 2001 From: Anton Kalyaev Date: Fri, 13 Jan 2017 19:27:31 +0400 Subject: [PATCH] test p2p pex reactor (Refs #335) --- test/p2p/fast_sync/test_peer.sh | 2 +- test/p2p/local_testnet_start.sh | 2 +- test/p2p/peer.sh | 9 +++------ test/p2p/pex/check_peer.sh | 17 +++++++++++++++++ test/p2p/pex/test.sh | 33 +++++++++++++++++++++++++++++++++ test/p2p/test.sh | 5 ++++- 6 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 test/p2p/pex/check_peer.sh create mode 100644 test/p2p/pex/test.sh diff --git a/test/p2p/fast_sync/test_peer.sh b/test/p2p/fast_sync/test_peer.sh index a065ea5c7..cab6fc6fc 100644 --- a/test/p2p/fast_sync/test_peer.sh +++ b/test/p2p/fast_sync/test_peer.sh @@ -27,7 +27,7 @@ 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 $ID $PROXY_APP $SEEDS +bash test/p2p/peer.sh $DOCKER_IMAGE $NETWORK_NAME $ID $PROXY_APP "--seeds $SEEDS" # wait for peer to sync and check the app hash bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME fs_$ID "test/p2p/fast_sync/check_peer.sh $ID" diff --git a/test/p2p/local_testnet_start.sh b/test/p2p/local_testnet_start.sh index 4dd2ab05d..3b842480f 100644 --- a/test/p2p/local_testnet_start.sh +++ b/test/p2p/local_testnet_start.sh @@ -18,5 +18,5 @@ done echo "Seeds: $seeds" for i in `seq 1 $N`; do - bash test/p2p/peer.sh $DOCKER_IMAGE $NETWORK_NAME $i $APP_PROXY $seeds + bash test/p2p/peer.sh $DOCKER_IMAGE $NETWORK_NAME $i $APP_PROXY "--seeds $seeds --pex" done diff --git a/test/p2p/peer.sh b/test/p2p/peer.sh index 611f5ac24..adeb01a10 100644 --- a/test/p2p/peer.sh +++ b/test/p2p/peer.sh @@ -7,11 +7,8 @@ ID=$3 APP_PROXY=$4 set +u -SEEDS=$5 +NODE_FLAGS=$5 set -u -if [[ "$SEEDS" != "" ]]; then - SEEDS=" --seeds $SEEDS " -fi set +eu @@ -29,7 +26,7 @@ if [[ "$CIRCLECI" == true ]]; then --log-opt syslog-address=udp://127.0.0.1:5514 \ --log-opt syslog-facility=daemon \ --log-opt tag="{{.Name}}" \ - $DOCKER_IMAGE node $SEEDS --log_level=debug --proxy_app=$APP_PROXY + $DOCKER_IMAGE node $NODE_FLAGS --log_level=debug --proxy_app=$APP_PROXY else set -u docker run -d \ @@ -38,5 +35,5 @@ else --name local_testnet_$ID \ --entrypoint tendermint \ -e TMROOT=/go/src/github.com/tendermint/tendermint/test/p2p/data/mach$ID/core \ - $DOCKER_IMAGE node $SEEDS --log_level=info --proxy_app=$APP_PROXY + $DOCKER_IMAGE node $NODE_FLAGS --log_level=info --proxy_app=$APP_PROXY fi diff --git a/test/p2p/pex/check_peer.sh b/test/p2p/pex/check_peer.sh new file mode 100644 index 000000000..ceabd2ac6 --- /dev/null +++ b/test/p2p/pex/check_peer.sh @@ -0,0 +1,17 @@ +#! /bin/bash +set -u + +ID=$1 +N=$2 + +addr=$(test/p2p/ip.sh "$ID"):46657 + +echo "2. wait until peer $ID connects to other nodes using pex reactor" +peers_count="0" +while [[ "$peers_count" -lt "$((N-1))" ]]; do + sleep 1 + peers_count=$(curl -s "$addr/net_info" | jq ".result[1].peers | length") + echo "... peers count = $peers_count, expected = $((N-1))" +done + +echo "... successful" diff --git a/test/p2p/pex/test.sh b/test/p2p/pex/test.sh new file mode 100644 index 000000000..84d832b91 --- /dev/null +++ b/test/p2p/pex/test.sh @@ -0,0 +1,33 @@ +#! /bin/bash +set -eu + +DOCKER_IMAGE=$1 +NETWORK_NAME=$2 +N=$3 +PROXY_APP=$4 + +ID=1 + +echo "----------------------------------------------------------------------" +echo "Testing pex creates the addrbook and uses it if seeds are not provided" +echo "(assuming peers are started with pex enabled)" + +echo "1. restart peer $ID" +docker stop "local_testnet_$ID" +# preserce addrbook.json +docker cp "local_testnet_$ID:/go/src/github.com/tendermint/tendermint/test/p2p/data/mach1/core/addrbook.json" "/tmp/addrbook.json" +docker rm -vf "local_testnet_$ID" + +# NOTE that we do not provide seeds this time +bash test/p2p/peer.sh "$DOCKER_IMAGE" "$NETWORK_NAME" "$ID" "$PROXY_APP" "--pex" +docker cp "/tmp/addrbook.json" "local_testnet_$ID:/go/src/github.com/tendermint/tendermint/test/p2p/data/mach1/core/addrbook.json" +echo "with the following addrbook:" +docker exec "local_testnet_$ID" cat "/go/src/github.com/tendermint/tendermint/test/p2p/data/mach1/core/addrbook.json" +echo "" + +# if the client runs forever, it means addrbook wasn't saved or was empty +bash test/p2p/client.sh "$DOCKER_IMAGE" "$NETWORK_NAME" "pex_$ID" "test/p2p/pex/check_peer.sh $ID $N" + +echo "" +echo "PASS" +echo "" diff --git a/test/p2p/test.sh b/test/p2p/test.sh index 0f29aa199..1157ac064 100644 --- a/test/p2p/test.sh +++ b/test/p2p/test.sh @@ -29,5 +29,8 @@ bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME ab "test/p2p/atomic_broadcas # for each node, kill it and readd via fast sync bash test/p2p/fast_sync/test.sh $DOCKER_IMAGE $NETWORK_NAME $N $PROXY_APP -# test killing all peers +# test killing all peers 3 times bash test/p2p/kill_all/test.sh $DOCKER_IMAGE $NETWORK_NAME $N 3 + +# test pex +bash test/p2p/pex/test.sh $DOCKER_IMAGE $NETWORK_NAME $N $PROXY_APP