Repository navigation
test(billing): give inflight estimate fixture a user group rate resolver - #7823
Closed
Ogannesson wants to merge 1 commit into
Closed
Ogannesson wants to merge 1 commit into
Ogannesson wants to merge 1 commit into
Conversation
newInflightEstimateGateway built a bare GatewayService without userGroupRateResolver, so every EstimateInflightReservation call fell back to newUserGroupRateResolver and allocated a fresh go-cache with its own janitor goroutine and ticker. Those are only released after their finalizers run, so TestInflightEstimate_AccountMappingNoDBAndBoundedMemory measured finalizer progress rather than per-model cache growth, and exceeded its 8 MiB bound on loaded CI runners (8.66 MB, twice in a row). With the resolver set as the production constructors do, the measured delta drops to under 2 KB.
riofutab
pushed a commit
to riofutab/sub2api
that referenced
this pull request
Oct 6, 2026
This was referenced Oct 21, 2026
This was referenced Nov 13, 2026
Contributor
Author
|
Superseded by #8598, which fixes the same fixture (the missing userGroupRateResolver in newInflightEstimateGateway) and has been merged. Closing this one. Thanks! |
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.
Summary
TestInflightEstimate_AccountMappingNoDBAndBoundedMemorycan fail on a loaded CI runner even though nothing grows per model name:We hit this twice in a row (8,664,872 and 8,675,904 bytes) when running
go test -tags=unit ./...on GitHub-hosted runners. On an idle machine, the same measurement ranges from 1 to 6 MB.This PR adds the missing
userGroupRateResolverto the test fixture. Only the test fixture changes. Production code is not touched.Root cause
newInflightEstimateGatewaybuilds a bareGatewayService{...}withoutuserGroupRateResolver. So everyEstimateInflightReservationcall reaches the fallback ingetUserGroupRateMultiplier:Each call creates a new
go-cachewith its own janitor goroutine and ticker. They are only freed after their finalizers run. The test runs 20,000 iterations, so theHeapAllocdelta measures how far finalization has progressed, not per-model cache growth.A heap profile diff (
pprof -base) of the measured window shows that 100% of the growth comes fromgetUserGroupRateMultiplier → newUserGroupRateResolver → gocache.New(janitor,time.NewTicker,newCache). Goroutine dumps taken right after the window show hundreds ofgo-cache.(*janitor).Rungoroutines.The production constructors (
NewGatewayService,NewOpenAIGatewayService) always setuserGroupRateResolver, so this fallback is not reached in production.Verification
We ran the full
internal/servicepackage on Linux, with a probe test that repeats the same 20,000-iteration window 6 times right after the original test:HeapAllocdeltago test -tags=unit ./internal/service/passes.