Repository navigation
[fix][tests] Fix Mockito mocks memory leak - #17851
Conversation
dd5e115 to
9b70123
Compare
…MockedPulsarServiceBaseTest
tisonkun
left a comment
There was a problem hiding this comment.
LGTM.
Since we already hard depend on org.mockito.internal.util.MockUtil, the comment above is not a blocker.
|
Perhaps we can report this OOM to the mockito community for a solution in idiom. Since they mark these methods as not recommended they could have some insights here :) |
There's nothing here that is caused by a Mockito bug. |
I have some experience in asking upstream experts for best practices. But let's say I should volunteer to report the case instead of requesting others. |
In this case, the reason for the memory leaks is the misuse of Mockito in the Pulsar internal test framework. org.apache.pulsar.tests.MockitoThreadLocalStateCleaner will log warnings about "Invalid usage of Mockito detected on thread ..." to help find the locations of the misuse of Mockito in Pulsar tests. I guess it would be helpful to have some support for checks like this directly in Mockito so that it would be possible to add such validation without using reflection. @tisonkun Since you seem to care about this topic, it would be useful to fix issues in Pulsar test code one issue at a time. |
* Call cleanup method in finally block to ensure it's not skipped * Clear invocations for the mocks that are left around without cleanup * Cleanup PulsarService and PulsarAdmin mocks/spies in MockedPulsarServiceBaseTest * Don't record invocations at all for PulsarService and PulsarAdmin in MockedPulsarServiceBaseTest * Don't record invocations for spies by default * Simplify reseting mocks * Fix PersistentTopicTest * Fix TokenExpirationProducerConsumerTest * Fix SimpleLoadManagerImplTest * Fix FilterEntryTest (cherry picked from commit d4893d1)
Fixes #17714
Motivation
There's a memory leak when using Mockito mocks since all invocations get recorded.
Modifications
Add multiple solutions for making sure that mocks are cleaned up properly.
Modify MockedPulsarServiceBaseTest to clean up PulsarService and PulsarAdmin mocks since the detected memory leaks are caused by these mocks.
Documentation
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
doc(Your PR contains doc changes)
doc-complete(Docs have been already added)
Matching PR in forked repository
PR in forked repository: lhotari#92