closed TG-1; git was inited;
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from ais_hub.core.bus import EventBus
|
||||
from ais_hub.core.models import Event
|
||||
from ais_hub.core.stats import Stats
|
||||
from ais_hub.publish.queues import put_drop_oldest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_put_drop_oldest_drops_and_counts():
|
||||
stats = Stats()
|
||||
q: asyncio.Queue[int] = asyncio.Queue(maxsize=2)
|
||||
put_drop_oldest(q, 1, stats, "drops")
|
||||
put_drop_oldest(q, 2, stats, "drops")
|
||||
put_drop_oldest(q, 3, stats, "drops") # should drop "1"
|
||||
assert q.qsize() == 2
|
||||
assert stats.counters["drops"] == 1
|
||||
first = await q.get()
|
||||
assert first == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_event_bus_drops_oldest_for_slow_subscriber():
|
||||
stats = Stats()
|
||||
bus = EventBus(stats=stats, default_maxsize=2)
|
||||
sub = bus.subscribe()
|
||||
for i in range(5):
|
||||
bus.publish(Event(type="stats.update", ts=float(i), data={"i": i}))
|
||||
assert sub.qsize() == 2
|
||||
# The two newest events survived.
|
||||
first = await sub.get()
|
||||
second = await sub.get()
|
||||
assert first.data["i"] == 3
|
||||
assert second.data["i"] == 4
|
||||
# 3 drops (5 - 2 capacity).
|
||||
assert stats.counters["bus_dropped"] == 3
|
||||
Reference in New Issue
Block a user