Skip to content

Commit 864c9dd

Browse files
committed
Run tests in the order given
1 parent c88c5cd commit 864c9dd

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

test/test-manager/src/main.rs

+28-30
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::{net::SocketAddr, path::PathBuf};
1313

1414
use anyhow::{Context, Result};
1515
use clap::Parser;
16+
use tests::{config::TEST_CONFIG, get_filtered_tests};
1617
use vm::provision;
1718

1819
use crate::tests::config::OpenVPNCertificate;
@@ -118,7 +119,8 @@ enum Commands {
118119
#[arg(long)]
119120
openvpn_certificate: Option<PathBuf>,
120121

121-
/// Only run tests matching substrings
122+
/// Names of tests to run. The order given will be respected. If not set, all tests will be
123+
/// run.
122124
test_filters: Vec<String>,
123125

124126
/// Print results live
@@ -294,6 +296,28 @@ async fn main() -> Result<()> {
294296
.await
295297
.context("Failed to run provisioning for VM")?;
296298

299+
TEST_CONFIG.init(tests::config::TestConfig::new(
300+
account,
301+
artifacts_dir,
302+
manifest
303+
.app_package_path
304+
.file_name()
305+
.unwrap()
306+
.to_string_lossy()
307+
.into_owned(),
308+
manifest
309+
.app_package_to_upgrade_from_path
310+
.map(|path| path.file_name().unwrap().to_string_lossy().into_owned()),
311+
manifest
312+
.gui_package_path
313+
.map(|path| path.file_name().unwrap().to_string_lossy().into_owned()),
314+
mullvad_host,
315+
vm::network::bridge()?,
316+
test_rpc::meta::Os::from(vm_config.os_type),
317+
openvpn_certificate,
318+
));
319+
let tests = get_filtered_tests(&test_filters)?;
320+
297321
// For convenience, spawn a SOCKS5 server that is reachable for tests that need it
298322
let socks = socks_server::spawn(SocketAddr::new(
299323
crate::vm::network::NON_TUN_GATEWAY.into(),
@@ -303,35 +327,9 @@ async fn main() -> Result<()> {
303327

304328
let skip_wait = vm_config.provisioner != config::Provisioner::Noop;
305329

306-
let result = run_tests::run(
307-
tests::config::TestConfig::new(
308-
account,
309-
artifacts_dir,
310-
manifest
311-
.app_package_path
312-
.file_name()
313-
.unwrap()
314-
.to_string_lossy()
315-
.into_owned(),
316-
manifest
317-
.app_package_to_upgrade_from_path
318-
.map(|path| path.file_name().unwrap().to_string_lossy().into_owned()),
319-
manifest
320-
.gui_package_path
321-
.map(|path| path.file_name().unwrap().to_string_lossy().into_owned()),
322-
mullvad_host,
323-
vm::network::bridge()?,
324-
test_rpc::meta::Os::from(vm_config.os_type),
325-
openvpn_certificate,
326-
),
327-
&*instance,
328-
&test_filters,
329-
skip_wait,
330-
!verbose,
331-
summary_logger,
332-
)
333-
.await
334-
.context("Tests failed");
330+
let result = run_tests::run(&*instance, tests, skip_wait, !verbose, summary_logger)
331+
.await
332+
.context("Tests failed");
335333

336334
if display {
337335
instance.wait().await;

test/test-manager/src/run_tests.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
logging::{Logger, Panic, TestOutput, TestResult},
33
mullvad_daemon::{self, MullvadClientArgument, RpcClientProvider},
44
summary::SummaryLogger,
5-
tests::{self, config::TEST_CONFIG, get_tests, TestContext},
5+
tests::{self, config::TEST_CONFIG, TestContext, TestMetadata},
66
vm,
77
};
88
use anyhow::{Context, Result};
@@ -101,15 +101,13 @@ impl TestHandler<'_> {
101101
}
102102

103103
pub async fn run(
104-
config: tests::config::TestConfig,
105104
instance: &dyn vm::VmInstance,
106-
test_filters: &[String],
105+
tests: Vec<&TestMetadata>,
107106
skip_wait: bool,
108107
print_failed_tests_only: bool,
109108
summary_logger: Option<SummaryLogger>,
110109
) -> Result<TestResult> {
111110
log::trace!("Setting test constants");
112-
TEST_CONFIG.init(config);
113111

114112
let pty_path = instance.get_pty();
115113

@@ -141,22 +139,6 @@ pub async fn run(
141139
logger: Logger::get_or_init(),
142140
};
143141

144-
let mut tests = get_tests();
145-
146-
tests.retain(|test| test.should_run_on_os(TEST_CONFIG.os));
147-
148-
if !test_filters.is_empty() {
149-
tests.retain(|test| {
150-
for command in test_filters {
151-
let command = command.to_lowercase();
152-
if test.command.to_lowercase().contains(&command) {
153-
return true;
154-
}
155-
}
156-
false
157-
});
158-
}
159-
160142
if TEST_CONFIG.app_package_to_upgrade_from_filename.is_some() {
161143
test_handler
162144
.run_test(

test/test-manager/src/tests/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ pub fn get_tests() -> Vec<&'static TestMetadata> {
7878
tests
7979
}
8080

81+
pub fn get_filtered_tests(specified_tests: &[String]) -> Result<Vec<&TestMetadata>, anyhow::Error> {
82+
let mut tests = get_tests();
83+
tests.retain(|test| test.should_run_on_os(TEST_CONFIG.os));
84+
if !specified_tests.is_empty() {
85+
specified_tests
86+
.iter()
87+
.map(|f| {
88+
tests
89+
.iter()
90+
.find(|t| t.command.eq_ignore_ascii_case(f))
91+
.cloned()
92+
.ok_or(anyhow::anyhow!("Test '{f}' not found"))
93+
})
94+
.collect()
95+
} else {
96+
// Keep all tests
97+
Ok(tests)
98+
}
99+
}
100+
81101
/// Make sure the daemon is installed and logged in and restore settings to the defaults.
82102
pub async fn prepare_daemon(
83103
rpc: &ServiceClient,

0 commit comments

Comments
 (0)