Fix port of test code to nix 0.29 to avoid flaky failures

epel10 imports/epel10/rust-clircle-0.4.0-5.el10
Fabio Valentini 4 months ago
parent 4c68de9c09
commit c137f94977
No known key found for this signature in database
GPG Key ID: 5AC5F572E5D410AF

@ -1,3 +1,5 @@
diff --git a/src/clircle_unix.rs b/src/clircle_unix.rs
index 101f208..56448b9 100644
--- a/src/clircle_unix.rs --- a/src/clircle_unix.rs
+++ b/src/clircle_unix.rs +++ b/src/clircle_unix.rs
@@ -4,7 +4,7 @@ use std::convert::TryFrom; @@ -4,7 +4,7 @@ use std::convert::TryFrom;
@ -5,11 +7,33 @@
use std::io::{self, Seek}; use std::io::{self, Seek};
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
-use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd}; -use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
+use std::os::unix::io::{AsRawFd,FromRawFd, IntoRawFd, RawFd}; +use std::os::unix::io::{FromRawFd, IntoRawFd, OwnedFd, RawFd};
use std::{cmp, hash, ops}; use std::{cmp, hash, ops};
/// Re-export of libc /// Re-export of libc
@@ -186,7 +186,7 @@ mod tests { @@ -53,6 +53,13 @@ impl UnixIdentifier {
ident
})
}
+
+ fn try_from_owned_fd(fd: OwnedFd) -> io::Result<Self> {
+ Self::try_from(File::from(fd)).map(|mut ident| {
+ ident.owns_fd = true;
+ ident
+ })
+ }
}
impl Clircle for UnixIdentifier {
@@ -135,6 +142,7 @@ mod tests {
use std::error::Error;
use std::io::Write;
+ use std::os::unix::io::AsRawFd;
use nix::pty::{openpty, OpenptyResult};
use nix::unistd::close;
@@ -186,7 +194,7 @@ mod tests {
#[test] #[test]
fn test_pty_equal_but_not_conflicting() -> Result<(), &'static str> { fn test_pty_equal_but_not_conflicting() -> Result<(), &'static str> {
let OpenptyResult { master, slave } = openpty(None, None).expect("Could not open pty."); let OpenptyResult { master, slave } = openpty(None, None).expect("Could not open pty.");
@ -18,23 +42,25 @@
.map_err(|_| "Error creating UnixIdentifier from pty fd") .map_err(|_| "Error creating UnixIdentifier from pty fd")
.and_then(|ident| { .and_then(|ident| {
if !ident.eq(&ident) { if !ident.eq(&ident) {
@@ -196,7 +196,7 @@ mod tests { @@ -196,7 +204,7 @@ mod tests {
return Err("pty fd does not conflict with itself, but conflict detected"); return Err("pty fd does not conflict with itself, but conflict detected");
} }
- let second_ident = unsafe { UnixIdentifier::try_from_raw_fd(slave, false) } - let second_ident = unsafe { UnixIdentifier::try_from_raw_fd(slave, false) }
+ let second_ident = unsafe { UnixIdentifier::try_from_raw_fd(slave.as_raw_fd(), false) } + let second_ident = UnixIdentifier::try_from_owned_fd(slave)
.map_err(|_| "Error creating second Identifier to pty")?; .map_err(|_| "Error creating second Identifier to pty")?;
if !ident.eq(&second_ident) { if !ident.eq(&second_ident) {
return Err("ident != second_ident"); return Err("ident != second_ident");
@@ -209,8 +209,8 @@ mod tests { @@ -209,12 +217,6 @@ mod tests {
Ok(()) Ok(())
}); });
- let r1 = close(master); - let r1 = close(master);
- let r2 = close(slave); - let r2 = close(slave);
+ let r1 = close(master.as_raw_fd()); -
+ let r2 = close(slave.as_raw_fd()); - r1.expect("Error closing master end of pty");
- r2.expect("Error closing slave end of pty");
r1.expect("Error closing master end of pty"); -
r2.expect("Error closing slave end of pty"); res
}
}

Loading…
Cancel
Save