diff --git a/v2/robotmk/src/config/internal.rs b/v2/robotmk/src/config/internal.rs index ab3cbf0a..60a4166d 100644 --- a/v2/robotmk/src/config/internal.rs +++ b/v2/robotmk/src/config/internal.rs @@ -5,8 +5,6 @@ use crate::session::Session; use crate::termination::TerminationFlag; use camino::Utf8PathBuf; -use log::{debug, warn}; -use std::collections::HashMap; use std::sync::Arc; use std::sync::Mutex; @@ -60,24 +58,6 @@ pub fn from_external_config( ) } -pub fn drop_suites<'a>( - suites: Vec, - suites_to_be_dropped: impl IntoIterator, -) -> Vec { - let mut suites_by_name: HashMap = - HashMap::from_iter(suites.into_iter().map(|suite| (suite.name.clone(), suite))); - for suite_name in suites_to_be_dropped { - if suites_by_name.remove(suite_name).is_some() { - debug!("Dropped suite {suite_name}") - } else { - warn!("Attempted to drop suite {suite_name}, but no suite with this name exists") - } - } - let mut suites = suites_by_name.into_values().collect::>(); - sort_suites_by_name(&mut suites); - suites -} - fn sort_suites_by_name(suites: &mut [Suite]) { suites.sort_by_key(|suite| suite.name.to_string()); } @@ -206,38 +186,4 @@ mod tests { ); assert_eq!(suites[1].session, Session::Current(CurrentSession {})); } - - #[test] - fn test_drop_suites() { - let (_global_config, suites) = from_external_config( - Config { - working_directory: Utf8PathBuf::from("/working"), - results_directory: Utf8PathBuf::from("/results"), - suites: HashMap::from([ - (String::from("system"), system_suite_config()), - (String::from("rcc1"), rcc_suite_config()), - (String::from("rcc2"), rcc_suite_config()), - ]), - }, - TerminationFlag::new(), - ); - let suites = drop_suites(suites, &vec!["rcc1".into()]); - assert_eq!(suites.len(), 2); - assert_eq!(suites[0].name, "rcc2"); - assert_eq!( - suites[0].environment, - Environment::Rcc(RCCEnvironment { - binary_path: Utf8PathBuf::from("/bin/rcc"), - robot_yaml_path: Utf8PathBuf::from("/suite/rcc/robot.yaml"), - controller: "robotmk".into(), - space: "rcc2".into(), - build_timeout: 300, - }) - ); - assert_eq!(suites[1].name, "system"); - assert_eq!( - suites[1].environment, - Environment::System(SystemEnvironment {}), - ); - } } diff --git a/v2/robotmk/src/environment.rs b/v2/robotmk/src/environment.rs index 83b7fe8b..4a7816c8 100644 --- a/v2/robotmk/src/environment.rs +++ b/v2/robotmk/src/environment.rs @@ -1,7 +1,7 @@ use super::child_process_supervisor::{ChildProcessOutcome, ChildProcessSupervisor, StdioPaths}; use super::command_spec::CommandSpec; use super::config::external::EnvironmentConfig; -use super::config::internal::{drop_suites, GlobalConfig, Suite}; +use super::config::internal::{GlobalConfig, Suite}; use super::logging::log_and_return_error; use super::results::{ EnvironmentBuildStatesAdministrator, EnvironmentBuildStatus, EnvironmentBuildStatusError, @@ -26,28 +26,28 @@ pub fn build_environments(global_config: &GlobalConfig, suites: Vec) -> R let env_building_stdio_directory = environment_building_stdio_directory(&global_config.working_directory); - let mut suites_to_be_dropped = vec![]; - for suite in suites.iter() { - let drop_suite = build_environment( - suite, - &mut environment_build_states_administrator, - &env_building_stdio_directory, - )?; - - if drop_suite { - suites_to_be_dropped.push(suite.name.clone()); - } - } - - Ok(drop_suites(suites, &suites_to_be_dropped)) + suites + .into_iter() + .filter_map(|suite| { + match build_environment( + suite, + &mut environment_build_states_administrator, + &env_building_stdio_directory, + ) { + Ok(None) => None, + Ok(Some(suite)) => Some(Ok(suite)), + Err(e) => Some(Err(e)), + } + }) + .collect() } -fn build_environment<'a>( - suite: &Suite, - environment_build_states_administrator: &mut EnvironmentBuildStatesAdministrator<'a>, +fn build_environment( + suite: Suite, + environment_build_states_administrator: &mut EnvironmentBuildStatesAdministrator<'_>, stdio_directory: &Utf8Path, -) -> Result { - let drop_suite = match suite.environment.build_instructions() { +) -> Result> { + let suite = match suite.environment.build_instructions() { Some(build_instructions) => { info!("Building environment for suite {}", suite.name); environment_build_states_administrator @@ -64,16 +64,16 @@ fn build_environment<'a>( let drop_suite = matches!(environment_build_status, EnvironmentBuildStatus::Failure(_)); environment_build_states_administrator .insert_and_write_atomic(&suite.name, environment_build_status)?; - drop_suite + (!drop_suite).then_some(suite) } None => { debug!("Nothing to do for suite {}", suite.name); environment_build_states_administrator .insert_and_write_atomic(&suite.name, EnvironmentBuildStatus::NotNeeded)?; - false + Some(suite) } }; - Ok(drop_suite) + Ok(suite) } fn run_environment_build( diff --git a/v2/robotmk/src/results.rs b/v2/robotmk/src/results.rs index 5ba9467e..5289c36a 100644 --- a/v2/robotmk/src/results.rs +++ b/v2/robotmk/src/results.rs @@ -1,10 +1,10 @@ +use super::config::internal::Suite; use anyhow::{Context, Result}; use atomicwrites::{AtomicFile, OverwriteBehavior}; use camino::{Utf8Path, Utf8PathBuf}; use serde::Serialize; use serde_json::to_string; use std::{collections::HashMap, io::Write}; -use super::config::internal::Suite; pub fn suite_results_directory(results_directory: &Utf8Path) -> Utf8PathBuf { results_directory.join("suites") @@ -40,7 +40,9 @@ impl<'a> EnvironmentBuildStatesAdministrator<'a> { ) -> EnvironmentBuildStatesAdministrator<'a> { Self { build_states: HashMap::from_iter( - suites.iter().map(|suite| (suite.name.to_string(), EnvironmentBuildStatus::Pending)), + suites + .iter() + .map(|suite| (suite.name.to_string(), EnvironmentBuildStatus::Pending)), ), working_directory, results_directory,