aboutsummaryrefslogtreecommitdiff
path: root/tests/tasks/test_scanner.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-30 13:24:53 +0100
committerDennis Fink2026-10-30 13:24:53 +0100
commitf6d96df2c3aecb51ca97426efddb101dce6350d7 (patch)
tree2968f65a627fbfd15051277d07eaa321db0e3cc4 /tests/tasks/test_scanner.py
parent2b59a3082000842d980f9e19931949dbe5011229 (diff)
downloadwebmentions-ssg-f6d96df2c3aecb51ca97426efddb101dce6350d7.tar.gz
webmentions-ssg-f6d96df2c3aecb51ca97426efddb101dce6350d7.zip
feat(sender): add persistent retry backoff
Persist retry state per source revision so temporary delivery failures survive worker restarts and duplicate queued tasks cannot bypass the retry schedule. Use capped exponential backoff, stop after a configurable attempt limit, and reset the retry budget when a source changes or an admin resends manually.
Diffstat (limited to '')
-rw-r--r--tests/tasks/test_scanner.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py
index 3d138ac..6ace77f 100644
--- a/tests/tasks/test_scanner.py
+++ b/tests/tasks/test_scanner.py
@@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: BSD-3-Clause
+from datetime import UTC, datetime, timedelta
from pathlib import Path
from types import ModuleType
from typing import Any
@@ -1552,6 +1553,56 @@ def test_pending_webmention_is_requeued_on_next_scan(
assert queued == [identifier]
+
+def test_temporary_failure_waits_until_retry_deadline_and_revision_resets_budget(
+ app: Flask, scanner_module: ModuleType, tmp_path: Path, monkeypatch: MonkeyPatch
+) -> None:
+ configure_scanner(app, tmp_path)
+ path = write_post(tmp_path, "example", '<a href="https://example.com/a">A</a>')
+ queued: list[UUID] = []
+ monkeypatch.setattr(scanner_module, "send_webmention", queued.append)
+
+ run_scan(app, scanner_module)
+ assert len(queued) == 1
+ identifier = queued.pop()
+
+ with app.app_context():
+ webmention = db.session.get(SentWebmention, identifier)
+ assert webmention is not None
+ webmention.attempt_count = 2
+ webmention.next_retry_at = datetime.now(UTC) + timedelta(hours=4)
+ db.session.commit()
+
+ run_scan(app, scanner_module)
+ assert queued == []
+
+ with app.app_context():
+ webmention = db.session.get(SentWebmention, identifier)
+ assert webmention is not None
+ webmention.next_retry_at = datetime.now(UTC) - timedelta(seconds=1)
+ db.session.commit()
+
+ run_scan(app, scanner_module)
+ assert queued == [identifier]
+ queued.clear()
+
+ # Changing the h-entry creates a new desired revision with a fresh budget.
+ path.write_text(path.read_text().replace('>A</a>', '>A updated</a>'))
+ with app.app_context():
+ webmention = db.session.get(SentWebmention, identifier)
+ assert webmention is not None
+ webmention.next_retry_at = datetime.now(UTC) + timedelta(days=2)
+ db.session.commit()
+
+ run_scan(app, scanner_module)
+ assert queued == [identifier]
+ with app.app_context():
+ webmention = db.session.get(SentWebmention, identifier)
+ assert webmention is not None
+ assert webmention.desired_revision == 2
+ assert webmention.attempt_count == 0
+ assert webmention.next_retry_at is None
+
def test_invalid_known_source_is_not_deleted(
app: Flask,
scanner_module: ModuleType,