From 255ec36f8a63c37b738c29a2bae020dbcd0874c9 Mon Sep 17 00:00:00 2001 From: Roman Meshko Date: Fri, 15 May 2026 12:45:18 +0300 Subject: [PATCH] Fix e2e tests --- e2e/conftest.py | 7 ++++--- e2e/tests/test_video.py | 3 +++ src/main.py | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/e2e/conftest.py b/e2e/conftest.py index af3da3f..118ea92 100644 --- a/e2e/conftest.py +++ b/e2e/conftest.py @@ -249,7 +249,7 @@ def _health(http_client): def _health_ai_active(data: dict) -> bool: - return data.get("aiAvailability") not in ("None", "Downloading", "Error") + return data.get("aiAvailability") == "Enabled" def _wait_for_ai_active(http_client, timeout: float = 30) -> dict | None: @@ -324,7 +324,8 @@ def corrupt_image(): @pytest.fixture(scope="module") def warm_engine(http_client, image_small, auth_headers): - deadline = time.time() + 120 + timeout = int(os.environ.get("E2E_ENGINE_WAIT_TIMEOUT", "900")) + deadline = time.time() + timeout last_status = None consecutive_errors = 0 @@ -403,4 +404,4 @@ def warm_engine(http_client, image_small, auth_headers): th.join(timeout=1) time.sleep(2) - pytest.fail(f"engine warm-up timed out after 120s (last status: {last_status})") + pytest.fail(f"engine warm-up timed out after {timeout}s (last status: {last_status})") diff --git a/e2e/tests/test_video.py b/e2e/tests/test_video.py index 2c4e852..b003332 100644 --- a/e2e/tests/test_video.py +++ b/e2e/tests/test_video.py @@ -72,6 +72,9 @@ def video_events(warm_engine, http_client, auth_headers): **auth_headers, "X-Channel-Id": channel_id, "X-Filename": "video_test01.mp4", + "X-Config": json.dumps( + {"model_batch_size": 1, "frame_period_recognition": 25} + ), "Content-Type": "application/octet-stream", }, timeout=15, diff --git a/src/main.py b/src/main.py index f8470a5..ff80459 100644 --- a/src/main.py +++ b/src/main.py @@ -515,6 +515,8 @@ async def detect_image( _post_annotation_to_service(token_mgr, content_hash, annotation, dtos) def run_sync(): + if not inf.is_engine_ready: + raise RuntimeError("Detection service unavailable") inf.run_detect_image(image_bytes, ai_cfg, media_name, on_annotation) try: @@ -609,6 +611,8 @@ async def detect_video_upload( _post_annotation_to_service(token_mgr, mid, annotation, dtos) def run_inference(): + if not inf.is_engine_ready: + raise RuntimeError("Detection service unavailable") inf.run_detect_video_stream(buffer, ai_cfg, media_name, on_annotation, lambda *_: None) inference_future = loop.run_in_executor(executor, run_inference)