From a75f6314de7966070a5ee80d514f84731e2ea8d2 Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo Date: Tue, 5 Apr 2022 16:01:44 -0400 Subject: [PATCH 1/4] Fix: receive_messages_with_exactly_once_delivery_enabled --- samples/snippets/subscriber_test.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 159aa3b54..696dec7cc 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -43,6 +43,7 @@ SUBSCRIPTION_EOD = f"subscription-test-subscription-eod-{PY_VERSION}-{UUID}" ENDPOINT = f"https://{PROJECT_ID}.appspot.com/push" NEW_ENDPOINT = f"https://{PROJECT_ID}.appspot.com/push2" +REGIONAL_ENDPOINT = f"us-east1-pubsub.googleapis.com:443" DEFAULT_MAX_DELIVERY_ATTEMPTS = 5 UPDATED_MAX_DELIVERY_ATTEMPTS = 20 FILTER = 'attributes.author="unknown"' @@ -59,7 +60,7 @@ def publisher_client() -> Generator[pubsub_v1.PublisherClient, None, None]: @pytest.fixture(scope="module") def regional_publisher_client() -> Generator[pubsub_v1.PublisherClient, None, None]: - client_options = {"api_endpoint": "us-east1-pubsub.googleapis.com:443"} + client_options = {"api_endpoint": REGIONAL_ENDPOINT} publisher = pubsub_v1.PublisherClient(client_options=client_options) yield publisher @@ -703,7 +704,7 @@ def eventually_consistent_test() -> None: eventually_consistent_test() -def test_receive_messages_with_exactly_once_delivery_enabled( +def test_receive_messages_with_exactly_once_delivery_enabled_regional_endpoint( regional_publisher_client: pubsub_v1.PublisherClient, exactly_once_delivery_topic: str, subscription_eod: str, @@ -721,6 +722,24 @@ def test_receive_messages_with_exactly_once_delivery_enabled( for message_id in message_ids: assert message_id in out +def test_receive_messages_with_exactly_once_delivery_enabled_( + publisher_client: pubsub_v1.PublisherClient, + exactly_once_delivery_topic: str, + subscription_eod: str, + capsys: CaptureFixture[str], +) -> None: + + message_ids = _publish_messages(publisher_client, exactly_once_delivery_topic) + + subscriber.receive_messages_with_exactly_once_delivery_enabled( + PROJECT_ID, SUBSCRIPTION_EOD, 10 + ) + + out, _ = capsys.readouterr() + assert subscription_eod in out + for message_id in message_ids: + assert message_id in out + def test_listen_for_errors( publisher_client: pubsub_v1.PublisherClient, From ffb3439b42403c6fccbc1f7e6b6c23129143fd50 Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo Date: Tue, 5 Apr 2022 16:25:07 -0400 Subject: [PATCH 2/4] fix lint --- samples/snippets/subscriber_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 696dec7cc..2d8a78625 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -43,7 +43,7 @@ SUBSCRIPTION_EOD = f"subscription-test-subscription-eod-{PY_VERSION}-{UUID}" ENDPOINT = f"https://{PROJECT_ID}.appspot.com/push" NEW_ENDPOINT = f"https://{PROJECT_ID}.appspot.com/push2" -REGIONAL_ENDPOINT = f"us-east1-pubsub.googleapis.com:443" +REGIONAL_ENDPOINT = "us-east1-pubsub.googleapis.com:443" DEFAULT_MAX_DELIVERY_ATTEMPTS = 5 UPDATED_MAX_DELIVERY_ATTEMPTS = 20 FILTER = 'attributes.author="unknown"' @@ -722,6 +722,7 @@ def test_receive_messages_with_exactly_once_delivery_enabled_regional_endpoint( for message_id in message_ids: assert message_id in out + def test_receive_messages_with_exactly_once_delivery_enabled_( publisher_client: pubsub_v1.PublisherClient, exactly_once_delivery_topic: str, From 91db0548b7adb8087f571213007548d9106a515c Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo Date: Tue, 5 Apr 2022 16:49:09 -0400 Subject: [PATCH 3/4] fix test title and add flaky to regional_endpoint test --- samples/snippets/subscriber_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 2d8a78625..6a4f401a8 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -703,7 +703,7 @@ def eventually_consistent_test() -> None: eventually_consistent_test() - +@typed_flaky def test_receive_messages_with_exactly_once_delivery_enabled_regional_endpoint( regional_publisher_client: pubsub_v1.PublisherClient, exactly_once_delivery_topic: str, @@ -723,7 +723,7 @@ def test_receive_messages_with_exactly_once_delivery_enabled_regional_endpoint( assert message_id in out -def test_receive_messages_with_exactly_once_delivery_enabled_( +def test_receive_messages_with_exactly_once_delivery_enabled( publisher_client: pubsub_v1.PublisherClient, exactly_once_delivery_topic: str, subscription_eod: str, From 361b0b7d738283c86f34ed83be8b28285950d309 Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo Date: Tue, 5 Apr 2022 17:21:07 -0400 Subject: [PATCH 4/4] fix flake --- samples/snippets/subscriber_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 6a4f401a8..708a6d1ed 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -703,6 +703,7 @@ def eventually_consistent_test() -> None: eventually_consistent_test() + @typed_flaky def test_receive_messages_with_exactly_once_delivery_enabled_regional_endpoint( regional_publisher_client: pubsub_v1.PublisherClient,