From 49333459b0f08ce542229631f57e9fd4d3b095fb Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo Date: Wed, 13 Apr 2022 19:34:05 +0000 Subject: [PATCH 1/5] Samples(test): Mark eod test super_flaky and extend timeout --- samples/snippets/subscriber_test.py | 63 ++++++++++++++++------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 5a5062564..6f6ae0807 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -51,7 +51,7 @@ C = TypeVar("C", bound=Callable[..., Any]) typed_flaky = cast(Callable[[C], C], flaky(max_runs=3, min_passes=1)) - +typed_super_flaky = cast(Callable[[C], C], flaky(max_runs=5, min_passes=5)) @pytest.fixture(scope="module") def publisher_client() -> Generator[pubsub_v1.PublisherClient, None, None]: @@ -158,7 +158,8 @@ def subscription_sync( yield subscription.name typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=300), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=300), ) @typed_backoff @@ -236,12 +237,15 @@ def subscription_eod( subscription_path = subscriber_client.subscription_path( PROJECT_ID, SUBSCRIPTION_EOD ) + print("for " + subscription_path) try: + print("calling get subscription") subscription = subscriber_client.get_subscription( request={"subscription": subscription_path} ) except NotFound: + print("except NotFound, creating subscription") subscription = subscriber_client.create_subscription( request={ "name": subscription_path, @@ -249,9 +253,10 @@ def subscription_eod( "enable_exactly_once_delivery": True, } ) + print("returning subscription.name = " + subscription.name) yield subscription.name - + subscriber_client.delete_subscription(request={"subscription": subscription.name}) @@ -497,7 +502,8 @@ def test_create_push_subscription( capsys: CaptureFixture[str], ) -> None: typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=60), ) # The scope of `subscription_path` is limited to this function. @@ -524,11 +530,13 @@ def eventually_consistent_test() -> None: def test_update_push_suscription( - subscription_admin: str, capsys: CaptureFixture[str], + subscription_admin: str, + capsys: CaptureFixture[str], ) -> None: typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff @@ -550,7 +558,8 @@ def test_delete_subscription( subscriber.delete_subscription(PROJECT_ID, SUBSCRIPTION_ADMIN) typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff @@ -571,7 +580,8 @@ def test_receive( ) -> None: typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff @@ -596,7 +606,8 @@ def test_receive_with_custom_attributes( ) -> None: typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff @@ -624,7 +635,8 @@ def test_receive_with_flow_control( ) -> None: typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=300), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=300), ) @typed_backoff @@ -654,7 +666,8 @@ def test_receive_with_blocking_shutdown( _shut_down = re.compile(r".*done waiting.*stream shutdown.*", flags=re.IGNORECASE) typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=300), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=300), ) @typed_backoff @@ -704,6 +717,7 @@ def eventually_consistent_test() -> None: eventually_consistent_test() +@typed_super_flaky def test_receive_messages_with_exactly_once_delivery_enabled( regional_publisher_client: pubsub_v1.PublisherClient, exactly_once_delivery_topic: str, @@ -711,26 +725,19 @@ def test_receive_messages_with_exactly_once_delivery_enabled( capsys: CaptureFixture[str], ) -> None: - typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=300), - ) - - @typed_backoff - def eventually_consistent_test() -> None: - message_ids = _publish_messages( + message_ids = _publish_messages( regional_publisher_client, exactly_once_delivery_topic ) - subscriber.receive_messages_with_exactly_once_delivery_enabled( - PROJECT_ID, SUBSCRIPTION_EOD, 10 + subscriber.receive_messages_with_exactly_once_delivery_enabled( + PROJECT_ID, SUBSCRIPTION_EOD, 100 ) - out, _ = capsys.readouterr() - assert subscription_eod in out - for message_id in message_ids: - assert message_id in out + out, _ = capsys.readouterr() + assert subscription_eod in out + for message_id in message_ids: + assert message_id in out - eventually_consistent_test() def test_listen_for_errors( @@ -741,7 +748,8 @@ def test_listen_for_errors( ) -> None: typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff @@ -782,7 +790,8 @@ def test_receive_synchronously_with_lease( ) -> None: typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=300), + Callable[[C], C], + backoff.on_exception(backoff.expo, Unknown, max_time=300), ) @typed_backoff From 26af77817e62e1d51069e0c3325a5b62622dbd6f Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo Date: Wed, 13 Apr 2022 19:41:10 +0000 Subject: [PATCH 2/5] format --- samples/snippets/subscriber_test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 6f6ae0807..6503922b6 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -53,6 +53,7 @@ typed_flaky = cast(Callable[[C], C], flaky(max_runs=3, min_passes=1)) typed_super_flaky = cast(Callable[[C], C], flaky(max_runs=5, min_passes=5)) + @pytest.fixture(scope="module") def publisher_client() -> Generator[pubsub_v1.PublisherClient, None, None]: yield pubsub_v1.PublisherClient() @@ -256,7 +257,7 @@ def subscription_eod( print("returning subscription.name = " + subscription.name) yield subscription.name - + subscriber_client.delete_subscription(request={"subscription": subscription.name}) @@ -726,12 +727,12 @@ def test_receive_messages_with_exactly_once_delivery_enabled( ) -> None: message_ids = _publish_messages( - regional_publisher_client, exactly_once_delivery_topic - ) + regional_publisher_client, exactly_once_delivery_topic + ) subscriber.receive_messages_with_exactly_once_delivery_enabled( - PROJECT_ID, SUBSCRIPTION_EOD, 100 - ) + PROJECT_ID, SUBSCRIPTION_EOD, 100 + ) out, _ = capsys.readouterr() assert subscription_eod in out @@ -739,7 +740,6 @@ def test_receive_messages_with_exactly_once_delivery_enabled( assert message_id in out - def test_listen_for_errors( publisher_client: pubsub_v1.PublisherClient, topic: str, From 1d59dc9456a6e3f11c66b13db3efaeaf7a8ee21a Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo Date: Wed, 13 Apr 2022 19:49:00 +0000 Subject: [PATCH 3/5] format --- samples/snippets/subscriber_test.py | 31 +++++++++-------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 6503922b6..86a918f4d 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -111,7 +111,6 @@ def exactly_once_delivery_topic( publisher_client.delete_topic(request={"topic": topic.name}) - @pytest.fixture(scope="module") def subscriber_client() -> Generator[pubsub_v1.SubscriberClient, None, None]: subscriber_client = pubsub_v1.SubscriberClient() @@ -159,8 +158,7 @@ def subscription_sync( yield subscription.name typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=300), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=300), ) @typed_backoff @@ -241,12 +239,10 @@ def subscription_eod( print("for " + subscription_path) try: - print("calling get subscription") subscription = subscriber_client.get_subscription( request={"subscription": subscription_path} ) except NotFound: - print("except NotFound, creating subscription") subscription = subscriber_client.create_subscription( request={ "name": subscription_path, @@ -254,7 +250,6 @@ def subscription_eod( "enable_exactly_once_delivery": True, } ) - print("returning subscription.name = " + subscription.name) yield subscription.name @@ -503,8 +498,7 @@ def test_create_push_subscription( capsys: CaptureFixture[str], ) -> None: typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), ) # The scope of `subscription_path` is limited to this function. @@ -559,8 +553,7 @@ def test_delete_subscription( subscriber.delete_subscription(PROJECT_ID, SUBSCRIPTION_ADMIN) typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff @@ -581,8 +574,7 @@ def test_receive( ) -> None: typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff @@ -607,8 +599,7 @@ def test_receive_with_custom_attributes( ) -> None: typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff @@ -636,8 +627,7 @@ def test_receive_with_flow_control( ) -> None: typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=300), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=300), ) @typed_backoff @@ -667,8 +657,7 @@ def test_receive_with_blocking_shutdown( _shut_down = re.compile(r".*done waiting.*stream shutdown.*", flags=re.IGNORECASE) typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=300), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=300), ) @typed_backoff @@ -748,8 +737,7 @@ def test_listen_for_errors( ) -> None: typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff @@ -790,8 +778,7 @@ def test_receive_synchronously_with_lease( ) -> None: typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=300), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=300), ) @typed_backoff From 540f181351f984938e9647f3e8d992cf32666ead Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo Date: Wed, 13 Apr 2022 19:51:45 +0000 Subject: [PATCH 4/5] format --- samples/snippets/subscriber_test.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 86a918f4d..c89310153 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -111,6 +111,7 @@ def exactly_once_delivery_topic( publisher_client.delete_topic(request={"topic": topic.name}) + @pytest.fixture(scope="module") def subscriber_client() -> Generator[pubsub_v1.SubscriberClient, None, None]: subscriber_client = pubsub_v1.SubscriberClient() @@ -236,7 +237,6 @@ def subscription_eod( subscription_path = subscriber_client.subscription_path( PROJECT_ID, SUBSCRIPTION_EOD ) - print("for " + subscription_path) try: subscription = subscriber_client.get_subscription( @@ -498,7 +498,7 @@ def test_create_push_subscription( capsys: CaptureFixture[str], ) -> None: typed_backoff = cast( - Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), ) # The scope of `subscription_path` is limited to this function. @@ -525,13 +525,11 @@ def eventually_consistent_test() -> None: def test_update_push_suscription( - subscription_admin: str, - capsys: CaptureFixture[str], + subscription_admin: str, capsys: CaptureFixture[str], ) -> None: typed_backoff = cast( - Callable[[C], C], - backoff.on_exception(backoff.expo, Unknown, max_time=60), + Callable[[C], C], backoff.on_exception(backoff.expo, Unknown, max_time=60), ) @typed_backoff From 3fc39506278221e78a8839dac27af0ea9e0de44d Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo Date: Wed, 13 Apr 2022 20:13:02 +0000 Subject: [PATCH 5/5] extending timeout --- 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 c89310153..868720fd4 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -51,7 +51,7 @@ C = TypeVar("C", bound=Callable[..., Any]) typed_flaky = cast(Callable[[C], C], flaky(max_runs=3, min_passes=1)) -typed_super_flaky = cast(Callable[[C], C], flaky(max_runs=5, min_passes=5)) +typed_super_flaky = cast(Callable[[C], C], flaky(max_runs=10, min_passes=10)) @pytest.fixture(scope="module") @@ -718,7 +718,7 @@ def test_receive_messages_with_exactly_once_delivery_enabled( ) subscriber.receive_messages_with_exactly_once_delivery_enabled( - PROJECT_ID, SUBSCRIPTION_EOD, 100 + PROJECT_ID, SUBSCRIPTION_EOD, 200 ) out, _ = capsys.readouterr()