Skip to content

Commit

Permalink
test_in_memory_redis_sync_e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan-jaff committed Nov 24, 2024
1 parent 5f04c04 commit 33a0744
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/local_testing/test_router_provider_budgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
import traceback
from dotenv import load_dotenv
from httpx import delete

load_dotenv()
import os, copy
Expand Down Expand Up @@ -276,6 +277,11 @@ async def test_in_memory_redis_sync_e2e():
Critical test for using provider budgets in a multi-instance environment
"""
original_sync_interval = getattr(
litellm.router_strategy.provider_budgets, "DEFAULT_REDIS_SYNC_INTERVAL"
)

# Modify for test
setattr(litellm.router_strategy.provider_budgets, "DEFAULT_REDIS_SYNC_INTERVAL", 2)

provider_budget_config = {
Expand Down Expand Up @@ -336,3 +342,13 @@ async def test_in_memory_redis_sync_e2e():
# Verify in-memory cache was updated
in_memory_spend = float(router.cache.in_memory_cache.get_cache(spend_key) or 0)
assert abs(in_memory_spend - test_spend_2) < 0.01

# clean up key from router cache
await router.cache.async_delete_cache(spend_key)

# Restore original value
setattr(
litellm.router_strategy.provider_budgets,
"DEFAULT_REDIS_SYNC_INTERVAL",
original_sync_interval,
)

0 comments on commit 33a0744

Please sign in to comment.