diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2023-11-17 15:37:13 +0100 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2023-12-06 14:37:06 +0100 |
| commit | 1b930b893fa3fcb06f5fee4affbfb62887d0e68a (patch) | |
| tree | 21b0836c5b5730f844950a2764aa652832f13849 /test/test-runner/src/sys.rs | |
| parent | ac3e222d031b0f599561c4c30504de5cd3f871a2 (diff) | |
| download | mullvadvpn-1b930b893fa3fcb06f5fee4affbfb62887d0e68a.tar.xz mullvadvpn-1b930b893fa3fcb06f5fee4affbfb62887d0e68a.zip | |
Implement RPC for reading & writing to app cache file
- Implement RPC for writing to a file in a test runner / guest VM.
- Implement RPC for getting app cache directory
- Implement RPC for restarting the app in a test runner / guest vm
- Implement RPC for starting the app in a test runner / guest vm
- Implement RPC for stopping the app in a test runner / guest vm
- Implement `find_cache_traces` on Window & macOS
Diffstat (limited to 'test/test-runner/src/sys.rs')
| -rw-r--r-- | test/test-runner/src/sys.rs | 103 |
1 files changed, 91 insertions, 12 deletions
diff --git a/test/test-runner/src/sys.rs b/test/test-runner/src/sys.rs index 93d148a2b5..cc89205425 100644 --- a/test/test-runner/src/sys.rs +++ b/test/test-runner/src/sys.rs @@ -193,16 +193,102 @@ ExecStart=/usr/bin/mullvad-daemon --disable-stdout-timestamps {verbosity}"# .await .map_err(|e| test_rpc::Error::Service(e.to_string()))?; + restart_app().await?; + Ok(()) +} + +/// Restart the Mullvad VPN application. +/// +/// This function waits for the app to successfully start again. +#[cfg(target_os = "linux")] +pub async fn restart_app() -> Result<(), test_rpc::Error> { tokio::process::Command::new("systemctl") .args(["restart", "mullvad-daemon"]) .status() .await .map_err(|e| test_rpc::Error::Service(e.to_string()))?; - wait_for_service_state(ServiceState::Running).await?; Ok(()) } +/// Stop the Mullvad VPN application. +/// +/// This function waits for the app to successfully shut down. +#[cfg(target_os = "linux")] +pub async fn stop_app() -> Result<(), test_rpc::Error> { + set_mullvad_daemon_service_state(false).await +} + +/// Start the Mullvad VPN application. +/// +/// This function waits for the app to successfully start again. +#[cfg(target_os = "linux")] +pub async fn start_app() -> Result<(), test_rpc::Error> { + set_mullvad_daemon_service_state(true).await +} + +/// Restart the Mullvad VPN application. +/// +/// This function waits for the app to successfully start again. +#[cfg(target_os = "windows")] +pub async fn restart_app() -> Result<(), test_rpc::Error> { + stop_app().await?; + start_app().await?; + Ok(()) +} + +/// Stop the Mullvad VPN application. +/// +/// This function waits for the app to successfully shut down. +#[cfg(target_os = "windows")] +pub async fn stop_app() -> Result<(), test_rpc::Error> { + let _ = tokio::process::Command::new("net") + .args(["stop", "mullvadvpn"]) + .status() + .await + .map_err(|e| test_rpc::Error::Service(e.to_string()))?; + Ok(()) +} + +/// Start the Mullvad VPN application. +/// +/// This function waits for the app to successfully start again. +#[cfg(target_os = "windows")] +pub async fn start_app() -> Result<(), test_rpc::Error> { + let _ = tokio::process::Command::new("net") + .args(["start", "mullvadvpn"]) + .status() + .await + .map_err(|e| test_rpc::Error::Service(e.to_string()))?; + Ok(()) +} + +/// Restart the Mullvad VPN application. +/// +/// This function waits for the app to successfully start again. +#[cfg(target_os = "macos")] +pub async fn restart_app() -> Result<(), test_rpc::Error> { + stop_app().await?; + start_app().await?; + Ok(()) +} + +/// Stop the Mullvad VPN application. +/// +/// This function waits for the app to successfully shut down. +#[cfg(target_os = "macos")] +pub async fn stop_app() -> Result<(), test_rpc::Error> { + set_mullvad_daemon_service_state(false).await +} + +/// Start the Mullvad VPN application. +/// +/// This function waits for the app to successfully start again. +#[cfg(target_os = "macos")] +pub async fn start_app() -> Result<(), test_rpc::Error> { + set_mullvad_daemon_service_state(true).await +} + #[cfg(target_os = "windows")] pub async fn set_daemon_log_level(verbosity_level: Verbosity) -> Result<(), test_rpc::Error> { log::debug!("Setting log level"); @@ -226,6 +312,7 @@ pub async fn set_daemon_log_level(verbosity_level: Verbosity) -> Result<(), test .map_err(|e| test_rpc::Error::Service(e.to_string()))?; // Stop the service + // TODO: Extract to separate function. service .stop() .map_err(|e| test_rpc::Error::Service(e.to_string()))?; @@ -266,6 +353,7 @@ pub async fn set_daemon_log_level(verbosity_level: Verbosity) -> Result<(), test .map_err(|e| test_rpc::Error::Service(e.to_string()))?; // Start the service + // TODO: Extract to separate function. service .start::<String>(&[]) .map_err(|e| test_rpc::Error::Service(e.to_string()))?; @@ -341,17 +429,8 @@ pub async fn set_daemon_environment(env: HashMap<String, String>) -> Result<(), } // Restart service - tokio::process::Command::new("net") - .args(["stop", "mullvadvpn"]) - .status() - .await - .map_err(|e| test_rpc::Error::Service(e.to_string()))?; - - tokio::process::Command::new("net") - .args(["start", "mullvadvpn"]) - .status() - .await - .map_err(|e| test_rpc::Error::Service(e.to_string()))?; + stop_app().await?; + start_app().await?; Ok(()) } |
