Close public API test coverage gaps, fix flaky tests - #40
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.