Files
crucible-agent-build-fastap…/tests/test_store.py

39 lines
1.4 KiB
Python

import asyncio
from app.models import CheckStatus, MonitorCreate, MonitorUpdate
from app.store import MonitorStore
async def test_concurrent_creates_are_not_lost():
store = MonitorStore()
await asyncio.gather(*[
store.create(MonitorCreate(name=f"m-{index}", url="https://example.com"))
for index in range(100)
])
items = await store.list()
assert len(items) == 100
assert len({item.id for item in items}) == 100
async def test_stale_check_cannot_overwrite_updated_monitor():
store = MonitorStore()
item = await store.create(MonitorCreate(name="before", url="https://example.com"))
old = await store.snapshot(item.id)
assert old is not None
await store.update(item.id, MonitorUpdate(name="after"))
applied = await store.apply_status(item.id, old.revision, CheckStatus(state="up"))
assert applied is False
current = await store.snapshot(item.id)
assert current is not None
assert current.monitor.name == "after"
assert current.monitor.status.state == "unknown"
async def test_delete_wins_over_in_flight_check():
store = MonitorStore()
item = await store.create(MonitorCreate(name="x", url="https://example.com"))
snapshot = await store.snapshot(item.id)
assert snapshot is not None
await store.delete(item.id)
assert await store.apply_status(item.id, snapshot.revision, CheckStatus(state="up")) is False