From 12cdf5a955a518ea20bd1b79e3b1fa71bbf28f82 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 7 Nov 2026 20:17:21 +0000 Subject: [PATCH] tests: auf den Listener warten statt zu schlafen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ein Lauf nach frischem `make clean` fiel mit vier Fehlern durch, die nichts mit dem Code zu tun hatten: "soft budget delays the request (8 ms)", "the refusal names the reason: text-only endpoint (missing 'text-only')" und "a one-line endpoint block is enough to serve a request (missing 'served by GATED')". Alle drei schicken eine einzige Anfrage kurz nach dem Start und nehmen an, dass "0,7 s" reicht — unter Last (kompiliert, gescrapt, Container-Churn) reicht es nicht immer, und dann misst die Prüfung eine Verbindung, die noch niemand annimmt. Jetzt wartet die Suite: wait_port pollt bis zu 10 s, bis der Listener annimmt, statt eine Zeit zu raten. Beim Soft-Budget-Test zusätzlich: statt 2,5 s zu schlafen wird gewartet, bis /status den Prozentwert wirklich zeigt (usage_poll 1 s) — das ist die Bedingung, die die Prüfung braucht. Zwei Läufe hintereinander: PASS, 146 Prüfungen, keine Restprozesse. --- tests/ctx-vision.sh | 2 +- tests/pools.sh | 2 +- tests/retry-metrics.sh | 4 ++-- tests/run.sh | 21 ++++++++++++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/ctx-vision.sh b/tests/ctx-vision.sh index 35a62c1..37c9135 100644 --- a/tests/ctx-vision.sh +++ b/tests/ctx-vision.sh @@ -120,7 +120,7 @@ req for "*" pass textonly CFG ./junction --config "$TMP/ctx3.conf" > "$TMP/ctx3.log" 2>&1 & PIDS+=($!) -sleep 0.7 +wait_port $((PORT+17)) 10 R=$(curl -s -m 20 -X POST -H 'Content-Type: application/json' \ -d '{"model":"m","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"http://example.org/a.png"}}]}],"max_tokens":8}' \ "http://127.0.0.1:$((PORT+17))/v1/chat/completions") diff --git a/tests/pools.sh b/tests/pools.sh index 8f6bbd1..0a3c762 100644 --- a/tests/pools.sh +++ b/tests/pools.sh @@ -11,7 +11,7 @@ req for "*" pass kurz CFG ./junction --config "$TMP/inline.conf" > "$TMP/inline.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port $((PORT+31)) 10 R=$(curl -s -m 10 -X POST -H 'Content-Type: application/json' \ -d '{"model":"x","messages":[{"role":"user","content":"hi"}]}' \ "http://127.0.0.1:$((PORT+31))/v1/chat/completions") diff --git a/tests/retry-metrics.sh b/tests/retry-metrics.sh index 623e2e3..1d0a897 100644 --- a/tests/retry-metrics.sh +++ b/tests/retry-metrics.sh @@ -25,7 +25,7 @@ endpoint box { req for "*" check none pass box CFG ./junction --config "$TMP/retry.conf" > "$TMP/retry.log" 2>&1 & PIDS+=($!) -sleep 0.5 +wait_port $P_RETRYJ 10 R=$(curl -s -m 20 -X POST -H 'Content-Type: application/json' \ -d '{"model":"m","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \ "http://127.0.0.1:$P_RETRYJ/v1/chat/completions") @@ -63,7 +63,7 @@ req for "*" check none pass box CFG P_KEY_FIRST=$P_KEY_FIRST P_KEY_SECOND=$P_KEY_SECOND \ ./junction --config "$TMP/pool.conf" > "$TMP/pool.log" 2>&1 & PIDS+=($!) -sleep 0.5 +wait_port $P_POOLJ 10 RH=$(curl -s -m 20 -D- -X POST -H 'Content-Type: application/json' \ -d '{"model":"m","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \ "http://127.0.0.1:$P_POOLJ/v1/chat/completions") diff --git a/tests/run.sh b/tests/run.sh index e75fbca..fd68a46 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -18,6 +18,18 @@ ok() { printf ' OK %s\n' "$1"; } bad() { printf ' FAIL %s\n' "$1"; FAILED=1; } contains() { case "$1" in *"$2"*) ok "$3";; *) bad "$3 (missing '$2')";; esac; } +# Auf den Listener warten statt zu schlafen. Unter Last (parallel kompiliert, ein +# Scrape dazwischen) war "junction nach 0,7 s erreichbar" nicht immer wahr, und dann +# scheiterten Prüfungen, die mit dem Code nichts zu tun hatten. +wait_port() { + local port=$1 limit=$(( ${2:-10} * 20 )) i=0 + while [ "$i" -lt "$limit" ]; do + if (exec 3<>"/dev/tcp/127.0.0.1/$port") 2>/dev/null; then exec 3>&-; return 0; fi + sleep 0.05; i=$((i+1)) + done + return 1 +} + # serviert wird vor dem Log-Eintrag: die Antwort ist beim Client, "served_by" folgt # einen Wimpernschlag später. Ein direkter grep verliert dieses Rennen je nach # Lastlage — deshalb kurz nachsehen statt sofort urteilen. @@ -588,7 +600,14 @@ req for "*" check none pass rich CFG ./junction --config "$TMP/soft.conf" > "$TMP/soft.log" 2>&1 & PIDS+=($!) -sleep 2.5 +wait_port $((PORT+13)) 10 +# Nicht schlafen und hoffen: warten, bis der Abruf den Prozentwert wirklich hat. +# usage_poll steht auf 1 s; unter Last war "nach 2,5 s ist es da" nicht immer wahr, +# und die Prüfung maß dann 8 ms statt der Drosselung. +for _i in $(seq 1 100); do + curl -s -m 2 "http://127.0.0.1:$((PORT+13))/status" | grep -q '"usage_percent":85' && break + sleep 0.1 +done T0=$(date +%s%N) curl -s -m 20 -X POST -H 'Content-Type: application/json' \ -d '{"model":"ds4","messages":[{"role":"user","content":"slow down"}]}' \