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.
Some checks failed
ci / validate (push) Has been cancelled
Some checks failed
ci / validate (push) Has been cancelled
This commit is contained in:
31
tests/test_atomic.py
Normal file
31
tests/test_atomic.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user