Skip to content

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]

test(limiter): inject the open-breaker Redis double instead of replacing script attributes

mateo-berri29145d13965d
diff --git a/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py b/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py
index f97d89b34a2..10c0bb88a82 100644
--- a/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py
+++ b/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py
@@ -6238,17 +6238,28 @@ async def test_post_call_success_hook_leaves_raw_provider_dict_untouched():
assert response == {"id": "msg_123", "type": "message", "role": "assistant", "content": []}
-async def test_an_open_circuit_breaker_falls_back_to_the_pipeline_without_a_warning(caplog):
- from litellm.caching.redis_cache import RedisCircuitBreakerOpenError
- from litellm.types.caching import RedisPipelineIncrementOperation
+class _OpenBreakerRedis:
+ def async_register_script(self, script: str):
+ async def refused(keys, args):
+ from litellm.caching.redis_cache import RedisCircuitBreakerOpenError
- handler = _PROXY_MaxParallelRequestsHandler(internal_usage_cache=InternalUsageCache(DualCache()))
+ raise RedisCircuitBreakerOpenError("Redis circuit breaker is open")
+
+ return refused
+
+ async def async_increment_pipeline(self, increment_list, **kwargs):
+ from litellm.caching.redis_cache import RedisCircuitBreakerOpenError
- async def refused_script(keys, args):
raise RedisCircuitBreakerOpenError("Redis circuit breaker is open")
- handler.token_increment_script = refused_script
+
+async def test_an_open_circuit_breaker_falls_back_to_the_pipeline_without_a_warning(caplog):
+ from litellm.types.caching import RedisPipelineIncrementOperation
+
+ handler = _PROXY_MaxParallelRequestsHandler(
+ internal_usage_cache=InternalUsageCache(DualCache(redis_cache=_OpenBreakerRedis())) # pyright: ignore[reportArgumentType] # duck-typed Redis double
+ )
with caplog.at_level(logging.DEBUG, logger="LiteLLM Proxy"):
await handler.async_increment_tokens_with_ttl_preservation(
@@ -6261,14 +6272,9 @@ async def test_an_open_circuit_breaker_falls_back_to_the_pipeline_without_a_warn
@pytest.mark.asyncio
async def test_an_open_circuit_breaker_reads_the_sliding_window_locally_without_a_warning(caplog):
- from litellm.caching.redis_cache import RedisCircuitBreakerOpenError
-
- handler = _PROXY_MaxParallelRequestsHandler(internal_usage_cache=InternalUsageCache(DualCache()))
-
- async def refused_script(keys, args):
- raise RedisCircuitBreakerOpenError("Redis circuit breaker is open")
-
- handler.batch_rate_limiter_script = refused_script
+ handler = _PROXY_MaxParallelRequestsHandler(
+ internal_usage_cache=InternalUsageCache(DualCache(redis_cache=_OpenBreakerRedis())) # pyright: ignore[reportArgumentType] # duck-typed Redis double
+ )
with caplog.at_level(logging.DEBUG, logger="LiteLLM Proxy"):
values = await handler._execute_redis_batch_rate_limiter_script(