Skip to content
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

@InjectMock with reactive RestClient breaks the RestClient for subsequent tests #26594

Closed
vonatzigenc opened this issue Jul 6, 2022 · 5 comments · Fixed by #26597
Closed
Assignees
Labels
area/testing kind/bug Something isn't working
Milestone

Comments

@vonatzigenc
Copy link
Contributor

Describe the bug

If a RestClient is mocked with @InjectMock (from io.quarkus:quarkus-junit5-mockito) in a test, the reactive RestClient will not work correctly for subsequent tests without mocks.

However, the error occurs only when io.quarkus:quarkus-rest-client-reactive-jackson is used. With the classic RestClient (io.quarkus:quarkus-rest-client-jackson), the RestClient is reset as expected after the tests.

Expected behavior

RestClient from io.quarkus:quarkus-rest-client-reactive-jackson can be used in different tests both as a mock and without.
The order in which the tests are run should not matter either.

The behavior should be the same for io.quarkus:quarkus-rest-client-reactive-jackson as for io.quarkus:quarkus-rest-client-jackson.

Actual behavior

After the first QuarkusTest, in which a RestClient is mocked with @io.quarkus.test.junit.mockito.InjectMock, the RestClient can no longer be used without a mock.
The requests, which are executed over the RestClient, are not executed and an empty response is always returned.

In the tests, which are executed before, the RestClient works as expected.

Subsequent tests, which also use a @InjectMock mocked RestClient, also work correctly.

How to Reproduce?

Reproducer: https://github.com/vonatzigenc/reproducer_quarkus_reactive_restclient_mockito

  1. Run ./mvnw clean verify
  2. Test TestWithoutMockAfterUsingInjectMock.testHelloEndpoint fails

Description of the tests:

  • Error does not occur when tests are run individually
  • Error can also be reproduced directly in IntelliJ. (Run all tests)
  • Tests are executed in the following order:
    • TestWithoutMockBeforeUsingInjectMock
    • TestWithInjectMock
    • SecondTestWithInjectMock
    • TestWithoutMockAfterUsingInjectMock
  • The first and the last test are equal (first works, last one doesn't)
  • the second and third test use InjectMock

"Workarounds"

  • When io.quarkus:quarkus-rest-client-reactive-jackson is replaced by io.quarkus:quarkus-rest-client-jackson all tests pass
  • If the tests are run with @InjectMocks with a custom TestProfile, the tests will pass

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.10.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@vonatzigenc vonatzigenc added the kind/bug Something isn't working label Jul 6, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 6, 2022

/cc @geoand

1 similar comment
@glefloch
Copy link
Member

glefloch commented Jul 6, 2022

/cc @geoand

@famod
Copy link
Member

famod commented Jul 6, 2022

I wouldn't be surprised if this is connected to #26556 (comment) because that test of mine that breaks subsequent tests is using @Nested and @InjectMock! (but not @RestClient)

Edit: This doesn't seem to be the case, although it sounded so similar; the reproducer still fails with reverted #26556.

@geoand
Copy link
Contributor

geoand commented Jul 7, 2022

I'll take a look

@geoand
Copy link
Contributor

geoand commented Jul 7, 2022

#26597 takes care of the issue

geoand added a commit to geoand/quarkus that referenced this issue Jul 8, 2022
geoand added a commit that referenced this issue Jul 8, 2022
Clear Reactive REST Client mocks after the test runs
@quarkus-bot quarkus-bot bot added this to the 2.11 - main milestone Jul 8, 2022
@gsmet gsmet modified the milestones: 2.11.0.CR1, 2.10.3.Final Jul 18, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants