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

下面显示的是英文原文。

advance

TestApp::advance lets a delay pass, fires the delayed redeliveries now due, and drives their reaction to a standstill.

A handler that answers retry_after(delay) settles at once, and the publish returns with the delivery pending. advance(delay) then delivers the message again, by a broker's native delayed redelivery or by the runtime's deferred copy. In process it moves the paused clock, so the test starts paused with #[tokio::test(start_paused = true)]. On a running clock the in-process advance panics. In a start_live test it lets the time pass for real, because the delay is the broker's own timer. A copy the runtime publishes for a zero delay arrives in the same reaction, without advance. settle drives a reaction without moving the clock.

Example​

#[tokio::test(start_paused = true)]
async fn an_uncleared_payment_is_checked_again_later() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let payment = Payment {
id: 7,
cleared: false,
};
tb.message(&payment).publish().await?;
tb.broker::<MemoryBroker>()
.subscriber("payments")
.assert_called_once()
.settled(HandlerOutcome::retry_after(RECHECK));

tb.advance(RECHECK).await?;
tb.broker::<MemoryBroker>()
.subscriber("payments")
.assert_called(2)
.with(&payment);
Ok(())
}