Skip to content

Commit

Permalink
Termination during scheduling: Wait for suites to terminate
Browse files Browse the repository at this point in the history
When receiving a termination signal while running suites, we should wait
until all suites have terminated before we shutdown. Otherwise,
currently running suites might not get the chance to tear down, since
apparently, terminating the main thread also terminates all other
spawned threads.
  • Loading branch information
jherbel committed Oct 12, 2023
1 parent 0705757 commit 198b438
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions v2/rust/src/scheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::time::Duration;

pub fn run_suites(config: &Config, termination_flag: &TerminationFlag) -> Result<()> {
let mut scheduler = Scheduler::new();
let mut suite_run_specs = vec![];

for (suite_name, suite_config) in config.suites() {
let suite_run_spec = Arc::new(SuiteRunSpec {
Expand All @@ -36,6 +37,7 @@ pub fn run_suites(config: &Config, termination_flag: &TerminationFlag) -> Result
suite_name,
),
});
suite_run_specs.push(suite_run_spec.clone());
scheduler
.every(
suite_config
Expand All @@ -48,6 +50,8 @@ pub fn run_suites(config: &Config, termination_flag: &TerminationFlag) -> Result

loop {
if termination_flag.should_terminate() {
error!("Received termination signal while scheduling, waiting for suites to terminate");
wait_until_all_suites_have_terminated(suite_run_specs);
bail!("Terminated");
}
scheduler.run_pending();
Expand Down Expand Up @@ -257,3 +261,18 @@ fn persist_suite_execution_report(
&suite_run_spec.result_file,
)
}

fn wait_until_all_suites_have_terminated(suite_run_specs: Vec<Arc<SuiteRunSpec>>) {
let mut still_running_suite_specs = suite_run_specs;
while !still_running_suite_specs.is_empty() {
let mut still_running = vec![];
for suite_run_spec in still_running_suite_specs {
let _ = try_acquire_suite_lock(&suite_run_spec).map_err(|_| {
error!("Suite {} is still running", suite_run_spec.suite_name);
still_running.push(suite_run_spec.clone())
});
}
still_running_suite_specs = still_running;
sleep(Duration::from_millis(250));
}
}

0 comments on commit 198b438

Please sign in to comment.