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(db): synchronize lock retry with first timeout (#6931)

LearningCircuitf9159c04f93f
diff --git a/tests/database/test_retry_on_db_lock.py b/tests/database/test_retry_on_db_lock.py
index 9338ec4470..857a983fa0 100644
--- a/tests/database/test_retry_on_db_lock.py
+++ b/tests/database/test_retry_on_db_lock.py
@@ -243,7 +243,8 @@ class TestRetryOnLockIntegration:
conn.close()
holder_started = threading.Event()
- holder_release = threading.Event()
+ first_lock_error = threading.Event()
+ holder_committed = threading.Event()
call_count = []
def holder():
@@ -255,9 +256,12 @@ class TestRetryOnLockIntegration:
c.execute("BEGIN IMMEDIATE")
c.execute("INSERT INTO counters (id, n) VALUES (2, 100)")
holder_started.set()
- # Hold the writer lock until the test releases us.
- holder_release.wait(timeout=5.0)
+ # Hold the lock until the writer has actually seen a lock
+ # error. A wall-clock release can race ahead of a writer
+ # delayed by a loaded CI runner.
+ assert first_lock_error.wait(timeout=30.0)
c.commit()
+ holder_committed.set()
finally:
c.close()
@@ -269,18 +273,21 @@ class TestRetryOnLockIntegration:
acquires the writer lock at BEGIN, so a contended writer
hits the spinner that ``busy_timeout`` bounds. With
``DEFERRED`` (the default), the write transaction would
- acquire the lock at the first UPDATE and SQLite would
- block the writer through the COMMIT call -- but the lock
- is only released at COMMIT, so the holder's release after
- 300 ms actually lets the first attempt squeeze through
- without tripping ``busy_timeout``.
+ acquire the lock at the first UPDATE instead.
"""
call_count.append(1)
c = self._open_with_tight_timeout(
sqlcipher_module, db_path, busy_timeout_ms=200
)
try:
- c.execute("BEGIN IMMEDIATE")
+ try:
+ c.execute("BEGIN IMMEDIATE")
+ except sqlcipher_module.OperationalError:
+ first_lock_error.set()
+ assert holder_committed.wait(timeout=10.0), (
+ "lock holder did not commit after the first timeout"
+ )
+ raise
c.execute("UPDATE counters SET n = n + 1 WHERE id = 1")
c.commit()
return "committed"
@@ -291,32 +298,16 @@ class TestRetryOnLockIntegration:
t_holder.start()
# Make sure the holder is in its BEGIN IMMEDIATE before the
# writer's first attempt.
- assert holder_started.wait(timeout=2.0)
-
- # Schedule the holder to release 500 ms from now -- well past
- # busy_timeout (200 ms) so the writer's first attempt
- # genuinely times out before the holder releases. The retry
- # then lands inside the gap between the busy_timeout expiry
- # (t ≈ 0.2 s) and the holder's COMMIT (t ≈ 0.5 s).
- def release_holder():
- time.sleep(
- 0.5
- ) # allow: unmarked-sleep -- thread-coordination delay, not a slow assertion
- holder_release.set()
-
- t_release = threading.Thread(target=release_holder)
- t_release.start()
-
- # Now invoke the helper -- first attempt fails (busy_timeout
- # = 200 ms vs holder's 500 ms hold), then we sleep 0.1 s
- # backoff, second attempt succeeds (the holder has released
- # in the meantime).
+ assert holder_started.wait(timeout=10.0)
+
+ # The first attempt times out while the holder still owns the
+ # lock. The holder commits only after that error, so the retry
+ # exercises the successful path without relying on scheduler timing.
result = retry_on_db_lock(
writer_callable, attempts=3, base_delay_seconds=0.1
)
assert result == "committed"
- t_release.join()
t_holder.join()
# The helper must have retried at least once (the first