Эта страница ещё не переведена
Ниже показан английский оригинал.
assert_called
assert_called(n) checks that a subscriber's handler ran exactly n times, counting a batch as one call.
n is the number of handler calls.
A single-message handler is called once per delivery, and once more for each redelivery.
A batch handler is called once per batch, so here n counts batches; assert_batch_sizes shows how big each one was.
A publish through the harness runs to completion before it returns, so three publishes make three calls.
On failure it panics with the number of calls it found.
assert_called_once is the same check for one call, and outcomes shows how each call settled.
A destination's assert_called(n) counts publishes instead.
Example
- Macros
- Manual
#[tokio::test]
async fn the_handler_ran_once_per_order() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
for id in 1..=3 {
broker.message(&Order { id }).to("orders").publish().await?;
}
broker.subscriber("orders").assert_called(3);
Ok(())
}
#[tokio::test]
async fn the_handler_ran_once_per_order() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
for id in 1..=3 {
broker.message(&Order { id }).to("orders").publish().await?;
}
broker.subscriber("orders").assert_called(3);
Ok(())
}