Skip to content

Commit 777d927

Browse files
lesnik512claude
andcommitted
test(retry-props): property test for the budget-exhaustion path
The existing AsyncRetry property tests build budgets with `min_retries_per_sec=1000.0` — floor of 60_000 retries permitted unconditionally — so the budget-exhaustion path is never exercised by Hypothesis. Add a focused property test on RetryBudget directly that configures `min_retries_per_sec=0.0` and asserts: exactly ceiling permits succeed, then the next one fails. Pairs with the math.ceil fix in commit 1 of this branch — the same ceiling formula is now the regression guard for both production and tests. Closes audit Nit finding (test_retry_props.py:60) from planning/audit/2026-06-07-deep-audit.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fd60067 commit 777d927

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎tests/test_retry_props.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
regardless of response status.
99
"""
1010

11+
import math
1112
from http import HTTPStatus
1213

1314
import httpx2
@@ -169,3 +170,28 @@ def handler(request: httpx2.Request) -> httpx2.Response:
169170
pass
170171
assert call_count["n"] == 1
171172
assert sleeper.calls == []
173+
174+
175+
@given(
176+
deposits=st.integers(min_value=1, max_value=20),
177+
percent=st.floats(
178+
min_value=0.0,
179+
max_value=0.5,
180+
allow_nan=False,
181+
allow_infinity=False,
182+
),
183+
)
184+
@settings(max_examples=50, deadline=None)
185+
def test_budget_exhaustion_is_reachable_and_deterministic(
186+
deposits: int,
187+
percent: float,
188+
) -> None:
189+
"""When floor=0 and a finite percent is set, the budget MUST refuse withdrawals after exactly ceiling permits."""
190+
budget = RetryBudget(ttl=60.0, min_retries_per_sec=0.0, percent_can_retry=percent)
191+
for _ in range(deposits):
192+
budget.deposit()
193+
expected_ceiling = math.ceil(deposits * percent)
194+
for permit in range(expected_ceiling):
195+
assert budget.try_withdraw(), f"budget refused early at permit {permit}/{expected_ceiling}"
196+
# The (ceiling + 1)-th withdrawal MUST fail.
197+
assert not budget.try_withdraw()

0 commit comments

Comments
 (0)