Debian Codegraph @

third_party/rust/tokio/src/runtime/tests/loom_current_thread/yield_now.rs

raw
1 use crate::runtime::park;
2 use crate::runtime::{self, Runtime};
3
4 #[test]
5 fn yield_calls_park_before_scheduling_again() {
6 // Don't need to check all permutations
7 let mut loom = loom::model::Builder::default();
8 loom.max_permutations = Some(1);
9 loom.check(|| {
10 let rt = mk_runtime();
11
12 let jh = rt.spawn(async {
13 let tid = loom::thread::current().id();
14 let park_count = park::current_thread_park_count();
15
16 crate::task::yield_now().await;
17
18 if tid == loom::thread::current().id() {
19 let new_park_count = park::current_thread_park_count();
20 assert_eq!(park_count + 1, new_park_count);
21 }
22 });
23
24 rt.block_on(jh).unwrap();
25 });
26 }
27
28 fn mk_runtime() -> Runtime {
29 runtime::Builder::new_current_thread().build().unwrap()
30 }