-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Use BankForks
on tests - Part 1
#34206
Conversation
Signed-off-by: Lucas Steuernagel <lucas.tnagel@gmail.com>
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #34206 +/- ##
=========================================
- Coverage 81.9% 81.9% -0.1%
=========================================
Files 819 819
Lines 219425 219471 +46
=========================================
+ Hits 179854 179869 +15
- Misses 39571 39602 +31 |
runtime/src/bank_forks.rs
Outdated
@@ -694,6 +695,16 @@ impl BankForks { | |||
&& bank.parent_slot() < start_slot | |||
&& bank.slot() >= start_slot | |||
} | |||
|
|||
pub fn new_bank_from_parent_for_tests( |
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.
Since new_with_fork_for_tests()
returns the instance of BankForks
, we can insert the new bank to forks in the tests itself. It's just two lines of code at the various call sites.
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.
I know two lines does not sound a lot, but function this called 57 times after fixing all the tests in the runtime
folder. It facilitates writing tests, making them conciser.
If not as a method of BankForks
I can code it as standalone function or add the #[cfg(tests)]
attribute. Is there any chance I can keep the function?
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.
How about move it to tests.rs
as a utility function? Keeping it it bank_forks
increases the possibility of accidental misuse.
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.
I didn't read through the majority of the code, but...
For any new test-only functions that cannot go into a tests submodule, can they be annotated with dev-context-only-utils
?
Here's an example:
Lines 4250 to 4253 in 57ec207
#[cfg(feature = "dev-context-only-utils")] | |
pub fn register_tick_for_test(&self, hash: &Hash) { | |
self.register_tick(hash, &BankWithScheduler::no_scheduler_available()) | |
} |
Code that is annotated with DCOU, is only usable where the DCOU feature (in the rust sense) is enabled, which prevents non-tests and non-dev-tools from accidentally calling these functions.
That's a great point. It's specially useful if someone wants to export these utility function to other crates. I suspect there are tests in other crates that will need these test_only constructors. When modifying those tests, DCOU can be used to make these functions accessible. |
Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis. |
Problem
In order for us to implement #34169 (remove
WorkSlot
fromLoadedPrograms::extract
), we need to make sure all tests create aBankFork
and use aBank
instance that has been added to the fork.Summary of Changes
This PR adds a few auxiliary functions to deal with
BankForks
and fixes some tests. Another PR that fixes more tests is waiting for this one to be merged.