1 use crate::runtime::park;
2 use crate::runtime::tests::loom_oneshot as oneshot;
3 use crate::runtime::{self, Runtime};
4 
5 #[test]
yield_calls_park_before_scheduling_again()6 fn yield_calls_park_before_scheduling_again() {
7     // Don't need to check all permutations
8     let mut loom = loom::model::Builder::default();
9     loom.max_permutations = Some(1);
10     loom.check(|| {
11         let rt = mk_runtime(2);
12         let (tx, rx) = oneshot::channel::<()>();
13 
14         rt.spawn(async {
15             let tid = loom::thread::current().id();
16             let park_count = park::current_thread_park_count();
17 
18             crate::task::yield_now().await;
19 
20             if tid == loom::thread::current().id() {
21                 let new_park_count = park::current_thread_park_count();
22                 assert_eq!(park_count + 1, new_park_count);
23             }
24 
25             tx.send(());
26         });
27 
28         rx.recv();
29     });
30 }
31 
mk_runtime(num_threads: usize) -> Runtime32 fn mk_runtime(num_threads: usize) -> Runtime {
33     runtime::Builder::new_multi_thread()
34         .worker_threads(num_threads)
35         .build()
36         .unwrap()
37 }
38