Skip to content

test(cache): pin RetryPolicy jitter band and backoff edge cases (#528) - #538

Merged
alpergundogdu merged 1 commit into
mainfrom
claude/fix-small-bugs-jzFfP
May 14, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
claude/fix-small-bugs-jzFfP

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

Adds three unit tests to crates/cache/src/retry.rs covering RetryPolicy::delay_for boundary conditions the existing tests left uncovered:

  • delay_for_jitter_stays_within_equal_jitter_band — samples four non-clamped ratios (0.1, 0.25, 0.5, 1.0) 256 times each and pins both bounds of the equal-jitter band. The existing delay_for_clamps_jitter_above_one only exercised the clamp at r > 1.0, so a regression in the formula at typical ratios was previously invisible.
  • delay_for_zero_jitter_is_deterministic — pins the contract that jitter_ratio = 0.0 collapses the formula to exactly base (the property tests pinning expected sleep schedules rely on).
  • delay_for_zero_initial_backoff_is_zero_regardless_of_jitter — covers the initial_backoff_ms = 0 edge case across attempts with a non-zero jitter; both factor paths collapse a zero base to a zero delay.

The max_retries = 0 "no sleep / single attempt" path remains covered by retry_disabled_policy_makes_a_single_attempt in crates/cache/tests/pull_through.rs:2065, which drives the full retry_fetch loop.

Closes #528.

Test plan

  • cargo test -p decdn-cache --lib retry:: — 9/9 pass (6 existing + 3 new)
  • cargo clippy -p decdn-cache --all-targets -- -D warnings — clean
  • cargo fmt -- --check — clean

https://claude.ai/code/session_01WimP9WEV6zXWiVNJRBnCNo


Generated by Claude Code

Three additional unit tests in `crates/cache/src/retry.rs` covering
boundary conditions of `RetryPolicy::delay_for` that the existing tests
left open:

- `delay_for_jitter_stays_within_equal_jitter_band`: samples each of
  four non-clamped jitter ratios (0.1, 0.25, 0.5, 1.0) 256 times and
  pins both bounds of the equal-jitter band. The existing
  `delay_for_clamps_jitter_above_one` only exercised the clamp at
  `r > 1.0`; a regression in the formula at typical ratios was
  previously invisible.
- `delay_for_zero_jitter_is_deterministic`: pins the contract that
  `jitter_ratio = 0.0` collapses the formula to exactly `base`, which
  tests pinning expected sleep schedules rely on.
- `delay_for_zero_initial_backoff_is_zero_regardless_of_jitter`: covers
  the `initial_backoff_ms = 0` edge case across attempts and a non-zero
  jitter — both factor paths collapse a 0 base to a 0 delay.

The `max_retries = 0` "no sleep / single attempt" path remains covered
by `retry_disabled_policy_makes_a_single_attempt` in
`crates/cache/tests/pull_through.rs:2065`, which drives the full
`retry_fetch` loop.

Closes #528.

https://claude.ai/code/session_01WimP9WEV6zXWiVNJRBnCNo
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 89.19% (was 89.16%, ▲ +0.02%) — 13632/15285 lines

File Coverage Lines Δ
crates/cache/src/retry.rs 97.40% 150/154 ▲ +0.94%
History
Commit Total Δ vs base
ce71097 (HEAD) 89.19% ▲ +0.02%

@gemini-code-assist

Copy link
Copy Markdown

Warning

Gemini is experiencing higher than usual traffic and was unable to create the review. Please try again in a few hours by commenting /gemini review.

@alpergundogdu
alpergundogdu merged commit 0c73b4a into main May 14, 2026
11 checks passed
@alpergundogdu
alpergundogdu deleted the claude/fix-small-bugs-jzFfP branch May 14, 2026 12:02
alpergundogdu added a commit that referenced this pull request May 14, 2026
…553)

Adds `coalesced_concurrent_misses_fire_origin_exactly_once` in
`crates/cache/tests/pull_through.rs`. Spawns 10 concurrent
`engine.get(hash)` tasks for an uncached blob against a `SlowOnceOrigin`
helper (sleeps 25ms before serving) and asserts the origin saw exactly
one fetch. The existing `coalesced_owner_retry_unblocks_waiters_on_success`
already pins coalescing under retry (`origin.fetches() == 3`); this is
the missing happy-path companion that pins `== 1` on the no-failure
path so a regression breaking coalescing — duplicate origin charges,
duplicate iroh-blobs inserts — shows up without retry noise muddying
the count.

`SlowOnceOrigin` mirrors the shape of `FailingThenSucceedingOrigin`
(atomic fetch counter, `OriginFetch::found_one_shot`) but takes a
`Duration` delay instead of a failure count. The delay is load-bearing:
an instantaneous fetch can complete before any waiter is scheduled,
making a coalescing assertion trivially pass for the wrong reason.

Also: backfill `buffered_max_bytes` in the three pre-#519 `RetryPolicy`
struct literals introduced by #538, which now don't compile because
#519 added the field after #538 landed.

Closes #530.

https://claude.ai/code/session_01WimP9WEV6zXWiVNJRBnCNo

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants