decomposer: generate files for Maintain only the latest check result for each monitored target in concurrency-safe memory and expose it through the specified FastAPI current-status endpoint.

This commit is contained in:
2026-08-09 15:09:13 +00:00
parent b88e7c4f88
commit faa207ee27

56
tests/test_concurrency.py Normal file
View File

@@ -0,0 +1,56 @@
import asyncio
from current_status import CurrentStatusCoordinator
async def test_older_overlapping_check_cannot_replace_newer_check() -> None:
coordinator = CurrentStatusCoordinator()
await coordinator.register_target("t")
release_old = asyncio.Event()
async def old(_target):
await release_old.wait()
return {"value": "old"}
async def new(_target):
return {"value": "new"}
old_task = asyncio.create_task(coordinator.run_check("t", {}, old))
await asyncio.sleep(0)
assert await coordinator.run_check("t", {}, new) is True
release_old.set()
assert await old_task is False
exists, status = await coordinator.read("t")
assert exists and status is not None
assert status["payload"] == {"value": "new"}
assert await coordinator.retained_status_count() == 1
async def test_delete_cleans_status_and_stale_check_cannot_resurrect_recreate() -> None:
coordinator = CurrentStatusCoordinator()
await coordinator.register_target("same-id")
async def initial(_target):
return {"value": "initial"}
assert await coordinator.run_check("same-id", {}, initial)
assert await coordinator.retained_status_count() == 1
release = asyncio.Event()
async def stale(_target):
await release.wait()
return {"value": "stale"}
stale_task = asyncio.create_task(coordinator.run_check("same-id", {}, stale))
await asyncio.sleep(0)
assert await coordinator.delete_target("same-id")
assert await coordinator.retained_status_count() == 0
await coordinator.register_target("same-id")
release.set()
assert await stale_task is False
exists, status = await coordinator.read("same-id")
assert exists is True
assert status is None
assert await coordinator.retained_status_count() == 0