settle
TestApp::settle drives a reaction the test started without the harness to a standstill, without publishing anything new.
A publish through the harness settles for you; settle is for input that arrived some other way, such as a bare publisher of the broker.
A batch handler needs it: each harness publish settles alone, so the batch it reaches holds one message.
Two messages sent through a bare publisher wait together, and settle delivers them as one batch, which assert_batch_sizes reads back.
In process settle waits until the transports report nothing in flight.
In live mode it waits until every subscription has handled what the harness saw published to it, up to the deadline of start_live.
advance settles after a delay has passed.
Example
- Macros
- Manual
#[tokio::test]
async fn two_orders_arrive_in_one_batch() -> Result<(), Box<dyn Error>> {
let broker = MemoryBroker::new();
let publisher = broker.publisher();
let tb = TestApp::start(app(broker)).await?;
for id in [1, 2] {
publisher.message(&Order { id }).publish().await?;
}
tb.settle().await?;
tb.broker::<MemoryBroker>()
.subscriber("orders")
.assert_called_once()
.assert_batch_sizes(&[2]);
Ok(())
}
#[tokio::test]
async fn two_orders_arrive_in_one_batch() -> Result<(), Box<dyn Error>> {
let broker = MemoryBroker::new();
let publisher = broker.publisher();
let tb = TestApp::start(app(broker)).await?;
for id in [1, 2] {
publisher.message(&Order { id }).publish().await?;
}
tb.settle().await?;
tb.broker::<MemoryBroker>()
.subscriber("orders")
.assert_called_once()
.assert_batch_sizes(&[2]);
Ok(())
}