Verify tests do not allocate resources early#15151
Closed
findepi wants to merge 3 commits intotrinodb:masterfrom
Closed
Verify tests do not allocate resources early#15151findepi wants to merge 3 commits intotrinodb:masterfrom
findepi wants to merge 3 commits intotrinodb:masterfrom
Conversation
5feb092 to
608d59d
Compare
losipiuk
reviewed
Nov 22, 2022
`session` is a final field initialized in the constructor.
nineinchnick
approved these changes
Nov 22, 2022
cb13dd8 to
d1e7d5c
Compare
Member
Author
|
@losipiuk @nineinchnick AC. i've made this a bit more complete. PTAL |
When running TestNG tests with surefire, the test class instance initialization (class initializer, test instance construction) happens before tests are run, for all instances. Allocating resources during this phase is bad for these reasons: - resources are allocated long before they are needed, so tests may exhaust available memory even if every single test is not memory-hungry - failure reporting during this phase is imperfect (it was observed that actual failure stacktrace may not be reported in the logs), so diagnosing failures is hard. This commit adds a runtime verification attempting to ensure that test instances do not hold on to any "resourceful" classes before the test is started. Of course, we don't want to prohibit any field initialization in test instances (that would affect readability and would be frustrating), so "resourceful" classes are some known ones. The list can be extended in the future. Besides checking test instances before test is run, it also checks instances after test class is completed, to catch any resources that were left behind and not closed.
d1e7d5c to
964bd6e
Compare
losipiuk
approved these changes
Nov 23, 2022
hashhar
reviewed
Nov 23, 2022
Member
hashhar
left a comment
There was a problem hiding this comment.
Useful (but a bit hacky).
Also please make sure to run CI with secrets since I assume there are other test classes which did not run in this PR.
MiguelWeezardo
approved these changes
Nov 23, 2022
Member
|
It already found 3 cases in |
Member
Author
Thanks, closing this one and will open a new one |
Member
Author
|
Superseded by #15165 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When running TestNG tests with surefire, the test class instance
initialization (class initializer, test instance construction) happens
before tests are run, for all instances. Allocating resources during
this phase is bad for these reasons:
exhaust available memory even if every single test is not memory-hungry
actual failure stacktrace may not be reported in the logs), so
diagnosing failures is hard.
This commit adds a runtime verification attempting to ensure that test
instances do not hold on to any "resourceful" classes before the test is
started. Of course, we don't want to prohibit any field initialization
in test instances (that would affect readability and would be
frustrating), so "resourceful" classes are some known ones. The list can
be extended in the future.
Besides checking test instances before test is run, it also checks
instances after test class is completed, to catch any resources that
were left behind and not closed.
Adds test coverage for #15133