mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 10:26:32 +00:00
097811a67b
- Pin all deps; h11==0.16.0 (CVE-2025-43859), python-multipart>=1.3.1 (CVE-2026-28356), PyJWT==2.12.1
- Add HMAC JWT verification (require_auth FastAPI dependency, JWT_SECRET-gated)
- Fix TokenManager._refresh() to use ADMIN_API_URL instead of ANNOTATIONS_URL
- Rename POST /detect → POST /detect/image (image-only, rejects video files)
- Replace global SSE stream with per-job SSE: GET /detect/{media_id} with event replay buffer
- Apply require_auth to all 4 protected endpoints
- Fix on_annotation/on_status closure to use mutable current_id for correct post-upload event routing
- Add non-root appuser to Dockerfile and Dockerfile.gpu
- Add JWT_SECRET to e2e/docker-compose.test.yml and run-tests.sh
- Update all e2e tests and unit tests for new endpoints and HMAC token signing
- 64/64 tests pass
Made-with: Cursor
81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
import json
|
|
import time
|
|
|
|
import pytest
|
|
|
|
|
|
def _percentile_ms(sorted_ms, p):
|
|
n = len(sorted_ms)
|
|
if n == 0:
|
|
return 0.0
|
|
if n == 1:
|
|
return float(sorted_ms[0])
|
|
k = (n - 1) * (p / 100.0)
|
|
lo = int(k)
|
|
hi = min(lo + 1, n - 1)
|
|
w = k - lo
|
|
return sorted_ms[lo] * (1 - w) + sorted_ms[hi] * w
|
|
|
|
|
|
@pytest.mark.timeout(60)
|
|
def test_nft_perf_01_single_image_latency_p95(
|
|
warm_engine, http_client, image_small, auth_headers
|
|
):
|
|
times_ms = []
|
|
for _ in range(10):
|
|
t0 = time.perf_counter()
|
|
r = http_client.post(
|
|
"/detect/image",
|
|
files={"file": ("img.jpg", image_small, "image/jpeg")},
|
|
headers=auth_headers,
|
|
timeout=8,
|
|
)
|
|
elapsed_ms = (time.perf_counter() - t0) * 1000.0
|
|
assert r.status_code == 200
|
|
times_ms.append(elapsed_ms)
|
|
sorted_ms = sorted(times_ms)
|
|
p50 = _percentile_ms(sorted_ms, 50)
|
|
p95 = _percentile_ms(sorted_ms, 95)
|
|
p99 = _percentile_ms(sorted_ms, 99)
|
|
print(
|
|
"nft_perf_01_csv,run_ms,"
|
|
+ ",".join(f"{x:.2f}" for x in sorted_ms)
|
|
+ f",p50,{p50:.2f},p95,{p95:.2f},p99,{p99:.2f}"
|
|
)
|
|
assert p95 < 5000.0
|
|
|
|
|
|
@pytest.mark.timeout(60)
|
|
def test_nft_perf_03_tiling_overhead_large_image(
|
|
warm_engine, http_client, image_small, image_large, auth_headers
|
|
):
|
|
t_small = time.perf_counter()
|
|
r_small = http_client.post(
|
|
"/detect/image",
|
|
files={"file": ("small.jpg", image_small, "image/jpeg")},
|
|
headers=auth_headers,
|
|
timeout=8,
|
|
)
|
|
small_ms = (time.perf_counter() - t_small) * 1000.0
|
|
assert r_small.status_code == 200
|
|
config = json.dumps(
|
|
{"altitude": 400, "focal_length": 24, "sensor_width": 23.5}
|
|
)
|
|
t_large = time.perf_counter()
|
|
r_large = http_client.post(
|
|
"/detect/image",
|
|
files={"file": ("large.jpg", image_large, "image/jpeg")},
|
|
data={"config": config},
|
|
headers=auth_headers,
|
|
timeout=20,
|
|
)
|
|
large_ms = (time.perf_counter() - t_large) * 1000.0
|
|
assert r_large.status_code == 200
|
|
assert large_ms < 30_000.0
|
|
print(
|
|
f"nft_perf_03_csv,baseline_small_ms,{small_ms:.2f},large_ms,{large_ms:.2f}"
|
|
)
|
|
assert large_ms > small_ms - 500.0
|
|
|
|
|