Skip to content

Feat/test broker sync dispatch#10

Merged
lesnik512 merged 2 commits into
mainfrom
feat/test-broker-sync-dispatch
May 21, 2026
Merged

Feat/test broker sync dispatch#10
lesnik512 merged 2 commits into
mainfrom
feat/test-broker-sync-dispatch

Conversation

@lesnik512
Copy link
Copy Markdown
Member

No description provided.

lesnik512 and others added 2 commits May 21, 2026 10:31
`TestOutboxBroker` now matches the FastStream test-broker idiom — `await
broker.publish(...)` synchronously drives the matching subscriber's consume
pipeline before returning, the same model as `TestKafkaBroker` /
`TestRabbitBroker`. No more background polling, no more `_wait_until` in
tests.

Mechanics:
- Extracted the per-row body of `OutboxSubscriber._worker_loop` into a
  public `dispatch_one(row)` so both the loop and the test broker share
  one code path.
- `fake_publish` / `fake_publish_batch` now feed the fake client, acquire
  the row's lease in place, and `await dispatch_one(msg)`. Future-dated
  rows (`activate_in` / `activate_at`) intentionally skip sync dispatch —
  they sit in the fake client, mirroring production where they wait for
  the gate.
- Added a `fake_fetch_unprocessed` shim so `broker.fetch_unprocessed`
  reads the in-memory store in test mode.
- `TestOutboxBroker(broker, run_loops=True)` is the opt-in escape hatch
  that restores the previous loop-driven behavior; required for tests
  that exercise retry rescheduling, lease-expiry reclaim, or fetch-loop
  error recovery.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… guard

Adds a sync-mode test that exercises ``_find_subscriber_for_queue``'s
``if not sub.calls: continue`` branch by publishing to a queue whose only
subscriber has no registered handler — the row stays in the fake client.

Marks the ``_fetch_loop``'s defensive ``client is None`` guard as
``pragma: no cover``: it only triggers during a teardown race
(``broker_config.client`` reset to None before the loop's ``while
self.running`` next-iteration check) that's hard to deterministically hit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 self-assigned this May 21, 2026
@lesnik512 lesnik512 merged commit a1147a5 into main May 21, 2026
3 checks passed
@lesnik512 lesnik512 deleted the feat/test-broker-sync-dispatch branch May 21, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant