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.

104 lines
2.1 KiB

8 years ago
  1. #! /bin/bash
  2. export TMROOT=$HOME/.tendermint_persist
  3. rm -rf $TMROOT
  4. tendermint init
  5. function start_procs(){
  6. name=$1
  7. indexToFail=$2
  8. echo "Starting persistent dummy and tendermint"
  9. dummy --persist $TMROOT/dummy &> "dummy_${name}.log" &
  10. PID_DUMMY=$!
  11. if [[ "$indexToFail" == "" ]]; then
  12. # run in background, dont fail
  13. tendermint node --log_level=debug &> tendermint_${name}.log &
  14. PID_TENDERMINT=$!
  15. else
  16. # run in foreground, fail
  17. FAIL_TEST_INDEX=$indexToFail tendermint node --log_level=debug &> tendermint_${name}.log
  18. PID_TENDERMINT=$!
  19. fi
  20. }
  21. function kill_procs(){
  22. kill -9 $PID_DUMMY $PID_TENDERMINT
  23. wait $PID_DUMMY
  24. wait $PID_TENDERMINT
  25. }
  26. # wait till node is up, send txs
  27. function send_txs(){
  28. addr="127.0.0.1:46657"
  29. curl -s $addr/status > /dev/null
  30. ERR=$?
  31. while [ "$ERR" != 0 ]; do
  32. sleep 1
  33. curl -s $addr/status > /dev/null
  34. ERR=$?
  35. done
  36. # send a bunch of txs over a few blocks
  37. echo "Node is up, sending txs"
  38. for i in `seq 1 5`; do
  39. for j in `seq 1 100`; do
  40. tx=`head -c 8 /dev/urandom | hexdump -ve '1/1 "%.2X"'`
  41. curl -s $addr/broadcast_tx_async?tx=0x$tx &> /dev/null
  42. done
  43. sleep 1
  44. done
  45. }
  46. failsStart=0
  47. fails=`grep -r "fail.Fail" --include \*.go . | wc -l`
  48. failsEnd=$(($fails-1))
  49. for failIndex in `seq $failsStart $failsEnd`; do
  50. echo ""
  51. echo "* Test FailIndex $failIndex"
  52. # test failure at failIndex
  53. send_txs &
  54. start_procs 1 $failIndex
  55. # tendermint should fail when it hits the fail index
  56. kill -9 $PID_DUMMY
  57. wait $PID_DUMMY
  58. start_procs 2
  59. # wait for node to handshake and make a new block
  60. addr="localhost:46657"
  61. curl -s $addr/status > /dev/null
  62. ERR=$?
  63. i=0
  64. while [ "$ERR" != 0 ]; do
  65. sleep 1
  66. curl -s $addr/status > /dev/null
  67. ERR=$?
  68. i=$(($i + 1))
  69. if [[ $i == 10 ]]; then
  70. echo "Timed out waiting for tendermint to start"
  71. exit 1
  72. fi
  73. done
  74. # wait for a new block
  75. h1=`curl -s $addr/status | jq .result[1].latest_block_height`
  76. h2=$h1
  77. while [ "$h2" == "$h1" ]; do
  78. sleep 1
  79. h2=`curl -s $addr/status | jq .result[1].latest_block_height`
  80. done
  81. kill_procs
  82. echo "* Passed Test for FailIndex $failIndex"
  83. echo ""
  84. done
  85. echo "Passed Test: Persistence"