diff --git a/v2/robotmk/tests/test_scheduler.rs b/v2/robotmk/tests/test_scheduler.rs index 4440f9d8..7e43e926 100644 --- a/v2/robotmk/tests/test_scheduler.rs +++ b/v2/robotmk/tests/test_scheduler.rs @@ -3,7 +3,8 @@ use assert_cmd::cargo::cargo_bin; use camino::{Utf8Path, Utf8PathBuf}; use robotmk::config::{ Config, EnvironmentConfig, ExecutionConfig, RCCEnvironmentConfig, RetryStrategy, - RobotFrameworkConfig, SessionConfig, SuiteConfig, WorkingDirectoryCleanupConfig, + RobotFrameworkConfig, SessionConfig, SuiteConfig, UserSessionConfig, + WorkingDirectoryCleanupConfig, }; use robotmk::section::Host; use serde_json::to_string; @@ -19,17 +20,19 @@ use walkdir::WalkDir; async fn test_scheduler() -> Result<()> { let test_dir = Utf8PathBuf::from(var("TEST_DIR")?); create_dir_all(&test_dir)?; + let current_user_name = var("UserName")?; let config = create_config( &test_dir, &Utf8PathBuf::from(var("CARGO_MANIFEST_DIR")?) .join("tests") .join("minimal_suite"), var("RCC_BINARY_PATH")?, + ¤t_user_name, ); run_scheduler(&test_dir, &config, var("RUN_FOR")?.parse::()?).await?; - assert_working_directory(&config.working_directory).await?; + assert_working_directory(&config.working_directory, ¤t_user_name).await?; assert_results_directory(&config.results_directory); assert_rcc(&config.rcc_binary_path).await?; @@ -40,34 +43,90 @@ fn create_config( test_dir: &Utf8Path, suite_dir: &Utf8Path, rcc_binary_path: impl Into, + user_name_headed: &str, ) -> Config { Config { working_directory: test_dir.join("working"), results_directory: test_dir.join("results"), rcc_binary_path: rcc_binary_path.into(), - suites: [( - String::from("suite"), - SuiteConfig { - robot_framework_config: RobotFrameworkConfig { - robot_target: suite_dir.join("tasks.robot"), - command_line_args: vec![], + suites: [ + ( + String::from("rcc_headless"), + SuiteConfig { + robot_framework_config: RobotFrameworkConfig { + robot_target: suite_dir.join("tasks.robot"), + command_line_args: vec![], + }, + execution_config: ExecutionConfig { + n_attempts_max: 1, + retry_strategy: RetryStrategy::Complete, + execution_interval_seconds: 30, + timeout: 10, + }, + environment_config: EnvironmentConfig::Rcc(RCCEnvironmentConfig { + robot_yaml_path: suite_dir.join("robot.yaml"), + build_timeout: 1200, + env_json_path: None, + }), + session_config: SessionConfig::Current, + working_directory_cleanup_config: WorkingDirectoryCleanupConfig::MaxExecutions( + 4, + ), + host: Host::Source, }, - execution_config: ExecutionConfig { - n_attempts_max: 1, - retry_strategy: RetryStrategy::Complete, - execution_interval_seconds: 30, - timeout: 10, + ), + ( + String::from("rcc_headed"), + SuiteConfig { + robot_framework_config: RobotFrameworkConfig { + robot_target: suite_dir.join("tasks.robot"), + command_line_args: vec![], + }, + execution_config: ExecutionConfig { + n_attempts_max: 1, + retry_strategy: RetryStrategy::Complete, + execution_interval_seconds: 45, + timeout: 15, + }, + environment_config: EnvironmentConfig::Rcc(RCCEnvironmentConfig { + robot_yaml_path: suite_dir.join("robot.yaml"), + build_timeout: 1200, + env_json_path: None, + }), + session_config: SessionConfig::SpecificUser(UserSessionConfig { + user_name: user_name_headed.into(), + }), + working_directory_cleanup_config: WorkingDirectoryCleanupConfig::MaxAgeSecs( + 120, + ), + host: Host::Source, }, - environment_config: EnvironmentConfig::Rcc(RCCEnvironmentConfig { - robot_yaml_path: suite_dir.join("robot.yaml"), - build_timeout: 1200, - env_json_path: None, - }), - session_config: SessionConfig::Current, - working_directory_cleanup_config: WorkingDirectoryCleanupConfig::MaxExecutions(4), - host: Host::Source, - }, - )] + ), + // Note: For our test, it doesn't matter if the suite can be executed on the target + // system. We are not checking for success. So even on systems with no Python, the test + // will succeed. + ( + String::from("no_rcc"), + SuiteConfig { + robot_framework_config: RobotFrameworkConfig { + robot_target: suite_dir.join("tasks.robot"), + command_line_args: vec![], + }, + execution_config: ExecutionConfig { + n_attempts_max: 1, + retry_strategy: RetryStrategy::Complete, + execution_interval_seconds: 37, + timeout: 17, + }, + environment_config: EnvironmentConfig::System, + session_config: SessionConfig::Current, + working_directory_cleanup_config: WorkingDirectoryCleanupConfig::MaxExecutions( + 4, + ), + host: Host::Piggyback("oink".into()), + }, + ), + ] .into(), } } @@ -100,7 +159,10 @@ async fn run_scheduler(test_dir: &Utf8Path, config: &Config, n_seconds_run: u64) Ok(()) } -async fn assert_working_directory(working_directory: &Utf8Path) -> Result<()> { +async fn assert_working_directory( + working_directory: &Utf8Path, + headed_user_name: &str, +) -> Result<()> { assert_working_directory_permissions(&working_directory).await?; assert!(working_directory.is_dir()); assert_eq!( @@ -112,23 +174,54 @@ async fn assert_working_directory(working_directory: &Utf8Path) -> Result<()> { [ "holotree_initialization_current_user.stderr", "holotree_initialization_current_user.stdout", + &format!("holotree_initialization_user_{headed_user_name}.bat"), + &format!("holotree_initialization_user_{headed_user_name}.exit_code"), + &format!("holotree_initialization_user_{headed_user_name}.pid"), + &format!("holotree_initialization_user_{headed_user_name}.run_flag",), + &format!("holotree_initialization_user_{headed_user_name}.stderr"), + &format!("holotree_initialization_user_{headed_user_name}.stdout"), "long_path_support_enabling.stderr", "long_path_support_enabling.stdout", "shared_holotree_init.stderr", "shared_holotree_init.stdout", "telemetry_disabling_current_user.stderr", - "telemetry_disabling_current_user.stdout" + "telemetry_disabling_current_user.stdout", + &format!("telemetry_disabling_user_{headed_user_name}.bat"), + &format!("telemetry_disabling_user_{headed_user_name}.exit_code"), + &format!("telemetry_disabling_user_{headed_user_name}.pid"), + &format!("telemetry_disabling_user_{headed_user_name}.run_flag"), + &format!("telemetry_disabling_user_{headed_user_name}.stderr"), + &format!("telemetry_disabling_user_{headed_user_name}.stdout") ] ); assert_eq!( directory_entries(working_directory.join("environment_building_stdio"), 1), - ["suite.stderr", "suite.stdout"] + [ + "rcc_headed.stderr", + "rcc_headed.stdout", + "rcc_headless.stderr", + "rcc_headless.stdout" + ] ); assert_eq!( directory_entries(working_directory.join("suites"), 1), - ["suite"] + ["no_rcc", "rcc_headed", "rcc_headless"] ); - assert!(!directory_entries(working_directory.join("suites").join("suite"), 1).is_empty()); + + // We expliclitly don't check for the rebot files in the case without RCC, since this must also + // work on systems that don't have the necessary Python environment. + assert!(!directory_entries(working_directory.join("suites").join("no_rcc"), 1).is_empty()); + + let entries_rcc_headed = + directory_entries(working_directory.join("suites").join("rcc_headed"), 2).join(""); + assert!(entries_rcc_headed.contains("rebot.xml")); + assert!(entries_rcc_headed.contains("0.bat")); + + let entries_rcc_headless = + directory_entries(working_directory.join("suites").join("rcc_headless"), 2).join(""); + assert!(entries_rcc_headless.contains("rebot.xml")); + assert!(!entries_rcc_headless.contains("0.bat")); + Ok(()) } @@ -149,7 +242,9 @@ fn assert_results_directory(results_directory: &Utf8Path) { "rcc_setup_failures.json", "scheduler_phase.json", "suites", - "suites\\suite.json" + "suites\\no_rcc.json", + "suites\\rcc_headed.json", + "suites\\rcc_headless.json" ] ); }