Skip to content

test(proxy): isolate run_server CLI tests from prisma DB-setup path - #28029

Merged
yuneng-berri merged 3 commits into
litellm_internal_stagingfrom
litellm_/determined-yalow-811fee
May 16, 2026
Merged

test(proxy): isolate run_server CLI tests from prisma DB-setup path#28029
yuneng-berri merged 3 commits into
litellm_internal_stagingfrom
litellm_/determined-yalow-811fee

Conversation

@yuneng-berri

@yuneng-berri yuneng-berri commented May 15, 2026

Copy link
Copy Markdown
Contributor

Summary

test_keepalive_timeout_flag and test_timeout_worker_healthcheck_flag in tests/test_litellm/proxy/test_proxy_cli.py were the only run_server tests in that file that neither stripped DATABASE_URL/DIRECT_URL from the environment nor mocked the prisma DB-setup path.

When a DATABASE_URL is present (CI env / cross-test leak within an xdist worker), run_server --local enters the DB-setup block and blocks in:

  • the un-timeout'd subprocess.run(["prisma"], capture_output=True) at litellm/proxy/proxy_cli.py:987, then
  • the ProxyExtrasDBManager prisma migrate deploy retry loops (4 × timeout=60 + backoff, repeated)

On the CI runner (no reachable Postgres) this is ~370s per test. Because --dist=loadscope pins both tests (same module) to one xdist worker, the Unit Tests: Proxy Infrastructure job spends ~12.5 min on that single worker while the other finishes in ~3 min — the run appears stuck at 99% and crosses the 20-minute job timeout.

The fix applies the same isolation every other run_server test in this file already uses: mock PrismaManager.setup_database + should_update_prisma_schema, and strip DATABASE_URL/DIRECT_URL via patch.dict(os.environ, clean_env, clear=True). Tests-only change; no production code touched.

Test plan

Reproduced and verified locally (tests/test_litellm/proxy/test_proxy_cli.py, full module):

before after
Full module (32 tests) 31.7s 2.9s
test_keepalive_timeout_flag 21.7s <0.01s
test_timeout_worker_healthcheck_flag 6.8s <0.01s
Either test with DATABASE_URL set 36.9s 0.01s

The two tests fall off the slow-durations list entirely and behave like the other 30 run_server siblings. Assertions (uvicorn arg threading) are unchanged and still pass.


Note

Low Risk
Tests now explicitly avoid the Prisma DB-setup path when DATABASE_URL/DIRECT_URL are present, reducing CI flakiness/timeouts; production behavior is unchanged. Risk is low since changes are limited to test isolation/mocking.

Overview
Makes test_keepalive_timeout_flag and test_timeout_worker_healthcheck_flag consistent with other run_server CLI tests by preventing accidental entry into the Prisma DB-setup path.

Both tests now (1) patch PrismaManager.setup_database and should_update_prisma_schema and (2) run under a sanitized env (patch.dict(..., clear=True)) that strips DATABASE_URL/DIRECT_URL, keeping assertions focused on uvicorn arg threading without triggering slow DB/migration subprocess work in CI.

Reviewed by Cursor Bugbot for commit aebb606. Bugbot is set up for automated code reviews on this repo. Configure here.

test_keepalive_timeout_flag and test_timeout_worker_healthcheck_flag
were the only run_server tests in test_proxy_cli.py that neither
stripped DATABASE_URL/DIRECT_URL nor mocked the prisma DB path. When a
DATABASE_URL is present (CI/env leak), run_server --local enters the DB
block and blocks in the un-timeout'd subprocess.run(["prisma"]) at
proxy_cli.py:987 plus the ProxyExtrasDBManager migrate-deploy retry
loops, ~370s per test on the CI runner. --dist=loadscope pins both to
one xdist worker, so the proxy-infra job appears stuck at 99% and hits
the 20-min timeout.

Apply the same isolation every other run_server test in this file
already uses: mock PrismaManager.setup_database +
should_update_prisma_schema and strip DATABASE_URL/DIRECT_URL. Full
module drops from 31.7s to 2.9s locally; both tests fall off the slow
list.
@greptile-apps

greptile-apps Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Two run_server tests in test_proxy_cli.py were missing the Prisma DB isolation that every other test in the same module uses, causing them to block on an un-timeout'd subprocess.run(["prisma"]) and subsequent migrate-deploy retry loops whenever DATABASE_URL was present in the environment. This PR adds the same @patch(PrismaManager.setup_database) / @patch(should_update_prisma_schema) decorator pair and patch.dict(os.environ, clean_env, clear=True) already used by all sibling tests.

  • test_keepalive_timeout_flag and test_timeout_worker_healthcheck_flag now mock PrismaManager.setup_database and should_update_prisma_schema, and strip DATABASE_URL/DIRECT_URL from the process environment for the duration of the test.
  • All original assertions (uvicorn arg threading) are unchanged and still pass; no production code is touched.

Confidence Score: 5/5

Tests-only change; no production code is modified and all assertions remain intact.

The two modified tests receive the exact same DB-isolation scaffolding already present in every other run_server test in the file. Decorator ordering matches the method signature, clear=True correctly replaces the full environment, and no test assertions were weakened or removed.

No files require special attention.

Important Files Changed

Filename Overview
tests/test_litellm/proxy/test_proxy_cli.py Applies the same DB-isolation mocks and env-stripping pattern to test_keepalive_timeout_flag and test_timeout_worker_healthcheck_flag that all other run_server tests in this file already use; no assertions weakened.

Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin/lit..." | Re-trigger Greptile

@codecov

codecov Bot commented May 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yuneng-berri
yuneng-berri merged commit c706184 into litellm_internal_staging May 16, 2026
115 of 116 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_/determined-yalow-811fee branch May 16, 2026 03:24
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…ow-811fee

test(proxy): isolate run_server CLI tests from prisma DB-setup path
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.

2 participants