Skip to content

Commit

Permalink
Auto merge of rust-lang#3358 - RalfJung:zzz, r=RalfJung
Browse files Browse the repository at this point in the history
give macOS even more time to sleep
  • Loading branch information
bors committed Mar 4, 2024
2 parents 790287a + 2b40181 commit 65ec028
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/tools/miri/tests/pass/concurrency/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
});

Expand All @@ -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();
}
Expand Down

0 comments on commit 65ec028

Please sign in to comment.