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

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

received

received::<T>() returns every payload a subscriber received, decoded with the default codec, for a check of your own.

The list is flat and in delivery order: a batch contributes each of its elements. batches keeps the same payloads grouped by call. It decodes with DefaultCodec; received_with(&codec) decodes with another codec. Every recorded payload must decode as T, so a delivery that failed to decode makes it panic. It fits a check that a chain of assertions cannot say: an order, a subset, a property of every element. with checks the latest payload only, and received_raw returns the same list as bytes.

Example​

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

let ids: Vec<u64> = broker
.subscriber("orders")
.received::<Order>()
.iter()
.map(|order| order.id)
.collect();
assert_eq!(ids, [3, 1, 2]);
Ok(())
}