github.com/MetalBlockchain/metalgo@v1.11.9/scripts/tests.e2e.existing.sh (about) 1 #!/usr/bin/env bash 2 3 set -euo pipefail 4 5 # This script verifies that a network can be reused across test runs. 6 7 # e.g., 8 # ./scripts/build.sh 9 # ./scripts/tests.e2e.sh --ginkgo.label-filter=x # All arguments are supplied to ginkgo 10 # AVALANCHEGO_PATH=./build/avalanchego ./scripts/tests.e2e.existing.sh # Customization of avalanchego path 11 if ! [[ "$0" =~ scripts/tests.e2e.existing.sh ]]; then 12 echo "must be run from repository root" 13 exit 255 14 fi 15 16 # Provide visual separation between testing and setup/teardown 17 function print_separator { 18 printf '%*s\n' "${COLUMNS:-80}" '' | tr ' ' ─ 19 } 20 21 # Ensure network cleanup on teardown 22 function cleanup { 23 print_separator 24 echo "cleaning up reusable network" 25 ginkgo -v ./tests/e2e/e2e.test -- --stop-network 26 } 27 trap cleanup EXIT 28 29 print_separator 30 echo "starting initial test run that should create the reusable network" 31 ./scripts/tests.e2e.sh --reuse-network --ginkgo.focus-file=xsvm.go "${@}" 32 33 print_separator 34 echo "determining the network path of the reusable network created by the first test run" 35 SYMLINK_PATH="${HOME}/.tmpnet/networks/latest_avalanchego-e2e" 36 INITIAL_NETWORK_DIR="$(realpath "${SYMLINK_PATH}")" 37 38 print_separator 39 echo "starting second test run that should reuse the network created by the first run" 40 ./scripts/tests.e2e.sh --reuse-network --ginkgo.focus-file=xsvm.go "${@}" 41 42 SUBSEQUENT_NETWORK_DIR="$(realpath "${SYMLINK_PATH}")" 43 echo "checking that the symlink path remains the same, indicating that the network was reused" 44 if [[ "${INITIAL_NETWORK_DIR}" != "${SUBSEQUENT_NETWORK_DIR}" ]]; then 45 print_separator 46 echo "network was not reused across test runs" 47 exit 1 48 fi