# Warten auf die Rückkehr der Kette (offline_wait) — sourced von tests/run.sh. # Erwartet PORT, TMP, PIDS, contains, log_has, ok, bad, wait_port aus run.sh. echo "== 29. Warten auf die Rückkehr der Kette ==" # Ein Endpunkt, der beim ersten Versuch nicht erreichbar ist, wird offline gesetzt. # Ist die GANZE Kette offline, ist sofortiges 503 die falsche Antwort — im Van kommt # der Uplink oft in Sekunden zurück. offline_wait lässt den Request so lange warten, # und zwar bevor er einen Upstream-Platz belegt. P_W=$((PORT+38)) P_DEADS=$((PORT+59)) cat > "$TMP/wait.conf" < "$TMP/wait.log" 2>&1 & PIDS+=($!) wait_port $P_W 10 C1=$(curl -s -m 15 -o /dev/null -w '%{http_code}' -X POST -H 'Content-Type: application/json' \ -d '{"model":"m","messages":[{"role":"user","content":"hi"}],"max_tokens":8}' \ "http://127.0.0.1:$P_W/v1/chat/completions") [ "$C1" = "503" ] && ok "with nothing listening the request fails as before" \ || bad "with nothing listening the request fails as before (got $C1)" # Jetzt kommt der Endpunkt hoch, aber junction hält ihn noch für offline. tests/stub $P_DEADS "LATE" & PIDS+=($!) # Ein belegter Port lässt den Stub still scheitern ("bind/listen") und die Prüfung # darunter wie ein Fehler im Router aussehen. Deshalb hier laut werden. wait_port $P_DEADS 5 || bad "the stub could not bind port $P_DEADS (is it taken?)" T0=$(date +%s%N) 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_W/v1/chat/completions") T1=$(date +%s%N) ELAPSED_MS=$(( (T1 - T0) / 1000000 )) contains "$R" "served by LATE" "a request waits for the chain instead of failing at once" if [ "$ELAPSED_MS" -ge 800 ]; then ok "it waited for the offline hold to expire (${ELAPSED_MS} ms)" else bad "it waited for the offline hold to expire (${ELAPSED_MS} ms)" fi log_has "$TMP/wait.log" "offline_wait rule_line=" "the wait is logged once" M=$(curl -s -m 5 "http://127.0.0.1:$P_W/metrics") contains "$M" "junction_offline_waits_total 1" "the wait is counted in /metrics" S=$(curl -s -m 5 "http://127.0.0.1:$P_W/status") contains "$S" '"offline_wait_s":5' "/status reports the configured wait"