Repository navigation
test(api): make the cached-token authorization check deterministic - #1100
Merged
Merged
Conversation
Contributor
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
SessionAuthorizationTest> "has on a cached token stays under one millisecond" timed 1000 calls ofcheckAuthorization(plan = "plus")withSystem.nanoTimeand required the 95th percentile to be under 1 ms. On shared CI runners, JIT warm-up, GC and other jobs on the same machine make that fail at random. It failed on #960 (run 38603921984,test-module :source:api, blacksmith-4vcpu-ubuntu-2404), and #960 doesn't touch this code.The test now checks how much work each call does instead of timing it:
JWT.getClaim, through a MockK constructor spy that calls the real method). It asserts that 100 more calls do exactly 100 × the claim reads of the first call, so the work per call stays the same and doesn't grow.true, and that the call leavesSessionTokensCacheempty: the read path neither stores nor fetches tokens.The result is deterministic and doesn't depend on runner speed.
Note:
SessionAuthorization.evaluatehas no memoization. Each call decodes the JWT again (TokenFreshness.matchesplusfeaturesClaim,plansClaim,issuedAtMillisandfactorVerificationAgeClaim). So a check that "the token is decoded once across calls" would fail against the current code. Adding a per-JWT claim cache would change production code, so it is left out of this test-only PR.Verification
./gradlew :source:api:testDebugUnitTest spotlessCheck detektpasses locally.source/api,source/uior:e2echanges at runtime.Summary by CodeRabbit