Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(stampede): use per-thread end-time spread, not total wall time (#3730)

LearningCircuit9b0266828b0c
diff --git a/tests/utilities/test_search_cache_stampede.py b/tests/utilities/test_search_cache_stampede.py
index 7270071d91..3b9e8667a5 100644
--- a/tests/utilities/test_search_cache_stampede.py
+++ b/tests/utilities/test_search_cache_stampede.py
@@ -225,15 +225,22 @@ class TestStampedeProtectionConcurrency:
assert all(r is not None for r in results)
def test_different_keys_independent(self, cache):
- """Concurrent requests for different keys don't block each other."""
- fetch_times = {}
+ """Concurrent requests for different keys don't block each other.
+
+ Measure each thread's fetch-end timestamp and assert their spread is
+ small. If the cache's per-key locking forced serialization, end times
+ would be staggered by ~0.1s each (≥0.4s spread for 5 threads). True
+ parallelism makes the spread close to zero, plus thread-scheduling
+ jitter — independent of overall CI load (which previously dominated
+ wall-clock thresholds and made the test flaky on slow runners).
+ """
+ end_times = {}
lock = threading.Lock()
def timed_fetch(key):
- start = time.time()
time.sleep(0.1)
with lock:
- fetch_times[key] = time.time() - start
+ end_times[key] = time.time()
return [
{"title": f"Result {key}", "link": f"https://example.com/{key}"}
]
@@ -243,25 +250,23 @@ class TestStampedeProtectionConcurrency:
f"query_{key}", lambda: timed_fetch(key), "engine1"
)
- threads = []
- for i in range(5):
- t = threading.Thread(target=worker, args=(i,))
- threads.append(t)
-
- # Start all threads almost simultaneously
- start_time = time.time()
+ threads = [threading.Thread(target=worker, args=(i,)) for i in range(5)]
for t in threads:
t.start()
-
for t in threads:
t.join(timeout=5)
- total_time = time.time() - start_time
+ assert len(end_times) == 5, "Some threads failed to complete"
- # If they blocked each other, total time would be ~0.5s (5 * 0.1s)
- # If independent, total time should be ~0.1s + overhead
- # Use generous threshold to avoid flakiness under CI load
- assert total_time < 1.0 # Should be much less than sequential 0.5s
+ # Serial floor: spread ≥ 0.4s (4 gaps of 0.1s between 5 sleeps).
+ # Parallel: spread is just thread-scheduling jitter.
+ # 0.3s threshold sits well below the serial floor and well above
+ # realistic jitter, even on loaded runners.
+ spread = max(end_times.values()) - min(end_times.values())
+ assert spread < 0.3, (
+ f"End-times spread {spread:.3f}s suggests serialization "
+ f"(serial floor is 0.4s). End times: {sorted(end_times.values())}"
+ )
class TestLRUEviction: