Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

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

Ishaan Jaff6ec16d583df2
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