litellm/tests/e2e/router/test_reliability_cache_e2e.py
Yassin Kortam 3810130105
test(e2e): add reliability suite covering fallback, timeout, and cache behavior (#34023)
* test(e2e): add reliability suite covering fallback, timeout, and cache behavior

* test(e2e): move reliability suite under router and drive it with real deployments

* test(e2e): make the router complexity fixture opt-in so reliability tests can coexist
2026-07-20 23:06:46 +00:00

37 lines
1.7 KiB
Python

"""Live e2e: the response cache returns a cached answer on an exact repeat.
The same unique prompt is sent twice to the real `gpt-5.5` deployment under the
same key: the first call is a cache miss (the proxy computes and stores the entry,
and returns no x-litellm-cache-key), the second is an exact hit (the proxy serves
from cache and returns x-litellm-cache-key). This relies on the standard Redis
response cache being enabled on the proxy under test.
"""
from __future__ import annotations
import pytest
from complexity_router_client import ComplexityRouterClient
from e2e_config import unique_marker
from reliability_support import chat_override
pytestmark = pytest.mark.e2e
class TestReliabilityCache:
@pytest.mark.covers("reliability.cache.exact.returns_cached")
def test_exact_cache_returns_cached(self, client: ComplexityRouterClient, scoped_key: str) -> None:
prompt = f"cache probe {unique_marker()}"
first = chat_override(client.proxy, scoped_key, "gpt-5.5", prompt)
assert first.status_code == 200, f"first call should succeed, got {first.status_code}: {first.body[:300]}"
assert "x-litellm-cache-key" not in first.headers, (
"first (uncached) call must not report a cache-key header"
)
second = chat_override(client.proxy, scoped_key, "gpt-5.5", prompt)
assert second.status_code == 200, f"second call should succeed, got {second.status_code}: {second.body[:300]}"
assert "x-litellm-cache-key" in second.headers, (
"second identical call should hit the response cache and report a cache-key header "
"(requires the proxy's Redis response cache to be enabled)"
)