feat: initialize Kurdistan SDK - independent fork of Polkadot SDK
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezkuwi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Unix only since it uses signals.
|
||||
#![cfg(unix)]
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use common::run_with_timeout;
|
||||
use nix::{
|
||||
sys::signal::{kill, Signal::SIGINT},
|
||||
unistd::Pid,
|
||||
};
|
||||
use std::{
|
||||
path::Path,
|
||||
process::{self, Command},
|
||||
result::Result,
|
||||
time::Duration,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
|
||||
pub mod common;
|
||||
|
||||
static RUNTIMES: &[&str] = &["zagros", "pezkuwichain"];
|
||||
|
||||
/// `benchmark block` works for all dev runtimes using the wasm executor.
|
||||
#[tokio::test]
|
||||
async fn benchmark_block_works() {
|
||||
for runtime in RUNTIMES {
|
||||
run_with_timeout(Duration::from_secs(10 * 60), async move {
|
||||
let tmp_dir = tempdir().expect("could not create a temp dir");
|
||||
let base_path = tmp_dir.path();
|
||||
let runtime = format!("{}-dev", runtime);
|
||||
|
||||
// Build a chain with a single block.
|
||||
build_chain(&runtime, base_path).await;
|
||||
// Benchmark the one block.
|
||||
benchmark_block(&runtime, base_path, 1).unwrap();
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds a chain with one block for the given runtime and base path.
|
||||
async fn build_chain(runtime: &str, base_path: &Path) {
|
||||
let mut cmd = Command::new(cargo_bin("pezkuwi"))
|
||||
.stdout(process::Stdio::piped())
|
||||
.stderr(process::Stdio::piped())
|
||||
.args([
|
||||
"--chain",
|
||||
runtime,
|
||||
"--force-authoring",
|
||||
"--alice",
|
||||
"--unsafe-force-node-key-generation",
|
||||
])
|
||||
.arg("-d")
|
||||
.arg(base_path)
|
||||
.arg("--no-hardware-benchmarks")
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
let (ws_url, _) = common::find_ws_url_from_output(cmd.stderr.take().unwrap());
|
||||
|
||||
// Wait for the chain to produce one block.
|
||||
common::wait_n_finalized_blocks(1, &ws_url).await;
|
||||
// Send SIGINT to node.
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
|
||||
assert!(cmd.wait().unwrap().success());
|
||||
}
|
||||
|
||||
/// Benchmarks the given block with the wasm executor.
|
||||
fn benchmark_block(runtime: &str, base_path: &Path, block: u32) -> Result<(), String> {
|
||||
// Invoke `benchmark block` with all options to make sure that they are valid.
|
||||
let status = Command::new(cargo_bin("pezkuwi"))
|
||||
.args(["benchmark", "block", "--chain", runtime])
|
||||
.arg("-d")
|
||||
.arg(base_path)
|
||||
.args(["--from", &block.to_string(), "--to", &block.to_string()])
|
||||
.args(["--repeat", "1"])
|
||||
.args(["--wasm-execution", "compiled"])
|
||||
.status()
|
||||
.map_err(|e| format!("command failed: {:?}", e))?;
|
||||
|
||||
if !status.success() {
|
||||
return Err("Command failed".into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezkuwi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::{process::Command, result::Result};
|
||||
|
||||
static RUNTIMES: &[&str] = &["zagros", "pezkuwichain"];
|
||||
|
||||
static EXTRINSICS: [(&str, &str); 2] = [("system", "remark"), ("balances", "transfer_keep_alive")];
|
||||
|
||||
/// `benchmark extrinsic` works for all dev runtimes and some extrinsics.
|
||||
#[test]
|
||||
fn benchmark_extrinsic_works() {
|
||||
for runtime in RUNTIMES {
|
||||
for (pallet, extrinsic) in EXTRINSICS {
|
||||
let runtime = format!("{}-dev", runtime);
|
||||
assert!(benchmark_extrinsic(&runtime, pallet, extrinsic).is_ok());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `benchmark extrinsic` rejects all non-dev runtimes.
|
||||
#[test]
|
||||
fn benchmark_extrinsic_rejects_non_dev_runtimes() {
|
||||
for runtime in RUNTIMES {
|
||||
assert!(benchmark_extrinsic(runtime, "system", "remark").is_err());
|
||||
}
|
||||
}
|
||||
|
||||
fn benchmark_extrinsic(runtime: &str, pallet: &str, extrinsic: &str) -> Result<(), String> {
|
||||
let status = Command::new(cargo_bin("pezkuwi"))
|
||||
.args(["benchmark", "extrinsic", "--chain", runtime])
|
||||
.args(["--pallet", pallet, "--extrinsic", extrinsic])
|
||||
// Run with low repeats for faster execution.
|
||||
.args(["--repeat=1", "--warmup=1", "--max-ext-per-block=1"])
|
||||
.status()
|
||||
.map_err(|e| format!("command failed: {:?}", e))?;
|
||||
|
||||
if !status.success() {
|
||||
return Err("Command failed".into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezkuwi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::{process::Command, result::Result};
|
||||
use tempfile::tempdir;
|
||||
|
||||
static RUNTIMES: &[&str] = &["zagros", "pezkuwichain"];
|
||||
|
||||
/// `benchmark overhead` works for all dev runtimes.
|
||||
#[test]
|
||||
fn benchmark_overhead_works() {
|
||||
for runtime in RUNTIMES {
|
||||
let runtime = format!("{}-dev", runtime);
|
||||
assert!(benchmark_overhead(&runtime).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
fn benchmark_overhead(runtime: &str) -> Result<(), String> {
|
||||
let tmp_dir = tempdir().expect("could not create a temp dir");
|
||||
let base_path = tmp_dir.path();
|
||||
|
||||
// Invoke `benchmark overhead` with all options to make sure that they are valid.
|
||||
let status = Command::new(cargo_bin("pezkuwi"))
|
||||
.args(["benchmark", "overhead", "--chain", &runtime])
|
||||
.arg("-d")
|
||||
.arg(base_path)
|
||||
.arg("--weight-path")
|
||||
.arg(base_path)
|
||||
.args(["--warmup", "5", "--repeat", "5"])
|
||||
.args(["--add", "100", "--mul", "1.2", "--metric", "p75"])
|
||||
// Only put 5 extrinsics into the block otherwise it takes forever to build it
|
||||
// especially for a non-release builds.
|
||||
.args(["--max-ext-per-block", "5"])
|
||||
.status()
|
||||
.map_err(|e| format!("command failed: {:?}", e))?;
|
||||
|
||||
if !status.success() {
|
||||
return Err("Command failed".into());
|
||||
}
|
||||
|
||||
// Weight files have been created.
|
||||
assert!(base_path.join("block_weights.rs").exists());
|
||||
assert!(base_path.join("extrinsic_weights.rs").exists());
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezkuwi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::{
|
||||
path::Path,
|
||||
process::{Command, ExitStatus},
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
|
||||
/// The `benchmark storage` command works for the dev runtime.
|
||||
#[test]
|
||||
fn benchmark_storage_works() {
|
||||
let tmp_dir = tempdir().expect("could not create a temp dir");
|
||||
let base_path = tmp_dir.path();
|
||||
|
||||
// Benchmarking the storage works and creates the weight file.
|
||||
assert!(benchmark_storage("rocksdb", base_path).success());
|
||||
assert!(base_path.join("rocksdb_weights.rs").exists());
|
||||
|
||||
assert!(benchmark_storage("paritydb", base_path).success());
|
||||
assert!(base_path.join("paritydb_weights.rs").exists());
|
||||
}
|
||||
|
||||
/// Invoke the `benchmark storage` sub-command.
|
||||
fn benchmark_storage(db: &str, base_path: &Path) -> ExitStatus {
|
||||
Command::new(cargo_bin("pezkuwi"))
|
||||
.args(["benchmark", "storage", "--dev"])
|
||||
.arg("--db")
|
||||
.arg(db)
|
||||
.arg("--weight-path")
|
||||
.arg(base_path)
|
||||
.args(["--state-version", "0"])
|
||||
.args(["--batch-size", "1"])
|
||||
.args(["--warmups", "0"])
|
||||
.args(["--add", "100", "--mul", "1.2", "--metric", "p75"])
|
||||
.status()
|
||||
.unwrap()
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezkuwi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use pezkuwi_core_primitives::{Block, Hash, Header};
|
||||
use std::{
|
||||
future::Future,
|
||||
io::{BufRead, BufReader, Read},
|
||||
time::Duration,
|
||||
};
|
||||
use substrate_rpc_client::{ws_client, ChainApi};
|
||||
|
||||
/// Run the given `future` and panic if the `timeout` is hit.
|
||||
pub async fn run_with_timeout(timeout: Duration, future: impl Future<Output = ()>) {
|
||||
tokio::time::timeout(timeout, future).await.expect("Hit timeout");
|
||||
}
|
||||
|
||||
/// Wait for at least `n` blocks to be finalized from a specified node.
|
||||
pub async fn wait_n_finalized_blocks(n: usize, url: &str) {
|
||||
let mut built_blocks = std::collections::HashSet::new();
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(6));
|
||||
|
||||
loop {
|
||||
let Ok(rpc) = ws_client(url).await else { continue };
|
||||
|
||||
if let Ok(block) = ChainApi::<(), Hash, Header, Block>::finalized_head(&rpc).await {
|
||||
built_blocks.insert(block);
|
||||
if built_blocks.len() > n {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
interval.tick().await;
|
||||
}
|
||||
}
|
||||
|
||||
/// Read the WS address from the output.
|
||||
///
|
||||
/// This is hack to get the actual bound sockaddr because
|
||||
/// pezkuwi assigns a random port if the specified port was already bound.
|
||||
///
|
||||
/// You must call
|
||||
/// `Command::new("cmd").stdout(process::Stdio::piped()).stderr(process::Stdio::piped())`
|
||||
/// for this to work.
|
||||
pub fn find_ws_url_from_output(read: impl Read + Send) -> (String, String) {
|
||||
let mut data = String::new();
|
||||
|
||||
let ws_url = BufReader::new(read)
|
||||
.lines()
|
||||
.find_map(|line| {
|
||||
let line = line.expect("failed to obtain next line from stdout for port discovery");
|
||||
|
||||
data.push_str(&line);
|
||||
|
||||
// does the line contain our port (we expect this specific output from substrate).
|
||||
let sock_addr = match line.split_once("Running JSON-RPC server: addr=") {
|
||||
None => return None,
|
||||
Some((_, after)) => after.split_once(',').unwrap().0,
|
||||
};
|
||||
|
||||
Some(format!("ws://{}", sock_addr))
|
||||
})
|
||||
.unwrap_or_else(|| panic!("Could not find address in process output:\n{}", &data));
|
||||
(ws_url, data)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezkuwi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::process::Command;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn invalid_order_arguments() {
|
||||
let tmpdir = tempdir().expect("could not create temp dir");
|
||||
|
||||
let status = Command::new(cargo_bin("pezkuwi"))
|
||||
.args(["--dev", "invalid_order_arguments", "-d"])
|
||||
.arg(tmpdir.path())
|
||||
.arg("-y")
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(!status.success());
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezkuwi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![cfg(unix)]
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use common::run_with_timeout;
|
||||
use nix::{
|
||||
sys::signal::{kill, Signal::SIGINT},
|
||||
unistd::Pid,
|
||||
};
|
||||
use std::{
|
||||
process::{self, Command},
|
||||
time::Duration,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
|
||||
pub mod common;
|
||||
|
||||
#[tokio::test]
|
||||
async fn purge_chain_rocksdb_works() {
|
||||
run_with_timeout(Duration::from_secs(10 * 60), async move {
|
||||
let tmpdir = tempdir().expect("could not create temp dir");
|
||||
|
||||
let mut cmd = Command::new(cargo_bin("pezkuwi"))
|
||||
.stdout(process::Stdio::piped())
|
||||
.stderr(process::Stdio::piped())
|
||||
.args(["--dev", "-d"])
|
||||
.arg(tmpdir.path())
|
||||
.arg("--port")
|
||||
.arg("33034")
|
||||
.arg("--no-hardware-benchmarks")
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
let (ws_url, _) = common::find_ws_url_from_output(cmd.stderr.take().unwrap());
|
||||
|
||||
// Let it produce 1 block.
|
||||
common::wait_n_finalized_blocks(1, &ws_url).await;
|
||||
|
||||
// Send SIGINT to node.
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
|
||||
// Wait for the node to handle it and exit.
|
||||
assert!(cmd.wait().unwrap().success());
|
||||
assert!(tmpdir.path().join("chains/pezkuwichain_dev").exists());
|
||||
assert!(tmpdir.path().join("chains/pezkuwichain_dev/db/full").exists());
|
||||
|
||||
// Purge chain
|
||||
let status = Command::new(cargo_bin("pezkuwi"))
|
||||
.args(["purge-chain", "--dev", "-d"])
|
||||
.arg(tmpdir.path())
|
||||
.arg("-y")
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(status.success());
|
||||
|
||||
// Make sure that the chain folder exists, but `db/full` is deleted.
|
||||
assert!(tmpdir.path().join("chains/pezkuwichain_dev").exists());
|
||||
assert!(!tmpdir.path().join("chains/pezkuwichain_dev/db/full").exists());
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn purge_chain_paritydb_works() {
|
||||
run_with_timeout(Duration::from_secs(10 * 60), async move {
|
||||
let tmpdir = tempdir().expect("could not create temp dir");
|
||||
|
||||
let mut cmd = Command::new(cargo_bin("pezkuwi"))
|
||||
.stdout(process::Stdio::piped())
|
||||
.stderr(process::Stdio::piped())
|
||||
.args(["--dev", "-d"])
|
||||
.arg(tmpdir.path())
|
||||
.arg("--database")
|
||||
.arg("paritydb-experimental")
|
||||
.arg("--no-hardware-benchmarks")
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
let (ws_url, _) = common::find_ws_url_from_output(cmd.stderr.take().unwrap());
|
||||
|
||||
// Let it produce 1 block.
|
||||
common::wait_n_finalized_blocks(1, &ws_url).await;
|
||||
|
||||
// Send SIGINT to node.
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
|
||||
// Wait for the node to handle it and exit.
|
||||
assert!(cmd.wait().unwrap().success());
|
||||
assert!(tmpdir.path().join("chains/pezkuwichain_dev").exists());
|
||||
assert!(tmpdir.path().join("chains/pezkuwichain_dev/paritydb/full").exists());
|
||||
|
||||
// Purge chain
|
||||
let status = Command::new(cargo_bin("pezkuwi"))
|
||||
.args(["purge-chain", "--dev", "-d"])
|
||||
.arg(tmpdir.path())
|
||||
.arg("--database")
|
||||
.arg("paritydb-experimental")
|
||||
.arg("-y")
|
||||
.status()
|
||||
.unwrap();
|
||||
assert!(status.success());
|
||||
|
||||
// Make sure that the chain folder exists, but `db/full` is deleted.
|
||||
assert!(tmpdir.path().join("chains/pezkuwichain_dev").exists());
|
||||
assert!(!tmpdir.path().join("chains/pezkuwichain_dev/paritydb/full").exists());
|
||||
})
|
||||
.await;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezkuwi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::process::{self, Command};
|
||||
use tempfile::tempdir;
|
||||
|
||||
pub mod common;
|
||||
|
||||
#[tokio::test]
|
||||
#[cfg(unix)]
|
||||
async fn running_the_node_works_and_can_be_interrupted() {
|
||||
use nix::{
|
||||
sys::signal::{
|
||||
kill,
|
||||
Signal::{self, SIGINT, SIGTERM},
|
||||
},
|
||||
unistd::Pid,
|
||||
};
|
||||
|
||||
async fn run_command_and_kill(signal: Signal) {
|
||||
let tmpdir = tempdir().expect("could not create temp dir");
|
||||
|
||||
let mut cmd = Command::new(cargo_bin("pezkuwi"))
|
||||
.stdout(process::Stdio::piped())
|
||||
.stderr(process::Stdio::piped())
|
||||
.args(["--dev", "-d"])
|
||||
.arg(tmpdir.path())
|
||||
.arg("--no-hardware-benchmarks")
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
let (ws_url, _) = common::find_ws_url_from_output(cmd.stderr.take().unwrap());
|
||||
|
||||
// Let it produce three blocks.
|
||||
common::wait_n_finalized_blocks(3, &ws_url).await;
|
||||
|
||||
assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running");
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), signal).unwrap();
|
||||
assert!(
|
||||
cmd.wait().unwrap().success(),
|
||||
"the process must exit gracefully after signal {signal}",
|
||||
);
|
||||
}
|
||||
|
||||
run_command_and_kill(SIGINT).await;
|
||||
run_command_and_kill(SIGTERM).await;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Pezkuwi.
|
||||
|
||||
// Pezkuwi is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Pezkuwi is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Pezkuwi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use pezkuwi_cli::NODE_VERSION;
|
||||
use std::process::Command;
|
||||
|
||||
const PREPARE_WORKER_EXE: &str = env!("CARGO_BIN_EXE_pezkuwi-prepare-worker");
|
||||
const EXECUTE_WORKER_EXE: &str = env!("CARGO_BIN_EXE_pezkuwi-execute-worker");
|
||||
|
||||
#[test]
|
||||
fn worker_binaries_have_same_version_as_node() {
|
||||
let prep_worker_version =
|
||||
Command::new(&PREPARE_WORKER_EXE).args(["--version"]).output().unwrap().stdout;
|
||||
let prep_worker_version = std::str::from_utf8(&prep_worker_version)
|
||||
.expect("version is printed as a string; qed")
|
||||
.trim();
|
||||
assert_eq!(prep_worker_version, NODE_VERSION);
|
||||
|
||||
let exec_worker_version =
|
||||
Command::new(&EXECUTE_WORKER_EXE).args(["--version"]).output().unwrap().stdout;
|
||||
let exec_worker_version = std::str::from_utf8(&exec_worker_version)
|
||||
.expect("version is printed as a string; qed")
|
||||
.trim();
|
||||
assert_eq!(exec_worker_version, NODE_VERSION);
|
||||
}
|
||||
Reference in New Issue
Block a user