Skip to main content

drain

TestApp::drain waits for the post-settle continuations of everything settled so far, for a test that asserts on their effects.

A continuation is work a handler attaches to its outcome, ack().and_after(..), or to its context with after(..) or after_settle(..). It runs on its own task after the delivery settles, so a publish can return before it has finished. A settlement registers its continuations before it releases the delivery, so drain after a publish finds them all. An effect of the handler body itself needs no drain: the publish has already settled it. In the example the test builds the state with with_state to read the mail client's record afterwards. shutdown waits for continuations too.

Example​

#[tokio::test]
async fn the_confirmation_follows_the_ack() -> Result<(), Box<dyn Error>> {
let mailer = Arc::new(Mailer::default());
let tb = TestApp::with_state(app(), |_| Arc::clone(&mailer)).await?;
tb.message(&Order { id: 7 }).publish().await?;
tb.drain().await;

let sent = mailer.sent.lock().map_err(|_| "a confirmation panicked")?;
assert_eq!(*sent, [7]);
Ok(())
}