1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
use crate::runtime::scheduler::inject;
#[test]
fn push_and_pop() {
const N: usize = 2;
let (inject, mut synced) = inject::Shared::new();
for i in 0..N {
assert_eq!(inject.len(), i);
let (task, _) = super::unowned(async {});
unsafe { inject.push(&mut synced, task) };
}
for i in 0..N {
assert_eq!(inject.len(), N - i);
assert!(unsafe { inject.pop(&mut synced) }.is_some());
}
println!("--------------");
assert!(unsafe { inject.pop(&mut synced) }.is_none());
}
#[test]
fn push_batch_and_pop() {
let (inject, mut inject_synced) = inject::Shared::new();
unsafe {
inject.push_batch(
&mut inject_synced,
(0..10).map(|_| super::unowned(async {}).0),
);
assert_eq!(5, inject.pop_n(&mut inject_synced, 5).count());
assert_eq!(5, inject.pop_n(&mut inject_synced, 5).count());
assert_eq!(0, inject.pop_n(&mut inject_synced, 5).count());
}
}
#[test]
fn pop_n_drains_on_drop() {
let (inject, mut inject_synced) = inject::Shared::new();
unsafe {
inject.push_batch(
&mut inject_synced,
(0..10).map(|_| super::unowned(async {}).0),
);
let _ = inject.pop_n(&mut inject_synced, 10);
assert_eq!(inject.len(), 0);
}
}
|