Closed holly-cummins closed 1 week ago
Just as a sense check, I put in an check to make sure that the object I'd add my verify
to was the same as the object verifyNoMoreInteractions
was being called on:
.then().github(mocks -> {
verify(mocks.pullRequest(527350930))
.addLabels("area/test1", "area/test2", "area/test3");
verify(mocks.pullRequest(527350930), times(2)).listFiles();
System.out.println("HOLLY equality check " + (mocks.pullRequest(527350930) == mocks.ghObjects()[1]));
verifyNoMoreInteractions(mocks.ghObjects());
});
With both continuous testing and mvn test
, the output is as expected:
HOLLY equality check true
The invocations you verified are actually stubbed (there's a call to when( ... listFiles() )
above).
Since we're using MockitoExtension
in this test, and this extension defaults to setting the Mockito strictness to "strict", we should not have to verify stubbed invocations. See the javadoc of org.mockito.quality.Strictness#STRICT_STUBS
:
Cleaner, more DRY tests ("Don't Repeat Yourself"): If you use org.mockito.Mockito.verifyNoMoreInteractions(Object...) you no longer need to explicitly verify stubbed invocations. They are automatically verified for you.
So, something is wrong with the integration with Mockito, and this PR is a workaround that should not be necessary.
As to where the problem lies exactly... I'd need to have a closer look. From the top of my head, I'd say the most likely cause is the weird dance with classloaders when doing continuous testing; it's possible that MockitoExtension is relying (perhaps indirectly) on static state that ends up being reinitialized by Quarkus' classloader operations.
I'd have to investigate, though... I'll give it a try when I have some time, unless you did first :)
Thanks, @yrodiere! Do you think it's worth raising an issue against the mockito extension (as in "the Quarkus mockito integration"), if only to act as a reminder?
Thanks, @yrodiere! Do you think it's worth raising an issue against the mockito extension (as in "the Quarkus mockito integration"), if only to act as a reminder?
Probably better to raise the issue here, as I'm not entirely sure where the problem comes from yet. I wouldn't want to point fingers until we have proof :)
I reported the problem upstream: https://github.com/quarkusio/quarkus/issues/27383
I think we can declare this stale, so closing. :)
I’m a little bit confused by what’s going on here, so would welcome some insight on why this fix is (apparently?) needed.
When I run
mvn quarkus:dev
, I get 4 test failures, all inPullRequestOpenedTest#triage*. I don’t see the failures with
mvn install test`.Tracing through the code, I can see that the problem line is this one
mocks.ghObjects[1]
is the pull request, andTriage
callslistFiles
on it, in both test modes. So I understand why the continuous testing is failing, but I don’t understand why the normal testing is passing.If I do the tactical fix of verifying the extra interaction, both test modes pass. That also confuses me - if Mockito knows the interaction has happened well enough for
verify
to pass, why isverifyNoMoreInteractions
passing?I’ve attached a pragmatic change with the fix, but I’d love to understand better the root cause of the difference.