@@ -7,6 +7,10 @@ use std::sync::{Arc, Barrier, Condvar, Mutex, Once, RwLock};
7
7
use std:: thread;
8
8
use std:: time:: { Duration , Instant } ;
9
9
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
+
10
14
// Check if Rust barriers are working.
11
15
12
16
/// This test is taken from the Rust documentation.
@@ -66,7 +70,7 @@ fn check_conditional_variables_timed_wait_timeout() {
66
70
let ( _guard, timeout) = cvar. wait_timeout ( guard, Duration :: from_millis ( 10 ) ) . unwrap ( ) ;
67
71
assert ! ( timeout. timed_out( ) ) ;
68
72
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 ( ) ) ;
70
74
}
71
75
72
76
/// Test that signaling a conditional variable when waiting with a timeout works
@@ -84,7 +88,8 @@ fn check_conditional_variables_timed_wait_notimeout() {
84
88
cvar. notify_one ( ) ;
85
89
} ) ;
86
90
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 ( ) ;
88
93
assert ! ( !timeout. timed_out( ) ) ;
89
94
handle. join ( ) . unwrap ( ) ;
90
95
}
@@ -213,20 +218,21 @@ fn check_once() {
213
218
fn park_timeout ( ) {
214
219
let start = Instant :: now ( ) ;
215
220
216
- thread:: park_timeout ( Duration :: from_millis ( 200 ) ) ;
221
+ thread:: park_timeout ( Duration :: from_millis ( 10 ) ) ;
217
222
// Normally, waiting in park/park_timeout may spuriously wake up early, but we
218
223
// 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.
221
224
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
+ ) ;
223
229
}
224
230
225
231
fn park_unpark ( ) {
226
232
let t1 = thread:: current ( ) ;
227
233
let t2 = thread:: spawn ( move || {
228
234
thread:: park ( ) ;
229
- thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
235
+ thread:: sleep ( Duration :: from_millis ( 10 ) ) ;
230
236
t1. unpark ( ) ;
231
237
} ) ;
232
238
@@ -236,10 +242,11 @@ fn park_unpark() {
236
242
thread:: park ( ) ;
237
243
// Normally, waiting in park/park_timeout may spuriously wake up early, but we
238
244
// 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.
241
245
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
+ ) ;
243
250
244
251
t2. join ( ) . unwrap ( ) ;
245
252
}
0 commit comments