From 58b96128fdd1c1da961255cc82b09bb364192c3d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 16 Jan 2023 10:39:03 +0100 Subject: Add error contexts Signed-off-by: Matthias Beyer --- .../behaviour/connack_flags_are_set_as_reserved.rs | 5 +++- .../first_packet_from_client_is_connect.rs | 4 +++- .../behaviour/invalid_first_packet_is_rejected.rs | 4 +++- .../src/behaviour/invalid_utf8_is_rejected.rs | 7 ++++-- .../src/behaviour/publish_qos_2_is_acked.rs | 7 ++++-- .../behaviour/publish_qos_zero_with_ident_fails.rs | 7 ++++-- .../src/behaviour/receiving_server_packet.rs | 7 ++++-- .../behaviour/utf8_with_nullchar_is_rejected.rs | 7 ++++-- mqtt-tester/src/behaviour/wait_for_connect.rs | 4 ++++ mqtt-tester/src/client_report.rs | 28 ++++++++++++++++------ 10 files changed, 60 insertions(+), 20 deletions(-) (limited to 'mqtt-tester/src') diff --git a/mqtt-tester/src/behaviour/connack_flags_are_set_as_reserved.rs b/mqtt-tester/src/behaviour/connack_flags_are_set_as_reserved.rs index b128be7..7229f94 100644 --- a/mqtt-tester/src/behaviour/connack_flags_are_set_as_reserved.rs +++ b/mqtt-tester/src/behaviour/connack_flags_are_set_as_reserved.rs @@ -4,6 +4,8 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // +use miette::Context; + use crate::{ behaviour_test::BehaviourTest, command::{Input, Output}, @@ -28,7 +30,8 @@ impl BehaviourTest for ConnackFlagsAreSetAsReserved { 0b0000_0000, // No session present 0b0000_0000, // Connection accepted ]) - .await?; + .await + .context("Sending bytes")?; Ok(()) } diff --git a/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs b/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs index 1315a63..5f114c2 100644 --- a/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs +++ b/mqtt-tester/src/behaviour/first_packet_from_client_is_connect.rs @@ -4,6 +4,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // +use miette::Context; use mqtt_format::v3::packet::MPacket; use crate::{ @@ -37,7 +38,8 @@ impl BehaviourTest for FirstPacketFromClientIsConnect { std::matches!(packet, MPacket::Connect { .. }) }), ) - .await?; + .await + .context("Waiting for bytes to check")?; Ok(()) } diff --git a/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs b/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs index ea3d663..d3f1a4a 100644 --- a/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs +++ b/mqtt-tester/src/behaviour/invalid_first_packet_is_rejected.rs @@ -4,6 +4,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // +use miette::Context; use mqtt_format::v3::{packet::MConnect, strings::MString}; use crate::{ @@ -34,7 +35,8 @@ impl BehaviourTest for InvalidFirstPacketIsRejected { keep_alive: 0, client_id: MString { value: "client" }, }) - .await?; + .await + .context("Sending bytes")?; Ok(()) } diff --git a/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs b/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs index cb77b80..b937ab1 100644 --- a/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs +++ b/mqtt-tester/src/behaviour/invalid_utf8_is_rejected.rs @@ -4,6 +4,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // +use miette::Context; use mqtt_format::v3::{connect_return::MConnectReturnCode, packet::MConnack}; use crate::{ @@ -28,7 +29,8 @@ impl BehaviourTest for InvalidUtf8IsRejected { session_present: false, connect_return_code: MConnectReturnCode::Accepted, }) - .await?; + .await + .context("Sending packet: CONNACK")?; input .send(&[ @@ -43,7 +45,8 @@ impl BehaviourTest for InvalidUtf8IsRejected { 0b0000_0001, 0x1, // Payload ]) - .await?; + .await + .context("Sending bytes")?; Ok(()) } diff --git a/mqtt-tester/src/behaviour/publish_qos_2_is_acked.rs b/mqtt-tester/src/behaviour/publish_qos_2_is_acked.rs index 1e57928..d18871c 100644 --- a/mqtt-tester/src/behaviour/publish_qos_2_is_acked.rs +++ b/mqtt-tester/src/behaviour/publish_qos_2_is_acked.rs @@ -4,6 +4,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // +use miette::Context; use mqtt_format::v3::{ connect_return::MConnectReturnCode, identifier::MPacketIdentifier, @@ -34,7 +35,8 @@ impl BehaviourTest for PublishQos2IsAcked { session_present: false, connect_return_code: MConnectReturnCode::Accepted, }) - .await?; + .await + .context("Sending packet CONNACK")?; input .send_packet(MPublish { @@ -45,7 +47,8 @@ impl BehaviourTest for PublishQos2IsAcked { id: Some(MPacketIdentifier(1)), payload: &[0x00], }) - .await?; + .await + .context("Sending packet PUBLISH")?; Ok(()) } diff --git a/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs b/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs index 5f80a66..64cbddd 100644 --- a/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs +++ b/mqtt-tester/src/behaviour/publish_qos_zero_with_ident_fails.rs @@ -4,6 +4,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // +use miette::Context; use mqtt_format::v3::{ connect_return::MConnectReturnCode, identifier::MPacketIdentifier, @@ -34,7 +35,8 @@ impl BehaviourTest for PublishQosZeroWithIdentFails { session_present: false, connect_return_code: MConnectReturnCode::Accepted, }) - .await?; + .await + .context("Sending packet CONNACK")?; input .send_packet(MPublish { @@ -45,7 +47,8 @@ impl BehaviourTest for PublishQosZeroWithIdentFails { id: Some(MPacketIdentifier(1)), payload: &[0x00], }) - .await?; + .await + .context("Sending packet PUBLISH")?; Ok(()) } diff --git a/mqtt-tester/src/behaviour/receiving_server_packet.rs b/mqtt-tester/src/behaviour/receiving_server_packet.rs index ee1e981..d2fdc03 100644 --- a/mqtt-tester/src/behaviour/receiving_server_packet.rs +++ b/mqtt-tester/src/behaviour/receiving_server_packet.rs @@ -4,6 +4,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // +use miette::Context; use mqtt_format::v3::{ connect_return::MConnectReturnCode, identifier::MPacketIdentifier, @@ -33,7 +34,8 @@ impl BehaviourTest for ReceivingServerPacket { session_present: false, connect_return_code: MConnectReturnCode::Accepted, }) - .await?; + .await + .context("Sending packet CONNACK")?; input .send_packet(MSubscribe { @@ -43,7 +45,8 @@ impl BehaviourTest for ReceivingServerPacket { data: b"a/b", }, }) - .await?; + .await + .context("Sending packet SUBSCRIBE")?; Ok(()) } diff --git a/mqtt-tester/src/behaviour/utf8_with_nullchar_is_rejected.rs b/mqtt-tester/src/behaviour/utf8_with_nullchar_is_rejected.rs index 1f1ad34..3192b12 100644 --- a/mqtt-tester/src/behaviour/utf8_with_nullchar_is_rejected.rs +++ b/mqtt-tester/src/behaviour/utf8_with_nullchar_is_rejected.rs @@ -4,6 +4,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // +use miette::Context; use mqtt_format::v3::{ connect_return::MConnectReturnCode, header::MPacketKind, packet::MConnack, qos::MQualityOfService, @@ -31,7 +32,8 @@ impl BehaviourTest for Utf8WithNullcharIsRejected { session_present: false, connect_return_code: MConnectReturnCode::Accepted, }) - .await?; + .await + .context("Sending packet CONNACK")?; input .send(&[ @@ -51,7 +53,8 @@ impl BehaviourTest for Utf8WithNullcharIsRejected { 0b0000_0001, 0x1, // Payload ]) - .await?; + .await + .context("Sending broken packet PUBLISH")?; Ok(()) } diff --git a/mqtt-tester/src/behaviour/wait_for_connect.rs b/mqtt-tester/src/behaviour/wait_for_connect.rs index 1d643e3..e63c415 100644 --- a/mqtt-tester/src/behaviour/wait_for_connect.rs +++ b/mqtt-tester/src/behaviour/wait_for_connect.rs @@ -4,6 +4,8 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. // +use miette::Context; + use crate::{ behaviour_test::BehaviourTest, command::{Input, Output}, @@ -41,6 +43,8 @@ impl BehaviourTest for WaitForConnect { }), ) .await + .context("Waiting for bytes to check") + .map_err(miette::Error::from) } fn report_name(&self) -> &str { diff --git a/mqtt-tester/src/client_report.rs b/mqtt-tester/src/client_report.rs index b22bfe1..36bdee3 100644 --- a/mqtt-tester/src/client_report.rs +++ b/mqtt-tester/src/client_report.rs @@ -9,6 +9,7 @@ use std::sync::Arc; use futures::FutureExt; +use miette::Context; use mqtt_format::v3::packet::{MConnect, MPacket}; use crate::behaviour_test::BehaviourTest; @@ -57,8 +58,10 @@ pub async fn create_client_report( let (client, input, mut output) = executable .call(&commands) - .map(crate::command::Command::new)? - .spawn()?; + .map(crate::command::Command::new) + .context("Creating client executable call")? + .spawn() + .context("Spawning client executable")?; output.with_invariants(invariants.iter().cloned()); @@ -110,7 +113,14 @@ pub async fn create_client_report( let res = flow.translate_client_exit_code(out.status.success()); (res, Some(out.stderr)) } - (Err(_), _) | (_, Err(_)) => (ReportResult::Failure, None), + (Err(e), _) => { + tracing::error!("Error during behaviour testing: {:?}", e); + (ReportResult::Failure, None) + } + (_, Err(e)) => { + tracing::error!("Error during behaviour testing: {:?}", e); + (ReportResult::Failure, None) + } } }; @@ -214,7 +224,8 @@ async fn check_connect_packet_reserved_flag_zero( bytes[0] == 0b0001_0000 // CONNECT packet with flags set to 0000 }), ) - .await?; + .await + .context("Waiting for bytes to check")?; let output = client.wait_with_output(); let (result, output) = wait_for_output! { @@ -290,7 +301,8 @@ async fn check_connect_flag_username_set_username_present( } }), ) - .await?; + .await + .context("Waiting for bytes to check")?; let output = client.wait_with_output(); let (result, output) = wait_for_output! { @@ -346,7 +358,8 @@ async fn check_connect_flag_password_set_password_present( } }), ) - .await?; + .await + .context("Waiting for bytes to check")?; let output = client.wait_with_output(); let (result, output) = wait_for_output! { @@ -393,7 +406,8 @@ async fn check_connect_flag_username_zero_means_password_zero( } }), ) - .await?; + .await + .context("Waiting for bytes to check")?; let output = client.wait_with_output(); let (result, output) = wait_for_output! { -- cgit v1.2.3