Skip to content

Commit

Permalink
Speed up scheduler system test
Browse files Browse the repository at this point in the history
Instead of running the scheduler for a fixed amount of time, we run it
until all expected plan result files are found or until a timeout is
reached.
  • Loading branch information
jherbel committed Aug 13, 2024
1 parent 1a5a5b7 commit 35fdd9c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/system_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
TEST_DIR: C:\test_scheduler
RCC_BINARY_PATH: C:\windows64\rcc.exe
MANAGED_ROBOT_ARCHIVE_PATH: C:\managed_robots\minimal_suite.tar.gz
RUN_FOR: 300
N_SECONDS_RUN_MAX: 300
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
TEST_DIR: /tmp/test_scheduler
RCC_BINARY_PATH: /tmp/linux64/rcc
MANAGED_ROBOT_ARCHIVE_PATH: /tmp/managed_robots/minimal_suite.tar.gz
RUN_FOR: 300
N_SECONDS_RUN_MAX: 300
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
Expand Down
56 changes: 46 additions & 10 deletions tests/test_scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod rcc;
use crate::rcc::read_configuration_diagnostics;
use anyhow::Result as AnyhowResult;
use anyhow::{bail, Result as AnyhowResult};
use assert_cmd::cargo::cargo_bin;
use camino::{Utf8Path, Utf8PathBuf};
#[cfg(windows)]
Expand All @@ -18,7 +18,11 @@ use std::ffi::OsStr;
use std::fs::{create_dir_all, remove_file, write};
use std::path::Path;
use std::time::Duration;
use tokio::{process::Command, time::timeout};
use tokio::{
process::Command,
select,
time::{sleep, timeout},
};
use walkdir::WalkDir;

#[tokio::test]
Expand All @@ -42,7 +46,12 @@ async fn test_scheduler() -> AnyhowResult<()> {
&current_user_name,
);

run_scheduler(&test_dir, &config, var("RUN_FOR")?.parse::<u64>()?).await?;
run_scheduler(
&test_dir,
&config,
var("N_SECONDS_RUN_MAX")?.parse::<u64>()?,
)
.await?;

assert_working_directory(
&config.working_directory,
Expand Down Expand Up @@ -271,7 +280,7 @@ fn create_config(
async fn run_scheduler(
test_dir: &Utf8Path,
config: &Config,
n_seconds_run: u64,
n_seconds_run_max: u64,
) -> AnyhowResult<()> {
let config_path = test_dir.join("config.json");
write(&config_path, to_string(&config)?)?;
Expand All @@ -286,12 +295,15 @@ async fn run_scheduler(
.arg(&run_flag_path);
let mut robotmk_child_proc = robotmk_cmd.spawn()?;

assert!(timeout(
Duration::from_secs(n_seconds_run),
robotmk_child_proc.wait()
)
.await
.is_err());
select! {
_ = await_plan_results(config) => {},
_ = robotmk_child_proc.wait() => {
bail!("Scheduler terminated unexpectedly")
},
_ = sleep(Duration::from_secs(n_seconds_run_max)) => {
bail!(format!("No plan result files appeared with {n_seconds_run_max} seconds"))
},
};
remove_file(&run_flag_path)?;
assert!(timeout(Duration::from_secs(3), robotmk_child_proc.wait())
.await
Expand All @@ -300,6 +312,30 @@ async fn run_scheduler(
Ok(())
}

async fn await_plan_results(config: &Config) {
let expected_result_files: Vec<Utf8PathBuf> = config
.plan_groups
.iter()
.flat_map(|plan_group| {
plan_group.plans.iter().map(|plan_config| {
config
.results_directory
.join("plans")
.join(format!("{}.json", &plan_config.id))
})
})
.collect();
loop {
if expected_result_files
.iter()
.all(|expected_result_file| expected_result_file.is_file())
{
break;
}
sleep(Duration::from_secs(5)).await;
}
}

async fn assert_working_directory(
working_directory: &Utf8Path,
#[cfg(windows)] headed_user_name: &str,
Expand Down

0 comments on commit 35fdd9c

Please sign in to comment.