diff options
| author | Ralf Jung <post@ralfj.de> | 2024-03-04 18:59:52 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-03-04 19:11:09 +0100 |
| commit | 2b40181cb3d79ea586d260c3dd647f2aa84473e2 (patch) | |
| tree | ec1586877fe25d31018cf99f06b9efc1f38e7790 /src | |
| parent | 8851f3cd731407d933eb472459223beeefd43dd4 (diff) | |
| download | rust-2b40181cb3d79ea586d260c3dd647f2aa84473e2.tar.gz rust-2b40181cb3d79ea586d260c3dd647f2aa84473e2.zip | |
give macOS even more time to sleep
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/miri/tests/pass/concurrency/sync.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/tools/miri/tests/pass/concurrency/sync.rs b/src/tools/miri/tests/pass/concurrency/sync.rs index a6c181098b7..91c67b215a1 100644 --- a/src/tools/miri/tests/pass/concurrency/sync.rs +++ b/src/tools/miri/tests/pass/concurrency/sync.rs @@ -7,6 +7,10 @@ use std::sync::{Arc, Barrier, Condvar, Mutex, Once, RwLock}; use std::thread; use std::time::{Duration, Instant}; +// We are expecting to sleep for 10ms. How long of a sleep we are accepting? +// Even with 1000ms we still see this test fail on macOS runners. +const MAX_SLEEP_TIME_MS: u64 = 2000; + // Check if Rust barriers are working. /// This test is taken from the Rust documentation. @@ -66,7 +70,7 @@ fn check_conditional_variables_timed_wait_timeout() { let (_guard, timeout) = cvar.wait_timeout(guard, Duration::from_millis(10)).unwrap(); assert!(timeout.timed_out()); let elapsed_time = now.elapsed().as_millis(); - assert!(10 <= elapsed_time && elapsed_time <= 1000); + assert!(10 <= elapsed_time && elapsed_time <= MAX_SLEEP_TIME_MS.into()); } /// Test that signaling a conditional variable when waiting with a timeout works @@ -84,7 +88,8 @@ fn check_conditional_variables_timed_wait_notimeout() { cvar.notify_one(); }); - let (_guard, timeout) = cvar.wait_timeout(guard, Duration::from_millis(1000)).unwrap(); + let (_guard, timeout) = + cvar.wait_timeout(guard, Duration::from_millis(MAX_SLEEP_TIME_MS)).unwrap(); assert!(!timeout.timed_out()); handle.join().unwrap(); } @@ -213,20 +218,21 @@ fn check_once() { fn park_timeout() { let start = Instant::now(); - thread::park_timeout(Duration::from_millis(200)); + thread::park_timeout(Duration::from_millis(10)); // Normally, waiting in park/park_timeout may spuriously wake up early, but we // know Miri's timed synchronization primitives do not do that. - // We allow much longer sleeps as well since the macOS GHA runners seem very oversubscribed - // and sometimes just pause for 1 second or more. let elapsed = start.elapsed(); - assert!((200..2000).contains(&elapsed.as_millis()), "bad sleep time: {elapsed:?}"); + assert!( + (10..MAX_SLEEP_TIME_MS.into()).contains(&elapsed.as_millis()), + "bad sleep time: {elapsed:?}" + ); } fn park_unpark() { let t1 = thread::current(); let t2 = thread::spawn(move || { thread::park(); - thread::sleep(Duration::from_millis(200)); + thread::sleep(Duration::from_millis(10)); t1.unpark(); }); @@ -236,10 +242,11 @@ fn park_unpark() { thread::park(); // Normally, waiting in park/park_timeout may spuriously wake up early, but we // know Miri's timed synchronization primitives do not do that. - // We allow much longer sleeps as well since the macOS GHA runners seem very oversubscribed - // and sometimes just pause for 1 second or more. let elapsed = start.elapsed(); - assert!((200..2000).contains(&elapsed.as_millis()), "bad sleep time: {elapsed:?}"); + assert!( + (10..MAX_SLEEP_TIME_MS.into()).contains(&elapsed.as_millis()), + "bad sleep time: {elapsed:?}" + ); t2.join().unwrap(); } |
