test: cover targeted and expired ledger claims

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-12 13:30:50 +00:00
committed by GitHub
co-authored by genichin
parent 0b5b4660e5
commit f801c53e0c
4 changed files with 40 additions and 8 deletions
+5 -2
View File
@@ -747,8 +747,11 @@ class PostgreSQLLedgerOutbox:
if expected_claim_expires_at is None:
where += "AND claim_owner IS NULL AND claim_expires_at IS NULL"
else:
where += "AND claim_owner=%s AND claim_expires_at=%s"
params.extend([self._worker_id, expected_claim_expires_at])
where += (
"AND claim_owner=%s "
"AND (claim_expires_at=%s OR (status='pending' AND claim_expires_at<=%s))"
)
params.extend([self._worker_id, expected_claim_expires_at, self._now()])
cur.execute(
"UPDATE ledger_outbox SET status=%s, attempts=attempts+%s, "
"last_outcome=%s, last_error=%s, next_retry_at=%s, updated_at=%s, "
+9 -3
View File
@@ -522,10 +522,16 @@ class InMemoryLedgerOutbox:
*,
correlation_id: str | None = None,
) -> list[LedgerWorkItem]:
pending = self.list_pending(limit if correlation_id is None else max(limit, 1))
if correlation_id is None:
return pending[:limit]
return [row for row in pending if row.correlation_id == correlation_id][:1]
return self.list_pending(limit)
now = self._now()
with self._lock:
row = self._rows.get(correlation_id)
if row is None or row.status is not WorkItemStatus.PENDING:
return []
if row.next_retry_at is not None and row.next_retry_at > now:
return []
return [row]
def pending_cash_delta(self) -> dict[str, float]:
with self._lock: