mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-25 05:54:53 +00:00
* test(integration): stop GET /__observations from draining the upstream log GET /__observations used to empty the queue, so a second read in a test saw nothing and a "never reached upstream" check could pass whether or not the request was forwarded. GET now returns every request since the last reset and DELETE /__observations is the reset. An autouse fixture resets the worker upstream before each test, which also covers tests that read without the gateway fixture. Discarded reads used as resets become DELETEs, helpers that accumulated drained reads now read one snapshot, and tests with several phases reset between them. The three vacuous negative checks (rag allowlist, guardrail opt-out chaos, xAI batch output) now assert the absence on the same read that shows a request which did reach the upstream. * style(integration): space the observations unit test like its neighbours
27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
import uuid
|
|
from typing import Final
|
|
|
|
import httpx
|
|
from integration._support.client import Gateway, object_value
|
|
|
|
|
|
def test_zero_parallel_slots_refuse_before_the_provider_and_one_slot_serves(gateway: Gateway) -> None:
|
|
with (
|
|
gateway.scenario() as scenario,
|
|
httpx.Client(base_url=gateway.upstream_url, timeout=5, trust_env=False) as upstream,
|
|
):
|
|
model: Final = scenario.model()
|
|
blocked: Final = scenario.key(models=[model], max_parallel_requests=0)
|
|
allowed: Final = scenario.key(models=[model], max_parallel_requests=1)
|
|
upstream.delete("/__observations").raise_for_status()
|
|
refused: Final = gateway.request(
|
|
"POST",
|
|
"/v1/chat/completions",
|
|
{"model": model, "messages": [{"role": "user", "content": f"no slots {uuid.uuid4().hex}"}]},
|
|
key=blocked,
|
|
)
|
|
assert refused.status_code == 429, refused.text
|
|
assert upstream.get("/__observations").json()["requests"] == []
|
|
served: Final = tuple(gateway.chat(model, key=allowed, text=f"one slot {uuid.uuid4().hex}") for _ in range(2))
|
|
assert [object_value(response["usage"])["total_tokens"] for response in served] == [40, 40]
|
|
assert len(upstream.get("/__observations").json()["requests"]) == 2
|