From 83a56eb11d705d1ac17fd5b9b36f4aff6e5f7780 Mon Sep 17 00:00:00 2001 From: Hermes Date: Thu, 19 Nov 2026 06:59:55 +0000 Subject: [PATCH] tests: wait for a port instead of sleeping before it Run 13 failed the whole cache section with six checks and no listener: the router was started with "sleep 0.8" and curl asked too early. The same fixed sleep sat in front of a dozen other routers and stubs. Every one now waits for its port (wait_port), and the two checks that need a listener to be *absent* (mesh without a secret, roll3 without SO_REUSEPORT) wait for their log line (wait_log) instead of hoping the message is there after 0.6 s. Same checks, no fixed windows left before a listener; the suite is also faster because it no longer sleeps through them. Full run: 537 OK, 0 FAIL, PASS. --- tests/balancing.sh | 6 +++--- tests/cache.sh | 2 +- tests/cluster.sh | 4 ++-- tests/compress.sh | 8 ++++---- tests/ctx-fallback.sh | 3 ++- tests/effort.sh | 2 +- tests/env-providers.sh | 2 +- tests/local-pool.sh | 2 +- tests/model-policy.sh | 2 +- tests/opencode.sh | 6 +++--- tests/run.sh | 12 ++++++++++++ 11 files changed, 31 insertions(+), 18 deletions(-) diff --git a/tests/balancing.sh b/tests/balancing.sh index 3dfc8a0..475cb58 100644 --- a/tests/balancing.sh +++ b/tests/balancing.sh @@ -12,7 +12,7 @@ BB=$((PORT+21)) BJ=$((PORT+23)) tests/stub $BB "ZWEIT" > /dev/null 2>&1 & PIDS+=($!) -sleep 0.4 +wait_port "$BB" 10 || bad "the weighted stub did not come up" cat > "$TMP/bal.conf" < "$TMP/bal.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port "$BJ" 30 || bad "the balance instance did not come up" # 1. Gewichtetes Reihum: 3:1 soll sich in der Verteilung zeigen A=0; B=0 @@ -93,7 +93,7 @@ req for "*" pass langsam, gesund CFG ./junction --config "$TMP/conn.conf" > "$TMP/conn.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port $((PORT + 24)) 30 || bad "the connect-timeout instance did not come up" START=$(date +%s%N) R=$(curl -s -m 30 -X POST -H 'Content-Type: application/json' \ -d '{"model":"x","messages":[{"role":"user","content":"hi"}]}' \ diff --git a/tests/cache.sh b/tests/cache.sh index f707b9c..8ca25b5 100644 --- a/tests/cache.sh +++ b/tests/cache.sh @@ -14,7 +14,7 @@ req for "*" pass a CFG ./junction --config "$TMP/cache.conf" > "$TMP/cache.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port "$XPORT" 30 || bad "the cache instance did not come up" ask() { # ask -> Cache-Zustand aus dem Kopf curl -s -m 10 -D - -o /dev/null -X POST -H 'Content-Type: application/json' -d "$1" \ diff --git a/tests/cluster.sh b/tests/cluster.sh index daf16f0..1b000e5 100755 --- a/tests/cluster.sh +++ b/tests/cluster.sh @@ -138,7 +138,7 @@ req for "*" pass a CFG ./junction --config "$TMP/meshC.conf" > "$TMP/meshC.log" 2>&1 & PIDS+=($!) -sleep 0.6 +wait_log "$TMP/meshC.log" "disabled: cache tcp without cache secret_env" 10 log_has "$TMP/meshC.log" "disabled: cache tcp without cache secret_env" \ "a peer port without a secret stays closed" @@ -202,7 +202,7 @@ code=$(curl -s -o /dev/null -w '%{http_code}' -m 10 -X POST -H 'Content-Type: ap sed 's/so_reuseport on/so_reuseport off/; s/roll1/roll3/' "$TMP/roll1.conf" > "$TMP/roll3.conf" ./junction --config "$TMP/roll3.conf" > "$TMP/roll3.log" 2>&1 & PIDS+=($!) -sleep 0.6 +wait_log "$TMP/roll3.log" "Address already in use" 10 log_has "$TMP/roll3.log" "Address already in use" \ "without so_reuseport the port stays exclusive" diff --git a/tests/compress.sh b/tests/compress.sh index d416f0d..0ffdefb 100644 --- a/tests/compress.sh +++ b/tests/compress.sh @@ -23,7 +23,7 @@ class H(http.server.BaseHTTPRequestHandler): http.server.HTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever() PY python3 "$TMP/echo.py" $((CPORT+1)) & PIDS+=($!) -sleep 0.6 +wait_port $((CPORT + 1)) 10 || bad "the compress echo stub did not come up" cat > "$TMP/comp.conf" < "$TMP/comp.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port "$CPORT" 30 || bad "the compress instance did not come up" # Rumpf bauen: eine sehr lange Werkzeugausgabe, danach zwei kurze Nachrichten. python3 - "$TMP/req.json" <<'PY' @@ -119,7 +119,7 @@ esac # 5. Pro Endpunkt: einer kürzt, der andere nicht — derselbe Rumpf, zwei Rümpfe python3 "$TMP/echo.py" $((CPORT+2)) & PIDS+=($!) -sleep 0.6 +wait_port $((CPORT + 2)) 10 || bad "the second echo stub did not come up" cat > "$TMP/split.conf" < "$TMP/split.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port $((CPORT + 3)) 30 || bad "the split instance did not come up" SEND=$(python3 -c ' import json diff --git a/tests/ctx-fallback.sh b/tests/ctx-fallback.sh index 3d43b6c..5019cb9 100644 --- a/tests/ctx-fallback.sh +++ b/tests/ctx-fallback.sh @@ -10,7 +10,8 @@ CFB=$((PORT+262)) STUB_CTX=4096 STUB_OUT=1000 tests/stub $CFS "SMALL" & PIDS+=($!) STUB_CTX=200000 STUB_OUT=1000 tests/stub $CFB "BIG" & PIDS+=($!) -sleep 0.3 +wait_port "$CFS" 10 && wait_port "$CFB" 10 \ + || bad "the ctx-fallback stubs did not come up" cat > "$TMP/ctx-fallback.conf" < "$TMP/env_stub.log" 2>&1 & PIDS+=($!) -sleep 0.4 +wait_port "$E2" 10 || bad "the env stub did not come up" # Keine Endpunkt-Blöcke, nur eine Regel — der Endpunkt soll aus der Umgebung kommen. cat > "$TMP/env.conf" < "$TMP/local_stub.log" 2>&1 & PIDS+=($!) -sleep 0.4 +wait_port "$LSTUB" 10 || bad "the parallel stub did not come up" cat > "$TMP/local.conf" < "$TMP/model-policy.conf" < "$TMP/oc-stub.log" 2>&1 & PIDS+=($!) -sleep 0.6 +wait_port "$OC_PORT" 10 || bad "the opencode stub did not come up" printf 'opencode:testpasswort\n' > "$TMP/oc.pass" chmod +x "$TMP/oc.pass" @@ -43,7 +43,7 @@ CFG ./junction --config "$TMP/oc.conf" > "$TMP/oc.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port "$OC_JUNC" 30 || bad "the opencode bridge did not come up" # 1. Modellliste kommt als OpenAI-Liste, ohne die Varianten der Modelle R=$(curl -s -m 20 "http://127.0.0.1:$OC_JUNC/v1/models") @@ -173,7 +173,7 @@ chmod +x "$TMP/oc.bad.sh" sed "s|pass_cmd .*|pass_cmd \"$TMP/oc.bad.sh\"|; s|$OC_JUNC|$((PORT+20))|" "$TMP/oc.conf" > "$TMP/oc2.conf" ./junction --config "$TMP/oc2.conf" > "$TMP/oc2.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port $((PORT + 20)) 30 || bad "the pass_cmd instance did not come up" R=$(curl -s -m 20 -X POST -H 'Content-Type: application/json' \ -d '{"model":"x","messages":[{"role":"user","content":"hi"}]}' \ "http://127.0.0.1:$((PORT+20))/v1/chat/completions") diff --git a/tests/run.sh b/tests/run.sh index 39e8ae9..db959c8 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -54,6 +54,18 @@ wait_port() { return 1 } +# Warten, bis eine Zeile im Log steht: ein Router, der nicht lauschen soll +# (mesh ohne Geheimnis) oder nicht lauschen darf (Port belegt), ist nur am Log +# zu erkennen. Ein fester sleep war hier reine Glueckssache. +wait_log() { + local file=$1 pat=$2 limit=$(( ${3:-10} * 20 )) i=0 + while [ "$i" -lt "$limit" ]; do + grep -q "$pat" "$file" 2>/dev/null && return 0 + sleep 0.05; i=$((i+1)) + done + return 1 +} + # Ein Port, der gerade freigegeben wurde, ist nicht sofort wieder belegbar: nach SIGTERM # hält junction den Listener noch restart_grace_s offen und antwortet "restarting". # Wer den Port wiederverwenden will, wartet, bis er wirklich frei ist.