Skip to content

Commit ab98678

Browse files
committed
handle spurious returns of wait_timeout in test
1 parent 5413f7d commit ab98678

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

library/std/tests/sync/condvar.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,18 @@ nonpoison_and_poison_unwrap_test!(
290290
cond.notify_all();
291291
});
292292

293-
let guard = maybe_unwrap(sent.lock());
294-
// If there is internal overflow, this call will return almost
295-
// immediately, before the other thread has reached the `notify_all`
296-
let (guard, res) = maybe_unwrap(cond.wait_timeout(guard, Duration::from_secs(u64::MAX.div_ceil(1_000_000_000))));
297-
assert!(!res.timed_out());
298-
assert!(*guard);
293+
let mut guard = maybe_unwrap(sent.lock());
294+
loop {
295+
if *guard {
296+
break;
297+
}
298+
299+
// If there is internal overflow, this call will return almost
300+
// immediately, before the other thread has reached the `notify_all`
301+
let (g, res) = maybe_unwrap(cond.wait_timeout(guard, Duration::from_secs(u64::MAX.div_ceil(1_000_000_000))));
302+
assert!(!res.timed_out());
303+
guard = g;
304+
}
299305
})
300306
}
301307
);

0 commit comments

Comments
 (0)