Перейти к основному содержимому
Эта страница ещё не переведена

Ниже показан английский оригинал.

assert_called

assert_called(n) checks that exactly n messages were published to the destination.

The count is of published messages, so one delivery that publishes three times counts three. A subscriber's assert_called(n) counts handler calls instead: the example asserts one call and three publishes. The assertion panics with both numbers when they differ, and returns the record for further checks. assert_called_once and assert_not_called cover one message and none, and messages returns the messages behind the count.

Example​

#[tokio::test]
async fn one_ticket_per_seat() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 7, seats: 3 })
.to("orders")
.publish()
.await?;

broker.subscriber("orders").assert_called_once();
broker.published::<Ticket>("tickets").assert_called(3);
Ok(())
}