fix(test): add timeout to flush() call to prevent 300s hang in CI

GLOBAL_LOGGING_WORKER.flush() calls queue.join() which blocks until all
items are task_done(). In CI with pytest-asyncio, each test gets a fresh
event loop so the worker reinitializes its queue - items from a previous
test never get task_done(), causing an infinite hang.

Fix: wrap flush() with asyncio.wait_for(..., timeout=10.0).
This commit is contained in:
Ishaan Jaffer 2026-02-21 13:31:00 -08:00
parent c810f5cd63
commit d9301c58ae

View file

@ -102,9 +102,14 @@ async def test_async_no_duplicate_spend_logs():
# Without this, flush() may block on a stale queue from a previous test's loop.
await asyncio.sleep(0)
# Wait for async logging to complete
# Wait for async logging to complete. Use a timeout so that if the
# worker is on a stale event loop (common in CI), flush() doesn't hang
# indefinitely — the queue.join() inside flush() would never resolve.
from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER
await GLOBAL_LOGGING_WORKER.flush()
try:
await asyncio.wait_for(GLOBAL_LOGGING_WORKER.flush(), timeout=10.0)
except asyncio.TimeoutError:
pass
await asyncio.sleep(0.5)
# Verify that log_success_event was called exactly once for our request