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

Merge pull request #3927 from niyaznigmatullin/fix_timeout_test_tmp_files_deleted_on_sigint

test_sort: Fix timeout issue `test_tmp_files_deleted_on_sigint`
This commit is contained in:
Sylvestre Ledru 2022-10-22 10:24:30 +02:00 committed by GitHub
commit 1d9ec1ed94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 2 deletions

10
Cargo.lock generated
View file

@ -367,6 +367,7 @@ dependencies = [
"pretty_assertions", "pretty_assertions",
"procfs", "procfs",
"rand", "rand",
"rand_pcg",
"regex", "regex",
"rlimit", "rlimit",
"selinux", "selinux",
@ -1664,6 +1665,15 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "rand_pcg"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e"
dependencies = [
"rand_core",
]
[[package]] [[package]]
name = "rayon" name = "rayon"
version = "1.5.3" version = "1.5.3"

View file

@ -408,6 +408,7 @@ rlimit = "0.8.3"
[target.'cfg(unix)'.dev-dependencies] [target.'cfg(unix)'.dev-dependencies]
nix = { version = "0.25", default-features = false, features = ["process", "signal", "user"] } nix = { version = "0.25", default-features = false, features = ["process", "signal", "user"] }
rust-users = { version="0.11", package="users" } rust-users = { version="0.11", package="users" }
rand_pcg = "0.3"
[build-dependencies] [build-dependencies]
phf_codegen = "0.11.1" phf_codegen = "0.11.1"

View file

@ -1117,14 +1117,36 @@ fn test_tmp_files_deleted_on_sigint() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("tmp_dir"); at.mkdir("tmp_dir");
let file_name = "big_file_to_sort.txt";
{
use rand::{Rng, SeedableRng};
use std::io::Write;
let mut file = at.make_file(file_name);
// approximately 20 MB
for _ in 0..40 {
let lines = rand_pcg::Pcg32::seed_from_u64(123)
.sample_iter(rand::distributions::uniform::Uniform::new(0, 10000))
.take(100000)
.map(|x| x.to_string() + "\n")
.collect::<String>();
file.write_all(lines.as_bytes()).unwrap();
}
}
ucmd.args(&[ ucmd.args(&[
"ext_sort.txt", file_name,
"--buffer-size=1", // with a small buffer size `sort` will be forced to create a temporary directory very soon. "--buffer-size=1", // with a small buffer size `sort` will be forced to create a temporary directory very soon.
"--temporary-directory=tmp_dir", "--temporary-directory=tmp_dir",
]); ]);
let mut child = ucmd.run_no_wait(); let mut child = ucmd.run_no_wait();
// wait a short amount of time so that `sort` can create a temporary directory. // wait a short amount of time so that `sort` can create a temporary directory.
std::thread::sleep(Duration::from_millis(100)); let mut timeout = Duration::from_millis(100);
for _ in 0..5 {
std::thread::sleep(timeout);
if read_dir(at.plus("tmp_dir")).unwrap().next().is_some() {
break;
}
timeout *= 2;
}
// `sort` should have created a temporary directory. // `sort` should have created a temporary directory.
assert!(read_dir(at.plus("tmp_dir")).unwrap().next().is_some()); assert!(read_dir(at.plus("tmp_dir")).unwrap().next().is_some());
// kill sort with SIGINT // kill sort with SIGINT