22 lines
793 B
Python
22 lines
793 B
Python
import asyncio
|
|
|
|
import pytest
|
|
|
|
from endpoint_monitor.models import MonitorCreate
|
|
from endpoint_monitor.store import Conflict, MonitorStore
|
|
|
|
|
|
async def test_concurrent_unique_name_is_atomic():
|
|
store = MonitorStore(10)
|
|
data = MonitorCreate(name="same", url="https://example.com")
|
|
results = await asyncio.gather(store.create(data), store.create(data), return_exceptions=True)
|
|
assert sum(not isinstance(item, Exception) for item in results) == 1
|
|
assert sum(isinstance(item, Conflict) for item in results) == 1
|
|
|
|
|
|
async def test_capacity():
|
|
store = MonitorStore(1)
|
|
await store.create(MonitorCreate(name="one", url="https://example.com"))
|
|
with pytest.raises(Conflict, match="capacity"):
|
|
await store.create(MonitorCreate(name="two", url="https://example.org"))
|