Skip to content

Commit

Permalink
Merge pull request #2380 from tseaver/2315-retry_instance_state-retry…
Browse files Browse the repository at this point in the history
…_result-raise

Raise exception if retry-backoff fails to pass predicate.
  • Loading branch information
tseaver authored Sep 21, 2016
2 parents 1f223f2 + 000dea6 commit 0c4fca3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
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

0 comments on commit 0c4fca3

Please sign in to comment.