diff --git a/releasenotes/notes/wait-random-exponential-min-2a4b7eed9f002436.yaml b/releasenotes/notes/wait-random-exponential-min-2a4b7eed9f002436.yaml new file mode 100644 index 0000000..34efd1c --- /dev/null +++ b/releasenotes/notes/wait-random-exponential-min-2a4b7eed9f002436.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Respects `min` arg for `wait_random_exponential` diff --git a/tenacity/wait.py b/tenacity/wait.py index 3addbb9..dc3c850 100644 --- a/tenacity/wait.py +++ b/tenacity/wait.py @@ -197,7 +197,7 @@ class wait_random_exponential(wait_exponential): def __call__(self, retry_state: "RetryCallState") -> float: high = super().__call__(retry_state=retry_state) - return random.uniform(0, high) + return random.uniform(self.min, high) class wait_exponential_jitter(wait_base): diff --git a/tests/test_tenacity.py b/tests/test_tenacity.py index ecc0312..b76fec2 100644 --- a/tests/test_tenacity.py +++ b/tests/test_tenacity.py @@ -472,9 +472,17 @@ def test_wait_random_exponential(self): self._assert_inclusive_range(fn(make_retry_state(8, 0)), 0, 60.0) self._assert_inclusive_range(fn(make_retry_state(9, 0)), 0, 60.0) - fn = tenacity.wait_random_exponential(10, 5) + # max wait + max_wait = 5 + fn = tenacity.wait_random_exponential(10, max_wait) for _ in range(1000): - self._assert_inclusive_range(fn(make_retry_state(1, 0)), 0.00, 5.00) + self._assert_inclusive_range(fn(make_retry_state(1, 0)), 0.00, max_wait) + + # min wait + min_wait = 5 + fn = tenacity.wait_random_exponential(min=min_wait) + for _ in range(1000): + self._assert_inclusive_range(fn(make_retry_state(1, 0)), min_wait, 5) # Default arguments exist fn = tenacity.wait_random_exponential()