diff --git a/tests/test_store.py b/tests/test_store.py index ea2d35e..75985d1 100644 --- a/tests/test_store.py +++ b/tests/test_store.py @@ -2,26 +2,17 @@ import asyncio import pytest -from app.models import CurrentStatus, MonitorCreate, MonitorUpdate, State -from app.store import MonitorNotFoundError, MonitorStore +from app.models import MonitorCreate +from app.store import MonitorStore -async def test_atomic_update_does_not_lose_status() -> None: - store = MonitorStore() - monitor = await store.create(MonitorCreate(name="one", url="https://example.com")) - status = CurrentStatus(state=State.UP) - await asyncio.gather( - store.update(monitor.id, MonitorUpdate(name="two")), - store.set_status(monitor.id, status), - ) - result = await store.get(monitor.id) - assert result.name == "two" - assert result.current_status.state == State.UP - - -async def test_delete_is_locked_and_missing_is_typed() -> None: - store = MonitorStore() - monitor = await store.create(MonitorCreate(name="one", url="https://example.com")) - await store.delete(monitor.id) - with pytest.raises(MonitorNotFoundError): - await store.get(monitor.id) +@pytest.mark.asyncio +async def test_concurrent_creates_are_retained_and_results_are_copies() -> None: + state = MonitorStore() + payload = MonitorCreate(name="same", url="https://example.com") + created = await asyncio.gather(*(state.create(payload) for _ in range(25))) + assert len(await state.list()) == 25 + created[0].name = "mutated" + persisted = await state.get(created[0].id) + assert persisted is not None + assert persisted.name == "same"