Skip to content

Commit

Permalink
Fix sporadic test failure (#12140)
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <[email protected]>

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez authored Aug 30, 2022
1 parent 5cdb054 commit ca1f81c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frame/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sp-storage = { version = "6.0.0", default-features = false, path = "../../primit

[dev-dependencies]
hex-literal = "0.3.4"
rusty-fork = { version = "0.3.0", default-features = false }
sp-keystore = { version = "0.12.0", path = "../../primitives/keystore" }

[features]
Expand Down
42 changes: 24 additions & 18 deletions frame/benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ mod benchmarks {
use crate::{account, BenchmarkError, BenchmarkParameter, BenchmarkResult, BenchmarkingSetup};
use frame_support::{assert_err, assert_ok, ensure, traits::Get};
use frame_system::RawOrigin;
use rusty_fork::rusty_fork_test;
use sp_std::prelude::*;

// Additional used internally by the benchmark macro.
Expand Down Expand Up @@ -409,24 +410,29 @@ mod benchmarks {
});
}

/// Test that the benchmarking uses the correct values for each component and
/// that the number of components can be controlled with `VALUES_PER_COMPONENT`.
#[test]
fn test_values_per_component() {
let tests = vec![
(Some("1"), Err("`VALUES_PER_COMPONENT` must be at least 2".into())),
(Some("asdf"), Err("Could not parse env var `VALUES_PER_COMPONENT` as u32.".into())),
(None, Ok(vec![0, 2, 4, 6, 8, 10])),
(Some("2"), Ok(vec![0, 10])),
(Some("4"), Ok(vec![0, 3, 6, 10])),
(Some("6"), Ok(vec![0, 2, 4, 6, 8, 10])),
(Some("10"), Ok(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 10])),
(Some("11"), Ok(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])),
(Some("99"), Ok(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])),
];

for (num, expected) in tests {
run_test_values_per_component(num, expected);
rusty_fork_test! {
/// Test that the benchmarking uses the correct values for each component and
/// that the number of components can be controlled with `VALUES_PER_COMPONENT`.
///
/// NOTE: This test needs to run in its own process, since it
/// otherwise messes up the env variable for the other tests.
#[test]
fn test_values_per_component() {
let tests = vec![
(Some("1"), Err("`VALUES_PER_COMPONENT` must be at least 2".into())),
(Some("asdf"), Err("Could not parse env var `VALUES_PER_COMPONENT` as u32.".into())),
(None, Ok(vec![0, 2, 4, 6, 8, 10])),
(Some("2"), Ok(vec![0, 10])),
(Some("4"), Ok(vec![0, 3, 6, 10])),
(Some("6"), Ok(vec![0, 2, 4, 6, 8, 10])),
(Some("10"), Ok(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 10])),
(Some("11"), Ok(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])),
(Some("99"), Ok(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])),
];

for (num, expected) in tests {
run_test_values_per_component(num, expected);
}
}
}

Expand Down

0 comments on commit ca1f81c

Please sign in to comment.