Skip to main content

publish

publish() sends the input onto the broker and returns once the whole reaction to it has settled, so the next line can assert.

The input, built with message(&v), enters the broker the way an external producer's message would. The reaction covers the handlers it reaches, their replies and slot publishes, and the handlers those reach, across brokers. In the example the receipt the first handler replies with is filed before publish returns, and with reads the value the handler received. A reaction that does not settle within 10,000 dispatched deliveries fails the publish with TestError::NotQuiescent, which catches an endless requeue. A publish after a fail-fast failure stopped the TestApp fails with TestError::ShutDown. settle drives a reaction the test started some other way, and advance lets a delayed redelivery come due.

Example​

#[tokio::test]
async fn the_whole_reaction_is_over_when_publish_returns() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
tb.message(&Order { id: 7 }).publish().await?;

tb.broker::<MemoryBroker>()
.subscriber("receipts")
.assert_called_once()
.with(&Receipt { order_id: 7 })
.settled(HandlerOutcome::ack());
Ok(())
}