Skip to content

Commit 7b2aeaf

Browse files
authored
[EventHubs] update test to test async producer (#19892)
- call async Producer for testing/improving code coverage - remove passing in fake kwarg to PartitionContext; untested lines in PartitionContext can only be tested with a user implemented CheckpointStore class, so not worrying about this
1 parent 8f28e2a commit 7b2aeaf

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

sdk/eventhub/azure-eventhub/tests/livetest/asynctests/test_consumer_client_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async def test_receive_no_partition_async(connstr_senders):
1616

1717
async def on_event(partition_context, event):
1818
on_event.received += 1
19-
await partition_context.update_checkpoint(event, fake_kwarg="arg") # ignores fake_kwarg
19+
await partition_context.update_checkpoint(event)
2020
on_event.namespace = partition_context.fully_qualified_namespace
2121
on_event.eventhub_name = partition_context.eventhub_name
2222
on_event.consumer_group = partition_context.consumer_group

sdk/eventhub/azure-eventhub/tests/livetest/asynctests/test_receive_async.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from azure.eventhub import EventData, TransportType
1212
from azure.eventhub.exceptions import EventHubError
13-
from azure.eventhub.aio import EventHubConsumerClient
13+
from azure.eventhub.aio import EventHubProducerClient, EventHubConsumerClient
1414

1515

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

3131
on_event.called = False
3232
connection_str, senders = connstr_senders
33+
# test async producer client
34+
producer_client = EventHubProducerClient.from_connection_string(connection_str)
35+
partitions = await producer_client.get_partition_ids()
36+
senders = []
37+
for p in partitions:
38+
sender = producer_client._create_producer(partition_id=p)
39+
senders.append(sender)
40+
3341
client = EventHubConsumerClient.from_connection_string(connection_str, consumer_group='$default')
3442
async with client:
3543
task = asyncio.ensure_future(client.receive(on_event, partition_id="0", starting_position="@latest"))
3644
await asyncio.sleep(10)
3745
assert on_event.called is False
38-
senders[0].send(EventData(b"Receiving only a single event"), partition_key='0')
46+
await senders[0].send(EventData(b"Receiving only a single event"), partition_key='0')
3947
await asyncio.sleep(10)
4048
assert on_event.called is True
4149

4250
await task
51+
for s in senders:
52+
await s.close()
53+
await producer_client.close()
4354

4455

4556
@pytest.mark.parametrize("position, inclusive, expected_result",

sdk/eventhub/azure-eventhub/tests/livetest/synctests/test_consumer_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_receive_no_partition(connstr_senders):
1717

1818
def on_event(partition_context, event):
1919
on_event.received += 1
20-
partition_context.update_checkpoint(event, fake_kwarg="arg") # ignores fake_kwarg
20+
partition_context.update_checkpoint(event)
2121
on_event.namespace = partition_context.fully_qualified_namespace
2222
on_event.eventhub_name = partition_context.eventhub_name
2323
on_event.consumer_group = partition_context.consumer_group

0 commit comments

Comments
 (0)