Skip to content
Permalink
Browse files
fix(sample): retry InternalServerError (#329)
fixes #321
  • Loading branch information
tmatsuo committed Mar 15, 2021
1 parent 5a97ef1 commit 34c9b11ae697c280f32642c3101b7f7da971f589
Showing with 16 additions and 8 deletions.
  1. +16 −8 samples/snippets/subscriber_test.py
@@ -18,6 +18,7 @@

import backoff
from flaky import flaky
from google.api_core.exceptions import InternalServerError
from google.api_core.exceptions import NotFound
from google.api_core.exceptions import Unknown
from google.cloud import pubsub_v1
@@ -245,7 +246,7 @@ def test_receive_with_delivery_attempts(

# The dlq subscription raises 404 before it's ready.
# We keep retrying up to 10 minutes for mitigating the flakiness.
@backoff.on_exception(backoff.expo, (Unknown, NotFound), max_time=600)
@backoff.on_exception(backoff.expo, (Unknown, NotFound), max_time=120)
def run_sample():
_publish_messages(publisher_client, topic)

@@ -260,13 +261,20 @@ def run_sample():

@flaky(max_runs=3, min_passes=1)
def test_update_dead_letter_policy(subscription_dlq, dead_letter_topic, capsys):
_ = subscriber.update_subscription_with_dead_letter_policy(
PROJECT_ID,
TOPIC,
SUBSCRIPTION_DLQ,
DEAD_LETTER_TOPIC,
UPDATED_MAX_DELIVERY_ATTEMPTS,
)

# We saw internal server error that suggests to retry.

@backoff.on_exception(backoff.expo, (Unknown, InternalServerError), max_time=60)
def run_sample():
subscriber.update_subscription_with_dead_letter_policy(
PROJECT_ID,
TOPIC,
SUBSCRIPTION_DLQ,
DEAD_LETTER_TOPIC,
UPDATED_MAX_DELIVERY_ATTEMPTS,
)

run_sample()

out, _ = capsys.readouterr()
assert dead_letter_topic in out

0 comments on commit 34c9b11

Please sign in to comment.