mirror of https://github.com/celery/kombu.git
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:
parent
0ad7d08c4c
commit
5f93e868cf
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue