Skip to content
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

Detect leaked containers when running with JUnit #20297

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

findepi
Copy link
Member

@findepi findepi commented Jan 8, 2024

With TestNG, ManageTestResources was attempting to prevent resource leaks, including container leaks, in tests. It relied on certain common test patterns to operate (like storing resource on instance fields).

This commit attempts to provide similar functionality for JUnit. For now it's limited to containers. As an added bonus, it works regardless of how the test class is written.

@findepi findepi added test no-release-notes This pull request does not require release notes entry labels Jan 8, 2024
@cla-bot cla-bot bot added the cla-signed label Jan 8, 2024
@findepi
Copy link
Member Author

findepi commented Jan 8, 2024

cc @trinodb/maintainers

@findepi findepi requested a review from wendigo January 8, 2024 12:48
@findepi findepi force-pushed the findepi/container-leaks branch 2 times, most recently from d797f4f to 9a0a82f Compare January 8, 2024 13:27
@findepi
Copy link
Member Author

findepi commented Jan 8, 2024

log.info("Checking for leaked containers");

try (DockerClient client = DockerClientFactory.instance().client()) {
List<Container> containers = client.listContainersCmd()
Copy link
Member

Choose a reason for hiding this comment

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

are containers immediately removed - are we sure those are gone by now?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, normally they are removed with equivalent of docker rm -f, so immediate

With TestNG, `ManageTestResources` was attempting to prevent resource
leaks, including container leaks, in tests. It relied on certain common
test patterns to operate (like storing resource on instance fields).

This commit attempts to provide similar functionality for JUnit. For now
it's limited to containers. As an added bonus, it works regardless of
how the test class is written.
@findepi findepi force-pushed the findepi/container-leaks branch from 9a0a82f to 9eb75d5 Compare January 8, 2024 15:07
@findepi
Copy link
Member Author

findepi commented Jan 8, 2024

Found a container leak in accumulo tests, in TestingAccumuloServer class. That one is intentional though, so added suppression mechanism.

@findepi findepi requested a review from losipiuk January 8, 2024 15:08
@losipiuk losipiuk merged commit 8fb9730 into master Jan 8, 2024
94 checks passed
@losipiuk losipiuk deleted the findepi/container-leaks branch January 8, 2024 16:46
@github-actions github-actions bot added this to the 436 milestone Jan 8, 2024
ssheikin added a commit to ssheikin/testcontainers-java that referenced this pull request Oct 30, 2024
reportLeakedContainers adapted from
trinodb/trino#20297
trinodb/trino#21280

Co-authored-by: Piotr Findeisen <piotr.findeisen@gmail.com>
Co-authored-by: Jan Waś <jan.was@starburstdata.com>
ssheikin added a commit to ssheikin/testcontainers-java that referenced this pull request Oct 31, 2024
reportLeakedContainers adapted from
trinodb/trino#20297
trinodb/trino#21280

Co-authored-by: Piotr Findeisen <piotr.findeisen@gmail.com>
Co-authored-by: Jan Waś <jan.was@starburstdata.com>
ssheikin added a commit to ssheikin/testcontainers-java that referenced this pull request Nov 5, 2024
reportLeakedContainers adapted from
trinodb/trino#20297
trinodb/trino#21280

Co-authored-by: Piotr Findeisen <piotr.findeisen@gmail.com>
Co-authored-by: Jan Waś <jan.was@starburstdata.com>
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.

2 participants