Use powershell script for Windows termination

Also added additional logging
next
Sayan Nandan 3 years ago
parent 923b267c61
commit b9d3318ef9
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

7
Cargo.lock generated

@ -488,6 +488,7 @@ dependencies = [
"env_logger",
"libsky",
"log",
"powershell_script",
"zip",
]
@ -850,6 +851,12 @@ version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]]
name = "powershell_script"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a5a338783191ce961183e8fbca5a4d2902b2595260cecfb55f61f083cdff865"
[[package]]
name = "ppv-lite86"
version = "0.2.16"

@ -1,3 +1,17 @@
$ProcessID=(get-process skyd).id
$encodedCommand = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("Add-Type -Names 'w' -Name 'k' -M '[DllImport(""kernel32.dll"")]public static extern bool FreeConsole();[DllImport(""kernel32.dll"")]public static extern bool AttachConsole(uint p);[DllImport(""kernel32.dll"")]public static extern bool SetConsoleCtrlHandler(uint h, bool a);[DllImport(""kernel32.dll"")]public static extern bool GenerateConsoleCtrlEvent(uint e, uint p);public static void SendCtrlC(uint p){FreeConsole();AttachConsole(p);GenerateConsoleCtrlEvent(0, 0);}';[w.k]::SendCtrlC($ProcessID)"))
start-process powershell.exe -argument "-nologo -noprofile -executionpolicy bypass -EncodedCommand $encodedCommand"
function Terminate-Process() {
[CmdletBinding()]
param(
[Parameter()]
[string] $ProcessID
)
$encodedCommand = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("Add-Type -Names 'w' -Name 'k' -M '[DllImport(""kernel32.dll"")]public static extern bool FreeConsole();[DllImport(""kernel32.dll"")]public static extern bool AttachConsole(uint p);[DllImport(""kernel32.dll"")]public static extern bool SetConsoleCtrlHandler(uint h, bool a);[DllImport(""kernel32.dll"")]public static extern bool GenerateConsoleCtrlEvent(uint e, uint p);public static void SendCtrlC(uint p){FreeConsole();AttachConsole(p);GenerateConsoleCtrlEvent(0, 0);}';[w.k]::SendCtrlC($ProcessID)"))
start-process powershell.exe -argument "-nologo -noprofile -executionpolicy bypass -EncodedCommand $encodedCommand"
}
$ProcessIDs=(get-process skyd).id
$Proc1=($ProcessIDs -split '\n')[0]
$Proc2=($ProcessIDs -split '\n')[1]
Terminate-Process -ProcessID $Proc1
Terminate-Process -ProcessID $Proc2

@ -10,3 +10,4 @@ libsky = { path = "../libsky" }
env_logger = "0.9.0"
log = "0.4.14"
zip = { version = "0.5.13", features = ["deflate"] }
powershell_script = "0.3.2"

@ -30,6 +30,8 @@ use std::process::Child;
use std::process::Command;
const WORKSPACE_ROOT: &str = env!("ROOT_DIR");
#[cfg(windows)]
const POWERSHELL_SCRIPT: &str = include_str!("../../ci/windows/stop.ps1");
pub fn get_run_server_cmd(server_id: &'static str, cmd_payload: &[String]) -> Command {
let mut cmd = Command::new("cargo");
@ -51,6 +53,7 @@ pub fn start_servers(s1_cmd: Command, s2_cmd: Command) -> HarnessResult<(Child,
Ok((s1, s2))
}
#[cfg(not(windows))]
fn kill_servers() -> HarnessResult<()> {
util::handle_child("kill servers", cmd!("pkill", "skyd"))?;
// sleep
@ -58,6 +61,16 @@ fn kill_servers() -> HarnessResult<()> {
Ok(())
}
#[cfg(windows)]
fn kill_servers() -> HarnessResult<()> {
match powershell_script::run(POWERSHELL_SCRIPT, false) {
Ok(_) => Ok(()),
Err(e) => Err(HarnessError::Other(format!(
"Failed to run powershell script with error: {e}"
))),
}
}
pub fn run_test() -> HarnessResult<()> {
let ret = run_test_inner();
kill_servers()?;
@ -109,20 +122,24 @@ pub fn run_test_inner() -> HarnessResult<()> {
}
// build skyd
info!("Building server binary ...");
util::handle_child("build skyd", build_cmd)?;
let s1_cmd = get_run_server_cmd("server1", &cmd);
let s2_cmd = get_run_server_cmd("server2", &cmd);
// start the servers, run tests and kill
info!("Starting servers ...");
let s1_cmd = get_run_server_cmd("server1", &cmd);
let s2_cmd = get_run_server_cmd("server2", &cmd);
let (_s1, _s2) = start_servers(s1_cmd, s2_cmd)?;
info!("All servers started. Now running standard test suite ...");
util::handle_child("standard test suite", standard_test_suite)?;
kill_servers()?;
// start server up again, run tests and kill
info!("Starting servers ...");
let s1_cmd = get_run_server_cmd("server1", &cmd);
let s2_cmd = get_run_server_cmd("server2", &cmd);
let (_s1, _s2) = start_servers(s1_cmd, s2_cmd)?;
info!("All servers started. Now running persistence test suite ...");
util::handle_child("standard test suite", persist_test_suite)?;
Ok(())

Loading…
Cancel
Save