Skip to content

Commit b4bf9a0

Browse files
committed
fix: make media port test resilient to backend startup races
Poll /health and retry connection-aborted requests inside the test, and require consecutive CI health checks, to avoid RemoteDisconnected on a freshly started status-backend container.
1 parent 84e6e69 commit b4bf9a0

2 files changed

Lines changed: 36 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ jobs:
2525

2626
- name: Wait for backend health
2727
run: |
28+
ok=0
2829
for i in $(seq 1 60); do
29-
if curl -fsS http://127.0.0.1:8080/health; then
30-
exit 0
30+
if curl -fsS http://127.0.0.1:8080/health >/dev/null; then
31+
ok=$((ok + 1))
32+
if [ "$ok" -ge 3 ]; then
33+
echo "backend healthy ($ok consecutive checks)"
34+
exit 0
35+
fi
36+
else
37+
ok=0
3138
fi
3239
sleep 5
3340
done

tests/test_media_server_port.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,32 @@ def close(self):
7575
self._stop = True
7676

7777

78-
def post_json(path: str, payload: dict | None = None) -> dict:
79-
resp = requests.post(f"{HTTP_BASE}/{path}", json=payload or {}, timeout=60)
80-
resp.raise_for_status()
81-
if not resp.content:
82-
return {}
83-
return resp.json()
78+
def post_json(path: str, payload: dict | None = None, retries: int = 3) -> dict:
79+
last_exc: Exception | None = None
80+
for attempt in range(retries):
81+
try:
82+
resp = requests.post(f"{HTTP_BASE}/{path}", json=payload or {}, timeout=60)
83+
resp.raise_for_status()
84+
if not resp.content:
85+
return {}
86+
return resp.json()
87+
except requests.ConnectionError as exc:
88+
last_exc = exc
89+
time.sleep(2 * (attempt + 1))
90+
raise RuntimeError(f"POST {path} failed after {retries} retries: {last_exc}")
91+
92+
93+
def wait_backend_healthy(timeout: float = 180) -> None:
94+
deadline = time.monotonic() + timeout
95+
last_exc: Exception | None = None
96+
while time.monotonic() < deadline:
97+
try:
98+
if requests.get("http://127.0.0.1:8080/health", timeout=5).status_code == 200:
99+
return
100+
except requests.RequestException as exc:
101+
last_exc = exc
102+
time.sleep(2)
103+
raise RuntimeError(f"backend not healthy within {timeout}s: {last_exc}")
84104

85105

86106
def initialize() -> dict:
@@ -176,6 +196,7 @@ def signals():
176196

177197

178198
def test_media_port_persists_across_logout_reinit(signals):
199+
wait_backend_healthy()
179200
logout(signals)
180201
since = signals.count("mediaserver.started")
181202
init_data = initialize()

0 commit comments

Comments
 (0)