From 8483477512ef1e7477f0be81fe5f294be00fdd96 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 21 Feb 2026 13:09:36 -0800 Subject: [PATCH] fix(test): add asyncio.sleep(0) before flush() to prevent hang in test_async_no_duplicate_spend_logs (#21813) --- .../test_litellm/responses/test_no_duplicate_spend_logs.py | 6 ++++++ 1 file changed, 6 insertions(+) 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 7c0d6c15d6d..f3183624058 100644 --- a/tests/test_litellm/responses/test_no_duplicate_spend_logs.py +++ b/tests/test_litellm/responses/test_no_duplicate_spend_logs.py @@ -96,6 +96,12 @@ async def test_async_no_duplicate_spend_logs(): litellm_call_id=test_request_id, ) + # Yield to the event loop so the _client_async_logging_helper task + # (scheduled via asyncio.create_task in the @client decorator) runs first + # and initializes GLOBAL_LOGGING_WORKER on the current event loop. + # 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 from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER await GLOBAL_LOGGING_WORKER.flush()