]>
git.proxmox.com Git - cargo.git/blob - vendor/jobserver/tests/helper.rs
2 use std
::sync
::atomic
::*;
10 Err(e
) => panic
!("{} failed with {}", stringify
!($e
), e
),
17 let client
= t
!(Client
::new(1));
18 drop(client
.clone().into_helper_thread(|_
| ()).unwrap());
19 drop(client
.clone().into_helper_thread(|_
| ()).unwrap());
20 drop(client
.clone().into_helper_thread(|_
| ()).unwrap());
21 drop(client
.clone().into_helper_thread(|_
| ()).unwrap());
22 drop(client
.clone().into_helper_thread(|_
| ()).unwrap());
23 drop(client
.into_helper_thread(|_
| ()).unwrap());
28 let (tx
, rx
) = mpsc
::channel();
29 let client
= t
!(Client
::new(1));
31 .into_helper_thread(move |a
| drop(tx
.send(a
)))
33 assert
!(rx
.try_recv().is_err());
34 helper
.request_token();
35 rx
.recv().unwrap().unwrap();
36 helper
.request_token();
37 rx
.recv().unwrap().unwrap();
39 helper
.request_token();
40 helper
.request_token();
41 rx
.recv().unwrap().unwrap();
42 rx
.recv().unwrap().unwrap();
44 helper
.request_token();
45 helper
.request_token();
50 fn prompt_shutdown() {
52 let client
= jobserver
::Client
::new(4).unwrap();
53 let count
= Arc
::new(AtomicU32
::new(0));
54 let count2
= count
.clone();
55 let tokens
= Arc
::new(Mutex
::new(Vec
::new()));
57 .into_helper_thread(move |token
| {
58 tokens
.lock().unwrap().push(token
);
59 count2
.fetch_add(1, Ordering
::SeqCst
);
63 // Request more tokens than what are available.
65 helper
.request_token();
67 // Wait for at least some of the requests to finish.
68 while count
.load(Ordering
::SeqCst
) < 3 {
69 std
::thread
::yield_now();
72 let t
= std
::time
::Instant
::now();
75 assert
!(d
.as_secs_f64() < 0.5);