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.
This commit is contained in:
1 parent
b582f34649
commit
83a56eb11d
11 files changed
+31
-18
No files matched your search
+3
-3
@@ -12,7 +12,7 @@ BB=$((PORT+21))
|
||||
BJ=$((PORT+23))
|
||||
tests/stub $BB "ZWEIT" > /dev/null 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.4
|
||||
wait_port "$BB" 10 || bad "the weighted stub did not come up"
|
||||
|
||||
cat > "$TMP/bal.conf" <<CFG
|
||||
listen 127.0.0.1:$BJ
|
||||
@@ -38,7 +38,7 @@ CFG
|
||||
|
||||
./junction --config "$TMP/bal.conf" > "$TMP/bal.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.8
|
||||
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
|
||||
@@ -93,7 +93,7 @@ req for "*" pass langsam, gesund
|
||||
CFG
|
||||
./junction --config "$TMP/conn.conf" > "$TMP/conn.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.8
|
||||
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"}]}' \
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ req for "*" pass a
|
||||
CFG
|
||||
./junction --config "$TMP/cache.conf" > "$TMP/cache.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.8
|
||||
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" \
|
||||
|
||||
+2
-2
@@ -138,7 +138,7 @@ req for "*" pass a
|
||||
CFG
|
||||
./junction --config "$TMP/meshC.conf" > "$TMP/meshC.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.6
|
||||
wait_log "$TMP/meshC.log" "disabled: cache tcp without cache secret_env" 10
|
||||
log_has "$TMP/meshC.log" "disabled: cache tcp without cache secret_env" \
|
||||
"a peer port without a secret stays closed"
|
||||
|
||||
@@ -202,7 +202,7 @@ code=$(curl -s -o /dev/null -w '%{http_code}' -m 10 -X POST -H 'Content-Type: ap
|
||||
sed 's/so_reuseport on/so_reuseport off/; s/roll1/roll3/' "$TMP/roll1.conf" > "$TMP/roll3.conf"
|
||||
./junction --config "$TMP/roll3.conf" > "$TMP/roll3.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.6
|
||||
wait_log "$TMP/roll3.log" "Address already in use" 10
|
||||
log_has "$TMP/roll3.log" "Address already in use" \
|
||||
"without so_reuseport the port stays exclusive"
|
||||
|
||||
|
||||
+4
-4
@@ -23,7 +23,7 @@ class H(http.server.BaseHTTPRequestHandler):
|
||||
http.server.HTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
|
||||
PY
|
||||
python3 "$TMP/echo.py" $((CPORT+1)) & PIDS+=($!)
|
||||
sleep 0.6
|
||||
wait_port $((CPORT + 1)) 10 || bad "the compress echo stub did not come up"
|
||||
|
||||
cat > "$TMP/comp.conf" <<CFG
|
||||
listen 127.0.0.1:$CPORT
|
||||
@@ -35,7 +35,7 @@ req for "*" pass echo
|
||||
CFG
|
||||
./junction --config "$TMP/comp.conf" > "$TMP/comp.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.8
|
||||
wait_port "$CPORT" 30 || bad "the compress instance did not come up"
|
||||
|
||||
# Rumpf bauen: eine sehr lange Werkzeugausgabe, danach zwei kurze Nachrichten.
|
||||
python3 - "$TMP/req.json" <<'PY'
|
||||
@@ -119,7 +119,7 @@ esac
|
||||
|
||||
# 5. Pro Endpunkt: einer kürzt, der andere nicht — derselbe Rumpf, zwei Rümpfe
|
||||
python3 "$TMP/echo.py" $((CPORT+2)) & PIDS+=($!)
|
||||
sleep 0.6
|
||||
wait_port $((CPORT + 2)) 10 || bad "the second echo stub did not come up"
|
||||
cat > "$TMP/split.conf" <<CFG
|
||||
listen 127.0.0.1:$((CPORT+3))
|
||||
compress off
|
||||
@@ -132,7 +132,7 @@ req for "gross*" pass gross
|
||||
CFG
|
||||
./junction --config "$TMP/split.conf" > "$TMP/split.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.8
|
||||
wait_port $((CPORT + 3)) 30 || bad "the split instance did not come up"
|
||||
|
||||
SEND=$(python3 -c '
|
||||
import json
|
||||
|
||||
@@ -10,7 +10,8 @@ CFB=$((PORT+262))
|
||||
|
||||
STUB_CTX=4096 STUB_OUT=1000 tests/stub $CFS "SMALL" & PIDS+=($!)
|
||||
STUB_CTX=200000 STUB_OUT=1000 tests/stub $CFB "BIG" & PIDS+=($!)
|
||||
sleep 0.3
|
||||
wait_port "$CFS" 10 && wait_port "$CFB" 10 \
|
||||
|| bad "the ctx-fallback stubs did not come up"
|
||||
|
||||
cat > "$TMP/ctx-fallback.conf" <<CFG
|
||||
listen 127.0.0.1:$CF
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ OP=$((PORT+252))
|
||||
EPS=$((PORT+251))
|
||||
|
||||
tests/stub $EPS "EFFORT" & PIDS+=($!)
|
||||
sleep 0.3
|
||||
wait_port "$EPS" 10 || bad "the effort stub did not come up"
|
||||
|
||||
# Anthropic: OpenAI-Effort wird output_config.effort; das Modell verliert "#variant".
|
||||
# Ein eigener Schlüssel und die statische Versionszeile prüfen zugleich, dass der
|
||||
|
||||
@@ -13,7 +13,7 @@ E2=$((PORT+227))
|
||||
|
||||
tests/stub $E2 "ENVSTUB" > "$TMP/env_stub.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.4
|
||||
wait_port "$E2" 10 || bad "the env stub did not come up"
|
||||
|
||||
# Keine Endpunkt-Blöcke, nur eine Regel — der Endpunkt soll aus der Umgebung kommen.
|
||||
cat > "$TMP/env.conf" <<CFG
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ LSTUB=$((PORT+221))
|
||||
# parallel (2 s) liefen.
|
||||
tests/stub $LSTUB "LOCAL" --delay 2 > "$TMP/local_stub.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.4
|
||||
wait_port "$LSTUB" 10 || bad "the parallel stub did not come up"
|
||||
|
||||
cat > "$TMP/local.conf" <<CFG
|
||||
listen 127.0.0.1:$LP
|
||||
|
||||
@@ -9,7 +9,7 @@ MPS=$((PORT+241))
|
||||
|
||||
STUB_MODELS="foo,bar,baz,ma/bla,opencode-go0/x,other/x,deepseek-v4.1-flash" \
|
||||
tests/stub $MPS "MODELS" & PIDS+=($!)
|
||||
sleep 0.3
|
||||
wait_port "$MPS" 10 || bad "the model-list stub did not come up"
|
||||
|
||||
cat > "$TMP/model-policy.conf" <<CFG
|
||||
listen 127.0.0.1:$MP
|
||||
|
||||
+3
-3
@@ -9,7 +9,7 @@ OC_JUNC=$((PORT+19))
|
||||
|
||||
python3 tests/opencode_stub.py $OC_PORT > "$TMP/oc-stub.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.6
|
||||
wait_port "$OC_PORT" 10 || bad "the opencode stub did not come up"
|
||||
|
||||
printf 'opencode:testpasswort\n' > "$TMP/oc.pass"
|
||||
chmod +x "$TMP/oc.pass"
|
||||
@@ -43,7 +43,7 @@ CFG
|
||||
|
||||
./junction --config "$TMP/oc.conf" > "$TMP/oc.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.8
|
||||
wait_port "$OC_JUNC" 30 || bad "the opencode bridge did not come up"
|
||||
|
||||
# 1. Modellliste kommt als OpenAI-Liste, ohne die Varianten der Modelle
|
||||
R=$(curl -s -m 20 "http://127.0.0.1:$OC_JUNC/v1/models")
|
||||
@@ -173,7 +173,7 @@ chmod +x "$TMP/oc.bad.sh"
|
||||
sed "s|pass_cmd .*|pass_cmd \"$TMP/oc.bad.sh\"|; s|$OC_JUNC|$((PORT+20))|" "$TMP/oc.conf" > "$TMP/oc2.conf"
|
||||
./junction --config "$TMP/oc2.conf" > "$TMP/oc2.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
sleep 0.8
|
||||
wait_port $((PORT + 20)) 30 || bad "the pass_cmd instance did not come up"
|
||||
R=$(curl -s -m 20 -X POST -H 'Content-Type: application/json' \
|
||||
-d '{"model":"x","messages":[{"role":"user","content":"hi"}]}' \
|
||||
"http://127.0.0.1:$((PORT+20))/v1/chat/completions")
|
||||
|
||||
@@ -54,6 +54,18 @@ wait_port() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# Warten, bis eine Zeile im Log steht: ein Router, der nicht lauschen soll
|
||||
# (mesh ohne Geheimnis) oder nicht lauschen darf (Port belegt), ist nur am Log
|
||||
# zu erkennen. Ein fester sleep war hier reine Glueckssache.
|
||||
wait_log() {
|
||||
local file=$1 pat=$2 limit=$(( ${3:-10} * 20 )) i=0
|
||||
while [ "$i" -lt "$limit" ]; do
|
||||
grep -q "$pat" "$file" 2>/dev/null && return 0
|
||||
sleep 0.05; i=$((i+1))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Ein Port, der gerade freigegeben wurde, ist nicht sofort wieder belegbar: nach SIGTERM
|
||||
# hält junction den Listener noch restart_grace_s offen und antwortet "restarting".
|
||||
# Wer den Port wiederverwenden will, wartet, bis er wirklich frei ist.
|
||||
|
||||
Reference in new issue
Block a user