Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Do not run slow running try state tests in CI #13286

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl ExtBuilder {
let mut ext = self.build();
ext.execute_with(test);
ext.execute_with(|| {
Staking::do_try_state(System::block_number()).unwrap();
Staking::do_try_state(System::block_number(), TestMode::All).unwrap();
});
}
}
Expand Down
22 changes: 19 additions & 3 deletions frame/staking/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,19 +1668,35 @@ impl<T: Config> StakingInterface for Pallet<T> {
}
}

#[cfg(any(test, feature = "try-runtime"))]
#[derive(PartialEq)]
pub(crate) enum TestMode {
// run only fast running tests
Fast,
// run all the tests
All,
}

#[cfg(any(test, feature = "try-runtime"))]
impl<T: Config> Pallet<T> {
pub(crate) fn do_try_state(_: BlockNumberFor<T>) -> Result<(), &'static str> {
pub(crate) fn do_try_state(_: BlockNumberFor<T>, mode: TestMode) -> Result<(), &'static str> {
// fast tests
ensure!(
T::VoterList::iter()
.all(|x| <Nominators<T>>::contains_key(&x) || <Validators<T>>::contains_key(&x)),
"VoterList contains non-staker"
);

Self::check_nominators()?;
Self::check_exposures()?;
Self::check_ledgers()?;
Self::check_count()
Self::check_count()?;

if mode == TestMode::All {
// slow running tests (should be avoided on CI)
Self::check_nominators()?;
}

Ok(())
}

fn check_count() -> Result<(), &'static str> {
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ pub mod pallet {

#[cfg(feature = "try-runtime")]
fn try_state(n: BlockNumberFor<T>) -> Result<(), &'static str> {
Self::do_try_state(n)
Self::do_try_state(n, TestMode::Fast)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should support passing data into try_state so that we can run the full tests manually without code change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we should look into how we want to do this across pallets and have a way to run full test manually probably as an arg to on-runtime-upgrade instead of having to change code.

}
}

Expand Down