Skip to content

Commit

Permalink
Bugfix in execution of setup steps
Browse files Browse the repository at this point in the history
Failed steps were not processed correctly. Also added corresponding unit test.
  • Loading branch information
jherbel committed Jan 14, 2025
1 parent 43185b0 commit d43c05a
Showing 1 changed file with 94 additions and 1 deletion.
95 changes: 94 additions & 1 deletion src/bin/scheduler/setup/steps/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn run_steps(
plans.extend(affected_plans);
}
Err(err) => {
for plan in &plans {
for plan in affected_plans {
error!(
"Plan {}: {}. Plan won't be scheduled.\nCaused by: {:?}",
plan.id, err.summary, err.cause,
Expand All @@ -83,3 +83,96 @@ pub fn run_steps(
}
Ok((plans, errors))
}

#[cfg(test)]
mod tests {
use camino::Utf8PathBuf;

use super::*;
use crate::internal_config::{GroupAffiliation, Source};
use robotmk::config::{PlanMetadata, RetryStrategy, WorkingDirectoryCleanupConfig};
use robotmk::environment::{Environment, SystemEnvironment};
use robotmk::lock::Locker;
use robotmk::rf::robot::Robot;
use robotmk::section::Host;
use robotmk::session::{CurrentSession, Session};
use tokio_util::sync::CancellationToken;

struct SetupStepOk {}

impl SetupStep for SetupStepOk {
fn label(&self) -> String {
"Ok".into()
}

fn setup(&self) -> Result<(), Error> {
Ok(())
}
}

struct SetupStepError {}

impl SetupStep for SetupStepError {
fn label(&self) -> String {
"Error".into()
}

fn setup(&self) -> Result<(), Error> {
Err(Error::new("Error".into(), anyhow::anyhow!("Error")))
}
}

#[test]
fn test_run_steps() {
let plan_bluerpint = Plan {
id: String::default(),
source: Source::Manual,
working_directory: Utf8PathBuf::default(),
results_file: Utf8PathBuf::default(),
timeout: u64::default(),
robot: Robot {
robot_target: Utf8PathBuf::default(),
command_line_args: Vec::default(),
envs_rendered_obfuscated: Vec::default(),
n_attempts_max: usize::default(),
retry_strategy: RetryStrategy::Incremental,
},
environment: Environment::System(SystemEnvironment {}),
session: Session::Current(CurrentSession {}),
working_directory_cleanup_config: WorkingDirectoryCleanupConfig::MaxAgeSecs(
u64::default(),
),
cancellation_token: CancellationToken::new(),
host: Host::Source,
results_directory_locker: Locker::new(Utf8PathBuf::default(), None),
metadata: PlanMetadata {
application: String::default(),
suite_name: String::default(),
variant: String::default(),
},
group_affiliation: GroupAffiliation {
group_index: usize::default(),
position_in_group: usize::default(),
execution_interval: u64::default(),
},
};
let mut plan_ok = plan_bluerpint.clone();
plan_ok.id = "ok".into();
let mut plan_error = plan_bluerpint.clone();
plan_error.id = "error".into();

let (passed_plans, errors) = run_steps(
vec![
(Box::new(SetupStepOk {}), vec![plan_ok]),
(Box::new(SetupStepError {}), vec![plan_error]),
],
&CancellationToken::new(),
)
.unwrap();

assert_eq!(passed_plans.len(), 1);
assert_eq!(passed_plans[0].id, "ok");
assert_eq!(errors.len(), 1);
assert_eq!(errors[0].plan_id, "error");
}
}

0 comments on commit d43c05a

Please sign in to comment.