question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sporadic mock verification failures related to hashCode/equals on 3.12.1

See original GitHub issue

Since 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

  1. mocks with interactions being tracked (and thus failing verifyNoInteractions(mock) after being put into HashSets (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)
    

    https://github.com/gocd/gocd/blob/b7bba59201c857efc010c3493664802f218d2bae/server/src/test-fast/java/com/thoughtworks/go/server/materials/postcommit/git/GitPostCommitHookImplementerTest.java#L81-L94

  2. mocks that are not considered equal to themselves when put inside a Collection and then searched for

    com.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)
    

    https://github.com/gocd/gocd/blob/b7bba59201c857efc010c3493664802f218d2bae/server/src/test-fast/java/com/thoughtworks/go/server/materials/postcommit/git/GitPostCommitHookImplementerTest.java#L41-L65

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
vyazelenkocommented, Aug 25, 2021
2reactions
TimvdLippecommented, Aug 24, 2021

3.12.2 is currently being pushed to Maven Central and should be available in a couple of hours.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mockito 2.25.1 API - javadoc.io
The Mockito library enables mock creation, verification and stubbing. This javadoc content is also available on the http://mockito.org web page.
Read more >
[GitHub] [maven-compiler-plugin] dependabot[bot] opened a ...
[(<a href="https://github-redirect.dependabot.com/mockito/mockito/issues ... mock verification failures related to hashCode/equals on 3.12.1 ...
Read more >
Mockito gives UnfinishedVerificationException when it seems ...
The exception notices that no final /private/equals/hash methods can be used. ... UnfinishedVerificationException: Missing method call for verify(mock) ...
Read more >
Bump mockito.version from 3.12.1 to 3.12.4 (!232) - GitLab
An error occurred while retrieving approval data for this merge request. Bump mockito.version from 3.12.1 to 3.12.
Read more >
Hazelcast IMDG Release Notes
The linked numbers refer to the issue number in the Hazelcast IMDG GitHub ... Fixed an issue where Address.equals() and hashCode was using ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found