Hello everyone, I am writing an integration test c...
# general
s
Hello everyone, I am writing an integration test case for one of the classes, I am getting errors while running .
/gradlew build.
I am sharing the error here:
com.github.tomakehurst.wiremock.client.VerificationException: Expected exactly 1 requests matching the following pattern but received 2:
Code snippet of my class is:
Copy code
public void test() {
        SignUpEvent event = createTestSignUpEvent(EnumEventType.SIGN_UP, userId);

        // create stubs
        setSuccessfulUserProfileResponse(userId);
        setSuccessfulServerApiTrackReferralStub(userId, personId);
        setSuccessfulGetExternalIdStub(userId, false);
        setSuccessfulGenerateFirebaseUrlStub();
        setSuccessfulUserProfileResponse(userId);

        // publish test event
        sendEvent(event);

        Awaitility.await().pollDelay(Durations.TWO_SECONDS).until(() -> true);
       
        wireMockServer.verify(1, getRequestedFor(urlMatching(
                String.format("{url}", userId))));

        wireMockServer.verify(0, postRequestedFor(urlMatching(
                "{url}"))); 
}
Is there anyone here who can help me with this? I tried with Thread.sleep also.
p
Hi, I obviously can only look at your test set up, I don't know if your WireMock assertions make sense, but: You should definitely change the await() statement to something like:
Copy code
Awaitility.await().pollDelay(Durations.TWO_SECONDS).untilAsserted(() -> {
       
        wireMockServer.verify(1, getRequestedFor(urlMatching(
                String.format("{url}", userId))));

        wireMockServer.verify(0, postRequestedFor(urlMatching(
                "{url}"))); 
});
It will wait until the assertions don't throw an exception. You might also want to add an
.atMost(...)
, to change the max runtime for the
await()
. But if in that time frame the unit under test sends two requests, then that is its behavior, then double check the prod code is doing the right thing.
BTW can you check the
urlMatching
statement if that is right, not sure if you have modified it for this post here.
s
Thanks, @Paul Petershagen, I modified the
urlMatching
. Let me make the changes that you have suggested then I'll let you know.
Can you please explain to me what is the reason for changing
await() statement
to what you have suggested? Like where is the problem.
I tried what you have suggested, it is still giving me error
Copy code
org.awaitility.core.ConditionTimeoutException: Assertion condition defined as a lambda expression in co.tala.atlas.promotions.integration.kafka.consumer.SignUpEventConsumerTest Expected exactly 1 requests matching the following pattern but received 2:
p
The idea beind await().until(..) statement is to wait until a test or scenario condition is fulfilled. But in your case you always return true, means the await() waits only once. If your service finishes up after 21 seconds, it won't honor / notice it.
The error says it retrieved 2 GET requests, but you wanted to verify there is only one. See logs for the request / response dumps. Also would also start debugging your service in regards to the 2 reqeusts, it that is not expected.
s
okay, does it requires any change in this test case or I need to check other files or classes?
p
Look into the production process flow, which is supposed to be tested by this test.
s
okay, Thanks for the help @Paul Petershagen.
🙏 1
This issue is not solved yet. Can anyone please help me with this?
Copy code
com.github.tomakehurst.wiremock.client.VerificationException: Expected exactly 1 requests matching the following pattern but received 2:
    {
      "urlPattern" : "/users/customer/profiles/844424930132106",
      "method" : "GET"
    }
        at com.github.tomakehurst.wiremock.client.WireMock.verifyThat(WireMock.java:538)
        at com.github.tomakehurst.wiremock.client.WireMock.verifyThat(WireMock.java:521)
        at com.github.tomakehurst.wiremock.WireMockServer.verify(WireMockServer.java:271)
        at
@Tom can you please check?