diff --git a/spinach/utils.py b/spinach/utils.py index 625cbd2..2056469 100644 --- a/spinach/utils.py +++ b/spinach/utils.py @@ -74,8 +74,8 @@ def exponential_backoff(attempt: int, cap: int=1200) -> timedelta: :arg cap: maximum delay, defaults to 20 minutes """ base = 3 - temp = min(base * 2 ** attempt, cap) - return timedelta(seconds=temp / 2 + random.randint(0, temp / 2)) + temp = min(base * 2 ** attempt, cap) // 2 + return timedelta(seconds=temp + random.randint(0, temp)) @contextlib.contextmanager diff --git a/tests/test_utils.py b/tests/test_utils.py index 0c0920b..f403305 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -65,9 +65,6 @@ def func(): def test_exponential_backoff(): - with pytest.raises(ValueError): - utils.exponential_backoff(0) - assert ( timedelta(seconds=3) <= utils.exponential_backoff(1) <= timedelta(seconds=6)