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:
commit
67cee26abe
1 changed files with 56 additions and 61 deletions
|
@ -1,28 +1,27 @@
|
||||||
// spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile
|
// 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))]
|
#[cfg(not(windows))]
|
||||||
extern crate libc;
|
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))]
|
#[cfg(not(windows))]
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
#[cfg(not(windows))]
|
use std::thread::sleep;
|
||||||
extern crate tempfile;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -142,7 +141,7 @@ fn test_ls_devices() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "chmod"))]
|
#[cfg(feature = "chmod")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ls_io_errors() {
|
fn test_ls_io_errors() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
@ -202,56 +201,52 @@ fn test_ls_io_errors() {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
at.touch("some-dir4/bad-fd.txt");
|
at.touch("some-dir4/bad-fd.txt");
|
||||||
let fd1 = at.open("some-dir4/bad-fd.txt").as_raw_fd();
|
let fd1 = at.open("some-dir4/bad-fd.txt").into_raw_fd();
|
||||||
let fd2 = 25000;
|
let fd2 = dup(dbg!(fd1)).unwrap();
|
||||||
let rv1 = dup2(fd1, fd2);
|
close(fd1).unwrap();
|
||||||
let rv2 = close(fd1);
|
|
||||||
|
|
||||||
// dup and close work on the mac, but doesn't work in some linux containers
|
// on the mac and in certain Linux containers bad fds are typed as dirs,
|
||||||
// so check to see that return values are non-error before proceeding
|
// however sometimes bad fds are typed as links and directory entry on links won't fail
|
||||||
if rv1.is_ok() && rv2.is_ok() {
|
if PathBuf::from(format!("/dev/fd/{fd}", fd = fd2)).is_dir() {
|
||||||
// on the mac and in certain Linux containers bad fds are typed as dirs,
|
scene
|
||||||
// however sometimes bad fds are typed as links and directory entry on links won't fail
|
.ucmd()
|
||||||
if PathBuf::from(format!("/dev/fd/{fd}", fd = fd2)).is_dir() {
|
.arg("-alR")
|
||||||
scene
|
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
||||||
.ucmd()
|
.fails()
|
||||||
.arg("-alR")
|
.stderr_contains(format!(
|
||||||
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
"cannot open directory '/dev/fd/{fd}': Bad file descriptor",
|
||||||
.fails()
|
fd = fd2
|
||||||
.stderr_contains(format!(
|
))
|
||||||
"cannot open directory '/dev/fd/{fd}': Bad file descriptor",
|
.stdout_does_not_contain(format!("{fd}:\n", fd = fd2));
|
||||||
fd = fd2
|
|
||||||
))
|
|
||||||
.stdout_does_not_contain(format!("{fd}:\n", fd = fd2));
|
|
||||||
|
|
||||||
scene
|
|
||||||
.ucmd()
|
|
||||||
.arg("-RiL")
|
|
||||||
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
|
||||||
.fails()
|
|
||||||
.stderr_contains(format!("cannot open directory '/dev/fd/{fd}': Bad file descriptor", fd = fd2))
|
|
||||||
// don't double print bad fd errors
|
|
||||||
.stderr_does_not_contain(format!("ls: cannot open directory '/dev/fd/{fd}': Bad file descriptor\nls: cannot open directory '/dev/fd/{fd}': Bad file descriptor", fd = fd2));
|
|
||||||
} else {
|
|
||||||
scene
|
|
||||||
.ucmd()
|
|
||||||
.arg("-alR")
|
|
||||||
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
|
||||||
.succeeds();
|
|
||||||
|
|
||||||
scene
|
|
||||||
.ucmd()
|
|
||||||
.arg("-RiL")
|
|
||||||
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
|
||||||
.succeeds();
|
|
||||||
}
|
|
||||||
|
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.arg("-alL")
|
.arg("-RiL")
|
||||||
|
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
||||||
|
.fails()
|
||||||
|
.stderr_contains(format!("cannot open directory '/dev/fd/{fd}': Bad file descriptor", fd = fd2))
|
||||||
|
// don't double print bad fd errors
|
||||||
|
.stderr_does_not_contain(format!("ls: cannot open directory '/dev/fd/{fd}': Bad file descriptor\nls: cannot open directory '/dev/fd/{fd}': Bad file descriptor", fd = fd2));
|
||||||
|
} else {
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-alR")
|
||||||
|
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
||||||
|
.succeeds();
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-RiL")
|
||||||
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
||||||
.succeeds();
|
.succeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-alL")
|
||||||
|
.arg(format!("/dev/fd/{fd}", fd = fd2))
|
||||||
|
.succeeds();
|
||||||
|
|
||||||
let _ = close(fd2);
|
let _ = close(fd2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue