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