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

Skip container leak check for unit tests #20743

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.platform.launcher.TestPlan;
import org.testcontainers.DockerClientFactory;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -58,6 +59,21 @@ public void testPlanExecutionFinished(TestPlan testPlan)
log.info("ReportLeakedContainers disabled");
return;
}

try {
if (ignoredIds.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

why?

Copy link
Member Author

Choose a reason for hiding this comment

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

if ignoredIds has anything, that means the containers were used and check should run (shouldn't skip)

Field instanceField = DockerClientFactory.class.getDeclaredField("instance");
instanceField.setAccessible(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

i didn't find anything less ugly.

if (instanceField.get(null) == null) {
log.info("DockerClientFactory not initialized, so there should be no leaked containers, skipping the check");
return;
}
}
}
catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}

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

@SuppressWarnings("resource") // Throws when close is attempted, as this is a global instance.
Expand Down
Loading