test(router_strategy): drop only asyncio records in the limiter caplog asserts and drain the response cache worker on the test loop

This commit is contained in:
mateo-berri 2026-10-29 05:27:26 -07:00
parent eb03c9b0ae
commit 47b5eea439
2 changed files with 6 additions and 6 deletions

View file

@ -2,6 +2,7 @@ import asyncio
from typing import Any, AsyncIterator, Dict, Final, List
import pytest
import pytest_asyncio
import datetime
@ -67,7 +68,7 @@ async def _collect(stream: AsyncIterator[bytes]) -> List[bytes]:
return [chunk async for chunk in stream]
@pytest.fixture(autouse=True)
@pytest_asyncio.fixture(autouse=True, loop_scope="function")
async def _drain_logging_worker():
yield
await GLOBAL_LOGGING_WORKER.flush()

View file

@ -10,7 +10,6 @@ from unittest.mock import AsyncMock, MagicMock
import pytest
import litellm
from litellm._logging import verbose_router_logger
from litellm.caching.caching import DualCache
from litellm.caching.redis_cache import RedisCache, RedisCircuitBreakerOpenError
from litellm.router_strategy.budget_limiter import RouterBudgetLimiting
@ -320,8 +319,8 @@ def _leave_a_task_pending_on_a_closed_loop() -> None:
parker.join()
def _limiter_error_lines(caplog: pytest.LogCaptureFixture) -> list[str]:
return [record.getMessage() for record in caplog.records if record.name == verbose_router_logger.name]
def _non_asyncio_log_lines(caplog: pytest.LogCaptureFixture) -> list[str]:
return [record.getMessage() for record in caplog.records if record.name != "asyncio"]
@pytest.mark.asyncio
@ -350,7 +349,7 @@ async def test_sync_refused_by_the_open_circuit_breaker_is_quiet_and_leaks_no_ta
finally:
loop.set_exception_handler(None)
assert _limiter_error_lines(caplog) == []
assert _non_asyncio_log_lines(caplog) == []
unretrieved.assert_not_called()
assert limiter.redis_increment_operation_queue == [
{"key": "provider_spend:openai:1d", "increment_value": 0.5, "ttl": 60}
@ -411,7 +410,7 @@ async def test_push_task_failure_is_logged_once_and_not_leaked(disable_budget_sy
finally:
loop.set_exception_handler(None)
assert _limiter_error_lines(caplog) == [
assert _non_asyncio_log_lines(caplog) == [
"Error syncing in-memory cache with Redis: Error 61 connecting to 127.0.0.1:6379"
]
unretrieved.assert_not_called()