From 5385dd9c097924106e98e5aceb0abaeba8262836 Mon Sep 17 00:00:00 2001 From: demo-bot Date: Sun, 9 Aug 2026 15:49:47 +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_atomic.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/test_atomic.py diff --git a/tests/test_atomic.py b/tests/test_atomic.py new file mode 100644 index 0000000..a29b45d --- /dev/null +++ b/tests/test_atomic.py @@ -0,0 +1,31 @@ +import asyncio + +import pytest + +from app.models import CurrentStatus, HealthState, MonitorCreate, MonitorUpdate, utc_now +from app.store import MonitorStore + + +@pytest.mark.asyncio +async def test_status_compare_and_set_rejects_stale_revision() -> None: + store = MonitorStore() + item = await store.create(MonitorCreate(name="old", url="https://example.com/a")) + result = CurrentStatus(state=HealthState.up, checked_at=utc_now(), latency_ms=1, http_status=200) + + await store.update(item.id, MonitorUpdate(name="new", url="https://example.com/b")) + assert await store.set_status_if_current(item.id, item.revision, result) is False + current = await store.get(item.id) + assert current is not None and current.current_status is None + + +@pytest.mark.asyncio +async def test_concurrent_writes_remain_consistent() -> None: + store = MonitorStore() + item = await store.create(MonitorCreate(name="start", url="https://example.com")) + await asyncio.gather(*[ + store.update(item.id, MonitorUpdate(name=f"name-{index}", url="https://example.com")) + for index in range(20) + ]) + current = await store.get(item.id) + assert current is not None + assert current.revision == 21