mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 05:37:58 +00:00
Always wipe DB state after benchmark (#12025)
* Add test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Always wipe the DB state Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Silence Clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
committed by
GitHub
parent
a68a80fbae
commit
a467983398
@@ -125,6 +125,8 @@ fn new_test_ext() -> sp_io::TestExternalities {
|
||||
GenesisConfig::default().build_storage().unwrap().into()
|
||||
}
|
||||
|
||||
// NOTE: This attribute is only needed for the `modify_in_` functions.
|
||||
#[allow(unreachable_code)]
|
||||
mod benchmarks {
|
||||
use super::{new_test_ext, pallet_test::Value, Test};
|
||||
use crate::{account, BenchmarkError, BenchmarkParameter, BenchmarkResult, BenchmarkingSetup};
|
||||
@@ -227,6 +229,24 @@ mod benchmarks {
|
||||
// This should never be reached.
|
||||
assert!(value > 100);
|
||||
}
|
||||
|
||||
modify_in_setup_then_error {
|
||||
Value::<T>::set(Some(123));
|
||||
return Err(BenchmarkError::Stop("Should error"));
|
||||
}: { }
|
||||
|
||||
modify_in_call_then_error {
|
||||
}: {
|
||||
Value::<T>::set(Some(123));
|
||||
return Err(BenchmarkError::Stop("Should error"));
|
||||
}
|
||||
|
||||
modify_in_verify_then_error {
|
||||
}: {
|
||||
} verify {
|
||||
Value::<T>::set(Some(123));
|
||||
return Err(BenchmarkError::Stop("Should error"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -350,4 +370,28 @@ mod benchmarks {
|
||||
assert_eq!(Pallet::<Test>::test_benchmark_skip_benchmark(), Err(BenchmarkError::Skip),);
|
||||
});
|
||||
}
|
||||
|
||||
/// An error return of a benchmark test function still causes the db to be wiped.
|
||||
#[test]
|
||||
fn benchmark_error_wipes_storage() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// It resets when the error happens in the setup:
|
||||
assert_err!(
|
||||
Pallet::<Test>::test_benchmark_modify_in_setup_then_error(),
|
||||
"Should error"
|
||||
);
|
||||
assert_eq!(Value::<Test>::get(), None);
|
||||
|
||||
// It resets when the error happens in the call:
|
||||
assert_err!(Pallet::<Test>::test_benchmark_modify_in_call_then_error(), "Should error");
|
||||
assert_eq!(Value::<Test>::get(), None);
|
||||
|
||||
// It resets when the error happens in the verify:
|
||||
assert_err!(
|
||||
Pallet::<Test>::test_benchmark_modify_in_verify_then_error(),
|
||||
"Should error"
|
||||
);
|
||||
assert_eq!(Value::<Test>::get(), None);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user