litellm/tests/integration/_support/runtime.py
yuneng-jiang ec58b889cc
test(integration): isolate shared proxy state behind six order-dependent flakes (#46172)
Each test below passed or failed on the same commit depending on test order
or port timing in the CircleCI integration workflow

- readiness probe only polls a port the launched proxy owns, so a stolen
  port no longer sends GET /health/integration-readiness to another test's
  wire server
- team update tests seed fresh member users, since a proxy admin relocation
  adds team members to the destination org and leaked org_b membership into
  the shared INTERNAL_USER
- realtime whisper tests wait until every proxy worker serves only the new
  gpt-realtime-whisper deployment, via a per-worker deployment id route
- configured fallbacks test runs on its own proxy and database, because
  /config/update persists router settings and cannot unset fallbacks, which
  left [] and changed the no-fallback error text other tests assert
- otel excluded services tests each get a private Redis so a sibling proxy
  cannot warm the budget registry cache the tenant span depends on
- Langfuse audit upstream uses unique response ids instead of len(targets),
  which could repeat under concurrency and drop SpendLogs rows
2026-10-13 09:55:11 -07:00

40 lines
1.4 KiB
Python

import asyncio
import os
from concurrent.futures import ThreadPoolExecutor
from typing import Final
from fastapi import Response
from fastapi.responses import JSONResponse
from pydantic import TypeAdapter
READINESS_BODY: Final = TypeAdapter(dict[str, object])
def configure_executor() -> None:
asyncio.get_running_loop().set_default_executor(
ThreadPoolExecutor(max_workers=32, thread_name_prefix="integration-provider")
)
async def worker_readiness() -> JSONResponse:
from litellm.proxy.health_endpoints._health_endpoints import health_readiness
response: Final = Response()
body: Final = READINESS_BODY.validate_python(await health_readiness(response))
return JSONResponse(
content=body, status_code=response.status_code, headers={"x-integration-worker-pid": str(os.getpid())}
)
async def worker_deployment_ids(model_name: str) -> JSONResponse:
from litellm.proxy.proxy_server import llm_router
model_ids: Final = [] if llm_router is None else llm_router.get_model_ids(model_name=model_name)
return JSONResponse(content={"model_ids": model_ids}, headers={"x-integration-worker-pid": str(os.getpid())})
def configure_readiness() -> None:
from litellm.proxy.proxy_server import app
app.add_api_route("/health/integration-readiness", worker_readiness, include_in_schema=False)
app.add_api_route("/health/integration-deployment-ids", worker_deployment_ids, include_in_schema=False)