Skip to content

Commit

Permalink
perf-test filtering and add txpool test (#966)
Browse files Browse the repository at this point in the history
* Add --tests switch to filter tests

* cargo fmt
  • Loading branch information
notlesh authored Nov 6, 2021
1 parent e7b3bdc commit a5f0e9b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions node/perf-test/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,19 @@ impl PerfCmd {

let mut all_test_results: Vec<TestResults> = Default::default();

let (have_filter, enabled_tests) = if let Some(filter) = &cmd.tests {
let enabled_tests: Vec<&str> = filter.split(',').collect();
(true, enabled_tests)
} else {
(false, Default::default())
};

for mut test in tests {
if have_filter {
if !enabled_tests.contains(&test.name().as_str()) {
continue;
}
}
let mut results: Vec<TestResults> = (*test.run(&runner)?).to_vec();
all_test_results.append(&mut results);
}
Expand Down
7 changes: 7 additions & 0 deletions node/perf-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ pub struct PerfCmd {
help = "File where results should be printed (STDOUT if omitted)."
)]
pub output_file: Option<PathBuf>,

// TODO: allow multiple tests (like the -l switch for logging)
#[structopt(
long = "tests",
help = "Comma-separated list of tests to run (if omitted, runs all tests)"
)]
pub tests: Option<String>,
}
4 changes: 4 additions & 0 deletions node/perf-test/src/tests/block_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ where
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
Executor: NativeExecutionDispatch + 'static,
{
fn name(&self) -> String {
"block_creation".into()
}

fn run(
&mut self,
context: &TestContext<RuntimeApi, Executor>,
Expand Down
4 changes: 4 additions & 0 deletions node/perf-test/src/tests/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ where
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
Executor: NativeExecutionDispatch + 'static,
{
fn name(&self) -> String {
"fibonacci".into()
}

fn run(
&mut self,
context: &TestContext<RuntimeApi, Executor>,
Expand Down
5 changes: 5 additions & 0 deletions node/perf-test/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ where
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
Executor: NativeExecutionDispatch + 'static,
{
/// Return a globally unique name for this test. This is used as a filter on the command line
/// so a CLI-friendly name is preferred.
fn name(&self) -> String;

/// Run the test
fn run(
&mut self,
context: &TestContext<RuntimeApi, Executor>,
Expand Down
4 changes: 4 additions & 0 deletions node/perf-test/src/tests/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ where
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
Executor: NativeExecutionDispatch + 'static,
{
fn name(&self) -> String {
"storage".into()
}

fn run(
&mut self,
context: &TestContext<RuntimeApi, Executor>,
Expand Down

0 comments on commit a5f0e9b

Please sign in to comment.