Repository navigation
test(auth): freeze cache clock in auth prefetch behavior tests - #41060
Closed
deepanshupal wants to merge 1 commit into
Closed
deepanshupal wants to merge 1 commit into
deepanshupal wants to merge 1 commit into
Conversation
The proxy-behavior test asserts the getters are served from the prefetched in-memory cache, but the prefetched org entries carry the 5s DEFAULT_IN_MEMORY_TTL while user/team entries get the 60s management TTL and the membership read is backstopped by the never-expiring reservation key. On a slow CI runner the first getter call alone can take seconds (3.2s observed on a quiet local machine), so by the time get_org_object runs the two org keys - the only ones without a no-expiry backstop - can have expired, and the getter falls through to the mocked dead prisma client (TypeError: object MagicMock can't be used in 'await' expression, seen on main push run 34737619378). Freeze the test cache's clock so TTL expiry cannot race the assertions. Production behavior is unchanged: the 5s org TTL is intentional (the org getter's own write uses it, and bumping the prefetch TTL to the management TTL breaks 45 management tests that rely on org freshness). Verified against a real Postgres 16 with the same prisma db push the CI job performs: tests/proxy_behavior (848 tests) and the fake-based prefetch unit tests (11 tests) all pass, and a 6s sleep between prefetch and the getters reproduces the exact CI failure without the fix and passes with it.
Contributor
Greptile SummaryThis PR makes three auth-object prefetch behavior tests deterministic by freezing their test-local cache clocks.
Confidence Score: 5/5The PR appears safe to merge because the deterministic clocks only affect tests and do not weaken their current behavioral assertions. The changed tests verify immediate cache-hit behavior rather than TTL expiration, and the injected clock removes an unrelated timing race without changing production code.
|
| Filename | Overview |
|---|---|
| tests/proxy_behavior/auth/test_auth_object_prefetch.py | Injects frozen clocks into test-local caches to prevent wall-clock timing from making immediate prefetch assertions flaky. |
Reviews (1): Last reviewed commit: "test(auth): freeze cache clock in auth p..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
6 tasks done
Author
|
Closing - main got the same fix in #40996 (frozen cache clock for these tests). Nothing left here. |
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.
What
Fixes the
proxy-behaviorflake from #41051:test_join_binds_the_membership_to_the_requested_teamfails on slow CI runners withTypeError: object MagicMock can't be used in 'await' expressionfrom theget_org_objectfallback. Currently red on main (push run 34737619378: 1 failed / 847 passed, test call took 5.48s).Root cause
The test asserts that after
prefetch_auth_objects, all four getters are served from the in-memory cache. But the prefetched org entries (org_id:*,org_id:*:with_budget) are written with the 5sDEFAULT_IN_MEMORY_TTL, while user/team entries get the 60s management TTL and the membership read is backstopped by the never-expiring reservation key. The org keys are the only prefetched entries with no no-expiry backstop.The getters normally run milliseconds after the prefetch write, but the first getter call can take seconds (3.2s measured on a quiet local machine - event-loop warmup right after the prefetch await; the CI run shows a 5.48s call). On a loaded runner the gap crosses 5s, the org entry expires, and
get_org_objectfalls through to the mocked dead prisma client.Reproduced locally: sleeping 6s between prefetch and the getters produces the exact CI error, with membership/team/user still served from cache.
Fix
Test-only: the test's
InMemoryCachegets a frozen clock (clock=lambda: 0.0), so TTL expiry can't race the assertions.Production behavior is unchanged on purpose. The 5s org TTL is intentional - the org getter's own cache write uses it too, and bumping the prefetch TTL to the management TTL breaks 45 management tests that rely on org freshness.
Verification
tests/proxy_behavior(848 tests) andtests/test_litellm/proxy/auth/test_auth_object_prefetch.py(11 tests) pass against a real Postgres 16, seeded with the sameprisma db pushthe CI job performs.