litellm/tests/unit/proxy/db
Mateo Wang a7ed4b9efa
fix(proxy): mint a fresh DB token when a respawned worker connects (#56094)
* fix(proxy): mint a fresh DB token when a respawned worker connects

A worker uvicorn respawns inherits the DATABASE_URL the CLI minted at
container start. Once that token expires the new worker's first connect is
refused, and it only recovers through the fallback refresh.

Fixes #49963

* test(proxy): cover a respawned worker whose inherited DB token is about to expire

* fix(proxy): stop a restarted worker's connection check from logging a false token expiry

* fix(proxy): judge each DB client's token by the URL its own engine connected with

A second PrismaClient in a running worker (POST /global/spend/refresh builds one) could mint a
fresh token into DATABASE_URL while the main client's engine still held its old one, so the main
client skipped its own refresh and its expired-token fallback. Each wrapper now reads the URL its
engine connected with for the refresh schedule, the refresh skip check and the fallback, and logs
when the pre-connect mint succeeds

* fix(proxy): skip the pre-connect token mint when the database uses a password

A password DATABASE_URL has no token to refresh, so the respawned-worker
check now returns before minting and no longer logs a false "Minted a fresh
database token" line on every connect.

Tests now pin the clock and also cover the refresh and recreate paths
recording the URL their new engine connected with.

* test(proxy): assert whole values with failure context in the token refresh tests

The respawned-worker and pre-connect mint tests now compare the full URL the
engine connected with, the refresh loop test checks both sleeps, and the
scheduling tests say which token the next refresh was computed from.

---------

Co-authored-by: akkupratap323 <akkupratap323@gmail.com>
2026-12-04 16:20:59 -08:00
..
db_transaction_queue fix(proxy): avoid blocking writes when attaching spend log partitions (#53858) 2026-11-23 11:19:33 -08:00
mcp_server refactor(mcp): drop the experimental label from the MCP server and client paths (#48513) 2026-10-27 17:47:50 +00:00
__init__.py
conftest.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
fake_prisma_engine.py fix(proxy): cancel the Admin UI's raw spend-log reads in Postgres after 30s (#49965) 2026-11-03 16:07:00 -08:00
test_autorouter_session_rollup.py fix(proxy): retain unwritten rollups after database disconnects (#51706) 2026-11-13 13:36:12 -08:00
test_budget_window_spend_writer.py fix(proxy): preserve budget window edits during resets (#53064) 2026-11-20 10:50:27 -08:00
test_check_migration.py fix(proxy): point the startup schema drift check at the packaged schema.prisma (#52435) 2026-11-19 17:49:06 -08:00
test_connection_budget.py feat(spend-logs): rust spend log callback (#52182) 2026-11-20 16:31:04 -08:00
test_create_views.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_daily_spend_bulk_upsert.py feat(proxy): add app groups with shared budgets and usage (#53232) 2026-11-21 12:50:58 -08:00
test_db_lookup_gate.py test: make three flaky unit tests deterministic (#50114) 2026-11-04 14:38:44 -08:00
test_db_span.py fix(otel): name postgres service spans by operation and table (#44240) 2026-10-03 09:20:28 -07:00
test_db_spend_update_writer.py revert(proxy): remove per AI tool limits for teams and members (#55670) 2026-12-03 04:28:08 +00:00
test_db_url_settings.py fix(db): keep the libpq verify-ca marker when a token refresh rebuilds the database url (#56307) 2026-12-04 14:09:28 -08:00
test_exception_handler.py fix(proxy): retain unwritten rollups after database disconnects (#51706) 2026-11-13 13:36:12 -08:00
test_exception_handler_reconnect_retry.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_gateway_request_tracking.py feat(proxy): track failed requests by HTTP status and caller (#45244) 2026-10-09 14:27:56 -07:00
test_health_check_latest.py fix(proxy): show the newest health check per model group on the model hub (#47552) 2026-10-20 16:42:53 -07:00
test_log_db_metrics.py fix(proxy): keep the database error when the log_db_metrics failure hook raises (#44383) 2026-10-03 16:38:15 +00:00
test_log_db_metrics_service_spans.py test: deflake proxy metrics and shutdown drain (#51078) 2026-11-10 21:05:41 -08:00
test_master_key_migration.py feat(mcp): cover stored profile credentials in key rotation and AES migration (#53671) 2026-11-28 15:07:22 -08:00
test_model_access_group_spend.py feat(proxy): enforce customer org, team and member budgets and limits on the request path (#51489) 2026-11-12 20:43:44 -08:00
test_model_insights_tasks.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_model_usage_rollup.py feat(alerts): detect daily changes in recorded usage (#50666) 2026-11-11 18:23:02 -08:00
test_native_database.py refactor(rust): rename participle functions in llms, bridge, redis and router crates (#55222) 2026-12-01 15:46:37 +00:00
test_object_permission_repository.py refactor(types): replace Any with proven types in 137 files (#44478) 2026-10-05 11:01:45 -07:00
test_pgbouncer.py fix(db): honor libpq verify-ca as a chain-only check in the Rust pool (#56043) 2026-12-03 20:45:01 +00:00
test_prisma_client.py fix(proxy): mint a fresh DB token when a respawned worker connects (#56094) 2026-12-04 16:20:59 -08:00
test_prisma_engine.py fix(proxy): start and serve the proxy with a database on Python 3.10 and prisma 0.13+ (#54416) 2026-11-26 00:09:17 +00:00
test_prisma_planned_engine_restart.py fix(proxy): start and serve the proxy with a database on Python 3.10 and prisma 0.13+ (#54416) 2026-11-26 00:09:17 +00:00
test_prisma_query_span.py test(unit): make 21 flaky unit tests deterministic (#54785) 2026-11-26 20:48:13 -08:00
test_prisma_self_heal.py fix(proxy): recover from a read replica reconnect that times out (#52592) 2026-11-18 12:03:24 -08:00
test_proxy_worker_heartbeat.py fix(otel): name postgres service spans by operation and table (#44240) 2026-10-03 09:20:28 -07:00
test_query_engine_reaper.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_rds_iam_token_expiry.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_replica_identity.py test: migrate proxy security, schema migration and MCP legacy tests (#45937) 2026-10-11 16:17:24 -07:00
test_request_error_tracking.py feat(proxy): track failed requests by HTTP status and caller (#45244) 2026-10-09 14:27:56 -07:00
test_routing_prisma_wrapper.py fix(proxy): recover from a read replica reconnect that times out (#52592) 2026-11-18 12:03:24 -08:00
test_rust_spend_log_writer.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
test_scheduled_job_runs.py feat(proxy): run spend log cleanup from a DB-backed scheduled job table (#50131) 2026-11-11 18:22:02 -08:00
test_shadow_eval_funnel.py feat(shadow-eval): skip redundant reverse evaluations on opt-in (#52192) 2026-11-16 21:38:00 -08:00
test_spend_counter_reseed.py feat(proxy): support budget_limits windows on internal users (#51763) 2026-11-14 07:44:35 -05:00
test_spend_log_batching.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_spend_log_tool_index.py fix(proxy): stop requeueing rejected tool discovery batches to Redis (#53886) 2026-11-23 11:57:09 -08:00
test_token_auth.py fix(proxy): sign RDS IAM tokens for the database's own region (#44782) 2026-10-09 15:41:07 -07:00
test_tool_registry_writer.py fix(proxy): stop requeueing rejected tool discovery batches to Redis (#53886) 2026-11-23 11:57:09 -08:00
test_tool_table_bulk_upsert.py fix(proxy): buffer tool discoveries in Redis and write LiteLLM_ToolTable in one statement per drain, on its own lock (#48089) 2026-10-24 12:34:13 -07:00
test_update_daily_tag_spend.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00