-
Notifications
You must be signed in to change notification settings - Fork 698
test: improve test loop builders #12995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fc4bbca
to
6f85247
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #12995 +/- ##
==========================================
- Coverage 69.68% 69.61% -0.07%
==========================================
Files 859 859
Lines 175699 175897 +198
Branches 175699 175897 +198
==========================================
+ Hits 122435 122451 +16
- Misses 48104 48282 +178
- Partials 5160 5164 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
6f85247
to
7451ee5
Compare
7451ee5
to
7b3091b
Compare
So, I took a detailed look at the epoch config builder and genesis builder and I have a couple of observations/suggestions
How about we make the following changes?
|
@@ -306,6 +307,12 @@ impl TestLoopBuilder { | |||
} | |||
} | |||
|
|||
// Creates TestLoop-compatible genesis builder | |||
pub(crate) fn new_genesis_builder() -> TestGenesisBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this additional function just for the call to genesis_time_from_clock
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this is needed to avoid copying .genesis_time_from_clock(&near_async::time::FakeClock::default().clock())
for every test loop test:
- code duplication is not nice
- forgetting that will result in very hard-to-debug test loop failure
The pattern would look something like this then...
We can even combine the last two steps to get something like this
|
@shreyan-gupta thanks for you suggestions, totally makes sense! I've updated the implementation, please take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you Anton
In a separate PR, should we consider replacing |
@shreyan-gupta yes, I would like to replace |
This PR replaces `build_genesis_and_epoch_config_store` with direct usage of builders introduced in #12995.
This PR introduces alternative way to configure genesis and epoch configs for test loop. Currently the most common way to do that is `build_genesis_and_epoch_config_store`. I have the following issues with it: * `GenesisAndEpochConfigParams` forces you to set values for parameters even if you are perfectly happy with `TestEpochConfigBuilder` defaults. This pollutes test setup because it is unclear which parameter values actually matter for the tests. * Callbacks to customise genesis and epoch config builders results in weird inversion of control. Also it just looks cumbersome for simple test setup. The alternative way is to derive epoch config builder from genesis state and use it directly. ``` let genesis = TestLoopBuilder::new_genesis_builder() .validators_spec(validators_spec.clone()) .shard_layout(shard_layout.clone()) .add_user_accounts_simple(..) .build(); let epoch_config_store = TestEpochConfigBuilder::build_store_from_genesis(&genesis); ``` and for more complicated cases where further customisation of epoch config is required: ``` let genesis = TestLoopBuilder::new_genesis_builder() .validators_spec(validators_spec.clone()) .shard_layout(shard_layout.clone()) .add_user_accounts_simple(..) .build(). let epoch_config_store = TestEpochConfigBuilder.from_genesis(&genesis) .minimum_validators_per_shard(2) .build_store_for_single_version(); ```
This PR replaces `build_genesis_and_epoch_config_store` with direct usage of builders introduced in near#12995.
This PR introduces alternative way to configure genesis and epoch configs for test loop. Currently the most common way to do that is `build_genesis_and_epoch_config_store`. I have the following issues with it: * `GenesisAndEpochConfigParams` forces you to set values for parameters even if you are perfectly happy with `TestEpochConfigBuilder` defaults. This pollutes test setup because it is unclear which parameter values actually matter for the tests. * Callbacks to customise genesis and epoch config builders results in weird inversion of control. Also it just looks cumbersome for simple test setup. The alternative way is to derive epoch config builder from genesis state and use it directly. ``` let genesis = TestLoopBuilder::new_genesis_builder() .validators_spec(validators_spec.clone()) .shard_layout(shard_layout.clone()) .add_user_accounts_simple(..) .build(); let epoch_config_store = TestEpochConfigBuilder::build_store_from_genesis(&genesis); ``` and for more complicated cases where further customisation of epoch config is required: ``` let genesis = TestLoopBuilder::new_genesis_builder() .validators_spec(validators_spec.clone()) .shard_layout(shard_layout.clone()) .add_user_accounts_simple(..) .build(). let epoch_config_store = TestEpochConfigBuilder.from_genesis(&genesis) .minimum_validators_per_shard(2) .build_store_for_single_version(); ```
This PR replaces `build_genesis_and_epoch_config_store` with direct usage of builders introduced in near#12995.
This PR introduces alternative way to configure genesis and epoch configs for test loop.
Currently the most common way to do that is
build_genesis_and_epoch_config_store
. I have the following issues with it:GenesisAndEpochConfigParams
forces you to set values for parameters even if you are perfectly happy withTestEpochConfigBuilder
defaults. This pollutes test setup because it is unclear which parameter values actually matter for the tests.The alternative way is to derive epoch config builder from genesis state and use it directly.
and for more complicated cases where further customisation of epoch config is required: