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

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

The live stand

A live test runs the service against a real server, for what the in-process transport leaves to the server: the connection, a persistent session and its redelivery, the handshakes behind QoS 1 and 2.

The stand is a mosquitto container with an anonymous listener and one that needs a password. just test-brokers starts it, runs the live suites with RUSTSTREAM_REQUIRE_LIVE set, and stops it. A live test reads the address of the stand from MQTT_TEST_URL; the variable RUSTSTREAM_REQUIRE_LIVE turns a missing stand into a failure, so a test that skipped itself is noticed. The test below runs the service on compio and talks to it as a second client of the same server.

Example​

A job published to the server is answered by the service, and the answer comes back through a subscription of the test.

#[test]
fn a_job_is_answered_through_the_server() -> Result<(), Box<dyn Error>> {
// The stand is `just test-brokers`; a run without one has nothing to test.
let Ok(url) = std::env::var("MQTT_TEST_URL") else {
return Ok(());
};
Runtime::new()?.block_on(async {
let running = app().start().await?;

// The test is another client of the same server.
let client = MqttBroker::compio(MqttConfig::new(url).client_id("tester"))
.connect()
.await?;
let mut answers = MqttTopic::new("live/done").subscribe(&client).await?;
let jobs = MqttPublish::default().pair(&client).await?;
jobs.publish(OutgoingMessage::new("live/jobs", br#"{"id":7}"#), None)
.await
.map_err(PublishMessageError::into_error)?;

let mut deliveries = core::pin::pin!(answers.stream());
let answer = deliveries.next().await.ok_or("the subscription ended")??;
assert_eq!(answer.payload(), br#"{"id":7}"#);
answer.ack().await?;
client.shutdown().await?;
running.shutdown().await?;
Ok(())
})
}