Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respects min argument for wait_random_exponential #425

Merged
merged 10 commits into from
Jul 29, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Respects `min` arg for `wait_random_exponential`
2 changes: 1 addition & 1 deletion tenacity/wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 10 additions & 2 deletions tests/test_tenacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down