Repository navigation
feat!: TestOutboxBroker publishes through the real producer - #238
Merged
Merged
Conversation
Benchmark gate✅ gate passed
Gated (fails the build): |
lesnik512
force-pushed
the
refactor/test-broker-real-producer
branch
from
October 17, 2026 16:51
681e3cc to
e800b13
Compare
The test broker now fakes only the storage. broker.publish, publish_batch, publisher.publish and OutboxResponse all run the production producer and the publish middlewares; a thin wrapper dispatches the rows the fake client stored once the producer returns, so published still precedes the handler's events. Removes FakeOutboxProducer, TestOutboxBroker.fake_producer, the broker.publish / publish_batch patches and the copied encoding and metric code. Adds faststream_outbox.testing.fake_session(). BREAKING CHANGE: broker.publish and publish_batch under TestOutboxBroker need a session, as in production. Pass session=fake_session(). Closes #219. Closes #236.
lesnik512
force-pushed
the
refactor/test-broker-real-producer
branch
from
October 17, 2026 17:11
e800b13 to
9b2f745
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #236 and #219. Follows #237.
TestOutboxBrokernow fakes only the storage, so publishing in tests runs the production producer and publish middlewares.Why
The test broker patched
broker.publishandpublish_batch, swapped inFakeOutboxProducer, and kept its own copies of the encoding, thepublishedevent and the dispatch. Each copy could drift from production:broker.publishin tests (Route TestOutboxBroker publish through _basic_publish #219);publishedtags had to be copied a second time in fix: align the fake client with the real one and return fetched rows oldest first #233.The change
broker.publish/publish_batchpatches;FakeOutboxProducer;TestOutboxBroker.fake_producerattribute;_fake_publish_*and_emit_published;validate_activate_args, which only those fakes used._DispatchingProducer. It calls the realpublish/publish_batch, then takes the rows the fake client recorded and dispatches them: sync mode runs the handlers, and loop mode wakes the fetch loops.publishedstays ahead of the handler's events;publishedduration;_OutboxConfigErrorisn't recorded as a failed publish for a row that was stored.fake_client.insert) are dropped when the test broker exits.faststream_outbox.testing.fake_session(): returns a mockAsyncSessionthat passes the session check and reports an open transaction, soOutboxResponseaccepts it too.Breaking change (0.16.0 upgrade note)
Tests
publish_scoperuns forbroker.publish. Thepublisher.publishandOutboxResponsepaths already ran it, and are now covered in the same test.broker.publishandpublish_batchwithout a session raiseTypeErrorunder the test broker.publishedis emitted before the handler runs;published{status="success"};session=fake_session(). The two tests that pinnedFakeOutboxProducercheck the swapped producer slot instead. The fake-producer copies of the B8 and request-refusal tests are deleted; the real producer already has both.Docs
testing.md: sessions andfake_session(), one producer for both publish paths, and publish middlewares running in tests. It also notes that the fake store ignores transactions, so a rolled-back row is still delivered (the behaviour TestOutboxBroker dispatches publishes from rolled-back transactions #218 is about).observability.md: the test-broker note.dlq.md: a code sample.AGENTS.md: the architecture note.Verification
ruffandtyare clean, andmkdocs build --strictpasses.