Fixed stabilize e2e SSE event handling
ci/woodpecker/push/02-build-push Pipeline was canceled
ci/woodpecker/manual/e2e-smoke-jetson Pipeline was successful
ci/woodpecker/manual/01-test Pipeline failed
ci/woodpecker/manual/02-build-push Pipeline was successful

This commit is contained in:
Roman Meshko
2026-05-08 18:05:51 +03:00
parent 562ad14b09
commit b2af48a2e5
2 changed files with 66 additions and 76 deletions
+2 -39
View File
@@ -1,10 +1,7 @@
import json
import threading
import time
import uuid
import pytest
import sseclient
def _ai_config_video() -> dict:
@@ -31,50 +28,16 @@ def test_ft_p08_immediate_async_response(
@pytest.mark.timeout(30)
def test_ft_p09_sse_event_delivery(
warm_engine, http_client, jwt_token
warm_engine, http_client, jwt_token, sse_events_until_terminal
):
media_id = f"event-{uuid.uuid4().hex}"
channel_id = str(uuid.uuid4())
body = _ai_config_video()
auth_header = {"Authorization": f"Bearer {jwt_token}"}
post_headers = {**auth_header, "X-Channel-Id": channel_id}
collected: list[dict] = []
thread_exc: list[BaseException] = []
first_event = threading.Event()
connected = threading.Event()
def _listen():
try:
with http_client.get(
f"/detect/events/{channel_id}",
stream=True,
timeout=600,
headers=auth_header,
) as resp:
resp.raise_for_status()
connected.set()
for event in sseclient.SSEClient(resp).events():
if not event.data or not str(event.data).strip():
continue
data = json.loads(event.data)
collected.append(data)
first_event.set()
if data.get("mediaStatus") in ("AIProcessed", "Error"):
break
except BaseException as e:
thread_exc.append(e)
finally:
connected.set()
first_event.set()
th = threading.Thread(target=_listen, daemon=True)
th.start()
connected.wait(timeout=5)
r = http_client.post(f"/detect/{media_id}", json=body, headers=post_headers)
assert r.status_code == 202
first_event.wait(timeout=5)
th.join(timeout=5)
assert not thread_exc, thread_exc
collected = sse_events_until_terminal(channel_id, headers=auth_header, timeout=20)
assert collected, "no SSE events received"