-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Verify tests do not allocate resources early and do not leave them behind #15165
Conversation
...trino-testing-services/src/main/java/io/trino/testng/services/ReportResourceHungryTests.java
Outdated
Show resolved
Hide resolved
a5deb2a
to
f5524c0
Compare
cd9062e
to
0f1693d
Compare
db97397
to
5a32f0c
Compare
testing/trino-testing-services/src/main/java/io/trino/testng/services/Listeners.java
Show resolved
Hide resolved
client/trino-jdbc/src/test/java/io/trino/jdbc/TestJdbcVendorCompatibility.java
Show resolved
Hide resolved
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. |
core/trino-main/src/test/java/io/trino/execution/TestSetSessionTask.java
Show resolved
Hide resolved
core/trino-main/src/test/java/io/trino/execution/TestResetSessionTask.java
Outdated
Show resolved
Hide resolved
@@ -107,8 +108,12 @@ public void tearDown() | |||
{ | |||
queryContexts.clear(); | |||
memoryPool = null; | |||
taskExecutor.stop(); |
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.
should we use closer here to make sure all cleanup routines are called?
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 don't see a need to. @AfterClass
failure is a failure for tests execution so we won't ignore it.
...o-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergGetTableStatisticsOperations.java
Show resolved
Hide resolved
...metheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusQueryMatrixResponseParse.java
Show resolved
Hide resolved
core/trino-main/src/test/java/io/trino/execution/TestSqlTaskManager.java
Show resolved
Hide resolved
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 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