From 879eac5241f66a8032d56757baa07c8f6a6e5f10 Mon Sep 17 00:00:00 2001 From: Hermes Date: Wed, 18 Nov 2026 08:47:15 +0000 Subject: [PATCH] =?UTF-8?q?tests:=20Startrennen=20und=20Hintergrundproben?= =?UTF-8?q?=20unter=20Last=20entsch=C3=A4rfen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Die sporadischen Ausfälle hatten zwei gemeinsame Ursachen: feste sleeps statt wait_port für frisch gestartete Stubs, und die Hintergrundprobe, die einen Endpunkt nach einem einzigen fehlgeschlagenen curl für offline_hold_s (20 s) aus dem Verkehr nahm. Unter Last traf beides gelegentlich einen Request: 503 offline statt text-only, 503 statt des Retry-After-Datums, oder ein nicht erreichbarer Stub. - probe_thread versucht eine fehlgeschlagene Probe nach 200 ms erneut; erst zwei Fehlschläge nehmen den Endpunkt offline. - retry-after.sh, ctx-vision.sh und flight.sh warten mit wait_port auf ihre Stubs, statt 0,3–0,8 s zu schlafen; probe_interval 0 schaltet die Hintergrundprobe in diesen deterministischen Abschnitten ab. - cluster.sh: probe_interval 0, größere Startfristen, der Peer-Cache wird gepollt statt nach 0,4 s einmal geprüft, und der Silent-Peer-Test erlaubt 5 s statt 2 s (er prüft, dass nichts hängt, nicht die CPU-Zeit). - mcp_concurrency.py: probe_interval 0; zerrissene Antworten werden mit Status und Rumpf ausgegeben, damit ein Wiederauftreten diagnostizierbar ist. Nachweis: zwei vollständige Läufe ohne nice -n -10 unter Last 6,8 bzw. 9,3, jeweils 484 OK / 0 FAIL. --- src/junction.c | 8 ++++++++ tests/cluster.sh | 31 ++++++++++++++++++++----------- tests/ctx-vision.sh | 18 ++++++++++++------ tests/flight.sh | 8 +++++--- tests/mcp_concurrency.py | 3 +++ tests/retry-after.sh | 23 +++++++++++++++-------- 6 files changed, 63 insertions(+), 28 deletions(-) diff --git a/src/junction.c b/src/junction.c index 97f18c3..8185206 100644 --- a/src/junction.c +++ b/src/junction.c @@ -4686,6 +4686,14 @@ static void *probe_thread(void *unused) j_endpoint *ep = &CFG.endpoints[i]; if (!ep->probe_on || ep->paused || !ep->base[0]) continue; int alive = probe_endpoint(ep) == 0; + if (!alive) { + /* A single failed probe under load must not take an endpoint out + * of service for offline_hold_s: the request path is the better + * witness. Give the probe one immediate second chance. */ + struct timespec again = { 0, 200 * 1000 * 1000 }; + nanosleep(&again, NULL); + alive = probe_endpoint(ep) == 0; + } int was_off = ep->offline_until > now_s(); STATE_LOCK(); if (!alive) { diff --git a/tests/cluster.sh b/tests/cluster.sh index 6e917cd..daf16f0 100755 --- a/tests/cluster.sh +++ b/tests/cluster.sh @@ -21,6 +21,7 @@ MESH=$(echo '{"model":"m","messages":[{"role":"user","content":"wo war ich"}],"m cat > "$TMP/meshA.conf" < "$TMP/meshB.conf" < "$TMP/meshA.log" PIDS+=($!) J_MESH_SECRET="$SECRET" ./junction --config "$TMP/meshB.conf" > "$TMP/meshB.log" 2>&1 & PIDS+=($!) -wait_port "$CA" 10 || bad "node A did not come up" -wait_port "$CB" 10 || bad "node B did not come up" +wait_port "$CA" 30 || bad "node A did not come up" +wait_port "$CB" 30 || bad "node B did not come up" # Der Secret-Schutz ist keine Zierde: ohne Kopfzeile gibt es nichts. code=$(curl -s -o /dev/null -w '%{http_code}' -m 5 "http://127.0.0.1:$PCA/cache/stats") @@ -68,12 +70,16 @@ c1=$(curl -s -m 10 -D - -o /dev/null -X POST -H 'Content-Type: application/json' [ "$c1" = "miss" ] && ok "node A misses and pays the provider" \ || bad "node A answered cache=$c1 on the first request" -sleep 0.4 # die Weitergabe läuft in einem eigenen Faden - -# Dieselbe Anfrage an B: sie darf den Anbieter nicht mehr fragen. -c2=$(curl -s -m 10 -D - -o /dev/null -X POST -H 'Content-Type: application/json' \ - -d "$MESH" "http://127.0.0.1:$CB/v1/chat/completions" \ - | tr -d '\r' | sed -n 's/^[Xx]-[Jj]unction-[Cc]ache: //p') +# Die Weitergabe läuft in einem eigenen Faden. Statt einer festen Pause warten +# wir, bis B den Eintrag wirklich hat (unter Last kann das länger dauern). +c2="" +for i in $(seq 1 50); do + c2=$(curl -s -m 10 -D - -o /dev/null -X POST -H 'Content-Type: application/json' \ + -d "$MESH" "http://127.0.0.1:$CB/v1/chat/completions" \ + | tr -d '\r' | sed -n 's/^[Xx]-[Jj]unction-[Cc]ache: //p') + [ "$c2" = "hit" ] && break + sleep 0.1 +done [ "$c2" = "hit" ] && ok "node B answers the same question from the shared cache" \ || bad "node B answered cache=$c2 instead of a hit from the peer" @@ -100,6 +106,7 @@ contains "$stats" '"entries"' "the cache port reports its own numbers" cat > "$TMP/meshD.conf" < "$TMP/meshD.log" 2>&1 & PIDS+=($!) -wait_port "$((PORT+207))" 10 || bad "node D did not come up" +wait_port "$((PORT+207))" 30 || bad "node D did not come up" read -r dcode dtime < <(curl -s -o /dev/null -m 10 -w '%{http_code} %{time_total}' \ -X POST -H 'Content-Type: application/json' -d "$MESH" \ "http://127.0.0.1:$((PORT+207))/v1/chat/completions") -if [ "$dcode" = "200" ] && awk "BEGIN{exit !($dtime < 2.0)}"; then +if [ "$dcode" = "200" ] && awk "BEGIN{exit !($dtime < 5.0)}"; then ok "a silent peer costs only the timeout ($dtime s), the request still succeeds" else bad "a silent peer stalled the request (http=$dcode after ${dtime}s)" @@ -123,6 +130,7 @@ fi cat > "$TMP/meshC.conf" < "$TMP/roll1.conf" < "$TMP/roll2.conf" ./junction --config "$TMP/roll1.conf" > "$TMP/roll1.log" 2>&1 & R1=$! PIDS+=($R1) -wait_port "$RP" 10 || bad "instance 1 did not come up" +wait_port "$RP" 30 || bad "instance 1 did not come up" ./junction --config "$TMP/roll2.conf" > "$TMP/roll2.log" 2>&1 & R2=$! PIDS+=($R2) diff --git a/tests/ctx-vision.sh b/tests/ctx-vision.sh index faf9425..15f78ec 100644 --- a/tests/ctx-vision.sh +++ b/tests/ctx-vision.sh @@ -7,6 +7,7 @@ echo "== 17. ctx filters and vision routing ==" cat > "$TMP/ctx.conf" < "$TMP/ctx.log" 2>&1 & PIDS+=($!) -wait_port $((PORT+15)) 10 +wait_port $((PORT+15)) 30 BASE="http://127.0.0.1:$((PORT+15))/v1/chat/completions" @@ -81,6 +82,7 @@ contains "$R" "served by SLOW" "a real image part still wins over the tool schem cat > "$TMP/ctx2.conf" < "$TMP/ctx2.log" 2>&1 & PIDS+=($!) -wait_port $((PORT+16)) 10 +wait_port $((PORT+16)) 30 R=$(curl -s -m 30 -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+16))/v1/chat/completions") @@ -110,6 +112,7 @@ contains "$R" "served by SLOW" "a text-only endpoint is skipped for an image req # Fall prüfen: nur ein Text-Endpunkt, Bild-Anfrage -> 503, das den Grund nennt. cat > "$TMP/ctx3.conf" < "$TMP/ctx3.log" 2>&1 & PIDS+=($!) -wait_port $((PORT+17)) 10 +wait_port $((PORT+17)) 30 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") @@ -144,13 +147,15 @@ P_META=$((PORT+25)) P_PLAIN=$((PORT+26)) STUB_CTX=1000000 tests/stub $P_META "BIGCTX" & PIDS+=($!) tests/stub $P_PLAIN "NOMETA" & PIDS+=($!) -sleep 0.3 +wait_port "$P_META" 30 || bad "the published-limit stub did not come up" +wait_port "$P_PLAIN" 30 || bad "the plain-limit stub did not come up" for pair in "$P_META:meta" "$P_PLAIN:plain"; do port=${pair%%:*}; tag=${pair##*:} cat > "$TMP/$tag.conf" < "$TMP/$tag.log" 2>&1 & PIDS+=($!) - wait_port $((PORT+27)) 10 + wait_port $((PORT+27)) 30 BIGP=$(python3 -c "print('wort ' * 4000)") # Der Client fragt das Modell, das der Endpunkt veröffentlicht -- nur dann # greift dessen Grenze. @@ -187,10 +192,11 @@ done P_SHOW=$((PORT+28)) P_SHOWJ=$((PORT+29)) STUB_SHOW_CTX=1000000 tests/stub $P_SHOW "SHOWCTX" & PIDS+=($!) -sleep 0.3 +wait_port "$P_SHOW" 30 || bad "the /api/show stub did not come up" cat > "$TMP/show.conf" < "$TMP/flight.conf" < "$TMP/flight.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port "$FPORT" 30 || bad "the flight instance did not come up" BODY='{"model":"m","messages":[{"role":"user","content":"teure frage"}],"max_tokens":5,"temperature":0}' ask() { @@ -78,6 +79,7 @@ esac # Modell-Listen sind reproduzierbar und werden ohne Temperatur gecacht. cat > "$TMP/models.conf" < "$TMP/models.log" 2>&1 & PIDS+=($!) -sleep 0.8 +wait_port $((FPORT+2)) 30 || bad "the model-list instance did not come up" # POST, weil der Test-Stub nur POST beantwortet; geprüft wird der Pfad, nicht die Methode. mfetch() { curl -s -m 10 -D - -o /dev/null -X POST -H 'Content-Type: application/json' \ diff --git a/tests/mcp_concurrency.py b/tests/mcp_concurrency.py index 84482a5..ee9d3e2 100644 --- a/tests/mcp_concurrency.py +++ b/tests/mcp_concurrency.py @@ -136,6 +136,7 @@ listen 127.0.0.1:{PORT} log_prefix jtest max_inflight 32 queue_timeout 60 +probe_interval 0 mcp_auth off mcp_cache_ttl 60 mcp fast url http://127.0.0.1:{fast_port}/mcp timeout 30 @@ -242,6 +243,8 @@ endpoint dummy {{ if z[1] == 200 and "fast:ok" not in z[2] and "slow:ok" not in z[2]] print(f" unversehrte Antworten: {40 - len(kaputt)}/40") if kaputt: + for z in kaputt[:3]: + print(f" kaputt: status={z[1]} body={z[2][:160]!r}") fehler.append(f"{len(kaputt)} zerrissene Antworten") finally: diff --git a/tests/retry-after.sh b/tests/retry-after.sh index ad4079e..49fb480 100755 --- a/tests/retry-after.sh +++ b/tests/retry-after.sh @@ -18,11 +18,13 @@ STUB_STATE="$TMP/ra.state" tests/stub $RSP "RA2" --fail-n 1 --retry-after 2 > "$ PIDS+=($!) STUB_STATE="$TMP/ra60.state" tests/stub $RDP "RA60" --fail-n 1 --retry-after 60 > "$TMP/ra_stub60.log" 2>&1 & PIDS+=($!) -sleep 0.4 +wait_port "$RSP" 30 || bad "the retry-after stub did not come up" +wait_port "$RDP" 30 || bad "the capped-retry stub did not come up" cat > "$TMP/ra.conf" < "$TMP/rc.conf" < "$TMP/rc.log" 2>&1 & PIDS+=($!) -wait_port "$RAP" 10 || bad "retry-after instance did not come up" -wait_port "$RCP" 10 || bad "capped-retry instance did not come up" +wait_port "$RAP" 30 || bad "retry-after instance did not come up" +wait_port "$RCP" 30 || bad "capped-retry instance did not come up" RABODY='{"model":"m","messages":[{"role":"user","content":"retry"}],"max_tokens":3}' @@ -83,11 +86,13 @@ PIDS+=($!) STUB_STATE="$TMP/rap.state" tests/stub $RPD "RAPAST" --fail-n 1 --retry-after-date -120 \ > "$TMP/ra_past.log" 2>&1 & PIDS+=($!) -sleep 0.4 +wait_port "$RDD" 30 || bad "the dated Retry-After stub did not come up" +wait_port "$RPD" 30 || bad "the past-date Retry-After stub did not come up" cat > "$TMP/rad.conf" < "$TMP/rap.conf" < "$TMP/rap.log" 2>&1 & PIDS+=($!) -wait_port "$RDP" 10 || bad "http-date instance did not come up" -wait_port "$RPP" 10 || bad "past-date instance did not come up" +wait_port "$RDP" 30 || bad "http-date instance did not come up" +wait_port "$RPP" 30 || bad "past-date instance did not come up" read -r dcode delapsed < <(curl -s -o /dev/null -m 30 -w '%{http_code} %{time_total}' \ -X POST -H 'Content-Type: application/json' -d "$RABODY" \ @@ -144,11 +150,12 @@ RBS=$((PORT+231)) STUB_STATE="$TMP/rab.state" tests/stub $RBS "RAB" --fail-n 100 --retry-after 30 \ > "$TMP/rab_stub.log" 2>&1 & PIDS+=($!) -wait_port "$RBS" 10 || bad "the cooldown stub did not come up" +wait_port "$RBS" 30 || bad "the cooldown stub did not come up" cat > "$TMP/rab.conf" < "$TMP/rab.log" 2>&1 & PIDS+=($!) -wait_port "$RBP" 10 || bad "cooldown instance did not come up" +wait_port "$RBP" 30 || bad "cooldown instance did not come up" curl -s -o /dev/null -m 20 -X POST -H 'Content-Type: application/json' -d "$RABODY" \ "http://127.0.0.1:$RBP/v1/chat/completions"