summaryrefslogtreecommitdiffstats
path: root/vendor/sysinfo/tests
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sysinfo/tests')
-rw-r--r--vendor/sysinfo/tests/code_checkers/docs.rs15
-rw-r--r--vendor/sysinfo/tests/code_checkers/headers.rs2
-rw-r--r--vendor/sysinfo/tests/code_checkers/mod.rs1
-rw-r--r--vendor/sysinfo/tests/code_checkers/utils.rs2
-rw-r--r--vendor/sysinfo/tests/process.rs90
5 files changed, 91 insertions, 19 deletions
diff --git a/vendor/sysinfo/tests/code_checkers/docs.rs b/vendor/sysinfo/tests/code_checkers/docs.rs
index 918e64bb0..7720d2dcf 100644
--- a/vendor/sysinfo/tests/code_checkers/docs.rs
+++ b/vendor/sysinfo/tests/code_checkers/docs.rs
@@ -21,14 +21,9 @@ fn to_correct_name(s: &str) -> String {
}
fn check_md_doc_path(p: &Path, md_line: &str, ty_line: &str) -> bool {
- let parts = md_line.split("/").collect::<Vec<_>>();
+ let parts = md_line.split('/').collect::<Vec<_>>();
if let Some(md_name) = parts.last().and_then(|n| n.split(".md").next()) {
- if let Some(name) = ty_line
- .split_whitespace()
- .filter(|s| !s.is_empty())
- .skip(2)
- .next()
- {
+ if let Some(name) = ty_line.split_whitespace().filter(|s| !s.is_empty()).nth(2) {
if let Some(name) = name
.split('<')
.next()
@@ -50,11 +45,11 @@ fn check_md_doc_path(p: &Path, md_line: &str, ty_line: &str) -> bool {
return false;
}
}
- show_error(p, &format!("Cannot extract type name from `{}`", ty_line));
+ show_error(p, &format!("Cannot extract type name from `{ty_line}`"));
} else {
- show_error(p, &format!("Cannot extract md name from `{}`", md_line));
+ show_error(p, &format!("Cannot extract md name from `{md_line}`"));
}
- return false;
+ false
}
fn check_doc_comments_before(p: &Path, lines: &[&str], start: usize) -> bool {
diff --git a/vendor/sysinfo/tests/code_checkers/headers.rs b/vendor/sysinfo/tests/code_checkers/headers.rs
index ac7a34ddb..d66aa4202 100644
--- a/vendor/sysinfo/tests/code_checkers/headers.rs
+++ b/vendor/sysinfo/tests/code_checkers/headers.rs
@@ -19,7 +19,7 @@ pub fn check_license_header(content: &str, p: &Path) -> TestResult {
Some(s) => {
show_error(
p,
- &format!("Expected empty line after license header, found `{}`", s),
+ &format!("Expected empty line after license header, found `{s}`"),
);
TestResult {
nb_tests: 1,
diff --git a/vendor/sysinfo/tests/code_checkers/mod.rs b/vendor/sysinfo/tests/code_checkers/mod.rs
index f6012da95..db645341d 100644
--- a/vendor/sysinfo/tests/code_checkers/mod.rs
+++ b/vendor/sysinfo/tests/code_checkers/mod.rs
@@ -8,6 +8,7 @@ mod utils;
use std::path::Path;
use utils::TestResult;
+#[allow(clippy::type_complexity)]
const CHECKS: &[(fn(&str, &Path) -> TestResult, &[&str])] = &[
(headers::check_license_header, &["src", "tests", "examples"]),
(signals::check_signals, &["src"]),
diff --git a/vendor/sysinfo/tests/code_checkers/utils.rs b/vendor/sysinfo/tests/code_checkers/utils.rs
index dadbc0a54..893201961 100644
--- a/vendor/sysinfo/tests/code_checkers/utils.rs
+++ b/vendor/sysinfo/tests/code_checkers/utils.rs
@@ -45,5 +45,5 @@ fn read_file<P: AsRef<Path>>(p: P) -> String {
}
pub fn show_error(p: &Path, err: &str) {
- eprintln!("=> [{}]: {}", p.display(), err);
+ eprintln!("=> [{}]: {err}", p.display());
}
diff --git a/vendor/sysinfo/tests/process.rs b/vendor/sysinfo/tests/process.rs
index 6745fc444..2b88c7b24 100644
--- a/vendor/sysinfo/tests/process.rs
+++ b/vendor/sysinfo/tests/process.rs
@@ -11,7 +11,6 @@ fn test_process() {
return;
}
assert!(!s.processes().is_empty());
- #[cfg(not(windows))]
assert!(s
.processes()
.values()
@@ -39,7 +38,7 @@ fn test_cwd() {
.unwrap()
};
- let pid = Pid::from_u32(p.id() as u32);
+ let pid = Pid::from_u32(p.id() as _);
std::thread::sleep(std::time::Duration::from_secs(1));
let mut s = sysinfo::System::new();
s.refresh_processes();
@@ -82,7 +81,7 @@ fn test_cmd() {
s.refresh_processes();
p.kill().expect("Unable to kill process.");
assert!(!s.processes().is_empty());
- if let Some(process) = s.process(Pid::from_u32(p.id() as u32)) {
+ if let Some(process) = s.process(Pid::from_u32(p.id() as _)) {
if cfg!(target_os = "windows") {
// Sometimes, we get the full path instead for some reasons... So just in case,
// we check for the command independently that from the arguments.
@@ -121,7 +120,7 @@ fn test_environ() {
.unwrap()
};
- let pid = Pid::from_u32(p.id() as u32);
+ let pid = Pid::from_u32(p.id() as _);
std::thread::sleep(std::time::Duration::from_secs(1));
let mut s = sysinfo::System::new();
s.refresh_processes();
@@ -225,6 +224,8 @@ fn cpu_usage_is_not_nan() {
return;
}
+ // We need `collect` otherwise we can't have mutable access to `system`.
+ #[allow(clippy::needless_collect)]
let first_pids = system
.processes()
.iter()
@@ -266,7 +267,7 @@ fn test_process_times() {
.unwrap()
};
- let pid = Pid::from_u32(p.id() as u32);
+ let pid = Pid::from_u32(p.id() as _);
std::thread::sleep(std::time::Duration::from_secs(1));
let mut s = sysinfo::System::new();
s.refresh_processes();
@@ -314,7 +315,7 @@ fn test_refresh_processes() {
.unwrap()
};
- let pid = Pid::from_u32(p.id() as u32);
+ let pid = Pid::from_u32(p.id() as _);
std::thread::sleep(std::time::Duration::from_secs(1));
// Checks that the process is listed as it should.
@@ -358,7 +359,7 @@ fn test_refresh_process() {
.unwrap()
};
- let pid = Pid::from_u32(p.id() as u32);
+ let pid = Pid::from_u32(p.id() as _);
std::thread::sleep(std::time::Duration::from_secs(1));
// Checks that the process is listed as it should.
@@ -379,3 +380,78 @@ fn test_refresh_process() {
// Checks that the process is still listed.
assert!(s.process(pid).is_some());
}
+
+#[test]
+fn test_wait_child() {
+ if !sysinfo::System::IS_SUPPORTED || cfg!(feature = "apple-sandbox") {
+ return;
+ }
+ let p = if cfg!(target_os = "windows") {
+ std::process::Command::new("waitfor")
+ .arg("/t")
+ .arg("300")
+ .arg("RefreshProcess")
+ .stdout(std::process::Stdio::null())
+ .spawn()
+ .unwrap()
+ } else {
+ std::process::Command::new("sleep")
+ .arg("300")
+ .stdout(std::process::Stdio::null())
+ .spawn()
+ .unwrap()
+ };
+
+ let before = std::time::Instant::now();
+ let pid = Pid::from_u32(p.id() as _);
+
+ let mut s = sysinfo::System::new();
+ s.refresh_process(pid);
+ let process = s.process(pid).unwrap();
+
+ // Kill the child process.
+ process.kill();
+ // Wait for child process should work.
+ process.wait();
+
+ // Child process should not be present.
+ assert!(!s.refresh_process(pid));
+ assert!(before.elapsed() < std::time::Duration::from_millis(1000));
+}
+
+#[test]
+fn test_wait_non_child() {
+ if !sysinfo::System::IS_SUPPORTED || cfg!(feature = "apple-sandbox") {
+ return;
+ }
+
+ // spawn non child process.
+ let p = if !cfg!(target_os = "linux") {
+ return;
+ } else {
+ std::process::Command::new("setsid")
+ .arg("-w")
+ .arg("sleep")
+ .arg("2")
+ .stdout(std::process::Stdio::null())
+ .spawn()
+ .unwrap()
+ };
+ let pid = Pid::from_u32(p.id());
+
+ let before = std::time::Instant::now();
+
+ let mut s = sysinfo::System::new();
+ s.refresh_process(pid);
+ let process = s.process(pid).expect("Process not found!");
+
+ // Wait for a non child process.
+ process.wait();
+
+ // Child process should not be present.
+ assert!(!s.refresh_process(pid));
+
+ // should wait for 2s.
+ assert!(before.elapsed() > std::time::Duration::from_millis(2000));
+ assert!(before.elapsed() < std::time::Duration::from_millis(3000));
+}