Skip to content

Commit

Permalink
test: integration test for stream as generators added
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosschroh committed Dec 4, 2023
1 parent 5f02f4e commit 59a1ee5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ async def consume(stream):
save_to_db.assert_called_once_with(event)


@pytest.mark.asyncio
async def test_stream_consume_events_as_generator(stream_engine: StreamEngine):
topic = "local--hello-kpn"
event = b'{"message": "Hello world!"}'
client = TestStreamClient(stream_engine)
save_to_db = Mock()

@stream_engine.stream(topic)
async def my_stream(stream: Stream):
async for cr in stream:
save_to_db(cr.value)
yield cr

async with client:
await client.send(topic, value=event, key="1")

async with my_stream as processor:
async for cr in processor:
assert cr.value == event
break

# check that the event was consumed
save_to_db.assert_called_once_with(event)


@pytest.mark.asyncio
async def test_only_consume_topics_with_streams(stream_engine: StreamEngine):
"""
Expand Down

0 comments on commit 59a1ee5

Please sign in to comment.