test-network-impl.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. if ! "$CHUTNEY_PATH/tools/bootstrap-network.sh" "$NETWORK_FLAVOUR"; then
  3. CHUTNEY_WARNINGS_IGNORE_EXPECTED=false CHUTNEY_WARNINGS_SUMMARY=false \
  4. "$WARNING_COMMAND"
  5. "$WARNINGS"
  6. $ECHO "bootstrap-network.sh failed"
  7. exit 1
  8. fi
  9. # chutney starts verifying after CHUTNEY_START_TIME seconds,
  10. # keeps on trying for CHUTNEY_BOOTSTRAP_TIME seconds,
  11. # and then stops after CHUTNEY_STOP_TIME seconds.
  12. # Even the fastest chutney networks take 5-10 seconds for their first consensus,
  13. # and then 10 seconds after that for relays to bootstrap and upload descriptors,
  14. # and then 10 seconds after that for clients and onion services to bootstrap.
  15. # But chutney defaults to running a bit more slowly, so it is more reliable,
  16. # and we allow a bit more time, in case the machine is heavily loaded.
  17. export CHUTNEY_START_TIME=${CHUTNEY_START_TIME:-120}
  18. export CHUTNEY_BOOTSTRAP_TIME=${CHUTNEY_BOOTSTRAP_TIME:-60}
  19. export CHUTNEY_STOP_TIME=${CHUTNEY_STOP_TIME:-0}
  20. CHUTNEY="$CHUTNEY_PATH/chutney"
  21. if [ "$CHUTNEY_START_TIME" -ge 0 ]; then
  22. $ECHO "Waiting $CHUTNEY_START_TIME seconds for a consensus containing relays to be generated..."
  23. # We log bootstrap status for debugging purposes.
  24. # We'll fix bootstrap errors in #20473.
  25. "$CHUTNEY" wait_for_bootstrap "$CHUTNEY_NETWORK" \
  26. || $ECHO "Tor bootstrap failed, ignoring for now."
  27. else
  28. $ECHO "Chutney network launched and running. To stop the network, use:"
  29. $ECHO "$CHUTNEY stop $CHUTNEY_NETWORK"
  30. "$WARNINGS"
  31. exit 0
  32. fi
  33. if [ "$CHUTNEY_BOOTSTRAP_TIME" -ge 0 ]; then
  34. # Chutney will try to verify for $CHUTNEY_BOOTSTRAP_TIME seconds each round
  35. n_rounds=0
  36. # Run CHUTNEY_ROUNDS verification rounds
  37. $ECHO "Running $CHUTNEY_ROUNDS verify rounds..."
  38. while [ "$n_rounds" -lt "$CHUTNEY_ROUNDS" ]; do
  39. n_rounds=$((n_rounds+1))
  40. if ! "$CHUTNEY" verify "$CHUTNEY_NETWORK"; then
  41. CHUTNEY_WARNINGS_IGNORE_EXPECTED=false \
  42. CHUTNEY_WARNINGS_SUMMARY=false \
  43. "$WARNING_COMMAND"
  44. "$WARNINGS"
  45. $ECHO "chutney verify $n_rounds/$CHUTNEY_ROUNDS failed"
  46. exit 1
  47. fi
  48. $ECHO "Completed $n_rounds/$CHUTNEY_ROUNDS verify rounds."
  49. done
  50. else
  51. $ECHO "Chutney network ready and running. To stop the network, use:"
  52. $ECHO "$CHUTNEY stop $CHUTNEY_NETWORK"
  53. "$WARNINGS"
  54. exit 0
  55. fi
  56. if [ "$CHUTNEY_STOP_TIME" -ge 0 ]; then
  57. if [ "$CHUTNEY_STOP_TIME" -gt 0 ]; then
  58. $ECHO "Waiting $CHUTNEY_STOP_TIME seconds before stopping the network..."
  59. fi
  60. sleep "$CHUTNEY_STOP_TIME"
  61. # work around a bug/feature in make -j2 (or more)
  62. # where make hangs if any child processes are still alive
  63. if ! "$CHUTNEY" stop "$CHUTNEY_NETWORK"; then
  64. CHUTNEY_WARNINGS_IGNORE_EXPECTED=false CHUTNEY_WARNINGS_SUMMARY=false \
  65. "$WARNING_COMMAND"
  66. "$WARNINGS"
  67. $ECHO "chutney stop failed"
  68. exit 1
  69. fi
  70. # Give tor time to exit gracefully
  71. sleep 3
  72. else
  73. $ECHO "Chutney network verified and running. To stop the network, use:"
  74. $ECHO "$CHUTNEY stop $CHUTNEY_NETWORK"
  75. "$WARNINGS"
  76. exit 0
  77. fi
  78. "$WARNINGS"
  79. exit 0