Skip to content

Commit

Permalink
Feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Dumchenko committed Nov 21, 2024
1 parent 20185a3 commit f662a8b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/brokers/kafka/test_consume.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,40 @@ async def handler(msg: KafkaMessage):
m.mock.assert_not_called()

assert event.is_set()

@pytest.mark.asyncio
async def test_concurrent_consume(
self,
queue: str,
mock
):
event = asyncio.Event()
event2 = asyncio.Event()

consume_broker = self.get_broker()
sub = consume_broker.subscriber(queue, max_workers=2)

@sub
async def handler(msg):
mock()
if event.is_set():
event2.set()
else:
event.set()
await asyncio.sleep(1.0)

async with self.patch_broker(consume_broker) as br:
await br.start()
for i in range(5):
await br.publish(i, queue)
await asyncio.wait(
(
asyncio.create_task(event.wait()),
asyncio.create_task(event2.wait()),
),
timeout=3,
)

assert event.is_set()
assert event2.is_set()
assert mock.call_count == 2, mock.call_count

0 comments on commit f662a8b

Please sign in to comment.