diff options
author | Alan Somers <asomers@gmail.com> | 2020-12-04 22:00:46 -0700 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2020-12-06 22:23:30 -0700 |
commit | 8b2374c4fdaecfefd287ef53816e3d37abb08172 (patch) | |
tree | 8ac998c0883bf14846621a707dfc70e6ea010d97 | |
parent | 1eb5733f09244cca3446a6a16fe2eba244e0ba02 (diff) | |
download | nix-8b2374c4fdaecfefd287ef53816e3d37abb08172.zip |
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.
-rw-r--r-- | test/test_poll.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/test/test_poll.rs b/test/test_poll.rs index d1974acf..a5e2d254 100644 --- a/test/test_poll.rs +++ b/test/test_poll.rs @@ -1,5 +1,21 @@ -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() { @@ -7,7 +23,7 @@ fn test_poll() { 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)); @@ -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)); |