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

下面显示的是英文原文。

assert_shut_down

TestApp::assert_shut_down asserts a fail-fast failure has shut the service down, as a handler panic does under the default policy.

The panicking delivery is still driven to a standstill, so the publish that caused it returns normally. The record of the subscription, subscriber(name), shows the call that panicked. After the shutdown every publish through the harness fails with TestError::ShutDown. The assertion fails when the service is still running, which assert_running asserts. run_result gives the failure as a value.

Example​

#[tokio::test]
async fn a_panic_shuts_the_service_down() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
tb.message(&Order { id: 0 }).publish().await?;

tb.broker::<MemoryBroker>()
.subscriber("orders")
.assert_called_once()
.panicked();
tb.assert_shut_down();
assert!(matches!(
tb.message(&Order { id: 7 }).publish().await,
Err(PublishError::Publish(TestError::ShutDown))
));
Ok(())
}