mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 11:16:31 +00:00
[AZ-139] [AZ-140] [AZ-141] [AZ-142] Implement integration tests for health, single image, tiling, and async SSE
Made-with: Cursor
This commit is contained in:
@@ -1 +1,74 @@
|
||||
"""Health & engine lifecycle tests (FT-P-01, FT-P-02, FT-P-14, FT-P-15)."""
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
_DETECT_TIMEOUT = 60
|
||||
|
||||
|
||||
def _get_health(http_client):
|
||||
r = http_client.get("/health")
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
|
||||
|
||||
def _assert_active_ai(data):
|
||||
assert data["status"] == "healthy"
|
||||
assert data["aiAvailability"] not in ("None", "Downloading")
|
||||
|
||||
|
||||
@pytest.mark.cpu
|
||||
class TestHealthEngineStep01PreInit:
|
||||
def test_ft_p_01_pre_init_health(self, http_client):
|
||||
t0 = time.monotonic()
|
||||
data = _get_health(http_client)
|
||||
assert time.monotonic() - t0 < 2.0
|
||||
assert data["status"] == "healthy"
|
||||
assert data["aiAvailability"] == "None"
|
||||
assert data.get("errorMessage") is None
|
||||
|
||||
|
||||
@pytest.mark.cpu
|
||||
@pytest.mark.slow
|
||||
class TestHealthEngineStep02LazyInit:
|
||||
def test_ft_p_14_lazy_initialization(self, http_client, image_small):
|
||||
before = _get_health(http_client)
|
||||
assert before["aiAvailability"] == "None"
|
||||
files = {"file": ("lazy.jpg", image_small, "image/jpeg")}
|
||||
r = http_client.post("/detect", files=files, timeout=_DETECT_TIMEOUT)
|
||||
r.raise_for_status()
|
||||
body = r.json()
|
||||
assert isinstance(body, list)
|
||||
after = _get_health(http_client)
|
||||
_assert_active_ai(after)
|
||||
|
||||
|
||||
@pytest.mark.cpu
|
||||
@pytest.mark.slow
|
||||
class TestHealthEngineStep03Warmed:
|
||||
@pytest.fixture(autouse=True)
|
||||
def _warm(self, warm_engine):
|
||||
pass
|
||||
|
||||
def test_ft_p_02_post_init_health(self, http_client):
|
||||
data = _get_health(http_client)
|
||||
_assert_active_ai(data)
|
||||
assert data.get("errorMessage") is None
|
||||
|
||||
def test_ft_p_15_onnx_cpu_detect(self, http_client, image_small):
|
||||
files = {"file": ("onnx.jpg", image_small, "image/jpeg")}
|
||||
r = http_client.post("/detect", files=files, timeout=_DETECT_TIMEOUT)
|
||||
r.raise_for_status()
|
||||
body = r.json()
|
||||
assert isinstance(body, list)
|
||||
if body:
|
||||
d = body[0]
|
||||
for k in (
|
||||
"centerX",
|
||||
"centerY",
|
||||
"width",
|
||||
"height",
|
||||
"classNum",
|
||||
"label",
|
||||
"confidence",
|
||||
):
|
||||
assert k in d
|
||||
|
||||
Reference in New Issue
Block a user