Skip to content

Commit

Permalink
Move daemon re-installation logic to restart_daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 committed Jul 29, 2024
1 parent a5c18f2 commit 13dc297
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
2 changes: 2 additions & 0 deletions test/test-manager/src/tests/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ pub async fn test_uninstall_app(
uninstalled_device,
);

// Re-install the app to ensure that the next test can run
install_app(&rpc, &TEST_CONFIG.app_package_filename).await?;
Ok(())
}

Expand Down
65 changes: 37 additions & 28 deletions test/test-manager/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
use anyhow::Context;
use config::TEST_CONFIG;
use helpers::install_app;
use mullvad_management_interface::MullvadProxyClient;
pub use test_metadata::TestMetadata;
use test_rpc::ServiceClient;

Expand Down Expand Up @@ -84,23 +85,15 @@ pub async fn cleanup_after_test(
log::debug!("Cleaning up daemon in test cleanup");
// Check if daemon should be restarted

if let Err(e) = restart_daemon(&rpc).await {
log::error!("Failed to restart daemon: {e}");
}
let mut mullvad_client = rpc_provider.new_client().await;

use crate::tests::Error::*;
match helpers::disconnect_and_wait(&mut mullvad_client).await {
Err(ManagementInterface(..) | DaemonNotRunning) => {
log::info!("Failed to reach daemon after test, re-installing app");
// Re-install the app to ensure that the next test can run
install_app(&rpc, &TEST_CONFIG.app_package_filename)
.await
.context("Failed to install app")?;
helpers::disconnect_and_wait(&mut mullvad_client).await?;
}
_ => (),
}
restart_daemon(&rpc, &mut mullvad_client)
.await
.context("Failed to restart daemon")?;

helpers::disconnect_and_wait(&mut mullvad_client)
.await
.context("Failed to disconnect daemon after test")?;

// Bring all the settings into scope so we remember to reset them.
let mullvad_types::settings::Settings {
Expand Down Expand Up @@ -212,19 +205,35 @@ pub async fn cleanup_after_test(
/// 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
.context("Failed to get daemon env variables")?;
let default_env = get_app_env()
.await
.context("Failed to get daemon default env variables")?;
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
.context("Failed to restart daemon")?;
async fn restart_daemon(
rpc: &ServiceClient,
mullvad_client: &mut MullvadProxyClient,
) -> anyhow::Result<()> {
use mullvad_management_interface::Error::*;
match mullvad_client.get_current_version().await {
Err(Rpc(..)) => {
log::info!("Failed to reach daemon after test, re-installing app");
// Re-install the app to ensure that the next test can run
install_app(rpc, &TEST_CONFIG.app_package_filename)
.await
.context("Failed to install app")?;
}
Err(e) => return Err(e.into()),
Ok(_version) => {
let current_env = rpc
.get_daemon_environment()
.await
.context("Failed to get daemon env variables")?;
let default_env = get_app_env()
.await
.context("Failed to get daemon default env variables")?;
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
.context("Failed to restart daemon")?;
}
}
}
Ok(())
}

0 comments on commit 13dc297

Please sign in to comment.