Skip to content

Commit

Permalink
Respects min argument for wait_random_exponential (#425)
Browse files Browse the repository at this point in the history
* Respects `min` argument for wait_random_exponential

* Update test_tenacity.py

* Update test_tenacity.py

* Update test_tenacity.py
  • Loading branch information
yxtay authored Jul 29, 2024
1 parent 31fe2d0 commit a662bbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit a662bbb

Please sign in to comment.