From 2b40181cb3d79ea586d260c3dd647f2aa84473e2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 4 Mar 2024 18:59:52 +0100 Subject: [PATCH] give macOS even more time to sleep --- src/tools/miri/tests/pass/concurrency/sync.rs | 27 ++++++++++++------- 1 file 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 a6c181098b74..91c67b215a1a 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(); }