Skip to content

Add unit tests for getShardID#149

Merged
kpango merged 2 commits intobugfix/shard-distribution-biasfrom
copilot/sub-pr-148
Feb 25, 2026
Merged

Add unit tests for getShardID#149
kpango merged 2 commits intobugfix/shard-distribution-biasfrom
copilot/sub-pr-148

Conversation

Copy link

Copilot AI commented Feb 25, 2026

getShardID had no test coverage despite containing branching logic across three hash strategies and two key-length modes. This adds gache_test.go covering all meaningful paths.

Tests added

  • maxKeyLength == 0 — full key used; exercises single-byte, ≤32-char (maphash), and >32-char (xxh3) paths
  • maxKeyLength == 1 — single-byte fast path with exact expected-value assertion (uint64(key[0]) & mask)
  • maxKeyLength 2–32maphash path; keys both shorter and longer than kl
  • maxKeyLength > 32xxh3 path; keys both shorter and longer than kl
  • Key shorter than maxKeyLength — verifies effective_kl = min(len(key), kl) clamping
  • Result always in [0, mask] — bounds check across all parameter combinations
  • Prefix isolation — keys sharing the same first kl bytes must map to the same shard, confirming truncation is applied before hashing

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…h scenarios

Co-authored-by: kpango <9798091+kpango@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on shard distribution bias bugfix PR Add unit tests for getShardID Feb 25, 2026
Copilot AI requested a review from kpango February 25, 2026 03:27
@kpango kpango marked this pull request as ready for review February 25, 2026 03:28
@kpango kpango merged commit 408cbfd into bugfix/shard-distribution-bias Feb 25, 2026
2 checks passed
@kpango kpango deleted the copilot/sub-pr-148 branch February 25, 2026 03:28
kpango added a commit that referenced this pull request Feb 25, 2026
Apply suggestions from code review
Add unit tests for getShardID (#149)
Fix shard distribution bias: restore default expiration, add WithMaxKeyLength docs, and getShardID tests (#150)

Signed-off-by: kpango <kpango@vdaas.org>
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.

2 participants