Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 05e3f2f

Browse filesBrowse files
authored
tests: mitigate flaky snippets tests (#432)
* test: add additional debug info to snippet test * Reduce the sleep timeout in message callback * Auto retry flaky delete schema test * More flaky tests whack-a-mole
1 parent 2446818 commit 05e3f2f
Copy full SHA for 05e3f2f

File tree

Expand file treeCollapse file tree

3 files changed

+21
-13
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-13
lines changed
Open diff view settings
Collapse file

‎samples/snippets/schema_test.py‎

Copy file name to clipboardExpand all lines: samples/snippets/schema_test.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import uuid
1919

20+
from flaky import flaky
2021
from google.api_core.exceptions import NotFound
2122
from google.cloud.pubsub import PublisherClient, SchemaServiceClient, SubscriberClient
2223
from google.pubsub_v1.types import Encoding
@@ -251,6 +252,7 @@ def test_subscribe_with_proto_schema(
251252
assert "Received a binary-encoded message" in out
252253

253254

255+
@flaky(max_runs=3, min_passes=1)
254256
def test_delete_schema(proto_schema, capsys):
255257
schema.delete_schema(PROJECT_ID, PROTO_SCHEMA_ID)
256258
out, _ = capsys.readouterr()
Collapse file

‎samples/snippets/subscriber.py‎

Copy file name to clipboardExpand all lines: samples/snippets/subscriber.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def receive_messages_with_blocking_shutdown(project_id, subscription_id, timeout
499499

500500
def callback(message):
501501
print(f"Received {message.data}.")
502-
time.sleep(timeout + 5.0) # Pocess longer than streaming pull future timeout.
502+
time.sleep(timeout + 3.0) # Pocess longer than streaming pull future timeout.
503503
message.ack()
504504
print(f"Done processing the message {message.data}.")
505505

Collapse file

‎samples/snippets/subscriber_test.py‎

Copy file name to clipboardExpand all lines: samples/snippets/subscriber_test.py
+18-12Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -425,21 +425,26 @@ def test_receive_with_blocking_shutdown(
425425
if re.search(r".*done waiting.*stream shutdown.*", line, flags=re.IGNORECASE)
426426
]
427427

428-
assert "Listening" in out
429-
assert subscription_async in out
428+
try:
429+
assert "Listening" in out
430+
assert subscription_async in out
430431

431-
assert len(stream_canceled_lines) == 1
432-
assert len(shutdown_done_waiting_lines) == 1
433-
assert len(msg_received_lines) == 3
434-
assert len(msg_done_lines) == 3
432+
assert len(stream_canceled_lines) == 1
433+
assert len(shutdown_done_waiting_lines) == 1
434+
assert len(msg_received_lines) == 3
435+
assert len(msg_done_lines) == 3
435436

436-
# The stream should have been canceled *after* receiving messages, but before
437-
# message processing was done.
438-
assert msg_received_lines[-1] < stream_canceled_lines[0] < msg_done_lines[0]
437+
# The stream should have been canceled *after* receiving messages, but before
438+
# message processing was done.
439+
assert msg_received_lines[-1] < stream_canceled_lines[0] < msg_done_lines[0]
439440

440-
# Yet, waiting on the stream shutdown should have completed *after* the processing
441-
# of received messages has ended.
442-
assert msg_done_lines[-1] < shutdown_done_waiting_lines[0]
441+
# Yet, waiting on the stream shutdown should have completed *after*
442+
# the processing of received messages has ended.
443+
assert msg_done_lines[-1] < shutdown_done_waiting_lines[0]
444+
except AssertionError: # pragma: NO COVER
445+
from pprint import pprint
446+
pprint(out_lines) # To make possible flakiness debugging easier.
447+
raise
443448

444449

445450
def test_listen_for_errors(publisher_client, topic, subscription_async, capsys):
@@ -464,6 +469,7 @@ def test_receive_synchronously(publisher_client, topic, subscription_sync, capsy
464469
assert f"{subscription_sync}" in out
465470

466471

472+
@flaky(max_runs=3, min_passes=1)
467473
def test_receive_synchronously_with_lease(
468474
publisher_client, topic, subscription_sync, capsys
469475
):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.