Skip to content

Close public API test coverage gaps, fix flaky tests - #40

Merged
mgnsk merged 1 commit into
masterfrom
test/close-coverage-gaps-and-flaky-tests
Aug 18, 2026
Merged

mgnsk merged 1 commit into
masterfrom
test/close-coverage-gaps-and-flaky-tests

Conversation

@mgnsk

@mgnsk mgnsk commented Aug 18, 2026

Copy link
Copy Markdown
Owner

cache.go and options.go had 0% direct coverage on their entire public surface (Len/Has/Load/Range/Evict/Store/Fetch/FetchTTL, WithPolicy, WithTTL) -- everything was only exercised one layer down against internal/backend.Backend directly. Add cache_test.go/options_test.go coverage for all of it, including Range's documented "f may modify the cache" contract and WithPolicy's panic on an invalid policy.

Also fixes two flaky tests found by repeatedly running the suite under -race:

  • TestMapShrink: not actually a GC-timing issue as it first appeared. The map-shrink heuristic in delete() bounds the live map to ~2x the current live count, not a fixed fraction of the original size, so evicting exactly 75% of entries sat right on that heuristic's worst-case boundary and never converged below the assertion's threshold. Evicting 90% instead lets multiple compaction passes fire and converge reliably.

  • New()'s default 1s expiry debounce (no public option to disable it) means a short TTL can take just under 2x the debounce interval to actually expire -- TestCacheFetchTTL and TestWithTTL were relying on the default 1s EventuallyTrue timeout, which the debounce can exceed depending on clock alignment.

Also splits TestFetchCallbackBlocks into independent tests, removing the shared, execution-order-dependent setup the author had already flagged with a TODO.

cache.go and options.go had 0% direct coverage on their entire public
surface (Len/Has/Load/Range/Evict/Store/Fetch/FetchTTL, WithPolicy,
WithTTL) -- everything was only exercised one layer down against
internal/backend.Backend directly. Add cache_test.go/options_test.go
coverage for all of it, including Range's documented "f may modify
the cache" contract and WithPolicy's panic on an invalid policy.

Also fixes two flaky tests found by repeatedly running the suite
under -race:

- TestMapShrink: not actually a GC-timing issue as it first appeared.
  The map-shrink heuristic in delete() bounds the live map to ~2x the
  current live count, not a fixed fraction of the original size, so
  evicting exactly 75% of entries sat right on that heuristic's
  worst-case boundary and never converged below the assertion's
  threshold. Evicting 90% instead lets multiple compaction passes
  fire and converge reliably.

- New()'s default 1s expiry debounce (no public option to disable it)
  means a short TTL can take just under 2x the debounce interval to
  actually expire -- TestCacheFetchTTL and TestWithTTL were relying
  on the default 1s EventuallyTrue timeout, which the debounce can
  exceed depending on clock alignment.

Also splits TestFetchCallbackBlocks into independent tests, removing
the shared, execution-order-dependent setup the author had already
flagged with a TODO.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mgnsk
mgnsk merged commit 66e11e8 into master Aug 18, 2026
1 check passed
@mgnsk
mgnsk deleted the test/close-coverage-gaps-and-flaky-tests branch August 18, 2026 11:11
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.

1 participant