From 5559a4976f3cb7db03be90655ed6264a5e496fe0 Mon Sep 17 00:00:00 2001 From: yucheng-berri <293926326+yucheng-berri@users.noreply.github.com> Date: Tue, 20 Oct 2026 10:23:47 -0700 Subject: [PATCH] test(router): freeze the clock in the health-check cooldown error test The unit test stamped the unhealthy state with time.time(), so its result depended on when it ran. Freeze time at a fixed value, stamp the state with it, and assert the health check really dropped the deployment first. --- .../unit/caching/test_request_redis_batch_pre_call.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/unit/caching/test_request_redis_batch_pre_call.py b/tests/unit/caching/test_request_redis_batch_pre_call.py index ac04bb434d2..f72580f893b 100644 --- a/tests/unit/caching/test_request_redis_batch_pre_call.py +++ b/tests/unit/caching/test_request_redis_batch_pre_call.py @@ -6,7 +6,6 @@ from __future__ import annotations import asyncio import hashlib import json -import time from collections.abc import Awaitable, Callable from datetime import datetime, timezone from itertools import chain @@ -16,6 +15,7 @@ from unittest.mock import AsyncMock, MagicMock import pytest import litellm.caching.dual_cache as dual_cache_module +import litellm.router_utils.health_state_cache as health_state_cache_module from litellm import Router from litellm._internal_context import current_service_target from litellm.caching.dual_cache import DualCache @@ -559,14 +559,19 @@ async def test_a_direct_cooldown_read_covers_only_the_groups_deployments_and_sti @pytest.mark.asyncio -async def test_a_cooling_deployment_the_health_check_already_dropped_still_shows_in_the_no_deployment_error() -> None: +async def test_a_cooling_deployment_the_health_check_already_dropped_still_shows_in_the_no_deployment_error( + monkeypatch: pytest.MonkeyPatch, +) -> None: + clock: Final = 1_000_000.0 + monkeypatch.setattr(health_state_cache_module.time, "time", lambda: clock) router: Final = Router( model_list=[_deployment(deployment_id) for deployment_id in sorted(_GROUP_IDS)], enable_health_check_routing=True, ) router.health_state_cache.set_deployment_health_states( - {"dep-a": {"is_healthy": False, "timestamp": time.time(), "reason": "probe failed"}} + {"dep-a": {"is_healthy": False, "timestamp": clock, "reason": "probe failed"}} ) + assert router.health_state_cache.get_unhealthy_deployment_ids() == {"dep-a"} memory: Final = router.cooldown_cache.cooldown_store.in_memory_cache assert memory is not None for model_id in sorted(_GROUP_IDS):