Files
Hermes 83a56eb11d 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.
2026-11-19 06:59:55 +00:00

89 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Wird von tests/run.sh eingebunden: ein Modell zur Zeit, aber mehrere Modelle parallel.
#
# Der Fall dahinter: eine lokale Box hält ein Modell im Speicher. Zwei Anfragen an
# dasselbe Modell machen sie nicht schneller, sondern treiben sie in den Swap. Zwei
# Anfragen an verschiedene Modelle dagegen sind zwei Modelle, die geladen sind — die
# dürfen gleichzeitig laufen. Und der Client soll `local/<modell>` verlangen dürfen,
# ohne dass die Box den Präfix je sieht.
echo
echo "== 37. Eine Anfrage je Modell, mehrere Modelle parallel =="
LP=$((PORT+220))
LSTUB=$((PORT+221))
# 2 s Antwortzeit: damit lässt sich messen, ob zwei Anfragen seriell (4 s) oder
# parallel (2 s) liefen.
tests/stub $LSTUB "LOCAL" --delay 2 > "$TMP/local_stub.log" 2>&1 &
PIDS+=($!)
wait_port "$LSTUB" 10 || bad "the parallel stub did not come up"
cat > "$TMP/local.conf" <<CFG
listen 127.0.0.1:$LP
log_prefix lp
queue_timeout 30
max_inflight 8
endpoint box {
base http://127.0.0.1:$LSTUB/v1
timeout 30
max_model_inflight 1
}
req for "local/*" strip "local/" pass box
req for "*" pass box
CFG
./junction --config "$TMP/local.conf" > "$TMP/local.log" 2>&1 &
PIDS+=($!)
wait_port "$LP" 10 || bad "the local pool instance did not come up"
ask_local() { # ask_local <model> -> Körper der Antwort
curl -s -m 30 -X POST -H 'Content-Type: application/json' \
-d "{\"model\":\"$1\",\"messages\":[{\"role\":\"user\",\"content\":\"hallo\"}],\"max_tokens\":4}" \
"http://127.0.0.1:$LP/v1/chat/completions"
}
timed_pair() { # timed_pair <mod1> <mod2> -> Sekunden für beide zusammen
local start=$(date +%s%N)
ask_local "$1" > "$TMP/lp1.txt" &
local a=$!
ask_local "$2" > "$TMP/lp2.txt" &
local b=$!
wait $a $b
echo $(( ($(date +%s%N) - start) / 1000000000 ))
}
same=$(timed_pair "local/qwen3.6-35b" "local/qwen3.6-35b")
if [ "$same" -ge 3 ] && [ "$same" -le 8 ]; then
ok "two requests for the same model wait for each other (${same}s, one at a time)"
else
bad "same model ran in parallel: ${same}s instead of ~4 s"
fi
diff=$(timed_pair "local/qwen3.6-35b" "local/llama-3-8b")
if [ "$diff" -ge 1 ] && [ "$diff" -le 4 ]; then
ok "two different models run in parallel (${diff}s, not serialised)"
else
bad "different models were serialised: ${diff}s instead of ~2 s"
fi
# Der Präfix darf die Box nie erreichen — sonst antwortet sie mit 404 oder hängt.
# Der Stub meldet, was er bekommen hat, in X-Stub-Model (der Rumpf nennt seinen eigenen
# Namen, nicht den angefragten).
curl -s -m 30 -D "$TMP/lp_h.txt" -o /dev/null -X POST -H 'Content-Type: application/json' \
-d '{"model":"local/qwen3.6-35b","messages":[{"role":"user","content":"hallo"}],"max_tokens":4}' \
"http://127.0.0.1:$LP/v1/chat/completions"
seen=$(tr -d '\r' < "$TMP/lp_h.txt" | sed -n 's/^X-Stub-Model: //p' | head -1)
if [ "$seen" = "qwen3.6-35b" ]; then
ok "the strip removed local/ before the request left the router ($seen)"
else
bad "the box received model '$seen' instead of qwen3.6-35b"
fi
# Und die Grenze ist wirklich pro Modell, nicht pro Box: zwei Modelle gleichzeitig
# dürfen die Box nicht als Ganzes blockieren (oben gemessen), aber ein Modell darf
# auch nicht mehr als einen Platz bekommen.
if grep -q "model_queue_timeout" "$TMP/local.log"; then
bad "a model request timed out instead of waiting"
else
ok "waiting requests are queued, not refused"
fi