-
Notifications
You must be signed in to change notification settings - Fork 10
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
Test run in multiple threads #20
Comments
This testng-team/testng#1872 is probably connected. |
I strongly guess it throws ConcurrentModificationExceptions because of the usage of HashMaps instead of ConcurrentHashMaps in the MockitoTestNGListener class. The (not thread safe) handling of the fixtures seems to be a problem in the framework and related to the referenced issue. But at least the listener itself could be thread safe with changing the Map implementation and make life a bit easier :) |
I ran into the I had used Mockito as shorthand for dummy instances where I am testing a builder class so the mocks are never invoked or configured. This was simple to change to actual instances that error if invoked and that found a mistake where using the mocks was desirable and its state leaked across test methods. A correct actual usages of the listener for initializing fields should require single threaded tests and that should be explicit in the documentation and ideally detected at runtime if possible. The internal crash implies a bug in the listener rather than in the developer's test code. java.util.ConcurrentModificationException
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1135)
at org.mockito.testng.MockitoTestNGListener.beforeInvocation(MockitoTestNGListener.java:101)
at org.testng.internal.invokers.InvokedMethodListenerInvoker.invokeListener(InvokedMethodListenerInvoker.java:55)
at org.testng.internal.invokers.BaseInvoker.runInvokedMethodListeners(BaseInvoker.java:82)
at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:651)
at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:230)
at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:63)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:992)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:203)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:154)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:134)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.testng.internal.thread.graph.TestNGFutureTask.run(TestNGFutureTask.java:22)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829) |
We can annotate test with:
In this case
MockitoTestNGListener
will not work as we want.In current implementation
MockitoSession
is bind to current test instance, butTestNG
create one test instance and run test in multiple thread.Issue need more investigate how to resolve problem.
We must to check and discover how mocked field should be distinguished on one test instance and multiple thread.
Please like / react on issue to we see how many people are interested this issue.
The text was updated successfully, but these errors were encountered: