Skip to content

Commit

Permalink
test termination 11: move sessions and rf
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SoloJacobs committed Dec 11, 2023
1 parent 5f8c3f6 commit 4d30ab2
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 31 deletions.
6 changes: 3 additions & 3 deletions v2/robotmk/src/bin/scheduler/internal_config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions v2/robotmk/src/bin/scheduler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ mod build;
mod cli;
mod internal_config;
mod logging;
mod rf;
mod scheduling;
mod sessions;
mod setup;
mod termination;

Expand Down
4 changes: 2 additions & 2 deletions v2/robotmk/src/bin/scheduler/scheduling/suites.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion v2/robotmk/src/bin/scheduler/setup/rcc.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 2 additions & 0 deletions v2/robotmk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String>,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
Expand All @@ -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<String> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
Expand Down

0 comments on commit 4d30ab2

Please sign in to comment.