Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise exception if retry-backoff fails to pass predicate. #2380

Merged
merged 2 commits into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions system_tests/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ def _job_done(instance):
retry = RetryInstanceState(_job_done, max_tries=8)
retry(job.reload)()

self.assertTrue(_job_done(job))
self.assertEqual(job.output_rows, len(ROWS))

rows, _, _ = table.fetch_data()
Expand Down Expand Up @@ -429,8 +428,6 @@ def _job_done(instance):
retry = RetryInstanceState(_job_done, max_tries=8)
retry(job.reload)()

self.assertTrue(job.state in ('DONE', 'done'))

rows, _, _ = table.fetch_data()
by_age = operator.itemgetter(1)
self.assertEqual(sorted(rows, key=by_age),
Expand Down
7 changes: 1 addition & 6 deletions system_tests/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ def test_topic_iam_policy(self):
# Retry / backoff up to 7 seconds (1 + 2 + 4)
retry = RetryResult(lambda result: result, max_tries=4)
retry(topic.exists)()

self.assertTrue(topic.exists())
self.to_delete.append(topic)

if topic.check_iam_permissions([PUBSUB_TOPICS_GET_IAM_POLICY]):
Expand All @@ -241,18 +239,15 @@ def test_subscription_iam_policy(self):
# Retry / backoff up to 7 seconds (1 + 2 + 4)
retry = RetryResult(lambda result: result, max_tries=4)
retry(topic.exists)()

self.assertTrue(topic.exists())
self.to_delete.append(topic)

SUB_NAME = 'test-sub-iam-policy-sub' + unique_resource_id('-')
subscription = topic.subscription(SUB_NAME)
subscription.create()

# Retry / backoff up to 7 seconds (1 + 2 + 4)
retry = RetryResult(lambda result: result, max_tries=4)
retry(subscription.exists)()

self.assertTrue(subscription.exists())
self.to_delete.insert(0, subscription)

if subscription.check_iam_permissions(
Expand Down
8 changes: 6 additions & 2 deletions system_tests/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def _retry_all(_):
return True


class BackoffFailed(Exception):
"""Retry w/ backoffs did not complete successfully."""


class RetryBase(object):
"""Base for retrying calling a decorated function w/ exponential backoff.

Expand Down Expand Up @@ -134,7 +138,7 @@ def wrapped_function(*args, **kwargs):

time.sleep(delay)
tries += 1
return to_wrap(*args, **kwargs)
raise BackoffFailed()

return wrapped_function

Expand Down Expand Up @@ -184,6 +188,6 @@ def wrapped_function(*args, **kwargs):

time.sleep(delay)
tries += 1
return to_wrap(*args, **kwargs)
raise BackoffFailed()

return wrapped_function