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.
All checks were successful
Smoke tests / Build and smoke test (push) Successful in 1m17s

This commit is contained in:
AI Agent
2026-03-19 15:47:21 -06:00
parent 1a545bbae7
commit 0914b5a32b
4 changed files with 29 additions and 11 deletions

View File

@@ -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"

View File

@@ -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.
---

View File

@@ -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

13
scripts/ci/wait-for-tcp.sh Executable file
View File

@@ -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