Skip to content

test(cache): use full-entropy keys in tinylfu policy tests (#1854) - #1856

Merged
thiras merged 1 commit into
mainfrom
fix/tinylfu-test-keys
Aug 26, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/tinylfu-test-keys

Conversation

@thiras

@thiras thiras commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1854. crates/cache/src/policy/tinylfu.rs used degenerate Hash::from([b; 32]) keys in all five tests. Those keys make the shard-routing slice and the four row slices perfectly correlated, putting every row on one column — so the tests cannot observe a routing bug. The sister module sketch.rs already establishes the full-entropy convention (Hash::new(i.to_le_bytes())).

Change

  • Replace the test helper fn h(b: u8) -> Hash { Hash::from([b; 32]) } with fn h(i: u32) -> Hash { Hash::new(i.to_le_bytes()) }, matching sketch.rs's key().
  • Update all five tests' call sites to pass u32 literals.

The cache crate's Hash is iroh_blobs::Hash, so Hash::new(bytes) computes a real BLAKE3 digest of the input — full-entropy keys with realistic shard distribution.

Verification

  • cargo nextest run -p decdn-cache — all 392 tests pass
  • cargo clippy — clean
  • cargo fmt -- --check — clean
  • pre-commit hooks all pass

Test-only change; no production code, wire, or format changes.

Copilot AI lite review requested due to automatic review settings August 26, 2026 22:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the tinylfu policy tests in decdn-cache to use realistic, full-entropy cache keys so the sharded frequency estimator routing logic is actually exercised (aligning with the established convention in sketch.rs and addressing #1854).

Changes:

  • Replaces the degenerate test helper Hash::from([b; 32]) with Hash::new(i.to_le_bytes()) to generate uniformly distributed test keys.
  • Updates all tinylfu.rs policy tests to pass u32 inputs to the new helper.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 82.08% (was 82.08%, ● 0.00%) — 68889/83925 lines

File Coverage Lines Δ
crates/cache/src/policy/tinylfu.rs 99.06% 211/213 ● 0.00%
History
Commit Total Δ vs base
d4973ed (HEAD) 82.08% ● 0.00%

@thiras
thiras merged commit 72e097a into main Aug 26, 2026
26 checks passed
@thiras
thiras deleted the fix/tinylfu-test-keys branch August 26, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cache: tinylfu policy tests use degenerate [b; 32] keys

2 participants