Files
2026Technology-Competition/tests/test_progress_hub.py
T

36 lines
1.1 KiB
Python

import asyncio
import pytest
from genesis.server.hub import ProgressHub
@pytest.mark.asyncio
async def test_subscribe_receives_emitted_event():
h = ProgressHub()
h.register_loop(asyncio.get_running_loop())
q = h.subscribe("s1")
h.emit("s1", {"type": "progress", "step": "parse", "status": "ok"})
event = await asyncio.wait_for(q.get(), 1.0)
assert event["step"] == "parse"
@pytest.mark.asyncio
async def test_unsubscribe_stops_delivery():
h = ProgressHub()
h.register_loop(asyncio.get_running_loop())
q = h.subscribe("s1")
h.unsubscribe("s1", q)
h.emit("s1", {"type": "progress"})
with pytest.raises(asyncio.TimeoutError):
await asyncio.wait_for(q.get(), 0.2)
@pytest.mark.asyncio
async def test_multiple_subscribers_all_receive():
h = ProgressHub()
h.register_loop(asyncio.get_running_loop())
q1, q2 = h.subscribe("s1"), h.subscribe("s1")
h.emit("s1", {"type": "progress", "step": "gen"})
a = await asyncio.wait_for(q1.get(), 1.0)
b = await asyncio.wait_for(q2.get(), 1.0)
assert a["step"] == b["step"] == "gen"