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

Revert "[fix][ci] Fix tests memory leak due to mockito-inline (#15513)" #16820

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 0 additions & 11 deletions buildtools/pom.xml
Expand Up @@ -50,7 +50,6 @@
<guava.version>31.0.1-jre</guava.version>
<ant.version>1.10.12</ant.version>
<snakeyaml.version>1.30</snakeyaml.version>
<mockito.version>3.12.4</mockito.version>
<!-- required for running tests on JDK11+ -->
<test.additional.args>
--add-opens java.base/jdk.internal.loader=ALL-UNNAMED
Expand Down Expand Up @@ -133,16 +132,6 @@
<version>4.1.77.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.pulsar.tests;

import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,22 +36,10 @@ public class MockitoCleanupListener extends BetweenTestClassesListenerAdapter {

@Override
protected void onBetweenTestClasses(Class<?> endedTestClass, Class<?> startedTestClass) {
if (MOCKITO_CLEANUP_ENABLED) {
if (MockitoThreadLocalStateCleaner.INSTANCE.isEnabled()) {
LOG.info("Cleaning up Mockito's ThreadSafeMockingProgress.MOCKING_PROGRESS_PROVIDER thread local state.");
MockitoThreadLocalStateCleaner.INSTANCE.cleanup();
}
cleanupMockitoInline();
if (MOCKITO_CLEANUP_ENABLED && MockitoThreadLocalStateCleaner.INSTANCE.isEnabled()) {
LOG.info("Cleaning up Mockito's ThreadSafeMockingProgress.MOCKING_PROGRESS_PROVIDER thread local state.");
MockitoThreadLocalStateCleaner.INSTANCE.cleanup();
}
}

/**
* Mockito-inline can leak mocked objects, we need to clean up the inline mocks after every test.
* See <a href="https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#47"}>
* mockito docs</a>.
*/
private void cleanupMockitoInline() {
Mockito.framework().clearInlineMocks();
}

}