Testing¶
The testing feature ships LapinTestBroker, an in-process stand-in for RabbitMQ in
application tests: the same handlers, descriptors, and wiring, no server. It routes by exact
queue name (the default-exchange model), records every publish, and plugs into the framework's
TestApp harness, which drives each publish to quiescence so assertions never race the
handlers.
#[subscriber(RabbitQueue::new("payments"))]
async fn accept(payment: &Payment) -> HandlerResult {
if payment.amount == 0 {
return HandlerResult::drop();
}
HandlerResult::Ack
}
let app = RustStream::new(AppInfo::new("payments", "0.1.0")).with_broker(
LapinTestBroker::new(),
|b| {
b.include(accept);
},
);
let tb = TestApp::start(app).await.expect("start");
tb.broker::<LapinTestBroker>()
.publish("payments", &Payment { amount: 100 })
.await
.expect("publish drives the handler to quiescence");
tb.broker::<LapinTestBroker>()
.subscriber("payments")
.assert_called_once()
.with(&Payment { amount: 100 })
.settled(HandlerResult::Ack);
tb.shutdown().await.expect("shutdown");
What the test broker does not simulate¶
Exchange types, bindings, dead-lettering, prefetch, and request/reply are transport behavior;
exercise them against a real server. The crate's own integration tests run that way, gated on
AMQP_TEST_URL: