From 6cbcce5d746b9c4dd3064cf3d2edd125b0233f04 Mon Sep 17 00:00:00 2001 From: demo-bot Date: Sun, 9 Aug 2026 16:07:16 +0000 Subject: [PATCH] decomposer: generate deliverable files for Define the service contract and project architecture for the FastAPI endpoint monitoring service.; Implement the typed monitor CRUD API and concurrency-safe in-memory state according to the service design.; Implement secure on-demand endpoint checks with status updates, latency measurement, robust error handling, and redacted structured logs.; Add operational API endpoints and environment-driven runtime configuration to the monitoring service.; Create automated tests for the monitoring service.; Package the service with Docker and developer documentation.; Validate the complete project. --- tests/test_store.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/test_store.py b/tests/test_store.py index b378ffd..2da6dc6 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -1,15 +1,22 @@ +import asyncio + import pytest -from app.models import CheckResult, MonitorCreate, MonitorStatus, utcnow +from app.models import CurrentStatus, MonitorCreate, MonitorState from app.store import MonitorStore -pytestmark = pytest.mark.anyio - -async def test_deleted_monitor_is_not_resurrected_by_late_result(): +@pytest.mark.anyio +async def test_concurrent_status_updates_are_valid() -> None: store = MonitorStore() - item = await store.create(MonitorCreate(name="x", url="https://example.com")) - assert await store.delete(item.id) - result = CheckResult(status=MonitorStatus.up, checked_at=utcnow(), latency_ms=1, http_status=200) - assert await store.record(item.id, result) is None - assert await store.get(item.id) is None + monitor = await store.create(MonitorCreate(name="x", target_url="https://example.com")) + + async def set_one(code: int) -> None: + await store.set_status( + monitor.id, + CurrentStatus(state=MonitorState.UP, latency_ms=1, http_status=code), + ) + + await asyncio.gather(*(set_one(code) for code in range(200, 210))) + saved = await store.get(monitor.id) + assert saved.current_status.http_status in range(200, 210)