Skip to content

Commit a1eb895

Browse files
committed
Handle SIGRT_1 in test_alarm
When run in Cirrus-CI's environment, the tests generate copious SIGRT_1 signals. This commit ensures that test_alarm will ignore them.
1 parent 8b2374c commit a1eb895

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

test/test_unistd.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,12 @@ pub extern fn alarm_signal_handler(raw_signal: libc::c_int) {
684684
#[test]
685685
#[cfg(not(target_os = "redox"))]
686686
fn test_alarm() {
687+
use std::{
688+
time::{Duration, Instant,},
689+
thread
690+
};
691+
692+
// Maybe other tests that fork interfere with this one?
687693
let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
688694

689695
let handler = SigHandler::Handler(alarm_signal_handler);
@@ -701,8 +707,16 @@ fn test_alarm() {
701707

702708
// We should be woken up after 1 second by the alarm, so we'll sleep for 2
703709
// seconds to be sure.
704-
sleep(2);
705-
assert_eq!(unsafe { ALARM_CALLED }, true, "expected our alarm signal handler to be called");
710+
let starttime = Instant::now();
711+
loop {
712+
thread::sleep(Duration::from_millis(100));
713+
if unsafe { ALARM_CALLED} {
714+
break;
715+
}
716+
if starttime.elapsed() > Duration::from_secs(3) {
717+
panic!("Timeout waiting for SIGALRM");
718+
}
719+
}
706720

707721
// Reset the signal.
708722
unsafe {

0 commit comments

Comments
 (0)