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.
66 lines
2.4 KiB
Bash
66 lines
2.4 KiB
Bash
#!/bin/bash
|
|
# Wird von tests/run.sh eingebunden: Antwort-Cache und seine Grenze.
|
|
|
|
echo "== 22. Cache nur für vorhersagbare Antworten =="
|
|
|
|
XPORT=$((PORT+51))
|
|
cat > "$TMP/cache.conf" <<CFG
|
|
listen 127.0.0.1:$XPORT
|
|
cache_ttl 300
|
|
cache_entries 50
|
|
cache_bytes 2000000
|
|
endpoint a { base http://127.0.0.1:$P_GATED/v1 }
|
|
req for "*" pass a
|
|
CFG
|
|
./junction --config "$TMP/cache.conf" > "$TMP/cache.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$XPORT" 30 || bad "the cache instance did not come up"
|
|
|
|
ask() { # ask <body> -> Cache-Zustand aus dem Kopf
|
|
curl -s -m 10 -D - -o /dev/null -X POST -H 'Content-Type: application/json' -d "$1" \
|
|
"http://127.0.0.1:$XPORT/v1/chat/completions" \
|
|
| tr -d '\r' | sed -n 's/^[Xx]-[Jj]unction-[Cc]ache: //p'
|
|
}
|
|
|
|
DET='{"model":"m","messages":[{"role":"user","content":"dieselbe frage"}],"max_tokens":5,"temperature":0}'
|
|
HOT='{"model":"m","messages":[{"role":"user","content":"dieselbe frage"}],"max_tokens":5,"temperature":0.7}'
|
|
NONE='{"model":"m","messages":[{"role":"user","content":"dieselbe frage"}],"max_tokens":5}'
|
|
|
|
[ "$(ask "$DET")" = "miss" ] && ok "first deterministic request misses the cache" \
|
|
|| bad "first deterministic request did not report a miss"
|
|
[ "$(ask "$DET")" = "hit" ] && ok "second identical request is served from the cache" \
|
|
|| bad "second identical request was not cached"
|
|
|
|
if [ "$(ask "$HOT")" = "off" ]; then
|
|
ok "a request with temperature above zero is never cached"
|
|
else
|
|
bad "a non-deterministic request was routed through the cache"
|
|
fi
|
|
|
|
if [ "$(ask "$NONE")" = "off" ]; then
|
|
ok "a request without a stated temperature is not cached"
|
|
else
|
|
bad "a request without a temperature was cached anyway"
|
|
fi
|
|
|
|
# Einbetter sind reproduzierbar: derselbe Text ergibt denselben Vektor.
|
|
EMB='{"model":"e","input":"derselbe text"}'
|
|
emb_state() {
|
|
curl -s -m 10 -D - -o /dev/null -X POST -H 'Content-Type: application/json' -d "$EMB" \
|
|
"http://127.0.0.1:$XPORT/v1/embeddings" | tr -d '\r' \
|
|
| sed -n 's/^[Xx]-[Jj]unction-[Cc]ache: //p'
|
|
}
|
|
emb_state >/dev/null # erster Aufruf füllt
|
|
OUT=$(emb_state)
|
|
if [ "$OUT" = "hit" ]; then
|
|
ok "an embedding request is cached without asking for a temperature"
|
|
else
|
|
bad "an embedding request was not cached (state: ${OUT:-none})"
|
|
fi
|
|
|
|
STATUS=$(curl -s -m 5 "http://127.0.0.1:$XPORT/status")
|
|
case "$STATUS" in
|
|
*'"hits":'*) ok "/status reports cache counters" ;;
|
|
*) bad "/status has no cache counters" ;;
|
|
esac
|