Skip to main content

with_options

with_options checks the per-message settings the latest recorded publish carried, the value a builder step set.

Per-message settings are the broker's Publisher::Options; the memory broker's publisher has none, so the example wraps it with a priority, as a networked broker ships one. The harness records the settings with every publish the runtime makes (a reply, a slot publish, a retry copy), on the broker it went to. Both records read them: a slot record, out::<M>(), and a destination record, published::<T>(name). A message the test publishes itself carries no recorded settings. The assertion names the broker's own type and panics when the latest publish carried no settings, carried another type, or carried a different value. It also panics when it cannot tell which settings the latest publish carried: another publish to the destination had the same payload, and either their order is unknown or the harness never saw that publish. assert_options_default checks that no step set any.

Example​

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

tb.out::<Shipments>()
.assert_called_once()
.with_options(&PriorityOptions { priority: Some(9) });
Ok(())
}