Skip to content

Commit

Permalink
Handle SIGRT_1 in test_alarm
Browse files Browse the repository at this point in the history
When run in Cirrus-CI's environment, the tests generate copious SIGRT_1
signals.  This commit ensures that test_alarm will ignore them.
  • Loading branch information
asomers committed Dec 7, 2020
1 parent 8b2374c commit a1eb895
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions test/test_unistd.rs
Expand Up @@ -684,6 +684,12 @@ pub extern fn alarm_signal_handler(raw_signal: libc::c_int) {
#[test]
#[cfg(not(target_os = "redox"))]
fn test_alarm() {
use std::{
time::{Duration, Instant,},
thread
};

// Maybe other tests that fork interfere with this one?
let _m = crate::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");

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

// We should be woken up after 1 second by the alarm, so we'll sleep for 2
// seconds to be sure.
sleep(2);
assert_eq!(unsafe { ALARM_CALLED }, true, "expected our alarm signal handler to be called");
let starttime = Instant::now();
loop {
thread::sleep(Duration::from_millis(100));
if unsafe { ALARM_CALLED} {
break;
}
if starttime.elapsed() > Duration::from_secs(3) {
panic!("Timeout waiting for SIGALRM");
}
}

// Reset the signal.
unsafe {
Expand Down

0 comments on commit a1eb895

Please sign in to comment.