Repository navigation
test(e2e): add Locust throughput load test that runs last - #33748
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR adds a Locust-based throughput load test to the
Confidence Score: 5/5Safe to merge — adds new test infrastructure only, touches no production code paths. All changed files are under tests/e2e/ (plus pyproject.toml adding locust to the e2e-dev group). The load runner, fixtures, and assertions are well-implemented: the subprocess pattern correctly isolates gevent, the RPS/failure-ratio assertions guard against false passes, the model-registration fixture handles races idempotently, and the JSON parse error path wraps failures descriptively. No production or SDK code is modified. No files require special attention.
|
| Filename | Overview |
|---|---|
| tests/e2e/load/locust_load.py | Core load runner: spawns Locust as a subprocess with --json output, wraps parse errors descriptively, aggregates RPS from per-entry timestamps correctly |
| tests/e2e/load/conftest.py | Session-scoped fixture registers the mock deployment (with idempotent check + race-condition guard) and provides a per-test scoped key; lifecycle cleanup is correct |
| tests/e2e/load/locustfile.py | Locust user class: reads API key and model from env at import time (correct since it runs in a subprocess), drives POST /chat/completions at maximum rate with zero wait time |
| tests/e2e/load/test_chat_completions_throughput_e2e.py | Three-assertion test: zero-traffic guard, failure-ratio ceiling, and RPS floor; all env-overridable; marked e2e+load; clear failure messages |
| tests/e2e/conftest.py | Adds load marker registration and a stable sort that places load-marked items last; sort key is correct (False < True puts non-load items first) |
| tests/e2e/e2e_config.py | Adds five env-overridable load parameters with sensible stage-EKS defaults; consistent with existing config pattern |
| tests/e2e/models.py | Adds optional mock_response field to LiteLLMParamsBody so the load suite can register a mock deployment via /model/new without touching prod models |
| pyproject.toml | Pins locust==2.45.0 to the e2e-dev dependency group; isolated from prod and SDK deps |
Reviews (2): Last reviewed commit: "test(e2e): add Locust throughput load te..." | Re-trigger Greptile
CodSpeed benchmarks the SDK with no IO, so it can't catch regressions that only appear under real concurrent load through the full proxy stack (auth, routing, logging, spend, Postgres, Redis). This adds a Locust load test under tests/e2e/load that drives concurrent POST /chat/completions traffic against a mock deployment (litellm_params.mock_response), so the measured throughput reflects proxy overhead rather than a provider's latency, and asserts an aggregate RPS SLO with a failure-ratio guard. The test is marked load and the parent conftest sorts load-marked items last so it never perturbs latency-sensitive suites. Covers reliability.perf.throughput.under_slo.
c880df3 to
abf2af1
Compare
|
@greptileai please review the current head abf2af1. Two items from the last review:
|
…itellm_lit4557_locust_load_test # Conflicts: # uv.lock
… merge The staging merge left two pytest_collection_modifyitems hooks in tests/e2e/conftest.py (one attaching JUnit result properties, one sorting load-marked items last), so basedpyright flagged the first as obscured by the second (reportRedeclaration) and pytest would only run the last. Fold both into a single hook.
Relevant issues
Linear ticket
Resolves LIT-4557
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Type
✅ Test
Changes
CodSpeed benchmarks the SDK with no IO, so it can't catch regressions that only appear under real concurrent load through the full proxy stack (auth, routing, logging, spend, Postgres, Redis). Past regressions in this class, for example a Redis SSL config bug that forced a TLS handshake per request and a dependency bump that added per-request overhead, were only visible under a real load test. The original customer load setup isn't reproducible, so this adds a Locust load test to the e2e suite that runs against the
berrie-litellm-stageEKS cluster insteadThe new
tests/e2e/loadsuite drives real concurrentPOST /chat/completionstraffic through the live proxy with Locust and asserts an aggregate throughput SLO (minimum RPS) with a failure-ratio guard so a run that mostly errors can't masquerade as passing throughput. Traffic targets a mock deployment (litellm_params.mock_response), so the number reflects proxy overhead rather than a provider's latency, cost, or rate limit, while still exercising the whole request path. Every knob (users, spawn rate, duration, RPS floor, failure ratio) is env-overridable, so the same test points at stage EKS (defaults: 750 users, 60s, 355 RPS floor) or a smaller local compose stackLocust runs as a subprocess because it monkey-patches the stdlib with gevent at import, which deadlocks pytest's own machinery when imported in-process; the generator lives in its own interpreter (
locustfile.py) and reports back through its--jsonsummary. Locust is invoked with--exit-code-on-error 0so that per-request failures are folded into that JSON summary and adjudicated by the test's explicit failure-ratio assertion, rather than surfacing as an opaqueCalledProcessError; a nonzero exit now means only a genuine startup failure, which the wrapper raises with the captured stderr. The shared model name lives in oneload_constants.pyso the fixture that registers the mock deployment and the test that drives traffic to it can never driftThe test is marked
loadandpytest_collection_modifyitemsin the parent conftest sortsload-marked items last, so on a whole-treepytest tests/e2erun it executes after the latency-sensitive suites and never perturbs them. It covers the existingreliability.perf.throughput.under_sloregistry cell.locust==2.45.0is added to thee2e-devdependency group withuv.lockkept in sync, andmock_responseis added to the e2eLiteLLMParamsBodymodel so the mock deployment can be registered through/model/newScreenshots / Proof of Fix
This test intentionally targets a mock deployment rather than a real provider (the whole point is to measure proxy overhead under concurrency, not provider latency), so the usual "real provider call costing real $" proof doesn't apply here; the proof below instead shows the full proxy path (proxy + Postgres + Redis via docker-compose) serving the mock model and Locust sustaining throughput with zero failures. Captured at commit
c880df3c64The suite itself, run through pytest against the full local stack, passes and reports its coverage cell:
Single request through the full proxy stack to the mock deployment:
Locust driving concurrent load through the same proxy (150 users, 15s, local single-container compose):
QA runbook
docker compose -f tests/e2e/docker-compose.yml up -dand wait forcurl -s -o /dev/null -w '%{http_code}' http://localhost:4000/health/livelinessto return 200E2E_LOAD_USERS=150 E2E_LOAD_SPAWN_RATE=75 E2E_LOAD_DURATION_SECONDS=15 E2E_LOAD_MIN_RPS=100 uv run pytest tests/e2e/load/ -vand expect the test to pass with 0 request failures (defaults of 750 users / 355 RPS are meant forberrie-litellm-stage, not a laptop)uv run pytest tests/e2e/router tests/e2e/load tests/e2e/access_control --collect-only -qlists the load test last regardless of the argument orderFinal Attestation