Verify tests do not allocate resources early and do not leave them behind#15165
Verify tests do not allocate resources early and do not leave them behind#15165
Conversation
a5deb2a to
f5524c0
Compare
cd9062e to
0f1693d
Compare
db97397 to
5a32f0c
Compare
5a32f0c to
6da68d1
Compare
|
(just rebased) |
Sorry about that, I will try to fix this check (#15210) so that PRs opened before it was merged won't need to be rebased. |
| { | ||
| queryContexts.clear(); | ||
| memoryPool = null; | ||
| taskExecutor.stop(); |
There was a problem hiding this comment.
should we use closer here to make sure all cleanup routines are called?
There was a problem hiding this comment.
I don't see a need to. @AfterClass failure is a failure for tests execution so we won't ignore it.
losipiuk
left a comment
There was a problem hiding this comment.
I agree this is somewhat fragile - but at the same time it proves helpful in current shape. If we notice logic in verifier class deteriorates over time we can either drop it or make it more up-to-date.
agreed |
Ever after `TestingTrinoServer.close()` is called, the `TestingTrinoServer` may hold on to quite some memory. Let's clear references to these upon test completion. This opportunistically includes freeing of a few more things that are of lesser importance.
It's never a good idea, so make it this fail cleanly. As an added bonus, it prevents use of `closeAfterClass` after closing was called. That could lead to resources being left behind.
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.
This also makes `DistributedQueryRunner.close` explicitly idempotent. Indeed, some tests call it twice, for example once explicitly and once via `QueryAssertions.close`.
714c78c to
aa0e114
Compare
|
@findepi Thank you for doing this! This is great! |
|
@kokosing with all due modesty, i think i agree! |
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
Already approved at #15151