diff --git a/backoff/_wait_gen.py b/backoff/_wait_gen.py index 33b37b8..1b54dde 100644 --- a/backoff/_wait_gen.py +++ b/backoff/_wait_gen.py @@ -22,12 +22,12 @@ def expo( """ # Advance past initial .send() call yield # type: ignore[misc] - n = 0 + base_n: float = 1 while True: - a = factor * base ** n + a = factor * base_n if max_value is None or a < max_value: yield a - n += 1 + base_n *= base else: yield max_value diff --git a/tests/test_wait_gen.py b/tests/test_wait_gen.py index a658712..bebe58b 100644 --- a/tests/test_wait_gen.py +++ b/tests/test_wait_gen.py @@ -67,6 +67,14 @@ def test_expo_max_value(): assert expect == next(gen) +def test_expo_max_value_factor(): + gen = backoff.expo(factor=3, max_value=2 ** 4) + gen.send(None) + expected = [3 * 1, 3 * 2, 3 * 4, 16, 16, 16, 16] + for expect in expected: + assert expect == next(gen) + + def test_fibo(): gen = backoff.fibo() gen.send(None)