Files
pezkuwi-subxt/polkadot/tests/benchmark_block_works.rs
T
Oliver Tale-Yazdi 08163de073 Co #11164: Sub-commands for benchmark (#5247)
* Restructure benchmark commands

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add benchmark storage test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* cargo update -p sp-io

* Revert "cargo update -p sp-io"

This reverts commit c321b570cef806934acfb7e1a18f543a681b9927.

* cargo update -p sp-io

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* update lockfile for {"substrate"}

* remove `useless_attribute`

* Remove rococo-native cfg

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make cumulus build

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix benchmark commands for the CI

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make cumulus build

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make cumulus build

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Disable new bench commands for rococo

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make cumulus build

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: parity-processbot <>
2022-04-07 22:29:16 +00:00

88 lines
2.9 KiB
Rust

// Copyright 2022 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot 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.
// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.
// Unix only since it uses signals.
#![cfg(unix)]
use assert_cmd::cargo::cargo_bin;
use nix::{
sys::signal::{kill, Signal::SIGINT},
unistd::Pid,
};
use std::{path::Path, process::Command, result::Result, time::Duration};
use tempfile::tempdir;
pub mod common;
static RUNTIMES: [&'static str; 3] = ["polkadot", "kusama", "westend"];
/// `benchmark block` works for all dev runtimes using the wasm executor.
#[tokio::test]
async fn benchmark_block_works() {
for runtime in RUNTIMES {
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.unwrap();
// Benchmark the that one.
benchmark_block(&runtime, base_path, 1).unwrap();
}
}
/// Builds a chain with one block for the given runtime and base path.
async fn build_chain(runtime: &str, base_path: &Path) -> Result<(), String> {
let mut cmd = Command::new(cargo_bin("polkadot"))
.args(["--chain", &runtime, "--force-authoring", "--alice"])
.arg("-d")
.arg(base_path)
.arg("--port")
.arg("33034")
.spawn()
.unwrap();
// Wait for the chain to produce one block.
let ok = common::wait_n_finalized_blocks(1, Duration::from_secs(60)).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!(common::wait_for(&mut cmd, 30).map(|x| x.success()).unwrap_or_default());
ok.map_err(|e| format!("Node did not build the chain: {:?}", e))
}
/// 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("polkadot"))
.args(["benchmark", "block", "--chain", &runtime])
.arg("-d")
.arg(base_path)
.args(["--pruning", "archive"])
.args(["--from", &block.to_string(), "--to", &block.to_string()])
.args(["--repeat", "1"])
.args(["--execution", "wasm", "--wasm-execution", "compiled"])
.status()
.map_err(|e| format!("command failed: {:?}", e))?;
if !status.success() {
return Err("Command failed".into())
}
Ok(())
}