Skip to content

Commit 8b2374c

Browse files
committed
Make the poll tests resilient against signals
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.
1 parent 1eb5733 commit 8b2374c

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

test/test_poll.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
use nix::poll::{PollFlags, poll, PollFd};
2-
use nix::unistd::{write, pipe};
1+
use nix::{
2+
Error,
3+
errno::Errno,
4+
poll::{PollFlags, poll, PollFd},
5+
unistd::{write, pipe}
6+
};
7+
8+
macro_rules! loop_while_eintr {
9+
($poll_expr: expr) => {
10+
loop {
11+
match $poll_expr {
12+
Ok(nfds) => break nfds,
13+
Err(Error::Sys(Errno::EINTR)) => (),
14+
Err(e) => panic!(e)
15+
}
16+
}
17+
}
18+
}
319

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

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

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

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

0 commit comments

Comments
 (0)