Skip to content

Commit aa0a830

Browse files
authored
Create test_event_bus.py
1 parent f206597 commit aa0a830

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test_event_bus.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import asyncio
2+
import pytest
3+
4+
from src.common.event_bus import EventBus
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_event_bus_publish_and_subscribe():
9+
10+
bus = EventBus()
11+
received_messages = []
12+
13+
async def handler(payload):
14+
received_messages.append(payload)
15+
16+
# Subscribe
17+
await bus.subscribe("test_topic", handler)
18+
19+
# Publish event
20+
await bus.publish("test_topic", {"value": 123})
21+
22+
# Allow async loop to process event
23+
await asyncio.sleep(0.1)
24+
25+
assert len(received_messages) == 1
26+
assert received_messages[0]["value"] == 123

0 commit comments

Comments
 (0)