Skip to content

Commit

Permalink
fix: TestStreamClient should not wait for topics that are empty (#93)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcos Schroh <[email protected]>
  • Loading branch information
marcosschroh and marcosschroh authored Jan 25, 2023
1 parent 58eb1e1 commit aa2ea42
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kstreams/test_utils/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ def all_messages_consumed(cls) -> bool:
@classmethod
async def join(cls) -> None:
"""
Wait for all topic messages to be processed
Wait for all topic messages to be processed.
Only topics that have a consumer assigned should be awaited.
"""
await asyncio.gather(*[topic.join() for topic in cls.topics.values()])
await asyncio.gather(
*[topic.join() for topic in cls.topics.values() if not topic.consumed]
)

@classmethod
def clean(cls) -> None:
Expand Down
25 changes: 25 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ async def consume(stream):
save_to_db.assert_called_once_with(event)


@pytest.mark.asyncio
async def test_only_consume_topics_with_streams(stream_engine: StreamEngine):
"""
The test creates a stream but no events are send to it,
it means that the `TestStreamClient` should not wait for the topic to be consumed
even thought the topic is exist.
"""
client = TestStreamClient(stream_engine)
topic = "local--kstreams"

@stream_engine.stream("a-different-topic", name="my-stream")
async def consume(stream):
async for cr in stream:
...

async with client:
metadata = await client.send(
topic, value=b'{"message": "Hello world!"}', key="1"
)

assert metadata.topic == topic
assert metadata.partition == 0
assert metadata.offset == 1


@pytest.mark.asyncio
async def test_topic_created(stream_engine: StreamEngine):
topic_name = "local--kstreams"
Expand Down

0 comments on commit aa2ea42

Please sign in to comment.