From 0914b5a32bf8b8a0283a959f1a4c4d6cc36047cf Mon Sep 17 00:00:00 2001 From: AI Agent Date: Thu, 19 Mar 2026 15:47:21 -0600 Subject: [PATCH] Replace sleep with wait-for-tcp script in run-tests.sh and CI workflow to improve reliability of smoke tests. Update TESTING.md to include prerequisites for the new script. --- .gitea/workflows/smoke-tests.yml | 23 ++++++++++++++--------- TESTING.md | 2 +- run-tests.sh | 2 +- scripts/ci/wait-for-tcp.sh | 13 +++++++++++++ 4 files changed, 29 insertions(+), 11 deletions(-) create mode 100755 scripts/ci/wait-for-tcp.sh diff --git a/.gitea/workflows/smoke-tests.yml b/.gitea/workflows/smoke-tests.yml index 5f27df2..4244575 100644 --- a/.gitea/workflows/smoke-tests.yml +++ b/.gitea/workflows/smoke-tests.yml @@ -2,6 +2,7 @@ name: Smoke tests on: workflow_dispatch: push: + pull_request: jobs: smoke: @@ -14,10 +15,14 @@ jobs: uses: actions/checkout@v4 - name: Install needed tools + env: + DEBIAN_FRONTEND: noninteractive run: | + set -e + sudo apt-get update + sudo apt-get install -y --no-install-recommends openssh-client netcat-openbsd ca-certificates curl curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - echo "$HOME/.cargo/bin" >> $GITHUB_PATH - sudo apt update && sudo apt install -y netcat-openbsd + echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" - name: Build run: cargo build @@ -34,7 +39,7 @@ jobs: RUST_LOG=info ./target/debug/mudserver -d "$TEST_DB" & MUD_PID=$! trap 'kill $MUD_PID 2>/dev/null || true' EXIT - sleep 2 + bash scripts/ci/wait-for-tcp.sh 127.0.0.1 2222 set +e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF' 1 @@ -56,13 +61,13 @@ jobs: set -e [[ $r -eq 0 || $r -eq 255 ]] - - name: Smoke — persistence (reconnect) + - name: Smoke - persistence (reconnect) run: | set -euo pipefail RUST_LOG=info ./target/debug/mudserver -d "$TEST_DB" & MUD_PID=$! trap 'kill $MUD_PID 2>/dev/null || true' EXIT - sleep 2 + bash scripts/ci/wait-for-tcp.sh 127.0.0.1 2222 set +e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF' look @@ -82,13 +87,13 @@ jobs: ./target/debug/mudtool -d "$TEST_DB" settings set registration_open false ./target/debug/mudtool -d "$TEST_DB" settings list - - name: Smoke — in-game admin + - name: Smoke - in-game admin run: | set -euo pipefail RUST_LOG=info ./target/debug/mudserver -d "$TEST_DB" & MUD_PID=$! trap 'kill $MUD_PID 2>/dev/null || true' EXIT - sleep 2 + bash scripts/ci/wait-for-tcp.sh 127.0.0.1 2222 set +e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF' admin help @@ -108,7 +113,7 @@ jobs: RUST_LOG=info ./target/debug/mudserver -d "$TEST_DB" & MUD_PID=$! trap 'kill $MUD_PID 2>/dev/null || true' EXIT - sleep 2 + bash scripts/ci/wait-for-tcp.sh 127.0.0.1 2222 set +e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 newplayer@localhost <<'EOF' quit @@ -125,7 +130,7 @@ jobs: RUST_LOG=info ./target/debug/mudserver -d "$TEST_DB" & MUD_PID=$! trap 'kill $MUD_PID 2>/dev/null || true' EXIT - sleep 2 + bash scripts/ci/wait-for-tcp.sh 127.0.0.1 2222 set +e ( echo "1" diff --git a/TESTING.md b/TESTING.md index e53e6d9..39e51b0 100644 --- a/TESTING.md +++ b/TESTING.md @@ -8,7 +8,7 @@ This builds the server and mudtool, starts the server with a temporary DB, and runs the same sequence as the smoke steps in [`.gitea/workflows/smoke-tests.yml`](.gitea/workflows/smoke-tests.yml) (new player, persistence, mudtool admin, in-game admin, registration gate, tick combat), then cleans up. Use `MUD_TEST_DB` (default `./mudserver.db.test`) so you do not overwrite your normal `mudserver.db`. -Prerequisites: Rust toolchain (cargo), ssh client. In CI, Rust is installed by the workflow. +Prerequisites: Rust toolchain (cargo), OpenSSH client, and OpenBSD `nc` (`netcat-openbsd` on Debian/Ubuntu) for [`scripts/ci/wait-for-tcp.sh`](scripts/ci/wait-for-tcp.sh). CI installs these explicitly before the smoke steps. --- diff --git a/run-tests.sh b/run-tests.sh index ab0e6a9..5f9bce3 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -25,7 +25,7 @@ trap cleanup EXIT cargo build RUST_LOG=info ./target/debug/mudserver -d "$TEST_DB" & SERVER_PID=$! -sleep 2 +bash "$ROOT/scripts/ci/wait-for-tcp.sh" 127.0.0.1 2222 ssh_mud smoketest@localhost <<'EOF' 1 diff --git a/scripts/ci/wait-for-tcp.sh b/scripts/ci/wait-for-tcp.sh new file mode 100755 index 0000000..e66f9d3 --- /dev/null +++ b/scripts/ci/wait-for-tcp.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e +host=${1:-127.0.0.1} +port=${2:-2222} +max_attempts=${3:-30} +for _ in $(seq 1 "$max_attempts"); do + if nc -z -w 1 "$host" "$port" 2>/dev/null; then + exit 0 + fi + sleep 1 +done +echo "timeout waiting for $host:$port" >&2 +exit 1