Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/common/util: Add possibility to set timeout for UCommand and UChild. Add rstest with timeout macro to dev dependencies #4231

Merged
merged 3 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/cspell.dictionaries/workspace.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ quickcheck
rand_chacha
ringbuffer
rlimit
rstest
smallvec
tempdir
tempfile
Expand Down
152 changes: 152 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ uucore = { version=">=0.0.16", package="uucore", path="src/uucore", features=["e
walkdir = "2.2"
atty = "0.2"
hex-literal = "0.3.1"
rstest = "0.16.0"

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dev-dependencies]
procfs = { version = "0.14", default-features = false }
Expand Down
6 changes: 4 additions & 2 deletions tests/by-util/test_factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use crate::common::util::*;

use std::time::SystemTime;
use std::time::{Duration, SystemTime};

#[path = "../../src/uu/factor/sieve.rs"]
mod sieve;
Expand All @@ -35,7 +35,7 @@ fn test_invalid_arg() {
fn test_parallel() {
use hex_literal::hex;
use sha1::{Digest, Sha1};
use std::fs::OpenOptions;
use std::{fs::OpenOptions, time::Duration};
use tempfile::TempDir;
// factor should only flush the buffer at line breaks
let n_integers = 100_000;
Expand All @@ -55,6 +55,7 @@ fn test_parallel() {
for child in (0..10)
.map(|_| {
new_ucmd!()
.timeout(Duration::from_secs(240))
.set_stdout(output.try_clone().unwrap())
.pipe_in(input_string.clone())
.run_no_wait()
Expand Down Expand Up @@ -275,6 +276,7 @@ fn run(input_string: &[u8], output_string: &[u8]) {
);
// now run factor
new_ucmd!()
.timeout(Duration::from_secs(240))
.pipe_in(input_string)
.run()
.stdout_is(String::from_utf8(output_string.to_owned()).unwrap());
Expand Down
3 changes: 3 additions & 0 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

// spell-checker:ignore (words) ints

use std::time::Duration;

use crate::common::util::*;

fn test_helper(file_name: &str, possible_args: &[&str]) {
Expand Down Expand Up @@ -948,6 +950,7 @@ fn test_compress_fail() {
fn test_merge_batches() {
TestScenario::new(util_name!())
.ucmd_keepenv()
.timeout(Duration::from_secs(120))
.args(&["ext_sort.txt", "-n", "-S", "150b"])
.succeeds()
.stdout_only_fixture("ext_sort.expected");
Expand Down