跳到主要内容
本页尚未翻译

下面显示的是英文原文。

assert_last_failed_to_decode

assert_last_failed_to_decode() checks that the latest delivery did not decode into the handler's input type.

The verdict comes from the codec, or from the broker when its client reports a decode error itself. The record holds the delivery as a call although the body never ran, so assert_called_once counts it. The decode policy settles it: the default drops the message and keeps the service running, which assert_running states. The test injects the bad bytes through a #[derive(Outgoing, Serialized)] newtype, which publishes them as they are. It returns nothing, so it ends a chain. assert_outcome gives the same verdict as Outcome::DecodeFailed, and panicked checks the other failure a call can end in.

Example​

#[tokio::test]
async fn bytes_that_are_no_order_are_dropped() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Wire(b"not json".to_vec()))
.to("orders")
.publish()
.await?;

broker
.subscriber("orders")
.assert_called_once()
.settled(HandlerOutcome::drop())
.assert_last_failed_to_decode();
tb.assert_running();
Ok(())
}