diff --git a/src/utils/metrics.rs b/src/utils/metrics.rs index 9805273..09722fa 100644 --- a/src/utils/metrics.rs +++ b/src/utils/metrics.rs @@ -32,7 +32,7 @@ mod metrics_unittets { assert!(true); } #[tokio::test] - async fn init_sumodules() { + async fn get_metrics_grubber() { assert!(true); } // Option> output diff --git a/src/utils/prcs.rs b/src/utils/prcs.rs index 87e8cbc..f76a68e 100644 --- a/src/utils/prcs.rs +++ b/src/utils/prcs.rs @@ -5,18 +5,19 @@ use std::process::{Command, Output}; use std::sync::Arc; use tokio::time::Duration; -pub async fn get_pid(name: &str) -> Result { +pub async fn get_pid(name: &str) -> Option { let name = Arc::new(name.to_string()); let res = - tokio::task::spawn_blocking(move || Command::new("pidof").arg(&*name).output()).await?; + // todo : unwrap change - can be unsafe + tokio::task::spawn_blocking(move || Command::new("pidof").arg(&*name).output()).await.unwrap(); if let Ok(output) = res { if output.stderr.is_empty() && output.stdout.is_empty() { - return Err(io::ErrorKind::NotFound.into()); + None } else { - Ok(output) + Some(output) } } else { - return Err(io::ErrorKind::NotFound.into()); + None } } // ! can be with bug !!! @@ -40,7 +41,7 @@ pub async fn is_active(name: &str) -> bool { // T is for stopped processes pub async fn is_frozen(name: &str) -> bool { let temp: Output; - if let Ok(output) = get_pid(name).await { + if let Some(output) = get_pid(name).await { temp = output; } else { return false; @@ -128,7 +129,6 @@ mod process_unittests { // rewrite, its a pipe #[tokio::test] async fn full_cycle_with_restart() { - assert!(true); let res1 = start_process("temp-process", "/home/user/monitor/runner-rs/temp-process").await; assert!(res1.is_ok()); let res2 = @@ -157,12 +157,12 @@ mod process_unittests { } #[tokio::test] async fn pidof_active_process() { - assert!(get_pid("systemd").await.is_ok()); + assert!(get_pid("systemd").await.is_some()); } // broken mechanism need to check #[tokio::test] async fn pidof_disabled_process() { - assert!(get_pid("invalid-process-name").await.is_err()); + assert!(get_pid("invalid-process-name").await.is_none()); } }