Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: integration test for stream as generators added #139

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading