test: cover stale ledger outbox lease updates
Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
co-authored by
genichin
parent
09b1b4f4c3
commit
31d6e5c02b
@@ -169,6 +169,45 @@ def test_claim_expiry_allows_safe_recovery_after_worker_crash(pg_clean):
|
||||
assert [item.correlation_id for item in claimed_b] == [row.correlation_id]
|
||||
|
||||
|
||||
def test_stale_claim_cannot_overwrite_new_owner_outcome(pg_clean):
|
||||
now = {"t": datetime(2026, 6, 4, tzinfo=UTC)}
|
||||
outbox_a = PostgreSQLLedgerOutbox(
|
||||
pg_clean,
|
||||
instance_key="inst-a",
|
||||
claim_ttl_sec=5.0,
|
||||
worker_id="worker-a",
|
||||
clock=lambda: now["t"],
|
||||
)
|
||||
outbox_b = PostgreSQLLedgerOutbox(
|
||||
pg_clean,
|
||||
instance_key="inst-a",
|
||||
claim_ttl_sec=5.0,
|
||||
worker_id="worker-b",
|
||||
clock=lambda: now["t"],
|
||||
)
|
||||
row = outbox_a.enqueue(_trade(execution_id="pg-stale"))
|
||||
|
||||
[claim_a] = outbox_a.claim_pending()
|
||||
now["t"] = datetime(2026, 6, 4, 0, 0, 6, tzinfo=UTC)
|
||||
[claim_b] = outbox_b.claim_pending()
|
||||
outbox_b.mark_outcome(
|
||||
row.correlation_id,
|
||||
OutboxOutcome.COMPLETED,
|
||||
expected_claim_expires_at=claim_b.claim_expires_at,
|
||||
)
|
||||
|
||||
stored = outbox_a.mark_outcome(
|
||||
row.correlation_id,
|
||||
OutboxOutcome.RETRYABLE_FAILURE,
|
||||
error="stale owner",
|
||||
next_retry_at=now["t"],
|
||||
expected_claim_expires_at=claim_a.claim_expires_at,
|
||||
)
|
||||
|
||||
assert stored.status is WorkItemStatus.COMPLETED
|
||||
assert stored.last_outcome is OutboxOutcome.COMPLETED
|
||||
|
||||
|
||||
def test_writer_records_retryable_403_without_cross_instance_delivery(pg_clean):
|
||||
class _ForbiddenLedger:
|
||||
def __init__(self):
|
||||
|
||||
@@ -71,9 +71,9 @@ def test_writer_retries_until_success():
|
||||
|
||||
|
||||
def test_process_correlation_id_only_drains_requested_row():
|
||||
outbox = InMemoryLedgerOutbox()
|
||||
outbox = InMemoryLedgerOutbox(instance_key="inst-a")
|
||||
ledger = InMemoryLedger()
|
||||
writer = LedgerWriter(outbox, ledger)
|
||||
writer = LedgerWriter(outbox, ledger, instance_key="inst-a")
|
||||
first = outbox.enqueue(_trade(execution_id="e-1"))
|
||||
second = outbox.enqueue(_trade(execution_id="e-2"))
|
||||
|
||||
@@ -81,6 +81,8 @@ def test_process_correlation_id_only_drains_requested_row():
|
||||
|
||||
assert outcome is OutboxOutcome.COMPLETED
|
||||
assert ledger.count() == 1
|
||||
assert writer.counters["claim:claimed"] == 1
|
||||
assert writer.counters["outcome:completed"] == 1
|
||||
assert outbox.get(first.correlation_id).status is WorkItemStatus.COMPLETED
|
||||
assert outbox.get(second.correlation_id).status is WorkItemStatus.PENDING
|
||||
|
||||
|
||||
Reference in New Issue
Block a user