feat: add deployment configuration and scripts for managed-portal, including Dockerfiles and environment settings
This commit is contained in:
101
managed/people_flow_project/tests/test_worker_status.py
Normal file
101
managed/people_flow_project/tests/test_worker_status.py
Normal file
@@ -0,0 +1,101 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from src.people_flow.worker_status import (
|
||||
load_worker_status,
|
||||
worker_status_age_seconds,
|
||||
worker_status_stall_reason,
|
||||
write_worker_status,
|
||||
)
|
||||
|
||||
|
||||
def test_write_worker_status_persists_progress(tmp_path: Path):
|
||||
status_path = tmp_path / "outputs" / "rtsp_stream" / "worker_status.json"
|
||||
last_processed_at = datetime(2026, 5, 13, 16, 30, 0).astimezone()
|
||||
|
||||
write_worker_status(
|
||||
status_path,
|
||||
"processed_frame",
|
||||
source="rtsp://camera/stream",
|
||||
window_index=3,
|
||||
frame_index=42,
|
||||
last_processed_at=last_processed_at,
|
||||
note="healthy",
|
||||
)
|
||||
|
||||
payload = load_worker_status(status_path)
|
||||
|
||||
assert payload is not None
|
||||
assert payload["phase"] == "processed_frame"
|
||||
assert payload["source"] == "rtsp://camera/stream"
|
||||
assert payload["window_index"] == 3
|
||||
assert payload["frame_index"] == 42
|
||||
assert payload["last_processed_at"] == last_processed_at.isoformat(
|
||||
timespec="seconds"
|
||||
)
|
||||
assert payload["note"] == "healthy"
|
||||
assert "updated_at" in payload
|
||||
|
||||
|
||||
def test_worker_status_age_seconds_uses_file_mtime(tmp_path: Path):
|
||||
status_path = tmp_path / "worker_status.json"
|
||||
|
||||
write_worker_status(
|
||||
status_path,
|
||||
"tracking_frame",
|
||||
source="rtsp://camera/stream",
|
||||
window_index=0,
|
||||
frame_index=0,
|
||||
last_processed_at=None,
|
||||
)
|
||||
|
||||
os.utime(status_path, (100.0, 100.0))
|
||||
|
||||
assert worker_status_age_seconds(status_path, now=280.0) == 180.0
|
||||
assert worker_status_age_seconds(tmp_path / "missing.json", now=280.0) is None
|
||||
|
||||
|
||||
def test_worker_status_stall_reason_reports_missing_and_stale_status(tmp_path: Path):
|
||||
missing_path = tmp_path / "missing.json"
|
||||
|
||||
assert (
|
||||
worker_status_stall_reason(
|
||||
missing_path,
|
||||
started_at=150.0,
|
||||
max_age_seconds=180.0,
|
||||
now=300.0,
|
||||
)
|
||||
is None
|
||||
)
|
||||
assert "status missing" in worker_status_stall_reason(
|
||||
missing_path,
|
||||
started_at=0.0,
|
||||
max_age_seconds=180.0,
|
||||
now=300.0,
|
||||
)
|
||||
|
||||
status_path = tmp_path / "worker_status.json"
|
||||
write_worker_status(
|
||||
status_path,
|
||||
"tracking_frame",
|
||||
source="rtsp://camera/stream",
|
||||
window_index=0,
|
||||
frame_index=2,
|
||||
last_processed_at=None,
|
||||
)
|
||||
os.utime(status_path, (100.0, 100.0))
|
||||
|
||||
reason = worker_status_stall_reason(
|
||||
status_path,
|
||||
started_at=0.0,
|
||||
max_age_seconds=180.0,
|
||||
now=300.0,
|
||||
)
|
||||
|
||||
assert reason is not None
|
||||
assert "status=missing" not in reason
|
||||
assert "phase=tracking_frame" in reason
|
||||
assert "age_seconds=200.0" in reason
|
||||
Reference in New Issue
Block a user