Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanYuan authored Aug 29, 2024
2 parents c160fb5 + f9c3c70 commit a086dce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
28 changes: 8 additions & 20 deletions test/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ use std::sync::{Arc, RwLock};
use std::thread::sleep;
use std::time::{Duration, Instant};

#[cfg(target_os = "windows")]
use windows_sys::Win32::System::Console::{GenerateConsoleCtrlEvent, CTRL_C_EVENT};

pub(crate) struct ProcessGuard {
pub name: String,
pub child: Child,
Expand Down Expand Up @@ -845,28 +842,19 @@ impl Node {
info!("accessed db done");
}

#[allow(unused_mut)]
pub fn stop_gracefully(&mut self) {
let guard = self.take_guard();
if let Some(mut guard) = guard {
if !guard.killed {
// on nix: send SIGINT to the child
// on windows: use taskkill to kill the child gracefully
Self::kill_gracefully(guard.child.id());
let _ = guard.child.wait();
guard.killed = true;
}
}
}

#[cfg(target_os = "windows")]
fn kill_gracefully(pid: u32) {
unsafe {
let ret = GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid);
if ret == 0 {
let err = std::io::Error::last_os_error();
error!("GenerateConsoleCtrlEvent failed: {}", err);
} else {
info!("GenerateConsoleCtrlEvent success");
// on windows: don't kill gracefully..... fix later
#[cfg(not(target_os = "windows"))]
{
Self::kill_gracefully(guard.child.id());
let _ = guard.child.wait();
guard.killed = true;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/src/specs/fault_injection/randomly_kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Spec for RandomlyKill {
node.mine(n);
}
info!("Stop the node");
node.stop();
node.stop_gracefully();
info!("Start the node");
node.start();
}
Expand Down

0 comments on commit a086dce

Please sign in to comment.