From 84e26e3f74a625a7006b4028604d00a98781da46 Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Sun, 24 May 2026 08:47:36 +0800 Subject: [PATCH] test: wait for basic health readiness --- docs/CHANGELOG.md | 2 ++ tests/test_basic.sh | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a034c30..29fdc62 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -58,6 +58,8 @@ as part of `make ci-test`. - Stress testing now uses isolated state, waits for real SSH health, avoids external `timeout` helpers, and is available through `make stress-test`. +- Basic integration tests now wait for real SSH `health` responses instead of + sleeping for a fixed startup delay. - Refreshed README and quick-reference module maps to match the current `cli_text`, `help_text`, `support_text`, i18n, exec, and rate-limit modules. - NORMAL mode now opens at the latest visible messages instead of the oldest diff --git a/tests/test_basic.sh b/tests/test_basic.sh index 46f4d9e..49dfe7c 100755 --- a/tests/test_basic.sh +++ b/tests/test_basic.sh @@ -8,6 +8,7 @@ FAIL=0 BIN="../tnt" SERVER_PID="" STATE_DIR=$(mktemp -d "${TMPDIR:-/tmp}/tnt-basic-test.XXXXXX") +SSH_HEALTH_OPTS="-n -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -p $PORT" cleanup() { if [ -n "$SERVER_PID" ]; then @@ -19,6 +20,19 @@ cleanup() { trap cleanup EXIT +wait_for_health() { + out="" + for _ in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do + if [ -n "$SERVER_PID" ] && ! kill -0 "$SERVER_PID" 2>/dev/null; then + return 1 + fi + out=$(ssh $SSH_HEALTH_OPTS localhost health 2>/dev/null || true) + [ "$out" = "ok" ] && return 0 + sleep 1 + done + return 1 +} + echo "=== TNT Basic Tests ===" if [ ! -f "$BIN" ]; then @@ -34,10 +48,9 @@ fi # Start server "$BIN" -p "$PORT" -d "$STATE_DIR" >"$STATE_DIR/server.log" 2>&1 & SERVER_PID=$! -sleep 2 -# Test 1: Server started -if kill -0 $SERVER_PID 2>/dev/null; then +# Test 1: Server started and accepts exec health checks +if wait_for_health; then echo "✓ Server started" PASS=$((PASS + 1)) else