tests: Startrennen und Hintergrundproben unter Last entschärfen

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.
This commit is contained in:
Hermes committed 2026-11-18 08:47:15 +00:00
1 parent 2c649691e2
commit 879eac5241
6 files changed
+63 -28

No files matched your search

+8
View File
@@ -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) {
+20 -11
View File
@@ -21,6 +21,7 @@ MESH=$(echo '{"model":"m","messages":[{"role":"user","content":"wo war ich"}],"m
cat > "$TMP/meshA.conf" <<CFG
listen 127.0.0.1:$CA
log_prefix meshA
probe_interval 0
cache_ttl 300
cache_entries 50
cache_bytes 2000000
@@ -33,6 +34,7 @@ CFG
cat > "$TMP/meshB.conf" <<CFG
listen 127.0.0.1:$CB
log_prefix meshB
probe_interval 0
cache_ttl 300
cache_entries 50
cache_bytes 2000000
@@ -48,8 +50,8 @@ J_MESH_SECRET="$SECRET" ./junction --config "$TMP/meshA.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" <<CFG
listen 127.0.0.1:$((PORT+207))
log_prefix meshD
probe_interval 0
cache_ttl 300
cache_secret_env J_MESH_SECRET
cache_peer 127.0.0.1:$P_SLOW
@@ -109,11 +116,11 @@ req for "*" pass a
CFG
J_MESH_SECRET="$SECRET" ./junction --config "$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" <<CFG
listen 127.0.0.1:$((PORT+204))
log_prefix meshC
probe_interval 0
cache_ttl 60
cache tcp 127.0.0.1:$((PORT+205))
endpoint a { base http://127.0.0.1:$P_GATED/v1 }
@@ -141,6 +149,7 @@ RP=$((PORT+206))
cat > "$TMP/roll1.conf" <<CFG
listen 127.0.0.1:$RP
log_prefix roll1
probe_interval 0
so_reuseport on
drain_timeout 5
cache_ttl 60
@@ -152,7 +161,7 @@ sed 's/roll1/roll2/' "$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)
+12 -6
View File
@@ -7,6 +7,7 @@ echo "== 17. ctx filters and vision routing =="
cat > "$TMP/ctx.conf" <<CFG
listen 127.0.0.1:$((PORT+15))
ctx_chars_per_token 4
probe_interval 0
endpoint textbox {
base http://127.0.0.1:$P_GATED/v1
@@ -33,7 +34,7 @@ CFG
./junction --config "$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" <<CFG
listen 127.0.0.1:$((PORT+16))
ctx_chars_per_token 4
probe_interval 0
endpoint textonly {
base http://127.0.0.1:$P_GATED/v1
@@ -100,7 +102,7 @@ req for "*" pass textonly, any
CFG
./junction --config "$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" <<CFG
listen 127.0.0.1:$((PORT+17))
probe_interval 0
endpoint textonly {
base http://127.0.0.1:$P_GATED/v1
context 64000
@@ -120,7 +123,7 @@ req for "*" pass textonly
CFG
./junction --config "$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" <<CFG
listen 127.0.0.1:$((PORT+27))
ctx_chars_per_token 4
probe_interval 0
endpoint box {
base http://127.0.0.1:$port/v1
context 1000
@@ -161,7 +166,7 @@ req for "*" pass box
CFG
./junction --config "$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" <<CFG
listen 127.0.0.1:$P_SHOWJ
ctx_chars_per_token 4
probe_interval 0
endpoint box {
base http://127.0.0.1:$P_SHOW/v1
context 1000
+5 -3
View File
@@ -25,10 +25,11 @@ class H(http.server.BaseHTTPRequestHandler):
http.server.HTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
PY
python3 "$TMP/slow.py" "$SPORT" & PIDS+=($!)
sleep 0.6
wait_port "$SPORT" 30 || bad "the slow stub did not come up"
cat > "$TMP/flight.conf" <<CFG
listen 127.0.0.1:$FPORT
probe_interval 0
cache_ttl 300
cache_entries 50
cache_bytes 2000000
@@ -37,7 +38,7 @@ req for "*" pass slow
CFG
./junction --config "$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" <<CFG
listen 127.0.0.1:$((FPORT+2))
probe_interval 0
cache_ttl 300
cache_entries 50
cache_bytes 2000000
@@ -87,7 +89,7 @@ req for "*" pass a
CFG
./junction --config "$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' \
+3
View File
@@ -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:
+15 -8
View File
@@ -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" <<CFG
listen 127.0.0.1:$RAP
log_prefix ra
probe_interval 0
retry_num 1
retry_backoff 0.2
retry_max_wait 30
@@ -32,6 +34,7 @@ CFG
cat > "$TMP/rc.conf" <<CFG
listen 127.0.0.1:$RCP
log_prefix rc
probe_interval 0
retry_num 1
retry_backoff 0.2
retry_max_wait 1
@@ -42,8 +45,8 @@ CFG
PIDS+=($!)
./junction --config "$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" <<CFG
listen 127.0.0.1:$RDP
log_prefix rad
probe_interval 0
retry_num 1
retry_backoff 0.2
retry_max_wait 30
@@ -97,6 +102,7 @@ CFG
cat > "$TMP/rap.conf" <<CFG
listen 127.0.0.1:$RPP
log_prefix rap
probe_interval 0
retry_num 1
retry_backoff 0.2
retry_max_wait 30
@@ -107,8 +113,8 @@ CFG
PIDS+=($!)
./junction --config "$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" <<CFG
listen 127.0.0.1:$RBP
log_prefix rab
probe_interval 0
retry_num 0
retry_backoff 0.2
endpoint a {
@@ -160,7 +167,7 @@ req for "*" check none pass a
CFG
./junction --config "$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"