Skip to content

Commit c532444

Browse files
committed
Fix tries counter and change comments.
1 parent 49b3027 commit c532444

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

system_tests/bigquery.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ def test_update_dataset(self):
9393
if grant.entity_id != 'projectWriters']
9494
dataset.access_grants = after
9595

96-
# We should try and keep `delay` and tries as low as possible to
97-
# reduce test running time. tries=3 and delay=30 worked consistenly
98-
# when updating a dataset.
96+
# We need to wait for the changes in the dataset to propgate and be
97+
# eventually consistent. The alternative outcome is a 403 Forbidden
98+
# response from upstream.
9999
@Retry(Forbidden, tries=2, delay=30)
100100
def update_dataset():
101101
dataset.update()
@@ -199,9 +199,9 @@ def test_update_table(self):
199199
dataset = Config.CLIENT.dataset(DATASET_NAME)
200200
self.assertFalse(dataset.exists())
201201

202-
# We should try and keep `delay` and tries as low as possible to
203-
# reduce test running time. tries=3 and delay=20 worked consistenly
204-
# when creating a dataset.
202+
# We need to wait for the changes in the dataset to propgate and be
203+
# eventually consistent. The alternative outcome is a 403 Forbidden
204+
# response from upstream.
205205
@Retry(Forbidden, tries=2, delay=30)
206206
def create_dataset():
207207
dataset.create()

system_tests/retry.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
class Retry(object):
88
"""Retry class for retrying eventually consistent resources in testing."""
99

10-
logger = None
11-
exception = None
12-
tries = None
13-
delay = None
14-
backoff = None
15-
1610
def __init__(self, exception, tries=4, delay=3, backoff=2, logger=None):
1711
"""Retry calling the decorated function using an exponential backoff.
1812
@@ -32,21 +26,19 @@ def __init__(self, exception, tries=4, delay=3, backoff=2, logger=None):
3226
3327
:type logger: logging.Logger instance
3428
:param logger: Logger to use. If None, print.
35-
36-
:rtype: func
37-
:returns: Retry wrapper function.
3829
"""
3930

4031
self.exception = exception
4132
self.tries = tries
4233
self.delay = delay
4334
self.backoff = backoff
44-
self.logger = logger.warning if self.logger else six.print_
35+
self.logger = logger.warning if logger else six.print_
4536

4637
def __call__(self, to_wrap):
4738
@wraps(to_wrap)
4839
def wrapped_function(*args, **kwargs):
49-
while self.tries > 1:
40+
tries_counter = self.tries
41+
while tries_counter > 0:
5042
try:
5143
return to_wrap(*args, **kwargs)
5244
except self.exception as caught_exception:
@@ -55,7 +47,7 @@ def wrapped_function(*args, **kwargs):
5547
self.logger(msg)
5648

5749
time.sleep(self.delay)
58-
self.tries -= 1
50+
tries_counter -= 1
5951
self.delay *= self.backoff
6052
return to_wrap(*args, **kwargs)
6153

0 commit comments

Comments
 (0)