Sporadic mock verification failures related to hashCode/equals on 3.12.1
See original GitHub issueSince updating from 3.11.2
to 3.12.0
(and getting similar errors on 3.12.1
), I have seen some strange sometimes-reproducible verification failures on Mockito for tests which previously passed consistently.
I can’t yet establish a pattern or simple reproduction; it feels like it is somehow dependent on the order of test evaluation/usage with respect to other tests within the same JVM instance, and I have been unable to replicate locally.
There are two main classes I am seeing
-
mocks with interactions being tracked (and thus failing
verifyNoInteractions(mock)
after being put intoHashSet
s (these did not seem to previously count as an interaction, and usually do not)com.thoughtworks.go.server.materials.postcommit.git.GitPostCommitHookImplementerTest > shouldReturnEmptyListIfParamHasNoValueForRepoURL() FAILED org.mockito.exceptions.verification.NoInteractionsWanted: No interactions wanted here: -> at com.thoughtworks.go.server.materials.postcommit.git.GitPostCommitHookImplementerTest.shouldReturnEmptyListIfParamHasNoValueForRepoURL(GitPostCommitHookImplementerTest.java:93) But found this interaction on mock 'gitMaterial': -> at java.base/java.util.HashMap.hash(HashMap.java:340) Actually, above is the only interaction with this mock. at com.thoughtworks.go.server.materials.postcommit.git.GitPostCommitHookImplementerTest.shouldReturnEmptyListIfParamHasNoValueForRepoURL(GitPostCommitHookImplementerTest.java:93)
-
mocks that are not considered equal to themselves when put inside a
Collection
and then searched forcom.thoughtworks.go.server.materials.postcommit.git.GitPostCommitHookImplementerTest > shouldReturnListOfMaterialMatchingThePayloadURL() FAILED java.lang.AssertionError: Expected: a collection containing <Mock for GitMaterial, hashCode: 0> but: was <Mock for GitMaterial, hashCode: 0>, was <Mock for GitMaterial, hashCode: 0> at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20) at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8) at com.thoughtworks.go.server.materials.postcommit.git.GitPostCommitHookImplementerTest.shouldReturnListOfMaterialMatchingThePayloadURL(GitPostCommitHookImplementerTest.java:58)
I have a handful of other examples too in different classes.
This could be confirmation bias, however since I saw some stuff was done with respect to hashCodes in #2331 I wondered if it could be related. Logging it here to see if anyone else has seen any similar weirdness or might know what is going on.
Environment
- Currently I cannot replicate locally (MacOS Big Sur w/AdoptOpenJDK
15.0.2
) even where it is replicable on build/CI automation environment. - The failures seem to be (somewhat) reproducible on AL2 Linux w/ Oracle JDK
15.0.1
) but I cannot distinguish a pattern, and sometimes a different combination/ordering of tests does not seem to yield the same failure on exactly the same test code.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (10 by maintainers)
Top GitHub Comments
@chadlwilson Correction. the changes in https://github.com/mockito/mockito/pull/2400 are not the root the breakage but the PR https://github.com/mockito/mockito/pull/2369 is. The https://github.com/mockito/mockito/pull/2402 reverted both, because https://github.com/mockito/mockito/pull/2400 is not needed if the https://github.com/mockito/mockito/pull/2369 is removed.
3.12.2 is currently being pushed to Maven Central and should be available in a couple of hours.