mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 08:56:32 +00:00
Refactor inference engine and task management: Remove obsolete inference engine and ONNX engine files, update inference processing to utilize batch handling, and enhance task management structure in documentation. Adjust paths for task specifications to align with new directory organization.
This commit is contained in:
+31
-9
@@ -1,5 +1,6 @@
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
@@ -35,7 +36,7 @@ class _SessionWithBase(requests.Session):
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def base_url():
|
||||
return "http://detections:8080"
|
||||
return os.environ.get("BASE_URL", "http://detections:8080")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@@ -56,12 +57,12 @@ def sse_client_factory(http_client):
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def mock_loader_url():
|
||||
return "http://mock-loader:8080"
|
||||
return os.environ.get("MOCK_LOADER_URL", "http://mock-loader:8080")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def mock_annotations_url():
|
||||
return "http://mock-annotations:8081"
|
||||
return os.environ.get("MOCK_ANNOTATIONS_URL", "http://mock-annotations:8081")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
@@ -96,13 +97,22 @@ def reset_mocks(mock_loader_url, mock_annotations_url):
|
||||
yield
|
||||
|
||||
|
||||
def _media_dir() -> Path:
|
||||
return Path(os.environ.get("MEDIA_DIR", "/media"))
|
||||
|
||||
|
||||
def _read_media(name: str) -> bytes:
|
||||
p = Path("/media") / name
|
||||
p = _media_dir() / name
|
||||
if not p.is_file():
|
||||
pytest.skip(f"missing {p}")
|
||||
return p.read_bytes()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def media_dir():
|
||||
return str(_media_dir())
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def image_small():
|
||||
return _read_media("image_small.jpg")
|
||||
@@ -135,17 +145,17 @@ def image_empty_scene():
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def video_short_path():
|
||||
return "/media/video_short01.mp4"
|
||||
return str(_media_dir() / "video_short01.mp4")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def video_short_02_path():
|
||||
return "/media/video_short02.mp4"
|
||||
return str(_media_dir() / "video_short02.mp4")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def video_long_path():
|
||||
return "/media/video_long03.mp4"
|
||||
return str(_media_dir() / "video_long03.mp4")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@@ -179,12 +189,24 @@ def jwt_token():
|
||||
def warm_engine(http_client, image_small):
|
||||
deadline = time.time() + 120
|
||||
files = {"file": ("warm.jpg", image_small, "image/jpeg")}
|
||||
consecutive_errors = 0
|
||||
last_status = None
|
||||
while time.time() < deadline:
|
||||
try:
|
||||
r = http_client.post("/detect", files=files)
|
||||
if r.status_code == 200:
|
||||
return
|
||||
last_status = r.status_code
|
||||
if r.status_code >= 500:
|
||||
consecutive_errors += 1
|
||||
if consecutive_errors >= 5:
|
||||
pytest.fail(
|
||||
f"engine warm-up aborted: {consecutive_errors} consecutive "
|
||||
f"HTTP {last_status} errors — server is broken, not starting up"
|
||||
)
|
||||
else:
|
||||
consecutive_errors = 0
|
||||
except OSError:
|
||||
pass
|
||||
consecutive_errors = 0
|
||||
time.sleep(2)
|
||||
pytest.fail("engine warm-up failed after 120s")
|
||||
pytest.fail(f"engine warm-up timed out after 120s (last status: {last_status})")
|
||||
|
||||
Reference in New Issue
Block a user