From 16c25c1038e73e914a006f0045287a4ec43a9f9a Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Wed, 23 Jun 2021 11:48:42 -0400 Subject: [PATCH 1/2] samples(test): flaky sync pull test --- samples/snippets/subscriber_test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 20355fe2b..557d38674 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -15,6 +15,7 @@ import os import re import sys +import time import uuid import backoff @@ -475,7 +476,8 @@ def test_receive_synchronously_with_lease( ): @backoff.on_exception(backoff.expo, Unknown, max_time=300) def run_sample(): - _publish_messages(publisher_client, topic, message_num=3) + _publish_messages(publisher_client, topic, message_num=10) + time.sleep(10) subscriber.synchronous_pull_with_lease_management(PROJECT_ID, SUBSCRIPTION_SYNC) run_sample() From 3229a80e87770f589539f95aa192eea2b59408c4 Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Wed, 23 Jun 2021 12:19:50 -0400 Subject: [PATCH 2/2] address peter's comment --- samples/snippets/subscriber_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 557d38674..bf26a79b9 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -477,6 +477,11 @@ def test_receive_synchronously_with_lease( @backoff.on_exception(backoff.expo, Unknown, max_time=300) def run_sample(): _publish_messages(publisher_client, topic, message_num=10) + # Pausing 10s to allow the subscriber to establish the connection + # because sync pull often returns fewer messages than requested. + # The intention is to fix flaky tests reporting errors like + # `google.api_core.exceptions.Unknown: None Stream removed` as + # in https://github.com/googleapis/python-pubsub/issues/341. time.sleep(10) subscriber.synchronous_pull_with_lease_management(PROJECT_ID, SUBSCRIPTION_SYNC)