use std::{
sync::mpsc,
time::Duration,
};
use qubit_thread_pool::DelayedTaskScheduler;
#[test]
fn test_delayed_task_handle_reports_cancelled_state() {
let scheduler =
DelayedTaskScheduler::new("test-delayed-handle").expect("scheduler should start");
let (sent_tx, sent_rx) = mpsc::channel::<()>();
let handle = scheduler
.schedule(Duration::from_millis(100), move || {
sent_tx.send(()).expect("cancelled task should not send");
})
.expect("delay should schedule");
assert!(!handle.is_cancelled());
assert!(handle.cancel());
assert!(handle.is_cancelled());
assert!(
sent_rx.recv_timeout(Duration::from_millis(140)).is_err(),
"cancelled task should not run"
);
scheduler.shutdown();
scheduler.wait_termination();
}