Skip to content

Verify tests do not allocate resources early#15151

Closed
findepi wants to merge 3 commits intotrinodb:masterfrom
findepi:findepi/resourceful-tests
Closed

Verify tests do not allocate resources early#15151
findepi wants to merge 3 commits intotrinodb:masterfrom
findepi:findepi/resourceful-tests

Conversation

@findepi
Copy link
Copy Markdown
Member

@findepi findepi commented Nov 22, 2022

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.

Adds test coverage for #15133

@findepi findepi added test no-release-notes This pull request does not require release notes entry labels Nov 22, 2022
@cla-bot cla-bot Bot added the cla-signed label Nov 22, 2022
@findepi findepi force-pushed the findepi/resourceful-tests branch from 5feb092 to 608d59d Compare November 22, 2022 13:51
Copy link
Copy Markdown
Member

@losipiuk losipiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny :)

`session` is a final field initialized in the constructor.
@findepi findepi force-pushed the findepi/resourceful-tests branch 3 times, most recently from cb13dd8 to d1e7d5c Compare November 22, 2022 16:33
@findepi
Copy link
Copy Markdown
Member Author

findepi commented Nov 22, 2022

@losipiuk @nineinchnick AC. i've made this a bit more complete. PTAL

Copy link
Copy Markdown
Member

@nineinchnick nineinchnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.
@findepi findepi force-pushed the findepi/resourceful-tests branch from d1e7d5c to 964bd6e Compare November 23, 2022 10:37
Copy link
Copy Markdown
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

MiguelWeezardo commented Nov 23, 2022

It already found 3 cases in test-other-modules.

@findepi
Copy link
Copy Markdown
Member Author

findepi commented Nov 23, 2022

Also please make sure to run CI with secrets since I assume there are other test classes which did not run in this PR.

Thanks, closing this one and will open a new one

@findepi findepi closed this Nov 23, 2022
@findepi findepi deleted the findepi/resourceful-tests branch November 23, 2022 12:35
@findepi
Copy link
Copy Markdown
Member Author

findepi commented Nov 23, 2022

Superseded by #15165

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed no-release-notes This pull request does not require release notes entry test

Development

Successfully merging this pull request may close these issues.

5 participants