Skip to content
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
22 changes: 15 additions & 7 deletions sdks/python/apache_beam/io/gcp/pubsub_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,22 @@ def test_batch_write_with_ordering_key(self):

# Retry pulling to handle PubSub delivery delays
received_messages = []
received_message_ids = set()
ack_ids = []
deadline = time.time() + 60 # wait up to 60 seconds
while time.time() < deadline:
response = self.sub_client.pull(
request={
'subscription': ordering_sub.name,
'max_messages': 10,
})
received_messages.extend(response.received_messages)
for msg in response.received_messages:
ack_ids.append(msg.ack_id)
# Pub/Sub guarantees at-least-once delivery, so we must deduplicate
# messages by message_id to handle potential duplicate deliveries.
if msg.message.message_id not in received_message_ids:
received_message_ids.add(msg.message.message_id)
received_messages.append(msg)
if len(received_messages) >= len(test_messages):
break
time.sleep(5)
Comment thread
shunping marked this conversation as resolved.
Expand All @@ -384,12 +392,12 @@ def test_batch_write_with_ordering_key(self):
self.assertEqual(received_map[b'order_data002'].ordering_key, 'key1')
self.assertEqual(received_map[b'order_data003'].ordering_key, 'key2')

ack_ids = [msg.ack_id for msg in received_messages]
self.sub_client.acknowledge(
request={
'subscription': ordering_sub.name,
'ack_ids': ack_ids,
})
if ack_ids:
self.sub_client.acknowledge(
request={
'subscription': ordering_sub.name,
'ack_ids': ack_ids,
})
Comment thread
shunping marked this conversation as resolved.
finally:
self.sub_client.delete_subscription(
request={'subscription': ordering_sub.name})
Expand Down
Loading