Ниже показан английский оригинал.
settled
settled(outcome) checks how the latest handler call settled, against the HandlerOutcome a handler returns.
It takes the value a handler answers with: ack(), retry(), drop(), retry_after(..).
It compares the settlement alone, so a hook attached with and_after plays no part.
For a batch it checks every element of the latest call, which is what one answer for the whole slice produces.
The record holds what the handler answered: on a transport that cannot requeue, a retry still reads as a retry, and the missing redelivery shows in assert_called.
A fail-fast panic leaves the delivery unsettled, which matches no outcome.
assert_outcome is the same check by Outcome, failures included, and outcomes returns every settlement in order.
Example
- Macros
- Manual
#[tokio::test]
async fn an_order_without_an_id_is_dropped() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 0 })
.to("orders")
.publish()
.await?;
broker
.subscriber("orders")
.assert_called_once()
.settled(HandlerOutcome::drop());
Ok(())
}
#[tokio::test]
async fn an_order_without_an_id_is_dropped() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 0 })
.to("orders")
.publish()
.await?;
broker
.subscriber("orders")
.assert_called_once()
.settled(HandlerOutcome::drop());
Ok(())
}