Skip to content

Commit 65ec028

Browse files
committed
Auto merge of rust-lang#3358 - RalfJung:zzz, r=RalfJung
give macOS even more time to sleep
2 parents 790287a + 2b40181 commit 65ec028

File tree

1 file changed

+17
-10
lines changed
  • src/tools/miri/tests/pass/concurrency

1 file changed

+17
-10
lines changed

src/tools/miri/tests/pass/concurrency/sync.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ use std::sync::{Arc, Barrier, Condvar, Mutex, Once, RwLock};
77
use std::thread;
88
use std::time::{Duration, Instant};
99

10+
// We are expecting to sleep for 10ms. How long of a sleep we are accepting?
11+
// Even with 1000ms we still see this test fail on macOS runners.
12+
const MAX_SLEEP_TIME_MS: u64 = 2000;
13+
1014
// Check if Rust barriers are working.
1115

1216
/// This test is taken from the Rust documentation.
@@ -66,7 +70,7 @@ fn check_conditional_variables_timed_wait_timeout() {
6670
let (_guard, timeout) = cvar.wait_timeout(guard, Duration::from_millis(10)).unwrap();
6771
assert!(timeout.timed_out());
6872
let elapsed_time = now.elapsed().as_millis();
69-
assert!(10 <= elapsed_time && elapsed_time <= 1000);
73+
assert!(10 <= elapsed_time && elapsed_time <= MAX_SLEEP_TIME_MS.into());
7074
}
7175

7276
/// Test that signaling a conditional variable when waiting with a timeout works
@@ -84,7 +88,8 @@ fn check_conditional_variables_timed_wait_notimeout() {
8488
cvar.notify_one();
8589
});
8690

87-
let (_guard, timeout) = cvar.wait_timeout(guard, Duration::from_millis(1000)).unwrap();
91+
let (_guard, timeout) =
92+
cvar.wait_timeout(guard, Duration::from_millis(MAX_SLEEP_TIME_MS)).unwrap();
8893
assert!(!timeout.timed_out());
8994
handle.join().unwrap();
9095
}
@@ -213,20 +218,21 @@ fn check_once() {
213218
fn park_timeout() {
214219
let start = Instant::now();
215220

216-
thread::park_timeout(Duration::from_millis(200));
221+
thread::park_timeout(Duration::from_millis(10));
217222
// Normally, waiting in park/park_timeout may spuriously wake up early, but we
218223
// know Miri's timed synchronization primitives do not do that.
219-
// We allow much longer sleeps as well since the macOS GHA runners seem very oversubscribed
220-
// and sometimes just pause for 1 second or more.
221224
let elapsed = start.elapsed();
222-
assert!((200..2000).contains(&elapsed.as_millis()), "bad sleep time: {elapsed:?}");
225+
assert!(
226+
(10..MAX_SLEEP_TIME_MS.into()).contains(&elapsed.as_millis()),
227+
"bad sleep time: {elapsed:?}"
228+
);
223229
}
224230

225231
fn park_unpark() {
226232
let t1 = thread::current();
227233
let t2 = thread::spawn(move || {
228234
thread::park();
229-
thread::sleep(Duration::from_millis(200));
235+
thread::sleep(Duration::from_millis(10));
230236
t1.unpark();
231237
});
232238

@@ -236,10 +242,11 @@ fn park_unpark() {
236242
thread::park();
237243
// Normally, waiting in park/park_timeout may spuriously wake up early, but we
238244
// know Miri's timed synchronization primitives do not do that.
239-
// We allow much longer sleeps as well since the macOS GHA runners seem very oversubscribed
240-
// and sometimes just pause for 1 second or more.
241245
let elapsed = start.elapsed();
242-
assert!((200..2000).contains(&elapsed.as_millis()), "bad sleep time: {elapsed:?}");
246+
assert!(
247+
(10..MAX_SLEEP_TIME_MS.into()).contains(&elapsed.as_millis()),
248+
"bad sleep time: {elapsed:?}"
249+
);
243250

244251
t2.join().unwrap();
245252
}

0 commit comments

Comments
 (0)