Skip to content

Commit bc15b2b

Browse files
authored
enhance coverage CI (#346)
2 parents efb513a + 1169225 commit bc15b2b

File tree

3 files changed

+74
-0
lines changed

3 files changed

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

core/src/common/work_steal.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,31 @@ 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+
#[test]
343+
fn test_work_steal_queue() {
344+
let queue = WorkStealQueue::new(2, 64);
345+
queue.push(6);
346+
queue.push(7);
347+
348+
let local0 = queue.local_queue();
349+
local0.push(2);
350+
local0.push(3);
351+
local0.push(4);
352+
local0.push(5);
353+
354+
let local1 = queue.local_queue();
355+
local1.push(0);
356+
local1.push(1);
357+
for i in 0..8 {
358+
assert_eq!(local1.pop(), Some(i));
359+
}
360+
assert_eq!(local0.pop(), None);
361+
assert_eq!(local1.pop(), None);
362+
assert_eq!(queue.pop(), None);
363+
}
364+
}

0 commit comments

Comments
 (0)