mirror of
https://github.com/uutils/procps.git
synced 2026-06-10 16:14:00 -07:00
test_pgrep: Try to fix flaky tests (#309)
test_delimiter and test_delimiter_last_wins seem to rely on the system running the test having 2 or more 'sh' processes running, but that doesn't seem to be reliably the case in GitHub pipelines. Explicitly spawn two sleep processes instead.
This commit is contained in:
@@ -3,6 +3,12 @@
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::{
|
||||
array,
|
||||
process::{Child, Command},
|
||||
};
|
||||
|
||||
use crate::common::util::TestScenario;
|
||||
#[cfg(target_os = "linux")]
|
||||
use regex::Regex;
|
||||
@@ -151,24 +157,32 @@ fn test_valid_regex() {
|
||||
new_ucmd!().arg("a*").succeeds();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn spawn_2_dummy_sleep_processes() -> [Child; 2] {
|
||||
array::from_fn(|_| Command::new("sleep").arg("2").spawn().unwrap())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn test_delimiter() {
|
||||
let mut sleep_processes = spawn_2_dummy_sleep_processes();
|
||||
for arg in ["-d", "--delimiter"] {
|
||||
new_ucmd!()
|
||||
.arg("sh")
|
||||
.arg("sleep")
|
||||
.arg(arg)
|
||||
.arg("|")
|
||||
.succeeds()
|
||||
.stdout_contains("|");
|
||||
}
|
||||
sleep_processes.iter_mut().for_each(|p| drop(p.kill()));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn test_delimiter_last_wins() {
|
||||
let mut sleep_processes = spawn_2_dummy_sleep_processes();
|
||||
new_ucmd!()
|
||||
.arg("sh")
|
||||
.arg("sleep")
|
||||
.arg("-d_")
|
||||
.arg("-d:")
|
||||
.succeeds()
|
||||
@@ -176,12 +190,13 @@ fn test_delimiter_last_wins() {
|
||||
.stdout_contains(":");
|
||||
|
||||
new_ucmd!()
|
||||
.arg("sh")
|
||||
.arg("sleep")
|
||||
.arg("-d:")
|
||||
.arg("-d_")
|
||||
.succeeds()
|
||||
.stdout_does_not_contain(":")
|
||||
.stdout_contains("_");
|
||||
sleep_processes.iter_mut().for_each(|p| drop(p.kill()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user