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: add tests for compute_retry_cooldown and fix daily limit test (#3314)

LearningCircuitec2b6cf7b71c
diff --git a/tests/library/download_management/test_compute_retry_cooldown.py b/tests/library/download_management/test_compute_retry_cooldown.py
new file mode 100644
index 0000000000..330cf1c088
--- /dev/null
+++ b/tests/library/download_management/test_compute_retry_cooldown.py
@@ -0,0 +1,92 @@
+"""Tests for compute_retry_cooldown and MAX_TOTAL_RETRIES."""
+
+from datetime import timedelta
+
+from local_deep_research.library.download_management.status_tracker import (
+ MAX_TOTAL_RETRIES,
+ compute_retry_cooldown,
+)
+
+
+class TestComputeRetryCooldown:
+ """Tests for the backoff schedule function."""
+
+ def test_first_attempt_uses_default_cooldown(self):
+ default = timedelta(hours=1)
+ assert compute_retry_cooldown(1, default) == default
+
+ def test_first_attempt_preserves_arbitrary_default(self):
+ default = timedelta(minutes=30)
+ assert compute_retry_cooldown(1, default) == default
+
+ def test_second_attempt_waits_one_day(self):
+ assert compute_retry_cooldown(2, timedelta(hours=1)) == timedelta(
+ days=1
+ )
+
+ def test_third_attempt_waits_30_days(self):
+ assert compute_retry_cooldown(3, timedelta(hours=1)) == timedelta(
+ days=30
+ )
+
+ def test_fourth_attempt_waits_30_days(self):
+ assert compute_retry_cooldown(4, timedelta(hours=1)) == timedelta(
+ days=30
+ )
+
+ def test_fifth_attempt_returns_none_permanent(self):
+ assert compute_retry_cooldown(5, timedelta(hours=1)) is None
+
+ def test_beyond_max_returns_none(self):
+ assert compute_retry_cooldown(10, timedelta(hours=1)) is None
+ assert compute_retry_cooldown(100, timedelta(hours=1)) is None
+
+ def test_schedule_matches_documented_table(self):
+ """Verify the full schedule matches the PR documentation."""
+ default = timedelta(hours=1)
+ expected = [
+ (1, default),
+ (2, timedelta(days=1)),
+ (3, timedelta(days=30)),
+ (4, timedelta(days=30)),
+ (5, None),
+ ]
+ for attempt, expected_cooldown in expected:
+ result = compute_retry_cooldown(attempt, default)
+ assert result == expected_cooldown, (
+ f"attempt {attempt}: expected {expected_cooldown}, got {result}"
+ )
+
+ def test_default_cooldown_ignored_after_first_attempt(self):
+ """Default cooldown only matters for attempt 1."""
+ short = timedelta(seconds=1)
+ long = timedelta(days=365)
+ # Attempt 2+ should return the same regardless of default
+ assert compute_retry_cooldown(2, short) == compute_retry_cooldown(
+ 2, long
+ )
+ assert compute_retry_cooldown(3, short) == compute_retry_cooldown(
+ 3, long
+ )
+ assert compute_retry_cooldown(5, short) == compute_retry_cooldown(
+ 5, long
+ )
+
+
+class TestMaxTotalRetries:
+ """Tests for the MAX_TOTAL_RETRIES constant."""
+
+ def test_value_is_five(self):
+ assert MAX_TOTAL_RETRIES == 5
+
+ def test_cooldown_returns_none_at_exactly_max(self):
+ assert (
+ compute_retry_cooldown(MAX_TOTAL_RETRIES, timedelta(hours=1))
+ is None
+ )
+
+ def test_cooldown_returns_value_just_below_max(self):
+ result = compute_retry_cooldown(
+ MAX_TOTAL_RETRIES - 1, timedelta(hours=1)
+ )
+ assert result is not None
diff --git a/tests/library/download_management/test_status_tracker.py b/tests/library/download_management/test_status_tracker.py
index 76a394fb16..4c43681e64 100644
--- a/tests/library/download_management/test_status_tracker.py
+++ b/tests/library/download_management/test_status_tracker.py
@@ -345,6 +345,9 @@ class TestCanRetry:
mock_status.status = "temporarily_failed"
mock_status.retry_after_timestamp = None
mock_status.today_retry_count = 5 # Exceeds limit of 3
+ mock_status.last_attempt_at = datetime.now(
+ UTC
+ ) # Must be today for daily check
mock_session.query.return_value.filter_by.return_value.first.return_value = mock_status
@contextmanager