From c1333f810ceb4c4cbc81b81e6501b62847899b33 Mon Sep 17 00:00:00 2001 From: Nathan Bloomfield Date: Fri, 6 Mar 2026 12:30:26 -0600 Subject: [PATCH 1/2] Update testrunner.sh --- testrunner.sh | 66 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/testrunner.sh b/testrunner.sh index add8934f672..9b8cc88da89 100755 --- a/testrunner.sh +++ b/testrunner.sh @@ -11,8 +11,48 @@ # by cardano-node, and cardano-node needs a topology file created by # test-runner. +# Setup ----------------------------------------------------------------------- +# ----------------------------------------------------------------------------- + export LC_ALL=C.UTF-8 -cabal run cardano-node:conformance-test-runner -- \ + +DBDIR="$(mktemp -d /tmp/conformance-db.XXXXXX)" + +reap_process() { + local pid="${1-}" + + # If the PID is empty, there's nothing to reap. + [ -n "$pid" ] || return 0 + + # If this PID is in use, attempt to kill it and wait for it to exit. + if kill -0 "$pid" 2>/dev/null; then + kill -TERM "$pid" 2>/dev/null || true + wait "$pid" 2>/dev/null || true + fi + + # notes: + # - `${1-}` avoids an unbound variable error if `$1` is not set + # - `kill -0` checks if a process is still running without sending a signal + # - `2>/dev/null` suppresses error messages if a process is not running + # - `|| true` prevents the script from exiting if `kill` or `wait` fails +} + +cleanup() { + # kill any remaining processes, just in case + reap_process "$TEST_PID" + reap_process "$NUT_PID" + # clean up the temporary database directory + rm -rf "$DBDIR" +} + +trap cleanup EXIT INT TERM + +# Run ------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- + +echo "Starting test-runner and cardano-node..." +cabal run cardano-node:conformance-test-runner \ + --ghc-options="-Wwarn" -- \ --topology-file=/tmp/topology.file \ --socket-path=/tmp/cardano.socket \ --port=6000 \ @@ -21,27 +61,29 @@ TEST_PID=$! # test-runner might require a build, so we can't necessarily start cardano-node # immediately. Therefore, we wait until test-runner starts listening on port -# 6000. -while ! nc -z localhost 6000; do - sleep 0.5 +# 6000. Also check that the topology file has been created. +while ! nc -z localhost 6000 || [ ! -s /tmp/topology.file ]; do + echo "Waiting for test-runner to start and create topology file..." + sleep 0.5 done # Now that the test harness is up, we can start the NUT, which will connect to # test-runner via the generated topology file. -cabal run cardano-node:cardano-node -- run \ +cabal run cardano-node:cardano-node \ + --ghc-options="-Wwarn" +RTS -V0 -RTS -- run \ --topology=/tmp/topology.file \ - --socket-path=/tmp/cardano.socket 1>/dev/null & + --database-path="$DBDIR" \ + --socket-path=/tmp/cardano.socket & NUT_PID=$! # Wait for test-runner to exit, and capture its exit code. +echo "Waiting for test-runner to finish..." wait "$TEST_PID" -NUT_RESULT=$? +TEST_RESULT=$? # Once it has finished, gracefully request that the NUT exit. -if [ -n "${NUT_PID-}" ]; then - kill "$NUT_PID" 2>/dev/null - wait "$NUT_PID" 2>/dev/null -fi +reap_process "$NUT_PID" # Exit with the same code that test-runner gave. -exit "$NUT_RESULT" +echo "Test runner exited with code $TEST_RESULT" +exit "$TEST_RESULT" From b21ef13d1f887fce781b7d53ba32ecbd8d824b33 Mon Sep 17 00:00:00 2001 From: Nathan Bloomfield Date: Tue, 10 Mar 2026 16:18:38 -0500 Subject: [PATCH 2/2] Add timeout --- testrunner.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/testrunner.sh b/testrunner.sh index 9b8cc88da89..5bf33b54987 100755 --- a/testrunner.sh +++ b/testrunner.sh @@ -62,9 +62,16 @@ TEST_PID=$! # test-runner might require a build, so we can't necessarily start cardano-node # immediately. Therefore, we wait until test-runner starts listening on port # 6000. Also check that the topology file has been created. +MAX_WAIT_ITERS=50 +wait_iters=0 while ! nc -z localhost 6000 || [ ! -s /tmp/topology.file ]; do + if [ "$wait_iters" -ge "$MAX_WAIT_ITERS" ]; then + echo "Timed out waiting for test runner startup after ${MAX_WAIT_ITERS} iterations" + exit 1 + fi echo "Waiting for test-runner to start and create topology file..." sleep 0.5 + wait_iters=$((wait_iters + 1)) done # Now that the test harness is up, we can start the NUT, which will connect to @@ -81,8 +88,7 @@ echo "Waiting for test-runner to finish..." wait "$TEST_PID" TEST_RESULT=$? -# Once it has finished, gracefully request that the NUT exit. -reap_process "$NUT_PID" +cleanup() # Exit with the same code that test-runner gave. echo "Test runner exited with code $TEST_RESULT"