#![cfg(feature = "tokio")]
use std::time::Duration;
use timerwheel::executor::{BoxTask, Executor as ExecutorTrait};
use tokio::sync::oneshot;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn tokio_executor_rejects_after_shutdown_with_task_ownership() {
let executor = timerwheel::tokio::Executor::current().expect("executor builds");
ExecutorTrait::shutdown(&executor).expect("executor shuts down");
let task: BoxTask = Box::new(|| {});
let rejected = match ExecutorTrait::try_execute(&executor, task) {
Ok(()) => panic!("closed executor should reject task"),
Err(rejected) => rejected,
};
assert_eq!(rejected.error(), &timerwheel::Error::Closed);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn tokio_timer_uses_tokio_executor_without_async_facade() {
let timer = timerwheel::tokio::Timer::builder()
.tick(Duration::from_millis(1))
.bucket_count(64)
.build()
.expect("timer builds");
let (tx, rx) = oneshot::channel();
timer
.schedule(Duration::from_millis(10), move || {
tx.send("fired").expect("send succeeds");
})
.expect("schedule succeeds");
assert_eq!(
tokio::time::timeout(Duration::from_secs(1), rx)
.await
.expect("task should fire")
.expect("sender should complete"),
"fired"
);
assert!(timer.shutdown().is_ok());
}