|
7 | 7 | """ |
8 | 8 |
|
9 | 9 | import datetime as dt |
| 10 | +import math |
10 | 11 |
|
11 | 12 | import httpx2 |
12 | 13 | import pytest |
@@ -206,3 +207,46 @@ def test_budget_refusal_raises_with_cause_and_fields() -> None: |
206 | 207 | def test_invalid_max_attempts_rejected() -> None: |
207 | 208 | with pytest.raises(ValueError, match="max_attempts must be >= 1"): |
208 | 209 | _policy(max_attempts=0) |
| 210 | + |
| 211 | + |
| 212 | +@pytest.mark.parametrize("base_delay", [-0.1, -1, math.nan]) |
| 213 | +def test_invalid_base_delay_rejected(base_delay: float) -> None: |
| 214 | + with pytest.raises(ValueError, match="base_delay must be >= 0"): |
| 215 | + _RetryPolicy( |
| 216 | + max_attempts=3, |
| 217 | + base_delay=base_delay, |
| 218 | + max_delay=_MAX_DELAY, |
| 219 | + retry_status_codes=DEFAULT_RETRY_STATUS_CODES, |
| 220 | + retry_methods=DEFAULT_IDEMPOTENT_METHODS, |
| 221 | + respect_retry_after=True, |
| 222 | + budget=None, |
| 223 | + ) |
| 224 | + |
| 225 | + |
| 226 | +@pytest.mark.parametrize("max_delay", [-0.1, -1, math.nan, math.inf]) |
| 227 | +def test_invalid_max_delay_rejected(max_delay: float) -> None: |
| 228 | + with pytest.raises(ValueError, match="max_delay must be a finite number >= 0"): |
| 229 | + _RetryPolicy( |
| 230 | + max_attempts=3, |
| 231 | + base_delay=_BASE_DELAY, |
| 232 | + max_delay=max_delay, |
| 233 | + retry_status_codes=DEFAULT_RETRY_STATUS_CODES, |
| 234 | + retry_methods=DEFAULT_IDEMPOTENT_METHODS, |
| 235 | + respect_retry_after=True, |
| 236 | + budget=None, |
| 237 | + ) |
| 238 | + |
| 239 | + |
| 240 | +@pytest.mark.parametrize(("base_delay", "max_delay"), [(0.0, 0.0), (0.0, _MAX_DELAY), (math.inf, _MAX_DELAY)]) |
| 241 | +def test_boundary_delays_accepted(base_delay: float, max_delay: float) -> None: |
| 242 | + policy = _RetryPolicy( |
| 243 | + max_attempts=3, |
| 244 | + base_delay=base_delay, |
| 245 | + max_delay=max_delay, |
| 246 | + retry_status_codes=DEFAULT_RETRY_STATUS_CODES, |
| 247 | + retry_methods=DEFAULT_IDEMPOTENT_METHODS, |
| 248 | + respect_retry_after=True, |
| 249 | + budget=None, |
| 250 | + ) |
| 251 | + request = _request("PUT") |
| 252 | + assert 0.0 <= policy.decide(attempt=0, request=request, exc=_status_exc(503, request)) <= max_delay |
0 commit comments