From 4d30ab24eac82db6e893ccb0730f23db58f4f4da Mon Sep 17 00:00:00 2001 From: Solomon Jacobs Date: Mon, 11 Dec 2023 12:17:25 +0100 Subject: [PATCH] test termination 11: move `sessions` and `rf` In order to write an integration test, the relevant functionality needs to be part of the libary crate `robotmk`. The goal is to move `run_attempts_until_succesful`. This change moves the `rf` and `sessions` module. CMK-15433 --- v2/robotmk/src/bin/scheduler/internal_config.rs | 6 +++--- v2/robotmk/src/bin/scheduler/main.rs | 2 -- v2/robotmk/src/bin/scheduler/scheduling/suites.rs | 4 ++-- v2/robotmk/src/bin/scheduler/setup/rcc.rs | 2 +- v2/robotmk/src/lib.rs | 2 ++ v2/robotmk/src/{bin/scheduler => }/rf/mod.rs | 0 v2/robotmk/src/{bin/scheduler => }/rf/rebot.rs | 10 +++++----- v2/robotmk/src/{bin/scheduler => }/rf/robot.rs | 7 +++---- .../src/{bin/scheduler => }/sessions/mod.rs | 0 .../src/{bin/scheduler => }/sessions/schtasks.rs | 9 ++++----- .../src/{bin/scheduler => }/sessions/session.rs | 15 ++++++--------- 11 files changed, 26 insertions(+), 31 deletions(-) rename v2/robotmk/src/{bin/scheduler => }/rf/mod.rs (100%) rename v2/robotmk/src/{bin/scheduler => }/rf/rebot.rs (96%) rename v2/robotmk/src/{bin/scheduler => }/rf/robot.rs (97%) rename v2/robotmk/src/{bin/scheduler => }/sessions/mod.rs (100%) rename v2/robotmk/src/{bin/scheduler => }/sessions/schtasks.rs (98%) rename v2/robotmk/src/{bin/scheduler => }/sessions/session.rs (89%) diff --git a/v2/robotmk/src/bin/scheduler/internal_config.rs b/v2/robotmk/src/bin/scheduler/internal_config.rs index 9afc9843..c69ec0e6 100644 --- a/v2/robotmk/src/bin/scheduler/internal_config.rs +++ b/v2/robotmk/src/bin/scheduler/internal_config.rs @@ -1,10 +1,10 @@ -use crate::rf::robot::Robot; -use crate::sessions::session::Session; use robotmk::config::{Config, RCCConfig, WorkingDirectoryCleanupConfig}; use robotmk::environment::Environment; use robotmk::lock::Locker; use robotmk::results::suite_results_directory; +use robotmk::rf::robot::Robot; use robotmk::section::Host; +use robotmk::sessions::session::Session; use camino::Utf8PathBuf; use tokio_util::sync::CancellationToken; @@ -89,12 +89,12 @@ pub fn sort_suites_by_id(suites: &mut [Suite]) { #[cfg(test)] mod tests { use super::*; - use crate::sessions::session::{CurrentSession, UserSession}; use robotmk::config::{ EnvironmentConfig, ExecutionConfig, RCCEnvironmentConfig, RCCProfileConfig, RetryStrategy, RobotFrameworkConfig, SessionConfig, SuiteConfig, UserSessionConfig, }; use robotmk::environment::{Environment, RCCEnvironment, SystemEnvironment}; + use robotmk::sessions::session::{CurrentSession, UserSession}; use std::collections::HashMap; diff --git a/v2/robotmk/src/bin/scheduler/main.rs b/v2/robotmk/src/bin/scheduler/main.rs index d515bd7d..393921fe 100644 --- a/v2/robotmk/src/bin/scheduler/main.rs +++ b/v2/robotmk/src/bin/scheduler/main.rs @@ -2,9 +2,7 @@ mod build; mod cli; mod internal_config; mod logging; -mod rf; mod scheduling; -mod sessions; mod setup; mod termination; diff --git a/v2/robotmk/src/bin/scheduler/scheduling/suites.rs b/v2/robotmk/src/bin/scheduler/scheduling/suites.rs index 0b18d954..765b30cb 100644 --- a/v2/robotmk/src/bin/scheduler/scheduling/suites.rs +++ b/v2/robotmk/src/bin/scheduler/scheduling/suites.rs @@ -1,8 +1,8 @@ use crate::internal_config::Suite; -use crate::rf::{rebot::Rebot, robot::Attempt}; -use crate::sessions::session::{RunOutcome, RunSpec}; use robotmk::environment::ResultCode; use robotmk::results::{AttemptOutcome, AttemptsConfig, SuiteExecutionReport}; +use robotmk::rf::{rebot::Rebot, robot::Attempt}; +use robotmk::sessions::session::{RunOutcome, RunSpec}; use anyhow::{bail, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; diff --git a/v2/robotmk/src/bin/scheduler/setup/rcc.rs b/v2/robotmk/src/bin/scheduler/setup/rcc.rs index 57d67fcb..8813d566 100644 --- a/v2/robotmk/src/bin/scheduler/setup/rcc.rs +++ b/v2/robotmk/src/bin/scheduler/setup/rcc.rs @@ -1,10 +1,10 @@ use super::icacls::run_icacls_command; use crate::internal_config::{sort_suites_by_id, GlobalConfig, Suite}; use crate::logging::log_and_return_error; -use crate::sessions::session::{CurrentSession, RunOutcome, RunSpec, Session}; use robotmk::command_spec::CommandSpec; use robotmk::environment::Environment; use robotmk::results::RCCSetupFailures; +use robotmk::sessions::session::{CurrentSession, RunOutcome, RunSpec, Session}; use anyhow::{bail, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; diff --git a/v2/robotmk/src/lib.rs b/v2/robotmk/src/lib.rs index 10dc8a81..76622b48 100644 --- a/v2/robotmk/src/lib.rs +++ b/v2/robotmk/src/lib.rs @@ -4,5 +4,7 @@ pub mod config; pub mod environment; pub mod lock; pub mod results; +pub mod rf; pub mod section; +pub mod sessions; pub mod termination; diff --git a/v2/robotmk/src/bin/scheduler/rf/mod.rs b/v2/robotmk/src/rf/mod.rs similarity index 100% rename from v2/robotmk/src/bin/scheduler/rf/mod.rs rename to v2/robotmk/src/rf/mod.rs diff --git a/v2/robotmk/src/bin/scheduler/rf/rebot.rs b/v2/robotmk/src/rf/rebot.rs similarity index 96% rename from v2/robotmk/src/bin/scheduler/rf/rebot.rs rename to v2/robotmk/src/rf/rebot.rs index 5edde63e..546d3eb6 100644 --- a/v2/robotmk/src/bin/scheduler/rf/rebot.rs +++ b/v2/robotmk/src/rf/rebot.rs @@ -1,8 +1,8 @@ use super::robot::PYTHON_EXECUTABLE; -use robotmk::command_spec::CommandSpec; -use robotmk::environment::Environment; -use robotmk::environment::ResultCode; -use robotmk::results::{RebotOutcome, RebotResult}; +use crate::command_spec::CommandSpec; +use crate::environment::Environment; +use crate::environment::ResultCode; +use crate::results::{RebotOutcome, RebotResult}; use anyhow::{Context, Result}; use base64::{engine::general_purpose, Engine}; @@ -111,7 +111,7 @@ impl Rebot<'_> { #[cfg(test)] mod tests { use super::*; - use robotmk::config::EnvironmentConfig; + use crate::config::EnvironmentConfig; #[test] fn build_rebot_command() { diff --git a/v2/robotmk/src/bin/scheduler/rf/robot.rs b/v2/robotmk/src/rf/robot.rs similarity index 97% rename from v2/robotmk/src/bin/scheduler/rf/robot.rs rename to v2/robotmk/src/rf/robot.rs index f578a4bb..bc2e4e3a 100644 --- a/v2/robotmk/src/bin/scheduler/rf/robot.rs +++ b/v2/robotmk/src/rf/robot.rs @@ -1,12 +1,11 @@ -use robotmk::command_spec::CommandSpec; -use robotmk::config::RetryStrategy; +use crate::command_spec::CommandSpec; +use crate::config::RetryStrategy; use camino::{Utf8Path, Utf8PathBuf}; pub const PYTHON_EXECUTABLE: &str = "python"; -#[derive(Clone)] -#[cfg_attr(test, derive(Debug, PartialEq))] +#[derive(Clone, Debug, PartialEq)] pub struct Robot { pub robot_target: Utf8PathBuf, pub command_line_args: Vec, diff --git a/v2/robotmk/src/bin/scheduler/sessions/mod.rs b/v2/robotmk/src/sessions/mod.rs similarity index 100% rename from v2/robotmk/src/bin/scheduler/sessions/mod.rs rename to v2/robotmk/src/sessions/mod.rs diff --git a/v2/robotmk/src/bin/scheduler/sessions/schtasks.rs b/v2/robotmk/src/sessions/schtasks.rs similarity index 98% rename from v2/robotmk/src/bin/scheduler/sessions/schtasks.rs rename to v2/robotmk/src/sessions/schtasks.rs index c8ab0228..c3b089e3 100644 --- a/v2/robotmk/src/bin/scheduler/sessions/schtasks.rs +++ b/v2/robotmk/src/sessions/schtasks.rs @@ -1,7 +1,6 @@ use super::session::RunOutcome; -use crate::logging::log_and_return_error; -use robotmk::command_spec::CommandSpec; -use robotmk::termination::{kill_process_tree, waited, Outcome}; +use crate::command_spec::CommandSpec; +use crate::termination::{kill_process_tree, waited, Outcome}; use anyhow::{bail, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; @@ -242,7 +241,7 @@ fn kill_and_delete_task(task_name: &str, paths: &Paths) { fn kill_task(paths: &Paths) { let _ = remove_file(&paths.run_flag) .context(format!("Failed to remove {}", paths.run_flag)) - .map_err(log_and_return_error); + .map_err(|e| error!("{:?}", e)); let _ = kill_task_via_pid(&paths.pid).map_err(|error| { warn!("{:?}", error); error @@ -262,7 +261,7 @@ fn delete_task(task_name: &str) { debug!("Deleting task {task_name}"); let _ = run_schtasks(["/delete", "/tn", task_name, "/f"]) .context(format!("Failed to delete task {}", task_name)) - .map_err(log_and_return_error); + .map_err(|e| error!("{:?}", e)); } fn read_until_first_whitespace(path: &Utf8Path) -> Result { diff --git a/v2/robotmk/src/bin/scheduler/sessions/session.rs b/v2/robotmk/src/sessions/session.rs similarity index 89% rename from v2/robotmk/src/bin/scheduler/sessions/session.rs rename to v2/robotmk/src/sessions/session.rs index 8e9882ca..0d34b654 100644 --- a/v2/robotmk/src/bin/scheduler/sessions/session.rs +++ b/v2/robotmk/src/sessions/session.rs @@ -1,15 +1,14 @@ use super::schtasks::{run_task, TaskSpec}; -use robotmk::child_process_supervisor::{ChildProcessOutcome, ChildProcessSupervisor, StdioPaths}; -use robotmk::command_spec::CommandSpec; -use robotmk::config::SessionConfig; +use crate::child_process_supervisor::{ChildProcessOutcome, ChildProcessSupervisor, StdioPaths}; +use crate::command_spec::CommandSpec; +use crate::config::SessionConfig; use anyhow::Result; use camino::{Utf8Path, Utf8PathBuf}; use std::fmt::{Display, Formatter, Result as FmtResult}; use tokio_util::sync::CancellationToken; -#[derive(Clone, Eq, Hash, PartialEq)] -#[cfg_attr(test, derive(Debug))] +#[derive(Clone, Eq, Hash, PartialEq, Debug)] pub enum Session { Current(CurrentSession), User(UserSession), @@ -46,8 +45,7 @@ impl Display for Session { } } -#[derive(Clone, Eq, Hash, PartialEq)] -#[cfg_attr(test, derive(Debug))] +#[derive(Clone, Eq, Hash, PartialEq, Debug)] pub struct CurrentSession {} impl Display for CurrentSession { @@ -56,8 +54,7 @@ impl Display for CurrentSession { } } -#[derive(Clone, Eq, Hash, PartialEq)] -#[cfg_attr(test, derive(Debug))] +#[derive(Clone, Eq, Hash, PartialEq, Debug)] pub struct UserSession { pub user_name: String, }