From 09c04d9f3f577b2b4fb853ee21bb23e360d42f71 Mon Sep 17 00:00:00 2001 From: Joining7943 <111500881+Joining7943@users.noreply.github.com> Date: Fri, 16 Dec 2022 01:18:27 +0100 Subject: [PATCH] tests: Set timeout for tests which would fail with the default timeout in test_factor, test_sort --- tests/by-util/test_factor.rs | 6 ++++-- tests/by-util/test_sort.rs | 3 +++ tests/common/util.rs | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index f84a86aa9..6a17c00ff 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -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; @@ -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; @@ -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() @@ -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()); diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 6e71f2664..a03217cb9 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -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]) { @@ -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"); diff --git a/tests/common/util.rs b/tests/common/util.rs index 312f4278a..fb3c8fb8d 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1641,8 +1641,8 @@ impl UChild { format!("wait: Timeout of '{}s' reached", timeout.as_secs_f64()), )), Err(RecvTimeoutError::Disconnected) => { - handle.join().unwrap().unwrap(); - panic!("Error receiving from waiting thread because of unexpected disconnect") + handle.join().expect("Panic caused disconnect").unwrap(); + panic!("Error receiving from waiting thread because of unexpected disconnect"); } } } else {