Skip to content

test(auth): freeze the prefetch join test cache clock - #41055

Closed
jibanez-staticduo wants to merge 1 commit into
BerriAI:mainfrom
jibanez-staticduo:litellm_auth_prefetch_clock
Closed

jibanez-staticduo wants to merge 1 commit into
BerriAI:mainfrom
jibanez-staticduo:litellm_auth_prefetch_clock

Conversation

@jibanez-staticduo

Copy link
Copy Markdown

TLDR

Problem this solves:

  • Slow runners can expire the auth test's prefetched organization

How it solves it:

  • Give this cache-hit test a fixed, injected clock

User Flow

Before: a contributor runs the auth prefetch join test on a slow runner and sees a cache-miss error

  1. Run the auth prefetch test with its PostgreSQL fixture
  2. Delay organization lookup beyond the five-second cache TTL
  3. Observe TypeError: object MagicMock can't be used in 'await' expression

After: the same contributor can run the test without depending on runner speed

  1. Run the auth prefetch test with its PostgreSQL fixture
  2. Delay organization lookup beyond the five-second cache TTL
  3. Observe the prefetched organization being returned and the test passing

Relevant issues

Found while diagnosing unrelated PR #41050: https://github.com/BerriAI/litellm/actions/runs/34821830089/job/103904913864

Affected release

Linear ticket

Pre-Submission checklist

  • The existing test checks meaningful SQL join and cache-hit behavior
  • All three tests in the affected file pass, including with a controlled lookup delay
  • Required CI/CD checks pass
  • Scope is limited to one test's clock
  • Greptile confidence is at least 4/5

Screenshots / Proof of Fix

This is a test-only timing fix. The reproduction uses the test suite's PostgreSQL fixture. Save the following temporary pytest plugin as ttl_probe.py outside the checkout and add its directory to PYTHONPATH. It delays the organization getter without changing repository files or the cache clock

import asyncio
import pytest

@pytest.fixture(autouse=True)
def ttl_probe(request, monkeypatch):
    module = request.module
    if not hasattr(module, "get_org_object"):
        return
    original_getter = module.get_org_object
    async def delayed_getter(*args, **kwargs):
        await asyncio.sleep(5.2)
        return await original_getter(*args, **kwargs)
    monkeypatch.setattr(module, "get_org_object", delayed_getter)

Before (30f33a9)

  1. With the proxy-behavior test database configured, run the affected test with the temporary delay plugin

    python -m pytest -p ttl_probe tests/proxy_behavior/auth/test_auth_object_prefetch.py::test_join_binds_the_membership_to_the_requested_team -q
  2. Observe the cache miss reach the deliberately unusable database fixture

    auth_checks.py:3798: await _model_dump_table(OrganizationRepository(prisma_client)).find_unique(**query_kwargs)
    TypeError: object MagicMock can't be used in 'await' expression
    1 failed
    

After (0736d75)

  1. Run the entire affected file with the same delay plugin

    python -m pytest -p ttl_probe tests/proxy_behavior/auth/test_auth_object_prefetch.py -q
  2. Observe the SQL join and cache-hit assertions pass despite the delay

    3 passed in 11.77s
    

Type

Test

Caveats (if any)

Low

  • The original CI log lacks per-operation cache timestamps

The controlled delay reproduces the exact exception on both unchanged upstream and the unrelated reasoning PR. This demonstrates the test's timing sensitivity; it does not measure when the original CI entry expired. Production authentication and cache TTLs are unchanged. The affected test-tree Ruff and quality-budget checks pass

Final Attestation

  • The join test still validates its original behavior with a deterministic cache clock

@jibanez-staticduo
jibanez-staticduo requested a review from a team September 14, 2026 09:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-14T09:11:55.654858Z 0736d75 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This test-only change injects a fixed clock into the prefetch join test's in-memory cache

  • Prevents slow runners from expiring prefetched entries before assertions
  • Preserves the SQL join, cache-key, returned-value, and no-database-call checks

Confidence Score: 5/5

The PR appears safe to merge because the fixed clock removes timing sensitivity while preserving the test's behavioral assertions

No actionable failures remain; incorrect prefetch data or cache keys would still fall through to the unusable database fixture and fail the test

Important Files Changed

Filename Overview
tests/proxy_behavior/auth/test_auth_object_prefetch.py Freezes the test-local cache clock so cache-hit assertions remain deterministic without weakening coverage

Reviews (1): Last reviewed commit: "test(auth): freeze the prefetch join tes..." | Re-trigger Greptile

@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jibanez-staticduo

Copy link
Copy Markdown
Author

Closing as superseded by #40996, which freezes all three test caches. #41102 also adds an explicit prefetched-organization assertion

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