Wait for servers to start/shut down instead of waiting blindly

next
Sayan Nandan 3 years ago
parent d306307fd8
commit 6234018077
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -33,7 +33,7 @@ jobs:
os: macos-latest
artifact: x86_64-macos
- rust: x86_64-pc-windows-msvc
os: windows-2019
os: windows-latest
artifact: x86_64-windows
env:
RUST_BACKTRACE: 1
@ -79,12 +79,12 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-2019]
os: [ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
rust: i686-unknown-linux-gnu
artifact: i686-linux-gnu
- os: windows-2019
- os: windows-latest
artifact: i686-windows
rust: i686-pc-windows-msvc

@ -20,7 +20,7 @@ jobs:
os: macos-latest
rust: stable
- build: windows-stable
os: windows-2019
os: windows-latest
rust: stable
steps:

@ -23,13 +23,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
rust: x86_64-unknown-linux-gnu
- os: macos-latest
rust: x86_64-apple-darwin
- os: windows-2019
- os: windows-latest
rust: x86_64-pc-windows-msvc
steps:
@ -113,11 +113,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-2019]
os: [ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
rust: i686-unknown-linux-gnu
- os: windows-2019
- os: windows-latest
rust: i686-pc-windows-msvc
steps:
- name: Checkout source code

214
Cargo.lock generated

@ -8,6 +8,18 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aes"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
dependencies = [
"cfg-if",
"cipher 0.3.0",
"cpufeatures",
"opaque-debug",
]
[[package]]
name = "ahash"
version = "0.7.6"
@ -71,6 +83,12 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "base64ct"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b"
[[package]]
name = "bb8"
version = "0.7.1"
@ -99,6 +117,15 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "block-buffer"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
dependencies = [
"generic-array",
]
[[package]]
name = "blowfish"
version = "0.9.1"
@ -106,7 +133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7"
dependencies = [
"byteorder",
"cipher",
"cipher 0.4.3",
]
[[package]]
@ -147,6 +174,9 @@ name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
dependencies = [
"jobserver",
]
[[package]]
name = "cfg-if"
@ -163,10 +193,19 @@ dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"time 0.1.44",
"winapi",
]
[[package]]
name = "cipher"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7"
dependencies = [
"generic-array",
]
[[package]]
name = "cipher"
version = "0.4.3"
@ -204,12 +243,27 @@ dependencies = [
"winapi",
]
[[package]]
name = "constant_time_eq"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "core-foundation-sys"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "cpufeatures"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b"
dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.3.2"
@ -305,6 +359,17 @@ version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907339959a92f6b98846570500c0a567c9aecbb3871cef00561eb5d20d47b7c1"
[[package]]
name = "digest"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [
"block-buffer",
"crypto-common",
"subtle",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
@ -491,6 +556,7 @@ dependencies = [
"log",
"openssl",
"powershell_script",
"skytable 0.7.0-alpha.4 (git+https://github.com/skytable/client-rust.git)",
"zip",
]
@ -512,6 +578,15 @@ dependencies = [
"libc",
]
[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest",
]
[[package]]
name = "humantime"
version = "2.1.0"
@ -569,6 +644,15 @@ dependencies = [
"libc",
]
[[package]]
name = "jobserver"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa"
dependencies = [
"libc",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -744,12 +828,27 @@ dependencies = [
"libc",
]
[[package]]
name = "num_threads"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aba1801fb138d8e85e11d0fc70baf4fe1cdfffda7c6cd34a854905df588e5ed0"
dependencies = [
"libc",
]
[[package]]
name = "once_cell"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]]
name = "opaque-debug"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "openssl"
version = "0.10.38"
@ -835,6 +934,29 @@ dependencies = [
"windows-sys 0.32.0",
]
[[package]]
name = "password-hash"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d791538a6dcc1e7cb7fe6f6b58aca40e7f79403c45b2bc274008b5e647af1d8"
dependencies = [
"base64ct",
"rand_core",
"subtle",
]
[[package]]
name = "pbkdf2"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7"
dependencies = [
"digest",
"hmac",
"password-hash",
"sha2",
]
[[package]]
name = "pin-project-lite"
version = "0.2.8"
@ -1097,6 +1219,28 @@ dependencies = [
"serde",
]
[[package]]
name = "sha1"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "sha2"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "signal-hook"
version = "0.3.13"
@ -1277,6 +1421,12 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "subtle"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.89"
@ -1352,6 +1502,24 @@ dependencies = [
"winapi",
]
[[package]]
name = "time"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd"
dependencies = [
"itoa",
"libc",
"num_threads",
"time-macros",
]
[[package]]
name = "time-macros"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792"
[[package]]
name = "tokio"
version = "1.17.0"
@ -1589,14 +1757,48 @@ checksum = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992"
[[package]]
name = "zip"
version = "0.5.13"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815"
checksum = "e6fa4aa90e99fb8d701bda16fb040d8ed2f9c7176fb44de750e880a74b580315"
dependencies = [
"aes",
"byteorder",
"bzip2",
"constant_time_eq",
"crc32fast",
"flate2",
"thiserror",
"time",
"hmac",
"pbkdf2",
"sha1",
"time 0.3.9",
"zstd",
]
[[package]]
name = "zstd"
version = "0.10.0+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b1365becbe415f3f0fcd024e2f7b45bacfb5bdd055f0dc113571394114e7bdd"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-safe"
version = "4.1.4+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f7cd17c9af1a4d6c24beb1cc54b17e2ef7b593dc92f19e9d9acad8b182bbaee"
dependencies = [
"libc",
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "1.6.3+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc49afa5c8d634e75761feda8c592051e7eeb4683ba827211eb0d731d3402ea8"
dependencies = [
"cc",
"libc",
]

@ -6,5 +6,7 @@ test: .harness
@${RUN_HARNESS} test
bundle: .harness
@${RUN_HARNESS} bundle
bundle-dbg: .harness
@${RUN_HARNESS} bundle-dbg
deb: .harness
@${RUN_HARNESS} deb

@ -9,6 +9,9 @@ edition = "2021"
libsky = { path = "../libsky" }
env_logger = "0.9.0"
log = "0.4.16"
zip = { version = "0.5.13", features = ["deflate"] }
zip = { version = "0.6.0", features = ["deflate"] }
powershell_script = "0.3.2"
openssl = { version = "0.10.38", features = ["vendored"] }
skytable = { git = "https://github.com/skytable/client-rust.git", features = [
"sync",
], default-features = false }

@ -27,6 +27,7 @@
use crate::util;
use crate::HarnessResult;
use std::{path::PathBuf, process::Command};
use zip::CompressionMethod;
/// The binaries that will be present in a bundle
pub const BINARIES: [&str; 4] = ["skyd", "sky-bench", "skysh", "sky-migrate"];
@ -46,6 +47,13 @@ impl BuildMode {
BuildMode::Release => Some("--release"),
}
}
/// Returns the compression method for the build mode
pub const fn get_compression_method(&self) -> CompressionMethod {
match self {
BuildMode::Debug => CompressionMethod::Stored,
BuildMode::Release => CompressionMethod::Deflated,
}
}
}
impl ToString for BuildMode {

@ -72,14 +72,9 @@ fn package_binaries(target_folder: PathBuf, mode: BuildMode) -> HarnessResult<()
// create a temp buffer
let mut buffer = Vec::new();
// ZIP settings
let mut options = FileOptions::default().unix_permissions(0o755);
if mode == BuildMode::Debug {
// avoid compressing in debug since the binaries will be huge, so it's
// better to avoid wasting CI time
options = options.compression_method(zip::CompressionMethod::Stored);
} else {
options = options.compression_method(zip::CompressionMethod::Deflated);
}
let options = FileOptions::default()
.unix_permissions(0o755)
.compression_method(mode.get_compression_method());
for file in file_index {
let path = file.as_path();
let name = path.strip_prefix(Path::new(&target_folder)).unwrap();

@ -26,7 +26,7 @@
use crate::{
build::BuildMode,
util::{self, SLEEP_FOR_STARTUP, SLEEP_FOR_TERMINATION},
util::{self, SLEEP_FOR_TERMINATION},
HarnessError, HarnessResult,
};
use openssl::{
@ -41,13 +41,15 @@ use openssl::{
X509NameBuilder, X509,
},
};
use std::fs;
use std::io::Write;
use skytable::Connection;
#[cfg(windows)]
use std::os::windows::process::CommandExt;
use std::path::{Path, PathBuf};
use std::process::Child;
use std::process::Command;
use std::{
fs,
io::{Error as IoError, ErrorKind, Write},
path::{Path, PathBuf},
process::{Child, Command, Stdio},
};
/// The workspace root
const WORKSPACE_ROOT: &str = env!("ROOT_DIR");
@ -57,6 +59,10 @@ const POWERSHELL_SCRIPT: &str = include_str!("../../ci/windows/stop.ps1");
#[cfg(windows)]
/// Flag for new console Window
const CREATE_NEW_CONSOLE: u32 = 0x00000010;
/// The test suite server host
const TESTSUITE_SERVER_HOST: &str = "127.0.0.1";
/// The test suite server ports
const TESTSUITE_SERVER_PORTS: [u16; 4] = [2003, 2004, 2005, 2006];
/// Get the command to start the provided server1
pub fn get_run_server_cmd(server_id: &'static str, target_folder: impl AsRef<Path>) -> Command {
@ -73,14 +79,81 @@ pub fn get_run_server_cmd(server_id: &'static str, target_folder: impl AsRef<Pat
cmd
}
fn connection_refused<T>(input: Result<T, IoError>) -> HarnessResult<bool> {
match input {
Ok(_) => Ok(false),
Err(e) if e.kind().eq(&ErrorKind::ConnectionRefused) => Ok(true),
Err(e) => Err(HarnessError::Other(format!(
"Expected ConnectionRefused while checking for startup. Got error {e} instead"
))),
}
}
/// Waits for the servers to start up or errors if something unexpected happened
fn wait_for_startup() -> HarnessResult<()> {
info!("Waiting for servers to start up");
for port in TESTSUITE_SERVER_PORTS {
let connection_string = format!("{TESTSUITE_SERVER_HOST}:{port}");
let mut backoff = 1;
let mut con = Connection::new(TESTSUITE_SERVER_HOST, port);
while connection_refused(con)? {
if backoff > 64 {
// enough sleeping, return an error
error!("Server didn't respond in {backoff} seconds. Something is wrong");
return Err(HarnessError::Other(format!(
"Startup backoff elapsed. Server at {connection_string} did not respond."
)));
}
info!(
"Server at {connection_string} not started. Sleeping for {backoff} second(s) ..."
);
util::sleep_sec(backoff);
con = Connection::new(TESTSUITE_SERVER_HOST, port);
backoff *= 2;
}
info!("Server at {connection_string} has started");
}
info!("All servers started up");
Ok(())
}
/// Wait for the servers to shutdown, returning an error if something unexpected happens
fn wait_for_shutdown() -> HarnessResult<()> {
info!("Waiting for servers to shut down");
for port in TESTSUITE_SERVER_PORTS {
let connection_string = format!("{TESTSUITE_SERVER_HOST}:{port}");
let mut backoff = 1;
let mut con = Connection::new(TESTSUITE_SERVER_HOST, port);
while !connection_refused(con)? {
if backoff > 64 {
// enough sleeping, return an error
error!("Server didn't shut down within {backoff} seconds. Something is wrong");
return Err(HarnessError::Other(format!(
"Shutdown backoff elapsed. Server at {connection_string} did not shut down."
)));
}
info!(
"Server at {connection_string} still active. Sleeping for {backoff} second(s) ..."
);
util::sleep_sec(backoff);
con = Connection::new(TESTSUITE_SERVER_HOST, port);
backoff *= 2;
}
info!("Server at {connection_string} has stopped accepting connections");
}
info!("All servers have stopped accepting connections. Allowing {SLEEP_FOR_TERMINATION} seconds for them to exit");
util::sleep_sec(SLEEP_FOR_TERMINATION);
info!("All servers have shutdown");
Ok(())
}
/// Start the servers returning handles to the child processes
pub fn start_servers(s1_cmd: Command, s2_cmd: Command) -> HarnessResult<(Child, Child)> {
info!("Starting server1 ...");
let s1 = util::get_child("start server1", s1_cmd)?;
util::sleep_sec(SLEEP_FOR_STARTUP);
info!("Starting server2 ...");
let s2 = util::get_child("start server2", s2_cmd)?;
util::sleep_sec(SLEEP_FOR_STARTUP);
wait_for_startup()?;
Ok((s1, s2))
}
@ -89,7 +162,7 @@ fn kill_servers() -> HarnessResult<()> {
info!("Terminating server instances ...");
kill_servers_inner()?;
// sleep
util::sleep_sec(SLEEP_FOR_TERMINATION);
wait_for_shutdown()?;
Ok(())
}

@ -43,8 +43,7 @@ pub const VAR_ARTIFACT: &str = "ARTIFACT";
#[cfg(test)]
pub const VAR_ARTIFACT: &str = "ARTIFACT_TESTSUITE";
pub const WORKSPACE_ROOT: &str = env!("ROOT_DIR");
pub const SLEEP_FOR_STARTUP: u64 = 15;
pub const SLEEP_FOR_TERMINATION: u64 = 20;
pub const SLEEP_FOR_TERMINATION: u64 = 15;
pub fn get_var(var: &str) -> Option<String> {
env::var_os(var).map(|v| v.to_string_lossy().to_string())

@ -56,7 +56,17 @@ pub async fn snapshot_service(
loop {
tokio::select! {
_ = time::sleep_until(time::Instant::now() + duration) => {
if engine.mksnap(handle.clone_store()).await == 0 {
let succeeded = engine.mksnap(handle.clone_store()).await == 0;
#[cfg(test)]
{
use std::env::set_var;
if succeeded {
set_var("SKYTEST_SNAPSHOT_OKAY", "true");
} else {
set_var("SKYTEST_SNAPSHOT_OKAY", "false");
}
}
if succeeded {
// it passed, so unpoison the handle
registry::unpoison();
} else if failsafe {

Loading…
Cancel
Save