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.

125 lines
2.5 KiB

8 years ago
  1. #! /bin/bash
  2. export TMROOT=$HOME/.tendermint_persist
  3. rm -rf "$TMROOT"
  4. tendermint init
  5. TM_CMD="tendermint node --log_level=debug" # &> tendermint_${name}.log"
  6. DUMMY_CMD="dummy --persist $TMROOT/dummy" # &> dummy_${name}.log"
  7. function start_procs(){
  8. name=$1
  9. indexToFail=$2
  10. echo "Starting persistent dummy and tendermint"
  11. if [[ "$CIRCLECI" == true ]]; then
  12. $DUMMY_CMD &
  13. else
  14. $DUMMY_CMD &> "dummy_${name}.log" &
  15. fi
  16. PID_DUMMY=$!
  17. if [[ "$indexToFail" == "" ]]; then
  18. # run in background, dont fail
  19. if [[ "$CIRCLECI" == true ]]; then
  20. $TM_CMD &
  21. else
  22. $TM_CMD &> "tendermint_${name}.log" &
  23. fi
  24. PID_TENDERMINT=$!
  25. else
  26. # run in foreground, fail
  27. if [[ "$CIRCLECI" == true ]]; then
  28. FAIL_TEST_INDEX=$indexToFail $TM_CMD
  29. else
  30. FAIL_TEST_INDEX=$indexToFail $TM_CMD &> "tendermint_${name}.log"
  31. fi
  32. PID_TENDERMINT=$!
  33. fi
  34. }
  35. function kill_procs(){
  36. kill -9 "$PID_DUMMY" "$PID_TENDERMINT"
  37. wait "$PID_DUMMY"
  38. wait "$PID_TENDERMINT"
  39. # wait for the ports to be released
  40. wait_for_port 46656
  41. wait_for_port 46657
  42. # XXX: sometimes the port is still bound :(
  43. sleep 5
  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 ./test/utils/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. addr="localhost:46657"
  80. curl -s "$addr/status" > /dev/null
  81. ERR=$?
  82. i=0
  83. while [ "$ERR" != 0 ]; do
  84. sleep 1
  85. curl -s "$addr/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 $addr/status | jq .result[1].latest_block_height)
  95. h2=$h1
  96. while [ "$h2" == "$h1" ]; do
  97. sleep 1
  98. h2=$(curl -s $addr/status | jq .result[1].latest_block_height)
  99. done
  100. kill_procs
  101. echo "* Passed Test for FailIndex $failIndex"
  102. echo ""
  103. done
  104. echo "Passed Test: Persistence"