Skip to content

Commit ea24bf0

Browse files
committed
test: fix windows
1 parent a3d54db commit ea24bf0

File tree

2 files changed

+101
-4
lines changed

2 files changed

+101
-4
lines changed

crates/libs/kill_tree/src/blocking.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,30 @@ mod tests {
130130
use super::*;
131131
use crate::get_available_max_process_id;
132132

133+
#[cfg(windows)]
133134
#[test]
134-
fn kill_tree_available_max_process_id() {
135+
fn kill_tree_available_max_process_id_windows() {
136+
let target_process_id = get_available_max_process_id();
137+
let result = kill_tree(target_process_id).expect("Failed to kill");
138+
assert_eq!(result.len(), 1);
139+
let output = &result[0];
140+
match output {
141+
crate::Output::Killed { .. } => {
142+
panic!("This should not happen");
143+
}
144+
crate::Output::MaybeAlreadyTerminated { process_id, source } => {
145+
assert_eq!(*process_id, target_process_id);
146+
assert_eq!(
147+
source.to_string(),
148+
"Windows error: The parameter is incorrect. (0x80070057)"
149+
);
150+
}
151+
}
152+
}
153+
154+
#[cfg(unix)]
155+
#[test]
156+
fn kill_tree_available_max_process_id_unix() {
135157
let target_process_id = get_available_max_process_id();
136158
let result = kill_tree(target_process_id).expect("Failed to kill");
137159
assert_eq!(result.len(), 1);
@@ -147,8 +169,34 @@ mod tests {
147169
}
148170
}
149171

172+
#[cfg(windows)]
173+
#[test]
174+
fn kill_tree_with_config_sigkill_available_max_process_id_windows() {
175+
let target_process_id = get_available_max_process_id();
176+
let config = Config {
177+
signal: String::from("SIGKILL"),
178+
..Default::default()
179+
};
180+
let result = kill_tree_with_config(target_process_id, &config).expect("Failed to kill");
181+
assert_eq!(result.len(), 1);
182+
let output = &result[0];
183+
match output {
184+
crate::Output::Killed { .. } => {
185+
panic!("This should not happen");
186+
}
187+
crate::Output::MaybeAlreadyTerminated { process_id, source } => {
188+
assert_eq!(*process_id, target_process_id);
189+
assert_eq!(
190+
source.to_string(),
191+
"Windows error: The parameter is incorrect. (0x80070057)"
192+
);
193+
}
194+
}
195+
}
196+
197+
#[cfg(unix)]
150198
#[test]
151-
fn kill_tree_with_config_sigkill_available_max_process_id() {
199+
fn kill_tree_with_config_sigkill_available_max_process_id_unix() {
152200
let target_process_id = get_available_max_process_id();
153201
let config = Config {
154202
signal: String::from("SIGKILL"),

crates/libs/kill_tree/src/tokio.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,28 @@ mod tests {
130130
use crate::get_available_max_process_id;
131131

132132
#[::tokio::test]
133-
async fn kill_tree_available_max_process_id() {
133+
async fn kill_tree_available_max_process_id_windows() {
134+
let target_process_id = get_available_max_process_id();
135+
let outputs = kill_tree(target_process_id).await.expect("Failed to kill");
136+
assert!(!outputs.is_empty());
137+
let output = &outputs[0];
138+
match output {
139+
crate::Output::Killed { .. } => {
140+
panic!("This should not happen");
141+
}
142+
crate::Output::MaybeAlreadyTerminated { process_id, source } => {
143+
assert_eq!(*process_id, target_process_id);
144+
assert_eq!(
145+
source.to_string(),
146+
"Windows error: The parameter is incorrect. (0x80070057)"
147+
);
148+
}
149+
}
150+
}
151+
152+
#[cfg(unix)]
153+
#[::tokio::test]
154+
async fn kill_tree_available_max_process_id_unix() {
134155
let target_process_id = get_available_max_process_id();
135156
let outputs = kill_tree(target_process_id).await.expect("Failed to kill");
136157
assert!(!outputs.is_empty());
@@ -146,8 +167,36 @@ mod tests {
146167
}
147168
}
148169

170+
#[cfg(windows)]
171+
#[::tokio::test]
172+
async fn kill_tree_with_config_sigkill_available_max_process_id_windows() {
173+
let target_process_id = get_available_max_process_id();
174+
let config = Config {
175+
signal: String::from("SIGKILL"),
176+
..Default::default()
177+
};
178+
let outputs = kill_tree_with_config(target_process_id, &config)
179+
.await
180+
.expect("Failed to kill");
181+
assert!(!outputs.is_empty());
182+
let output = &outputs[0];
183+
match output {
184+
crate::Output::Killed { .. } => {
185+
panic!("This should not happen");
186+
}
187+
crate::Output::MaybeAlreadyTerminated { process_id, source } => {
188+
assert_eq!(*process_id, target_process_id);
189+
assert_eq!(
190+
source.to_string(),
191+
"Windows error: The parameter is incorrect. (0x80070057)"
192+
);
193+
}
194+
}
195+
}
196+
197+
#[cfg(unix)]
149198
#[::tokio::test]
150-
async fn kill_tree_with_config_sigkill_available_max_process_id() {
199+
async fn kill_tree_with_config_sigkill_available_max_process_id_unix() {
151200
let target_process_id = get_available_max_process_id();
152201
let config = Config {
153202
signal: String::from("SIGKILL"),

0 commit comments

Comments
 (0)