#[cfg(test)]
mod tests {
use crate::fast_thread_pool::{channel_types, TaskExecutor, init};
use std::sync::Arc;
use crossbeam::atomic::AtomicCell;
#[test]
fn test_channel_types() {
let (tx, rx) = channel_types::unbounded::<i32>();
tx.send(42).unwrap();
tx.send(100).unwrap();
assert_eq!(rx.recv().unwrap(), 42);
assert_eq!(rx.recv().unwrap(), 100);
println!("Channel test passed!");
}
#[test]
fn test_task_executor_unified() {
unsafe { std::env::set_var("RUST_LOG", "debug") };
env_logger::try_init().ok();
init(false);
let executor = TaskExecutor::new(
core_affinity::CoreId { id: 0 },
-1
);
let counter = Arc::new(AtomicCell::new(0_i32));
let test_counter = counter.clone();
for i in 0..10 {
let counter = counter.clone();
executor.spawn(move |core_id| {
counter.fetch_add(1);
println!("Task {} executed on core {}", i, core_id);
});
}
std::thread::sleep(std::time::Duration::from_millis(100));
assert_eq!(test_counter.load(), 10);
println!("TaskExecutorUnified test passed!");
}
#[test]
fn test_channel_feature_info() {
#[cfg(feature = "crossbeam_channel")]
println!("Using crossbeam::channel implementation");
#[cfg(not(feature = "crossbeam_channel"))]
println!("Using std::sync::mpsc implementation");
}
}