Repository navigation
Closed
Description
Mockito spy creation fails sporadically and causes an exception and Mockito misuse warning:
Error: Tests run: 83, Failures: 22, Errors: 0, Skipped: 41, Time elapsed: 13.054 s <<< FAILURE! - in org.apache.pulsar.broker.service.persistent.PersistentTopicStreamingDispatcherTest
Error: setup(org.apache.pulsar.broker.service.persistent.PersistentTopicStreamingDispatcherTest) Time elapsed: 0.088 s <<< FAILURE!
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
BrokerService$MockitoMock$967912326 cannot be returned by getPulsarResources()
getPulsarResources() should return PulsarResources
***
If you're unsure why you're getting above error read on.
Due to the nature of the syntax above problem might occur because:
1. This exception *might* occur in wrongly written multi-threaded tests.
Please refer to Mockito FAQ on limitations of concurrency testing.
2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies -
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
at org.apache.pulsar.broker.service.PersistentTopicTest.setup(PersistentTopicTest.java:209)
at org.apache.pulsar.broker.service.persistent.PersistentTopicStreamingDispatcherTest.setup(PersistentTopicStreamingDispatcherTest.java:34)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:61)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:366)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:320)
at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:701)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:112)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeLazy(TestNGDirectoryTestSuite.java:123)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:90)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:146)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
Activity
lhotari commentedon Jan 5, 2022
Related to #13570 . That issue contained several issues, including this one.
lhotari commentedon Jan 28, 2022
reopening based on feedback from @gaozhangmin. It looks like PowerMock could be the culprit. @nicoloboschi WDYT?
Add null check to workaround NPE in unit tests with Mockito/PowerMock
lhotari commentedon Jan 28, 2022
@gaozhangmin I created a workaround for the NPE in #14006 .
@nicoloboschi has a plan to send a PR for replacing PowerMock usage with Mockito's built-in support for mocking static methods. It's possible that PowerMock is one source of problems.
Add null check to workaround NPE in unit tests with Mockito/PowerMock (…
Add null check to workaround NPE in unit tests with Mockito/PowerMock (…
lhotari commentedon Feb 3, 2022
There were multiple issues and some were resolved. However, there are still some open issues with Mockito. I'll reopen this issue once more.
lhotari commentedon Feb 3, 2022
More failures in this report: https://github.com/lhotari/pulsar-flakes/blob/master/2022-01-27-to-2022-02-03/org.apache.pulsar.broker.service.PersistentTopicTest.setup.md
listed under org.apache.pulsar.broker.service.PersistentTopicTest.setup in the most recent flaky test report.
lhotari commentedon Feb 3, 2022
also https://github.com/lhotari/pulsar-flakes/blob/master/2022-01-27-to-2022-02-03/org.apache.pulsar.broker.service.persistent.PersistentTopicStreamingDispatcherTest.setup.md
listed under org.apache.pulsar.broker.service.persistent.PersistentTopicStreamingDispatcherTest.setup in the most recent flaky test report.
github-actions commentedon Mar 6, 2022
The issue had no activity for 30 days, mark with Stale label.
lhotari commentedon Mar 7, 2022
recent failure
wuxuanqicn commentedon Mar 21, 2022
@lhotari
this problem will be seen when one thread invoke original method while other thread creating stub for the same method. A simple reproducer can be used at mockito/mockito#2599
there are plenty of async task in plusar, for instance metadata event process
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
Lines 1949 to 1958 in 577c2dc
maybe we can pending these async tasks util stub defined, do you have a better solution for the problem?
Add null check to workaround NPE in unit tests with Mockito/PowerMock (…
github-actions commentedon Apr 21, 2022
The issue had no activity for 30 days, mark with Stale label.
github-actions commentedon May 29, 2022
The issue had no activity for 30 days, mark with Stale label.
lhotari commentedon Jan 19, 2023
Recent failure https://github.com/apache/pulsar/actions/runs/3957519115/jobs/6778165658#step:11:1013
lhotari commentedon Jan 25, 2023
@wuxuanqicn I have dealt with the issue in #19323, please review