Skip to content

Commit

Permalink
Remove drop_suites
Browse files Browse the repository at this point in the history
CMK-14884
  • Loading branch information
SoloJacobs committed Oct 24, 2023
1 parent d9a0599 commit 36e72b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 79 deletions.
54 changes: 0 additions & 54 deletions v2/robotmk/src/config/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -60,24 +58,6 @@ pub fn from_external_config(
)
}

pub fn drop_suites<'a>(
suites: Vec<Suite>,
suites_to_be_dropped: impl IntoIterator<Item = &'a String>,
) -> Vec<Suite> {
let mut suites_by_name: HashMap<String, Suite> =
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::<Vec<Suite>>();
sort_suites_by_name(&mut suites);
suites
}

fn sort_suites_by_name(suites: &mut [Suite]) {
suites.sort_by_key(|suite| suite.name.to_string());
}
Expand Down Expand Up @@ -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 {}),
);
}
}
46 changes: 23 additions & 23 deletions v2/robotmk/src/environment.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -26,28 +26,28 @@ pub fn build_environments(global_config: &GlobalConfig, suites: Vec<Suite>) -> 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<bool> {
let drop_suite = match suite.environment.build_instructions() {
) -> Result<Option<Suite>> {
let suite = match suite.environment.build_instructions() {
Some(build_instructions) => {
info!("Building environment for suite {}", suite.name);
environment_build_states_administrator
Expand All @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions v2/robotmk/src/results.rs
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 36e72b6

Please sign in to comment.