From 1169225485bc95f2eb65dd8b2364fe32d41f14b2 Mon Sep 17 00:00:00 2001 From: dragon-zhang Date: Thu, 19 Dec 2024 13:08:24 +0800 Subject: [PATCH] enhance coverage CI --- core/src/co_pool/state.rs | 19 ++++++++++++++++++ core/src/common/ordered_work_steal.rs | 27 ++++++++++++++++++++++++++ core/src/common/work_steal.rs | 28 +++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/core/src/co_pool/state.rs b/core/src/co_pool/state.rs index 234448ed..6b227cc0 100644 --- a/core/src/co_pool/state.rs +++ b/core/src/co_pool/state.rs @@ -43,3 +43,22 @@ impl CoroutinePool<'_> { )) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_state() -> std::io::Result<()> { + let mut pool = CoroutinePool::default(); + _ = pool.stopping()?; + assert_eq!(PoolState::Stopping, pool.state()); + _ = pool.stopping()?; + assert_eq!(PoolState::Stopping, pool.state()); + _ = pool.stopped()?; + assert!(pool.stopped().is_ok()); + assert!(pool.stopping().is_err()); + assert!(pool.try_schedule_task().is_err()); + Ok(()) + } +} diff --git a/core/src/common/ordered_work_steal.rs b/core/src/common/ordered_work_steal.rs index 30fb3af3..a38f939f 100644 --- a/core/src/common/ordered_work_steal.rs +++ b/core/src/common/ordered_work_steal.rs @@ -422,3 +422,30 @@ impl<'l, T: Debug> OrderedLocalQueue<'l, T> { None } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_ordered_work_steal_queue() { + let queue = OrderedWorkStealQueue::new(2, 64); + for i in 6..8 { + queue.push_with_priority(i, i); + } + let local0 = queue.local_queue(); + for i in 2..6 { + local0.push_with_priority(i, i); + } + let local1 = queue.local_queue(); + for i in 0..2 { + local1.push_with_priority(i, i); + } + for i in 0..8 { + assert_eq!(local1.pop(), Some(i)); + } + assert_eq!(local0.pop(), None); + assert_eq!(local1.pop(), None); + assert_eq!(queue.pop(), None); + } +} diff --git a/core/src/common/work_steal.rs b/core/src/common/work_steal.rs index 3477e299..2e671c6f 100644 --- a/core/src/common/work_steal.rs +++ b/core/src/common/work_steal.rs @@ -334,3 +334,31 @@ impl<'l, T: Debug> LocalQueue<'l, T> { self.shared.pop() } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_work_steal_queue() { + let queue = WorkStealQueue::new(2, 64); + queue.push(6); + queue.push(7); + + let local0 = queue.local_queue(); + local0.push(2); + local0.push(3); + local0.push(4); + local0.push(5); + + let local1 = queue.local_queue(); + local1.push(0); + local1.push(1); + for i in 0..8 { + assert_eq!(local1.pop(), Some(i)); + } + assert_eq!(local0.pop(), None); + assert_eq!(local1.pop(), None); + assert_eq!(queue.pop(), None); + } +}