From e87e11d21818aceb66125684d583e161233b6f48 Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Mon, 21 Jun 2021 14:24:56 +0200 Subject: [PATCH 1/4] test: add additional debug info to snippet test --- samples/snippets/subscriber_test.py | 35 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py index 8d034949d..bf4eea7fa 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -425,21 +425,26 @@ def test_receive_with_blocking_shutdown( if re.search(r".*done waiting.*stream shutdown.*", line, flags=re.IGNORECASE) ] - assert "Listening" in out - assert subscription_async in out - - assert len(stream_canceled_lines) == 1 - assert len(shutdown_done_waiting_lines) == 1 - assert len(msg_received_lines) == 3 - assert len(msg_done_lines) == 3 - - # The stream should have been canceled *after* receiving messages, but before - # message processing was done. - assert msg_received_lines[-1] < stream_canceled_lines[0] < msg_done_lines[0] - - # Yet, waiting on the stream shutdown should have completed *after* the processing - # of received messages has ended. - assert msg_done_lines[-1] < shutdown_done_waiting_lines[0] + try: + assert "Listening" in out + assert subscription_async in out + + assert len(stream_canceled_lines) == 1 + assert len(shutdown_done_waiting_lines) == 1 + assert len(msg_received_lines) == 3 + assert len(msg_done_lines) == 3 + + # The stream should have been canceled *after* receiving messages, but before + # message processing was done. + assert msg_received_lines[-1] < stream_canceled_lines[0] < msg_done_lines[0] + + # Yet, waiting on the stream shutdown should have completed *after* + # the processing of received messages has ended. + assert msg_done_lines[-1] < shutdown_done_waiting_lines[0] + except AssertionError: # pragma: NO COVER + from pprint import pprint + pprint(out_lines) # To make possible flakiness debugging easier. + raise def test_listen_for_errors(publisher_client, topic, subscription_async, capsys): From 5f85c1cb04bb986c9229dd5025441121dcea4d0b Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Mon, 21 Jun 2021 14:28:42 +0200 Subject: [PATCH 2/4] Reduce the sleep timeout in message callback --- samples/snippets/subscriber.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/subscriber.py b/samples/snippets/subscriber.py index d01860cf8..011414296 100644 --- a/samples/snippets/subscriber.py +++ b/samples/snippets/subscriber.py @@ -499,7 +499,7 @@ def receive_messages_with_blocking_shutdown(project_id, subscription_id, timeout def callback(message): print(f"Received {message.data}.") - time.sleep(timeout + 5.0) # Pocess longer than streaming pull future timeout. + time.sleep(timeout + 3.0) # Pocess longer than streaming pull future timeout. message.ack() print(f"Done processing the message {message.data}.") From a99e918c276f55bb22488f906a0de6d4eb52eb08 Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Mon, 21 Jun 2021 14:55:51 +0200 Subject: [PATCH 3/4] Auto retry flaky delete schema test --- samples/snippets/schema_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/snippets/schema_test.py b/samples/snippets/schema_test.py index f0a4470f7..1e0dc8f1a 100644 --- a/samples/snippets/schema_test.py +++ b/samples/snippets/schema_test.py @@ -17,6 +17,7 @@ import os import uuid +from flaky import flaky from google.api_core.exceptions import NotFound from google.cloud.pubsub import PublisherClient, SchemaServiceClient, SubscriberClient from google.pubsub_v1.types import Encoding @@ -251,6 +252,7 @@ def test_subscribe_with_proto_schema( assert "Received a binary-encoded message" in out +@flaky(max_runs=3, min_passes=1) def test_delete_schema(proto_schema, capsys): schema.delete_schema(PROJECT_ID, PROTO_SCHEMA_ID) out, _ = capsys.readouterr() From b2b351d58be3c6f6343e6248c74448d872f9a8dc Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Mon, 21 Jun 2021 15:23:22 +0200 Subject: [PATCH 4/4] More flaky tests whack-a-mole --- 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 bf4eea7fa..20355fe2b 100644 --- a/samples/snippets/subscriber_test.py +++ b/samples/snippets/subscriber_test.py @@ -469,6 +469,7 @@ def test_receive_synchronously(publisher_client, topic, subscription_sync, capsy assert f"{subscription_sync}" in out +@flaky(max_runs=3, min_passes=1) def test_receive_synchronously_with_lease( publisher_client, topic, subscription_sync, capsys ):