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(queue): prove progress update deduplication (#5368)

Ziyang Guo2f178abd0946
diff --git a/tests/web/queue/test_processor_v2_lock_contention.py b/tests/web/queue/test_processor_v2_lock_contention.py
index 74285f02b2..4432a6a71b 100644
--- a/tests/web/queue/test_processor_v2_lock_contention.py
+++ b/tests/web/queue/test_processor_v2_lock_contention.py
@@ -2,7 +2,7 @@
Tests for processor_v2 handling of SQLite/SQLCipher lock contention, batching, deduplication, and re-queuing.
"""
-from unittest.mock import MagicMock, patch
+from unittest.mock import MagicMock, patch, PropertyMock
import pytest
from sqlalchemy.exc import OperationalError
@@ -17,17 +17,34 @@ def processor():
def test_process_pending_operations_deduplicates_and_batches(processor):
- """Verify that multiple progress updates for the same research_id are deduplicated before batch commit and batch queried."""
+ """Only the latest timestamp per research is applied once."""
username = "test_user"
research_id_1 = "res-111"
research_id_2 = "res-222"
- # Queue multiple progress updates for res-111 and res-222
- for i in range(1, 10):
- processor.queue_progress_update(username, research_id_1, float(i * 10))
-
- processor.queue_progress_update(username, research_id_2, 50.0)
- processor.queue_progress_update(username, research_id_2, 90.0)
+ # Deliberately make insertion order disagree with timestamp order. Without
+ # deduplication, last-write-wins would leave both models at 90.0 and the
+ # old assertions would still pass.
+ timestamps = [
+ 100.0,
+ 900.0, # res-111's real latest value is 20.0
+ 200.0,
+ 300.0,
+ 400.0,
+ 500.0,
+ 600.0,
+ 700.0,
+ 800.0,
+ 1000.0, # res-222's real latest value is 50.0
+ 950.0,
+ ]
+ with patch("time.time", side_effect=timestamps):
+ for i in range(1, 10):
+ processor.queue_progress_update(
+ username, research_id_1, float(i * 10)
+ )
+ processor.queue_progress_update(username, research_id_2, 50.0)
+ processor.queue_progress_update(username, research_id_2, 90.0)
assert len(processor.pending_operations) == 11
@@ -35,8 +52,12 @@ def test_process_pending_operations_deduplicates_and_batches(processor):
mock_session = MagicMock()
mock_history_1 = MagicMock(spec=ResearchHistory)
mock_history_1.id = research_id_1
+ progress_1 = PropertyMock()
+ type(mock_history_1).progress = progress_1
mock_history_2 = MagicMock(spec=ResearchHistory)
mock_history_2.id = research_id_2
+ progress_2 = PropertyMock()
+ type(mock_history_2).progress = progress_2
filter_mock = MagicMock()
filter_mock.all.return_value = [mock_history_1, mock_history_2]
@@ -50,9 +71,10 @@ def test_process_pending_operations_deduplicates_and_batches(processor):
assert processed == 11
assert len(processor.pending_operations) == 0
- # Verify latest progress values applied
- assert mock_history_1.progress == 90.0
- assert mock_history_2.progress == 90.0
+ # Dedup must apply exactly one update per research, chosen by timestamp
+ # rather than insertion order.
+ progress_1.assert_called_once_with(20.0)
+ progress_2.assert_called_once_with(50.0)
# Consolidated batch query called exactly once for the batch
assert mock_session.query.call_count == 1