Debian Codegraph @

.cargo/vendor/crossbeam-utils/tests/parker.rs

raw
1 use std::thread::sleep;
2 use std::time::Duration;
3 use std::u32;
4
5 use crossbeam_utils::sync::Parker;
6 use crossbeam_utils::thread;
7
8 #[test]
9 fn park_timeout_unpark_before() {
10 let p = Parker::new();
11 for _ in 0..10 {
12 p.unparker().unpark();
13 p.park_timeout(Duration::from_millis(u32::MAX as u64));
14 }
15 }
16
17 #[test]
18 fn park_timeout_unpark_not_called() {
19 let p = Parker::new();
20 for _ in 0..10 {
21 p.park_timeout(Duration::from_millis(10))
22 }
23 }
24
25 #[test]
26 fn park_timeout_unpark_called_other_thread() {
27 for _ in 0..10 {
28 let p = Parker::new();
29 let u = p.unparker().clone();
30
31 thread::scope(|scope| {
32 scope.spawn(move |_| {
33 sleep(Duration::from_millis(50));
34 u.unpark();
35 });
36
37 p.park_timeout(Duration::from_millis(u32::MAX as u64))
38 })
39 .unwrap();
40 }
41 }