Skip to content

Commit a783079

Browse files
committed
enhance coverage CI
1 parent efb513a commit a783079

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

core/src/co_pool/state.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,22 @@ impl CoroutinePool<'_> {
4343
))
4444
}
4545
}
46+
47+
#[cfg(test)]
48+
mod tests {
49+
use super::*;
50+
51+
#[test]
52+
fn test_state() -> std::io::Result<()> {
53+
let mut pool = CoroutinePool::default();
54+
_ = pool.stopping()?;
55+
assert_eq!(PoolState::Stopping, pool.state());
56+
_ = pool.stopping()?;
57+
assert_eq!(PoolState::Stopping, pool.state());
58+
_ = pool.stopped()?;
59+
assert!(pool.stopped().is_ok());
60+
assert!(pool.stopping().is_err());
61+
assert!(pool.try_schedule_task().is_err());
62+
Ok(())
63+
}
64+
}

core/src/common/ordered_work_steal.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,29 @@ impl<'l, T: Debug> OrderedLocalQueue<'l, T> {
422422
None
423423
}
424424
}
425+
426+
#[cfg(test)]
427+
mod tests {
428+
use super::*;
429+
430+
fn test_ordered_work_steal_queue() {
431+
let queue = OrderedWorkStealQueue::new(2, 64);
432+
for i in 6..8 {
433+
queue.push_with_priority(i, i);
434+
}
435+
let local0 = queue.local_queue();
436+
for i in 2..6 {
437+
local0.push_with_priority(i, i);
438+
}
439+
let local1 = queue.local_queue();
440+
for i in 0..2 {
441+
local1.push_with_priority(i, i);
442+
}
443+
for i in 0..8 {
444+
assert_eq!(local1.pop(), Some(i));
445+
}
446+
assert_eq!(local0.pop(), None);
447+
assert_eq!(local1.pop(), None);
448+
assert_eq!(queue.pop(), None);
449+
}
450+
}

core/src/common/work_steal.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,30 @@ impl<'l, T: Debug> LocalQueue<'l, T> {
334334
self.shared.pop()
335335
}
336336
}
337+
338+
#[cfg(test)]
339+
mod tests {
340+
use super::*;
341+
342+
fn test_work_steal_queue() {
343+
let queue = WorkStealQueue::new(2, 64);
344+
queue.push(6);
345+
queue.push(7);
346+
347+
let local0 = queue.local_queue();
348+
local0.push(2);
349+
local0.push(3);
350+
local0.push(4);
351+
local0.push(5);
352+
353+
let local1 = queue.local_queue();
354+
local1.push(0);
355+
local1.push(1);
356+
for i in 0..8 {
357+
assert_eq!(local1.pop(), Some(i));
358+
}
359+
assert_eq!(local0.pop(), None);
360+
assert_eq!(local1.pop(), None);
361+
assert_eq!(queue.pop(), None);
362+
}
363+
}

0 commit comments

Comments
 (0)