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.
109 lines
3.4 KiB
Bash
109 lines
3.4 KiB
Bash
#!/bin/bash
|
|
# Wird von tests/run.sh eingebunden: Gewichtung, Balance pro Regel, Zeitlimits.
|
|
# Erwartet: $TMP, $PORT, $P_GATED, $P_FAIL, ok/bad/contains, ./junction
|
|
|
|
echo "== 19. Gewichtung, Balance pro Regel, Verbindungs-Zeitlimit =="
|
|
|
|
# Für die Verteilung braucht es ZWEI gesunde Ziele. GATED antwortet; ein zweiter Stub
|
|
# mit eigenem Namen kommt dazu, weil der vorhandene "FAILING" absichtlich ausfällt und
|
|
# dann immer das erste Ziel bedient würde.
|
|
BA=$P_GATED
|
|
BB=$((PORT+21))
|
|
BJ=$((PORT+23))
|
|
tests/stub $BB "ZWEIT" > /dev/null 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$BB" 10 || bad "the weighted stub did not come up"
|
|
|
|
cat > "$TMP/bal.conf" <<CFG
|
|
listen 127.0.0.1:$BJ
|
|
connect_timeout_ms 2000
|
|
balance round-robin
|
|
|
|
endpoint stark {
|
|
base http://127.0.0.1:$BA/v1
|
|
weight 3
|
|
timeout 10
|
|
}
|
|
|
|
endpoint schwach {
|
|
base http://127.0.0.1:$BB/v1
|
|
weight 1
|
|
timeout 10
|
|
}
|
|
|
|
# Diese Regel will reines Failover, egal was global eingestellt ist.
|
|
req for "starr*" balance first pass stark, schwach
|
|
req for "*" pass stark, schwach
|
|
CFG
|
|
|
|
./junction --config "$TMP/bal.conf" > "$TMP/bal.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$BJ" 30 || bad "the balance instance did not come up"
|
|
|
|
# 1. Gewichtetes Reihum: 3:1 soll sich in der Verteilung zeigen
|
|
A=0; B=0
|
|
for i in $(seq 1 40); do
|
|
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:$BJ/v1/chat/completions")
|
|
case "$R" in
|
|
*"served by GATED"*) A=$((A+1));;
|
|
*"served by ZWEIT"*) B=$((B+1));;
|
|
esac
|
|
done
|
|
# Ein Ziel mit Gewicht 3 soll deutlich häufiger drankommen als eines mit Gewicht 1.
|
|
if [ "$A" -ge 24 ] && [ "$B" -ge 6 ]; then
|
|
ok "weighted round-robin: $A zu $B bei Gewicht 3:1"
|
|
else
|
|
bad "weighted round-robin verteilte $A zu $B, erwartet etwa 30 zu 10"
|
|
fi
|
|
|
|
# 2. balance first in der Regel schlägt das globale round-robin
|
|
FIRST=0
|
|
for i in $(seq 1 6); do
|
|
R=$(curl -s -m 10 -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"starr-modell","messages":[{"role":"user","content":"hi"}]}' \
|
|
"http://127.0.0.1:$BJ/v1/chat/completions")
|
|
case "$R" in *"served by GATED"*) FIRST=$((FIRST+1));; esac
|
|
done
|
|
if [ "$FIRST" -eq 6 ]; then
|
|
ok "a rule's own 'balance first' overrides the global round-robin"
|
|
else
|
|
bad "rule-level balance did not override the global mode ($FIRST/6 on the first target)"
|
|
fi
|
|
|
|
# 3. Verbindungs-Zeitlimit pro Endpunkt: ein unerreichbares Ziel darf die Kette nicht
|
|
# aufhalten, sondern muss schnell weiterreichen.
|
|
cat > "$TMP/conn.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+24))
|
|
connect_timeout_ms 30000
|
|
|
|
endpoint langsam {
|
|
base http://10.255.255.1:9/v1
|
|
connect_timeout_ms 400
|
|
timeout 30
|
|
}
|
|
|
|
endpoint gesund {
|
|
base http://127.0.0.1:$BA/v1
|
|
timeout 10
|
|
}
|
|
|
|
req for "*" pass langsam, gesund
|
|
CFG
|
|
./junction --config "$TMP/conn.conf" > "$TMP/conn.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port $((PORT + 24)) 30 || bad "the connect-timeout instance did not come up"
|
|
START=$(date +%s%N)
|
|
R=$(curl -s -m 30 -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"x","messages":[{"role":"user","content":"hi"}]}' \
|
|
"http://127.0.0.1:$((PORT+24))/v1/chat/completions")
|
|
END=$(date +%s%N)
|
|
MS=$(( (END-START)/1000000 ))
|
|
contains "$R" "served by GATED" "the chain moves past an unreachable endpoint"
|
|
if [ "$MS" -lt 5000 ]; then
|
|
ok "the per-endpoint connect timeout fired after ${MS} ms, not the global 30 s"
|
|
else
|
|
bad "the per-endpoint connect timeout did not apply (${MS} ms)"
|
|
fi
|