Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 61 additions & 13 deletions testrunner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -21,27 +61,35 @@ 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.
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
# 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
cleanup()

# Exit with the same code that test-runner gave.
exit "$NUT_RESULT"
echo "Test runner exited with code $TEST_RESULT"
exit "$TEST_RESULT"
Loading