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

[EventHubs] update test to test async producer #19892

Merged
2 commits merged into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def test_receive_no_partition_async(connstr_senders):

async def on_event(partition_context, event):
on_event.received += 1
await partition_context.update_checkpoint(event, fake_kwarg="arg") # ignores fake_kwarg
await partition_context.update_checkpoint(event)
on_event.namespace = partition_context.fully_qualified_namespace
on_event.eventhub_name = partition_context.eventhub_name
on_event.consumer_group = partition_context.consumer_group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from azure.eventhub import EventData, TransportType
from azure.eventhub.exceptions import EventHubError
from azure.eventhub.aio import EventHubConsumerClient
from azure.eventhub.aio import EventHubProducerClient, EventHubConsumerClient


@pytest.mark.liveTest
Expand All @@ -30,16 +30,27 @@ async def on_event(partition_context, event):

on_event.called = False
connection_str, senders = connstr_senders
# test async producer client
producer_client = EventHubProducerClient.from_connection_string(connection_str)
partitions = await producer_client.get_partition_ids()
senders = []
for p in partitions:
sender = producer_client._create_producer(partition_id=p)
senders.append(sender)

client = EventHubConsumerClient.from_connection_string(connection_str, consumer_group='$default')
async with client:
task = asyncio.ensure_future(client.receive(on_event, partition_id="0", starting_position="@latest"))
await asyncio.sleep(10)
assert on_event.called is False
senders[0].send(EventData(b"Receiving only a single event"), partition_key='0')
await senders[0].send(EventData(b"Receiving only a single event"), partition_key='0')
await asyncio.sleep(10)
assert on_event.called is True

await task
for s in senders:
await s.close()
await producer_client.close()


@pytest.mark.parametrize("position, inclusive, expected_result",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_receive_no_partition(connstr_senders):

def on_event(partition_context, event):
on_event.received += 1
partition_context.update_checkpoint(event, fake_kwarg="arg") # ignores fake_kwarg
partition_context.update_checkpoint(event)
on_event.namespace = partition_context.fully_qualified_namespace
on_event.eventhub_name = partition_context.eventhub_name
on_event.consumer_group = partition_context.consumer_group
Expand Down