From 15e0bd531a5241884ea89c7cc7c5de1aedd5d3ee Mon Sep 17 00:00:00 2001 From: Bittrance Date: Tue, 31 Oct 2023 21:32:33 +0100 Subject: [PATCH] Test to verify that panicing workloads fail task. --- src/errors.rs | 2 +- src/task/scheduled.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 0f51ae9..17fc971 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{path::PathBuf, fmt::Debug}; use thiserror::Error; diff --git a/src/task/scheduled.rs b/src/task/scheduled.rs index a610ee7..c6a97f1 100644 --- a/src/task/scheduled.rs +++ b/src/task/scheduled.rs @@ -61,7 +61,7 @@ impl ScheduledTask { .take() .expect("result only called once") .join() - .unwrap()?; + .expect("thread not to panic")?; self.state.current_sha = new_sha; Ok(()) } @@ -113,6 +113,16 @@ mod tests { task.await_eligible(); } + #[test] + #[should_panic] + fn scheduled_task_on_panic() { + let mut task = ScheduledTask::new(TestWorkload::fail_with(|| panic!("BOOM!"))); + task.start().unwrap(); + task.await_finished(); + assert!(!task.is_running()); + task.finalize().unwrap(); + } + #[test] fn scheduled_task_on_existing_state() { let mut task = ScheduledTask::new(TestWorkload::default());