From d9301c58ae6b2a00e326cd129d90d6e66ddcb445 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Sat, 21 Feb 2026 13:31:00 -0800 Subject: [PATCH] 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). --- .../responses/test_no_duplicate_spend_logs.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_litellm/responses/test_no_duplicate_spend_logs.py b/tests/test_litellm/responses/test_no_duplicate_spend_logs.py index f3183624058..b6dad2354b9 100644 --- a/tests/test_litellm/responses/test_no_duplicate_spend_logs.py +++ b/tests/test_litellm/responses/test_no_duplicate_spend_logs.py @@ -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