From 24136befdc5dd9851cfceaa07b098aa82b85520c Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Fri, 9 Oct 2026 18:20:53 -0700 Subject: [PATCH] test: prove qdrant truncation runs off the event loop without wall-clock thresholds The test measured event loop stalls against real elapsed time, so it failed on a loaded CI runner. It now records the thread the truncation runs on through the injected router and asserts it is not the event loop thread --- .../caching/test_qdrant_semantic_cache.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/unit/caching/test_qdrant_semantic_cache.py b/tests/unit/caching/test_qdrant_semantic_cache.py index b67cbd90b32..e1448af12ea 100644 --- a/tests/unit/caching/test_qdrant_semantic_cache.py +++ b/tests/unit/caching/test_qdrant_semantic_cache.py @@ -1,4 +1,5 @@ import sys +import threading import types from unittest.mock import AsyncMock, MagicMock, patch @@ -993,23 +994,21 @@ def test_qdrant_semantic_cache_defaults_embedding_timeout(): @pytest.mark.asyncio async def test_qdrant_async_embedding_truncates_off_the_event_loop(monkeypatch): - from tests.large_text import text - from tests.unit.litellm_core_utils.event_loop_lag import ( - assert_loop_stayed_free, - timed_with_loop_lags, - warm_tokenizer, - ) - from litellm.caching.qdrant_semantic_cache import QdrantSemanticCache - warm_tokenizer("sem-embed") cache = QdrantSemanticCache.__new__(QdrantSemanticCache) cache.embedding_model = "sem-embed" - cache.embedding_max_input_tokens = 5 + cache.embedding_max_input_tokens = None cache.embedding_timeout = 5 + truncation_threads = [] + + def deployment_limits(model): + truncation_threads.append(threading.get_ident()) + return (5, None) + router = MagicMock() - router.get_configured_token_limits.return_value = (8191, None) + router.get_configured_token_limits.side_effect = deployment_limits router.aembedding = AsyncMock(return_value={"data": [{"embedding": [0.1, 0.2]}]}) monkeypatch.setitem( sys.modules, @@ -1017,8 +1016,9 @@ async def test_qdrant_async_embedding_truncates_off_the_event_loop(monkeypatch): _router_proxy_module(router, "sem-embed"), ) - response, took, lags = await timed_with_loop_lags(lambda: cache._get_async_embedding(text * 100)) + response = await cache._get_async_embedding("one two three four five six seven eight nine ten") assert response["data"][0]["embedding"] == [0.1, 0.2] assert _token_count("sem-embed", router.aembedding.call_args.kwargs["input"]) == 5 - assert_loop_stayed_free(took, lags) + assert len(truncation_threads) == 1 + assert truncation_threads[0] != threading.get_ident()