summaryrefslogtreecommitdiff
path: root/test/test.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2017-07-09 18:48:11 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2017-07-09 18:48:11 +0000
commit386c50cf0a9c3d5c1e481fb76ee2f17a12b3fc44 (patch)
treefa67dc34237bad2021fdfee3956ebfd4f732de2c /test/test.rs
parent1b1f15c27c73197bc256220644440a2d0874d9aa (diff)
parenta50b4765780adbbf637ba0ea2190b33260d4c38e (diff)
downloadnix-386c50cf0a9c3d5c1e481fb76ee2f17a12b3fc44.zip
Merge #660
660: Fix double close bugs in test_lseek and test_lseek64 r=asomers std::fs::File closes the underlying file descriptor on Drop, without checking for errors. test_lseek and test_lseek64 also manually close the file descriptor. That works for single threaded test runs. But for multithreaded runs, it causes EBADF errors in other tests. Fix the tests by consuming the File with into_raw_fd(), so its drop method will never be called.
Diffstat (limited to 'test/test.rs')
-rw-r--r--test/test.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/test.rs b/test/test.rs
index e2f5a024..2cf30360 100644
--- a/test/test.rs
+++ b/test/test.rs
@@ -24,6 +24,18 @@ mod test_stat;
mod test_unistd;
use nixtest::assert_size_of;
+use std::os::unix::io::RawFd;
+use nix::unistd::read;
+
+/// Helper function analogous to std::io::Read::read_exact, but for `RawFD`s
+fn read_exact(f: RawFd, buf: &mut [u8]) {
+ let mut len = 0;
+ while len < buf.len() {
+ // get_mut would be better than split_at_mut, but it requires nightly
+ let (_, remaining) = buf.split_at_mut(len);
+ len += read(f, remaining).unwrap();
+ }
+}
#[test]
pub fn test_size_of_long() {