diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-04-09 13:48:07 +0200 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-04-12 15:01:54 +0200 |
| commit | 9531b3085b3831108fee3e4d7a8563ac79dc4225 (patch) | |
| tree | 3e088931812cf2c158ffbc9f4795924d54cc9f2a /test/test-manager/src | |
| parent | 60562b51bfaae339230b9a6bc552f8c7a65a99d7 (diff) | |
| download | mullvadvpn-9531b3085b3831108fee3e4d7a8563ac79dc4225.tar.xz mullvadvpn-9531b3085b3831108fee3e4d7a8563ac79dc4225.zip | |
Reset daemon environment when needed
Diffstat (limited to 'test/test-manager/src')
| -rw-r--r-- | test/test-manager/src/run_tests.rs | 4 | ||||
| -rw-r--r-- | test/test-manager/src/tests/mod.rs | 31 |
2 files changed, 29 insertions, 6 deletions
diff --git a/test/test-manager/src/run_tests.rs b/test/test-manager/src/run_tests.rs index 005d0c89d4..73c72ebc2e 100644 --- a/test/test-manager/src/run_tests.rs +++ b/test/test-manager/src/run_tests.rs @@ -105,8 +105,8 @@ pub async fn run( // Try to reset the daemon state if the test failed OR if the test doesn't explicitly // disabled cleanup. if test.cleanup || matches!(test_result.result, Err(_) | Ok(Err(_))) { - let mut client = test_context.rpc_provider.new_client().await; - crate::tests::cleanup_after_test(&mut client).await?; + crate::tests::cleanup_after_test(client.clone(), &test_context.rpc_provider) + .await?; } } diff --git a/test/test-manager/src/tests/mod.rs b/test/test-manager/src/tests/mod.rs index b89b4f0fd0..ce38308b0d 100644 --- a/test/test-manager/src/tests/mod.rs +++ b/test/test-manager/src/tests/mod.rs @@ -13,14 +13,16 @@ mod tunnel; mod tunnel_state; mod ui; -use crate::mullvad_daemon::{MullvadClientArgument, RpcClientProvider}; +use crate::{ + mullvad_daemon::{MullvadClientArgument, RpcClientProvider}, + tests::helpers::get_app_env, +}; use anyhow::Context; pub use test_metadata::TestMetadata; use test_rpc::ServiceClient; use futures::future::BoxFuture; -use mullvad_management_interface::MullvadProxyClient; use std::time::Duration; const WAIT_FOR_TUNNEL_STATE_TIMEOUT: Duration = Duration::from_secs(40); @@ -69,10 +71,16 @@ pub fn get_tests() -> Vec<&'static TestMetadata> { } /// Restore settings to the defaults. -pub async fn cleanup_after_test(mullvad_client: &mut MullvadProxyClient) -> anyhow::Result<()> { +pub async fn cleanup_after_test( + rpc: ServiceClient, + rpc_provider: &RpcClientProvider, +) -> anyhow::Result<()> { log::debug!("Cleaning up daemon in test cleanup"); + // Check if daemon should be restarted + restart_daemon(rpc).await?; + let mut mullvad_client = rpc_provider.new_client().await; - helpers::disconnect_and_wait(mullvad_client).await?; + helpers::disconnect_and_wait(&mut mullvad_client).await?; // Bring all the settings into scope so we remember to reset them. let mullvad_types::settings::Settings { @@ -176,3 +184,18 @@ pub async fn cleanup_after_test(mullvad_client: &mut MullvadProxyClient) -> anyh Ok(()) } + +/// Conditionally restart the running daemon +/// +/// If the daemon was started with non-standard environment variables, subsequent tests may break +/// due to assuming a default configuration. In that case, reset the environment variables and +/// restart. +async fn restart_daemon(rpc: ServiceClient) -> anyhow::Result<()> { + let current_env = rpc.get_daemon_environment().await?; + let default_env = get_app_env(); + if current_env != default_env { + log::debug!("Restarting daemon due changed environment variables. Values since last test {current_env:?}"); + rpc.set_daemon_environment(default_env).await?; + } + Ok(()) +} |
