diff --git a/kombu/utils/functional.py b/kombu/utils/functional.py index 0b594a6a..30c3ae8c 100644 --- a/kombu/utils/functional.py +++ b/kombu/utils/functional.py @@ -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 diff --git a/t/unit/utils/test_functional.py b/t/unit/utils/test_functional.py index c8b4485e..2ed64761 100644 --- a/t/unit/utils/test_functional.py +++ b/t/unit/utils/test_functional.py @@ -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