Skip to content

Commit

Permalink
Use temporary db for benchmarking (paritytech#12254)
Browse files Browse the repository at this point in the history
* Use temporary db for benchmarking

If no db option was given benchmarks shall use temporary database.
Otherwise the test can use locally stored database which maybe
out-of-date causing test to fail.

* nicer syntax

* explanatory comment added

* Update utils/frame/benchmarking-cli/src/lib.rs

Co-authored-by: Bastian Köcher <info@kchr.de>
  • Loading branch information
2 people authored and ark0f committed Feb 27, 2023
1 parent c8035d4 commit 341d62c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions utils/frame/benchmarking-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub use extrinsic::{ExtrinsicBuilder, ExtrinsicCmd, ExtrinsicFactory};
pub use machine::{MachineCmd, Requirements, SUBSTRATE_REFERENCE_HARDWARE};
pub use overhead::OverheadCmd;
pub use pallet::PalletCmd;
pub use sc_service::BasePath;
pub use storage::StorageCmd;

use sc_cli::{CliConfiguration, DatabaseParams, ImportParams, PruningParams, Result, SharedParams};
Expand Down Expand Up @@ -87,6 +88,19 @@ impl CliConfiguration for BenchmarkCmd {
}
}

fn base_path(&self) -> Result<Option<BasePath>> {
let inner = unwrap_cmd! {
self, cmd, cmd.base_path()
};

// If the base path was not provided, benchmark command shall use temporary path. Otherwise
// we may end up using shared path, which may be inappropriate for benchmarking.
match inner {
Ok(None) => Some(BasePath::new_temp_dir()).transpose().map_err(|e| e.into()),
e => e,
}
}

fn pruning_params(&self) -> Option<&PruningParams> {
unwrap_cmd! {
self, cmd, cmd.pruning_params()
Expand Down

0 comments on commit 341d62c

Please sign in to comment.