Ein Lauf nach frischem `make clean` fiel mit vier Fehlern durch, die nichts mit dem Code zu tun hatten: "soft budget delays the request (8 ms)", "the refusal names the reason: text-only endpoint (missing 'text-only')" und "a one-line endpoint block is enough to serve a request (missing 'served by GATED')". Alle drei schicken eine einzige Anfrage kurz nach dem Start und nehmen an, dass "0,7 s" reicht — unter Last (kompiliert, gescrapt, Container-Churn) reicht es nicht immer, und dann misst die Prüfung eine Verbindung, die noch niemand annimmt. Jetzt wartet die Suite: wait_port pollt bis zu 10 s, bis der Listener annimmt, statt eine Zeit zu raten. Beim Soft-Budget-Test zusätzlich: statt 2,5 s zu schlafen wird gewartet, bis /status den Prozentwert wirklich zeigt (usage_poll 1 s) — das ist die Bedingung, die die Prüfung braucht. Zwei Läufe hintereinander: PASS, 146 Prüfungen, keine Restprozesse.
70 lines
2.5 KiB
Bash
70 lines
2.5 KiB
Bash
#!/bin/bash
|
|
# Wird von tests/run.sh eingebunden: benannte Ketten (pool) und einzeilige Blöcke.
|
|
|
|
echo "== 20. Pools und einzeilige Endpunkt-Blöcke =="
|
|
|
|
# 1. Einzeiliger Block: alles in einer Zeile, keine Klammerzeile nötig.
|
|
cat > "$TMP/inline.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+31))
|
|
endpoint kurz { base http://127.0.0.1:$P_GATED/v1; timeout 5; weight 2 }
|
|
req for "*" pass kurz
|
|
CFG
|
|
./junction --config "$TMP/inline.conf" > "$TMP/inline.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port $((PORT+31)) 10
|
|
R=$(curl -s -m 10 -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"x","messages":[{"role":"user","content":"hi"}]}' \
|
|
"http://127.0.0.1:$((PORT+31))/v1/chat/completions")
|
|
contains "$R" "served by GATED" "a one-line endpoint block is enough to serve a request"
|
|
grep -q 'endpoint kurz: block not closed' "$TMP/inline.log" && \
|
|
bad "the one-line block was mistaken for an open block" || \
|
|
ok "the one-line block leaves no block open"
|
|
|
|
# 2. Pool: eine Kette bekommt einen Namen, die Regel benutzt ihn.
|
|
cat > "$TMP/pool.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+32))
|
|
endpoint eins { base http://127.0.0.1:$P_GATED/v1 }
|
|
endpoint zwei { base http://127.0.0.1:$((PORT+21))/v1 }
|
|
|
|
pool kette eins, zwei
|
|
req for "*" pass kette
|
|
CFG
|
|
./junction --config "$TMP/pool.conf" > "$TMP/pool.log" 2>&1 &
|
|
PIDS+=($!)
|
|
sleep 0.8
|
|
POOL=$(curl -s -m 5 "http://127.0.0.1:$((PORT+32))/status")
|
|
case "$POOL" in
|
|
*'"targets":"eins, zwei"'*|*'eins, zwei'*) ok "pool expands to its targets in the rule" ;;
|
|
*) bad "pool did not expand (status: $(printf '%s' "$POOL" | head -c 120))" ;;
|
|
esac
|
|
|
|
# 3. Verschachtelte Pools: alles → lokal → zwei Ziele
|
|
cat > "$TMP/pool2.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+33))
|
|
endpoint a { base http://127.0.0.1:$P_GATED/v1 }
|
|
endpoint b { base http://127.0.0.1:$((PORT+21))/v1 }
|
|
pool lokal a, b
|
|
pool alles lokal
|
|
req for "*" pass alles
|
|
CFG
|
|
./junction --config "$TMP/pool2.conf" > "$TMP/pool2.log" 2>&1 &
|
|
PIDS+=($!)
|
|
sleep 0.8
|
|
P2=$(curl -s -m 5 "http://127.0.0.1:$((PORT+33))/status")
|
|
case "$P2" in
|
|
*'a, b'*) ok "a pool may name another pool" ;;
|
|
*) bad "nested pools did not resolve" ;;
|
|
esac
|
|
|
|
# 4. Ein unbekannter Name bleibt ein Fehler — kein stiller Durchlauf.
|
|
cat > "$TMP/poolbad.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+34))
|
|
endpoint a { base http://127.0.0.1:$P_GATED/v1 }
|
|
req for "*" pass gibtesnicht
|
|
CFG
|
|
OUT=$(./junction --config "$TMP/poolbad.conf" --port $((PORT+34)) 2>&1 | head -1)
|
|
case "$OUT" in
|
|
*"unknown endpoint"*) ok "an unknown pool or endpoint name is refused" ;;
|
|
*) bad "unknown name was not refused: $OUT" ;;
|
|
esac
|