From 7ba259200e25e57c80ae5636d66aaa57a60bce9e Mon Sep 17 00:00:00 2001 From: Markus Pettersson Date: Thu, 12 Oct 2023 16:32:28 +0200 Subject: [PATCH] Make `run_test` infallible Running a test should never abort the execution of the remaining tests. This could happen before if `get_mullvad_app_logs()` failed, which was a bit surprising. --- test/test-manager/src/logging.rs | 31 ++++++++++++++++++------------ test/test-manager/src/run_tests.rs | 15 ++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/test/test-manager/src/logging.rs b/test/test-manager/src/logging.rs index e7bd8a9ed8a1..c11fdf28bfbc 100644 --- a/test/test-manager/src/logging.rs +++ b/test/test-manager/src/logging.rs @@ -115,7 +115,7 @@ pub struct TestOutput { pub error_messages: Vec, pub test_name: &'static str, pub result: Result, PanicMessage>, - pub log_output: LogOutput, + pub log_output: Option, } impl TestOutput { @@ -150,21 +150,28 @@ impl TestOutput { } println!("{}", format!("TEST {} HAD LOGS:", self.test_name).red()); - match &self.log_output.settings_json { - Ok(settings) => println!("settings.json: {}", settings), - Err(e) => println!("Could not get settings.json: {}", e), - } + match &self.log_output { + Some(log) => { + match &log.settings_json { + Ok(settings) => println!("settings.json: {}", settings), + Err(e) => println!("Could not get settings.json: {}", e), + } - match &self.log_output.log_files { - Ok(log_files) => { - for log in log_files { - match log { - Ok(log) => println!("Log {}:\n{}", log.name.to_str().unwrap(), log.content), - Err(e) => println!("Could not get log: {}", e), + match &log.log_files { + Ok(log_files) => { + for log in log_files { + match log { + Ok(log) => { + println!("Log {}:\n{}", log.name.to_str().unwrap(), log.content) + } + Err(e) => println!("Could not get log: {}", e), + } + } } + Err(e) => println!("Could not get logs: {}", e), } } - Err(e) => println!("Could not get logs: {}", e), + None => println!("Missing logs for {}", self.test_name), } println!( diff --git a/test/test-manager/src/run_tests.rs b/test/test-manager/src/run_tests.rs index c1f29dbea812..f0ff40203404 100644 --- a/test/test-manager/src/run_tests.rs +++ b/test/test-manager/src/run_tests.rs @@ -100,8 +100,7 @@ pub async fn run( test.name, test_context.clone(), ) - .await - .context("Failed to run test")?; + .await; if test.mullvad_client_version == MullvadClientVersion::New { // Try to reset the daemon state if the test failed OR if the test doesn't explicitly @@ -183,7 +182,7 @@ pub async fn run_test( test: &F, test_name: &'static str, test_context: super::tests::TestContext, -) -> Result +) -> TestOutput where F: Fn(super::tests::TestContext, ServiceClient, MullvadClient) -> R, R: Future>, @@ -211,15 +210,13 @@ where } } } - let log_output = runner_rpc - .get_mullvad_app_logs() - .await - .map_err(Error::Rpc)?; - Ok(TestOutput { + let log_output = runner_rpc.get_mullvad_app_logs().await.ok(); + + TestOutput { log_output, test_name, error_messages: output, result, - }) + } }