You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.1 KiB

8 years ago
  1. #! /bin/bash
  2. export PATH="$GOBIN:$PATH"
  3. export TMHOME=$HOME/.tendermint_persist
  4. rm -rf "$TMHOME"
  5. tendermint init
  6. # use a unix socket so we can remove it
  7. RPC_ADDR="$(pwd)/rpc.sock"
  8. TM_CMD="tendermint node --log_level=debug --rpc.laddr=unix://$RPC_ADDR" # &> tendermint_${name}.log"
  9. DUMMY_CMD="abci-cli kvstore --persist $TMHOME/kvstore" # &> kvstore_${name}.log"
  10. function start_procs(){
  11. name=$1
  12. indexToFail=$2
  13. echo "Starting persistent kvstore and tendermint"
  14. if [[ "$CIRCLECI" == true ]]; then
  15. $DUMMY_CMD &
  16. else
  17. $DUMMY_CMD &> "kvstore_${name}.log" &
  18. fi
  19. PID_DUMMY=$!
  20. # before starting tendermint, remove the rpc socket
  21. rm -f $RPC_ADDR
  22. if [[ "$indexToFail" == "" ]]; then
  23. # run in background, dont fail
  24. if [[ "$CIRCLECI" == true ]]; then
  25. $TM_CMD &
  26. else
  27. $TM_CMD &> "tendermint_${name}.log" &
  28. fi
  29. PID_TENDERMINT=$!
  30. else
  31. # run in foreground, fail
  32. if [[ "$CIRCLECI" == true ]]; then
  33. FAIL_TEST_INDEX=$indexToFail $TM_CMD
  34. else
  35. FAIL_TEST_INDEX=$indexToFail $TM_CMD &> "tendermint_${name}.log"
  36. fi
  37. PID_TENDERMINT=$!
  38. fi
  39. }
  40. function kill_procs(){
  41. kill -9 "$PID_DUMMY" "$PID_TENDERMINT"
  42. wait "$PID_DUMMY"
  43. wait "$PID_TENDERMINT"
  44. }
  45. # wait for port to be available
  46. function wait_for_port() {
  47. port=$1
  48. # this will succeed while port is bound
  49. nc -z 127.0.0.1 $port
  50. ERR=$?
  51. i=0
  52. while [ "$ERR" == 0 ]; do
  53. echo "... port $port is still bound. waiting ..."
  54. sleep 1
  55. nc -z 127.0.0.1 $port
  56. ERR=$?
  57. i=$((i + 1))
  58. if [[ $i == 10 ]]; then
  59. echo "Timed out waiting for port to be released"
  60. exit 1
  61. fi
  62. done
  63. echo "... port $port is free!"
  64. }
  65. failsStart=0
  66. fails=$(grep -r "fail.Fail" --include \*.go . | wc -l)
  67. failsEnd=$((fails-1))
  68. for failIndex in $(seq $failsStart $failsEnd); do
  69. echo ""
  70. echo "* Test FailIndex $failIndex"
  71. # test failure at failIndex
  72. bash $(dirname $0)/txs.sh "localhost:46657" &
  73. start_procs 1 "$failIndex"
  74. # tendermint should already have exited when it hits the fail index
  75. # but kill -9 for good measure
  76. kill_procs
  77. start_procs 2
  78. # wait for node to handshake and make a new block
  79. # NOTE: --unix-socket is only available in curl v7.40+
  80. curl -s --unix-socket "$RPC_ADDR" http://localhost/status > /dev/null
  81. ERR=$?
  82. i=0
  83. while [ "$ERR" != 0 ]; do
  84. sleep 1
  85. curl -s --unix-socket "$RPC_ADDR" http://localhost/status > /dev/null
  86. ERR=$?
  87. i=$((i + 1))
  88. if [[ $i == 20 ]]; then
  89. echo "Timed out waiting for tendermint to start"
  90. exit 1
  91. fi
  92. done
  93. # wait for a new block
  94. h1=$(curl -s --unix-socket "$RPC_ADDR" http://localhost/status | jq .result.sync_info.latest_block_height)
  95. h2=$h1
  96. while [ "$h2" == "$h1" ]; do
  97. sleep 1
  98. h2=$(curl -s --unix-socket "$RPC_ADDR" http://localhost/status | jq .result.sync_info.latest_block_height)
  99. done
  100. kill_procs
  101. echo "* Passed Test for FailIndex $failIndex"
  102. echo ""
  103. done
  104. echo "Passed Test: Persistence"