Skip to content

Commit

Permalink
Make the poll tests resilient against signals
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 the poll tests will retry on EINTR.
  • Loading branch information
asomers committed Dec 7, 2020
1 parent 1eb5733 commit 8b2374c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions test/test_poll.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
use nix::poll::{PollFlags, poll, PollFd};
use nix::unistd::{write, pipe};
use nix::{
Error,
errno::Errno,
poll::{PollFlags, poll, PollFd},
unistd::{write, pipe}
};

macro_rules! loop_while_eintr {
($poll_expr: expr) => {
loop {
match $poll_expr {
Ok(nfds) => break nfds,
Err(Error::Sys(Errno::EINTR)) => (),
Err(e) => panic!(e)
}
}
}
}

#[test]
fn test_poll() {
let (r, w) = pipe().unwrap();
let mut fds = [PollFd::new(r, PollFlags::POLLIN)];

// Poll an idle pipe. Should timeout
let nfds = poll(&mut fds, 100).unwrap();
let nfds = loop_while_eintr!(poll(&mut fds, 100));
assert_eq!(nfds, 0);
assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));

Expand Down Expand Up @@ -37,7 +53,8 @@ fn test_ppoll() {
let mut fds = [PollFd::new(r, PollFlags::POLLIN)];

// Poll an idle pipe. Should timeout
let nfds = ppoll(&mut fds, Some(timeout), SigSet::empty()).unwrap();
let sigset = SigSet::empty();
let nfds = loop_while_eintr!(ppoll(&mut fds, Some(timeout), sigset));
assert_eq!(nfds, 0);
assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));

Expand Down

0 comments on commit 8b2374c

Please sign in to comment.