From 85be431728c0a12135f3710984cc5a3efebba56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Walski?= Date: Tue, 26 Mar 2024 17:23:07 +0100 Subject: [PATCH] No uses_gpu config property. Automatic config parse test. --- src/offer_template.rs | 9 ++-- src/process.rs | 1 - src/process/automatic/config.rs | 23 ++++++---- src/process/dummy.rs | 4 -- tests/runtime_config.rs | 77 --------------------------------- 5 files changed, 18 insertions(+), 96 deletions(-) delete mode 100644 tests/runtime_config.rs diff --git a/src/offer_template.rs b/src/offer_template.rs index dd3dbc8..c875f44 100644 --- a/src/offer_template.rs +++ b/src/offer_template.rs @@ -11,12 +11,9 @@ struct OfferTemplate { constraints: String, } pub(crate) fn gpu_detection(config: &CONFIG) -> anyhow::Result> { - if config.uses_gpu() { - let gpu_detection = gpu_detection::GpuDetection::init()?; - let gpu = gpu_detection.detect(config.gpu_uuid())?; - return Ok(Some(gpu)); - } - Ok(None) + let gpu_detection = gpu_detection::GpuDetection::init()?; + let gpu = gpu_detection.detect(config.gpu_uuid())?; + Ok(Some(gpu)) } pub(crate) fn template( diff --git a/src/process.rs b/src/process.rs index 450d29e..7bd6e92 100644 --- a/src/process.rs +++ b/src/process.rs @@ -44,7 +44,6 @@ pub(crate) trait Runtime: Sized { pub(crate) trait RuntimeConfig: DeserializeOwned + Default + Debug + Clone { fn gpu_uuid(&self) -> Option; - fn uses_gpu(&self) -> bool; } #[derive(Clone)] diff --git a/src/process/automatic/config.rs b/src/process/automatic/config.rs index 585877e..154f161 100644 --- a/src/process/automatic/config.rs +++ b/src/process/automatic/config.rs @@ -33,19 +33,12 @@ pub(crate) struct Config { pub monitored_msgs_w_trace_lvl: Vec, pub gpu_uuid: Option, - - // Property for testing purposes - pub uses_gpu: bool, } impl RuntimeConfig for Config { fn gpu_uuid(&self) -> Option { self.gpu_uuid.clone() } - - fn uses_gpu(&self) -> bool { - self.uses_gpu - } } impl Default for Config { @@ -70,7 +63,21 @@ impl Default for Config { "\"GET / HTTP/1.1\" 404 Not Found".into(), ], gpu_uuid: None, - uses_gpu: true, } } } + +#[cfg(test)] +mod config_tests { + use std::{fs, path::PathBuf}; + + use super::Config; + + #[test] + fn config_test() { + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push("tests/resources/runtime_config.json"); + let config = fs::read_to_string(path).unwrap(); + serde_json::from_str::(&config).expect("Can parse config"); + } +} diff --git a/src/process/dummy.rs b/src/process/dummy.rs index 1c2816c..45787d4 100644 --- a/src/process/dummy.rs +++ b/src/process/dummy.rs @@ -29,10 +29,6 @@ impl RuntimeConfig for Config { fn gpu_uuid(&self) -> Option { None } - - fn uses_gpu(&self) -> bool { - false - } } #[async_trait] diff --git a/tests/runtime_config.rs b/tests/runtime_config.rs deleted file mode 100644 index f86403b..0000000 --- a/tests/runtime_config.rs +++ /dev/null @@ -1,77 +0,0 @@ -use assert_cmd::prelude::*; // Add methods on commands -use std::{path::PathBuf, process::Command}; // Run programs - -#[test] -fn runtime_config_as_text_ok() { - let mut cmd = Command::cargo_bin("ya-runtime-ai").unwrap(); - cmd.arg("--runtime") - .arg("automatic") - .arg("--runtime-config") - .arg( - r##"{ - "startup_script": "path/run.bat", - "api_port": 80, - "api_host": "domain.com", - "api_shutdown_path": "/kill/me", - "model_arg": "", - "additional_args": ["--arg-one", "--arg-two"], - "startup_timeout": "1s", - "api_ping_delay": "100ms", - "monitored_startup_msg": "Started", - "monitored_model_failure_msg": "Failed", - "monitored_msgs_w_trace_lvl": ["Unimportant", "Boring log"], - "uses_gpu": false - }"##, - ) - .arg("test") - .assert() - .success(); -} - -#[test] -fn config_parse_succ_single_field() { - let mut cmd = Command::cargo_bin("ya-runtime-ai").unwrap(); - cmd.arg("--runtime") - .arg("automatic") - .arg("--runtime-config") - .arg(r##"{ "startup_script": "path/bin.exe", "uses_gpu": false }"##) - .arg("test") - .assert() - .success(); -} - -#[test] -fn config_parse_fail_field_bat_type() { - let mut cmd = Command::cargo_bin("ya-runtime-ai").unwrap(); - cmd.arg("--runtime") - .arg("automatic") - .arg("--runtime-config") - .arg(r##"{ "startup_script": 13, "uses_gpu": false }"##) - .arg("test") - .assert() - .failure(); -} - -#[test] -fn succ_without_runtime_config_arg() { - let mut cmd = Command::cargo_bin("ya-runtime-ai").unwrap(); - cmd.arg("--runtime") - .arg("dummy") - .arg("test") - .assert() - .success(); -} - -#[test] -fn config_parse_file_succ() { - let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - path.push("tests/resources/runtime_config.json"); - let mut cmd = Command::cargo_bin("ya-runtime-ai").unwrap(); - cmd.arg("--runtime") - .arg("automatic") - .arg("--runtime-config") - .arg(path.to_str().unwrap()) - .arg("test") - .assert() - .success(); -}