The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(batch): prove an open Redis breaker keeps enqueued-token reservations quiet
mateo-berrid62493a7794b
diff --git a/tests/test_litellm/proxy/hooks/test_batch_enqueued_tokens.py b/tests/test_litellm/proxy/hooks/test_batch_enqueued_tokens.pyindex edc921a40a3..e3e39a87009 100644--- a/tests/test_litellm/proxy/hooks/test_batch_enqueued_tokens.py+++ b/tests/test_litellm/proxy/hooks/test_batch_enqueued_tokens.py@@ -7,6 +7,7 @@ response-shape helpers the v3 limiter's post-call hooks rely on."""import base64+import loggingimport socketimport uuidfrom collections.abc import Mapping, Sequence@@ -16,6 +17,7 @@ from typing import Finalimport pytestfrom litellm.caching.caching import DualCache+from litellm.caching.redis_cache import RedisCircuitBreakerOpenErrorfrom litellm.constants import BATCH_ENQUEUED_TOKEN_TTL_SECONDSfrom litellm.proxy._types import UserAPIKeyAuthfrom litellm.proxy.hooks.batch_enqueued_tokens import (@@ -439,3 +441,29 @@ async def test_redis_lua_path_full_lifecycle():refill = await store.reserve(tokens=50, scopes=(key_scope, team_scope))assert isinstance(refill, BatchEnqueuedTokenReservation)await store.refund(refill)+++class _OpenBreakerRedis:+ def async_register_script(self, script: str):+ async def refused(keys: Sequence[str], args: Sequence[str | bytes | int | float]) -> object:+ raise RedisCircuitBreakerOpenError("Redis circuit breaker is open")++ return refused+++async def test_an_open_circuit_breaker_keeps_reservations_in_memory_without_a_warning(caplog):+ scope = _scope(limit=100)+ store = BatchEnqueuedTokenStore(+ internal_usage_cache=InternalUsageCache(DualCache(redis_cache=_OpenBreakerRedis(), default_in_memory_ttl=60)) # pyright: ignore[reportArgumentType] # duck-typed Redis double+ )++ with caplog.at_level(logging.DEBUG, logger="LiteLLM Proxy"):+ reservation = await store.reserve(tokens=60, scopes=(scope,))+ assert isinstance(reservation, BatchEnqueuedTokenReservation)+ assert reservation.backend == "memory"+ await store.save_reservation("batch_quiet", reservation)+ assert await store.pop_reservation("batch_quiet") == reservation++ assert not [record for record in caplog.records if record.levelno >= logging.WARNING]+ assert sum("circuit breaker is open" in record.getMessage() for record in caplog.records) == 3