Skip to content

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.

[dev-dependencies]
ruststream-lapin = { version = "0.5", features = ["testing"] }
#[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:

just brokers-up
AMQP_TEST_URL=amqp://127.0.0.1:5672 cargo test --workspace --all-features -- --test-threads=1