~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
test: add concurrent QueuePool smoke test for metrics sessions (#3473)
LearningCircuit6e161c4d0f6e
diff --git a/tests/database/test_encrypted_db_manager.py b/tests/database/test_encrypted_db_manager.pyindex 830fe5c06a..d0e99f548e 100644--- a/tests/database/test_encrypted_db_manager.py+++ b/tests/database/test_encrypted_db_manager.py@@ -751,6 +751,113 @@ class TestThreadSafeSessionForMetrics:)assert session.bind is mock_engine+ @patch("local_deep_research.database.encrypted_db.get_data_directory")+ def test_concurrent_metrics_sessions_via_shared_queuepool(+ self, mock_data_dir, tmp_path+ ):+ """Multiple threads sharing a QueuePool can write concurrently+ without errors, deadlocks, or lost writes.++ Regression test for the #3441 refactor that replaced per-thread+ NullPool engines with a single shared per-user QueuePool.+ """+ from sqlalchemy import text+ from sqlalchemy.pool import QueuePool++ from local_deep_research.database.encrypted_db import DatabaseManager++ mock_data_dir.return_value = tmp_path++ db_file = tmp_path / "encrypted_databases" / "concurrent.db"+ db_file.parent.mkdir(parents=True, exist_ok=True)++ manager = DatabaseManager()+ manager._use_static_pool = False+ manager._pool_class = QueuePool++ # Create a plain SQLite database (no encryption needed for this test)+ from sqlalchemy import create_engine++ engine = create_engine(+ f"sqlite:///{db_file}",+ connect_args={"check_same_thread": False, "timeout": 30},+ poolclass=QueuePool,+ pool_size=5,+ max_overflow=10,+ )+ with engine.connect() as conn:+ conn.execute(+ text(+ "CREATE TABLE metric_test "+ "(id INTEGER PRIMARY KEY, thread_id INTEGER, seq INTEGER)"+ )+ )+ conn.commit()++ # Inject the engine so create_thread_safe_session_for_metrics+ # finds it on cache hit.+ manager.connections["testuser"] = engine++ try:+ with patch.object(+ manager, "_get_user_db_path", return_value=db_file+ ):+ num_threads = 10+ writes_per_thread = 10+ errors = []+ write_count = [0]+ lock = threading.Lock()++ def writer(tid):+ try:+ session = (+ manager.create_thread_safe_session_for_metrics(+ "testuser", "unused"+ )+ )+ for seq in range(writes_per_thread):+ uid = tid * 1000 + seq+ session.execute(+ text(+ f"INSERT INTO metric_test VALUES "+ f"({uid}, {tid}, {seq})"+ )+ )+ session.commit()+ with lock:+ write_count[0] += 1+ session.close()+ except Exception as e:+ errors.append(f"Thread {tid}: {e}")++ threads = [+ threading.Thread(target=writer, args=(i,))+ for i in range(num_threads)+ ]+ for t in threads:+ t.start()+ for t in threads:+ t.join(timeout=30)++ for t in threads:+ assert not t.is_alive(), f"{t.name} hung past timeout"++ assert not errors, f"Concurrent write errors: {errors}"+ expected = num_threads * writes_per_thread+ assert write_count[0] == expected++ # Verify all rows persisted+ with engine.connect() as conn:+ result = conn.execute(+ text("SELECT COUNT(*) FROM metric_test")+ )+ count = result.fetchone()[0]+ assert count == expected, (+ f"Expected {expected} rows, got {count}"+ )+ finally:+ engine.dispose()+class TestSessionManagement:"""Tests for get_session functionality."""