Skip to content

Commit

Permalink
Try problem test with escargot
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Oct 26, 2024
1 parent 8e84cbe commit 7fb6787
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ procfs = "0.17"
assert_cmd = "2.0.11"
retry = "2.0.0"
tokio = { version = "1", features = ["time", "rt", "macros"] }
escargot = "0.5"

[features]
default = ["proc"]
Expand Down
16 changes: 4 additions & 12 deletions tests/lib_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use assert_cmd::cargo::CommandCargoExt;
use retry::delay::Fixed;
use retry::retry;
use std::io::Write;
use std::process::Command;

struct DropChild(std::process::Child);
Expand Down Expand Up @@ -123,24 +122,17 @@ async fn port_query_with_async_retry() {
fn proc_query_by_name() {
use proc_ctl::ProcQuery;

let binder = Command::cargo_bin("waiter").unwrap();
let mut handle = DropChild::spawn(binder);
let _cmd = escargot::CargoBuild::new().bin("waiter").run().unwrap().command().spawn().unwrap();

let query = ProcQuery::new().process_name("waiter");

let processes = retry(Fixed::from_millis(100).take(1000), move || {
let processes = retry(Fixed::from_millis(100).take(10), move || {
match query.list_processes().ok() {
Some(processes) if !processes.is_empty() => Ok(processes),
_ => Err("No processes found"),
}
})
.expect("Failed to find process in time");

if let Some(stdin) = handle.stdin.as_mut() {
stdin.write_all(b"\r\n").unwrap();
} else {
handle.kill().unwrap();
}
.expect("Failed to find process in time");

assert_eq!(1, processes.len());
}
Expand All @@ -166,7 +158,7 @@ fn proc_query_for_children() {
.children()
.map(|v| v.into_iter().map(|p| p.name).collect::<Vec<String>>())
})
.unwrap();
.unwrap();

handle.kill().unwrap();

Expand Down

0 comments on commit 7fb6787

Please sign in to comment.