1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #3003 from tertsdiepraam/ls-fix-another-flaky-test

`ls`: fix flaky test `test_ls_io_errors`
This commit is contained in:
Sylvestre Ledru 2022-02-15 20:11:48 +01:00 committed by GitHub
commit 67cee26abe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,28 +1,27 @@
// spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile
#[cfg(unix)]
extern crate unix_socket;
use crate::common::util::*;
extern crate regex;
use self::regex::Regex;
#[cfg(all(unix, feature = "chmod"))]
use nix::unistd::{close, dup2};
use std::collections::HashMap;
#[cfg(all(unix, feature = "chmod"))]
use std::os::unix::io::AsRawFd;
use std::path::Path;
use std::thread::sleep;
use std::time::Duration;
#[cfg(not(windows))]
extern crate libc;
extern crate regex;
#[cfg(not(windows))]
extern crate tempfile;
#[cfg(unix)]
extern crate unix_socket;
use self::regex::Regex;
use crate::common::util::*;
#[cfg(all(unix, feature = "chmod"))]
use nix::unistd::{close, dup};
use std::collections::HashMap;
#[cfg(all(unix, feature = "chmod"))]
use std::os::unix::io::IntoRawFd;
use std::path::Path;
#[cfg(not(windows))]
use std::path::PathBuf;
#[cfg(not(windows))]
use std::sync::Mutex;
#[cfg(not(windows))]
extern crate tempfile;
use std::thread::sleep;
use std::time::Duration;
#[cfg(not(windows))]
lazy_static! {
@ -142,7 +141,7 @@ fn test_ls_devices() {
}
}
#[cfg(all(feature = "chmod"))]
#[cfg(feature = "chmod")]
#[test]
fn test_ls_io_errors() {
let scene = TestScenario::new(util_name!());
@ -202,14 +201,10 @@ fn test_ls_io_errors() {
#[cfg(unix)]
{
at.touch("some-dir4/bad-fd.txt");
let fd1 = at.open("some-dir4/bad-fd.txt").as_raw_fd();
let fd2 = 25000;
let rv1 = dup2(fd1, fd2);
let rv2 = close(fd1);
let fd1 = at.open("some-dir4/bad-fd.txt").into_raw_fd();
let fd2 = dup(dbg!(fd1)).unwrap();
close(fd1).unwrap();
// dup and close work on the mac, but doesn't work in some linux containers
// so check to see that return values are non-error before proceeding
if rv1.is_ok() && rv2.is_ok() {
// on the mac and in certain Linux containers bad fds are typed as dirs,
// however sometimes bad fds are typed as links and directory entry on links won't fail
if PathBuf::from(format!("/dev/fd/{fd}", fd = fd2)).is_dir() {
@ -251,7 +246,7 @@ fn test_ls_io_errors() {
.arg("-alL")
.arg(format!("/dev/fd/{fd}", fd = fd2))
.succeeds();
}
let _ = close(fd2);
}
}