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.

123 lines
2.7 KiB

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