Skip to content

Commit

Permalink
Ensure both backoff methods clamp correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Aug 18, 2024
1 parent f3a37fe commit 3f71703
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import datetime as dt

from types import SimpleNamespace

import pytest
import tenacity

Expand Down Expand Up @@ -180,6 +182,23 @@ def test_next_wait():
raise ValueError


def test_backoff_computation_clamps():
"""
The backoff returned by _RetryContextIterator._backoff_for_attempt_number
and _RetryContextIterator._jittered_backoff_for_rcs never exceeds wait_max.
"""
rci = stamina.retry_context(on=ValueError, wait_max=0.42)

for i in range(1, 10):
backoff = rci._backoff_for_attempt_number(i)
assert backoff <= 0.42

jittered = rci._jittered_backoff_for_rcs(
SimpleNamespace(attempt_number=i)
)
assert jittered <= 0.42


class TestMakeStop:
def test_never(self):
"""
Expand Down

0 comments on commit 3f71703

Please sign in to comment.