Make sure that max_retries=0 is treated differently than None (#1080)

* Make sure that max_retries=0 is treated differently than None

When max_retries=0, it should not retry at all instead of retrying infinitely.

* retry_always should use max_retries=None instead of 0.

* Added test for zero retries

* Removed Offending spaces from blank line
This commit is contained in:
Eric Higdon 2019-08-13 13:51:40 -04:00 committed by Asif Saif Uddin
parent 0ad7d08c4c
commit 5f93e868cf
2 changed files with 17 additions and 2 deletions

View File

@ -342,7 +342,7 @@ def retry_over_time(fun, catch, args=None, kwargs=None, errback=None,
try:
return fun(*args, **kwargs)
except catch as exc:
if max_retries and retries >= max_retries:
if max_retries is not None and retries >= max_retries:
raise
if end and time() > end:
raise

View File

@ -226,6 +226,21 @@ class test_retry_over_time:
errback=None, timeout=1,
)
@mock.sleepdeprived(module=utils)
def test_retry_zero(self):
with pytest.raises(self.Predicate):
retry_over_time(
self.myfun, self.Predicate,
max_retries=0, errback=self.errback, interval_max=14,
)
assert self.index == 0
# no errback
with pytest.raises(self.Predicate):
retry_over_time(
self.myfun, self.Predicate,
max_retries=0, errback=None, interval_max=14,
)
@mock.sleepdeprived(module=utils)
def test_retry_once(self):
with pytest.raises(self.Predicate):
@ -261,7 +276,7 @@ class test_retry_over_time:
assert retry_over_time(
fun, self.Predicate,
max_retries=0, errback=None, interval_max=14) == 42
max_retries=None, errback=None, interval_max=14) == 42
assert fun.calls == 11