Hello Team, Need to ask something related to Wirem...
# help
r
Hello Team, Need to ask something related to Wiremock scenarios. I am using wiremock scenario to test one endpoint with different scenarios , and at the end I am verifying the number of http requests made to a stubbed url path. In my case I have made 3 stubs/scenarios and I can see those scenarios while running the test. Since I have 3 stubs for the same url with different responses I am verifying that the http request calls made to the url is equal to 3. It was working fine with Spring boot 2.x and started failing when I migrated to Spring Boot 3.x
While running the test I can see 3 scenarios and 4 server events, and also see that 2 server events with same stubMapping but in my knowledge it should not be there.
l
This is a little tricky to diagnose given the information. I don't know of anything that will have changed with regards to scenarios so not sure why an upgrade of spring will have impacted it. What libraries are you using to interact with Wiremock in your spring app?
Also, did you migrate to the jetty 12 version of Wiremock when you updated to Spring 3.x?
r
Copy code
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-contract-wiremock</artifactId>
</dependency>
Let me check what version of Jetty I ma using
I am using jetty 12.0.7
l
If I remember correctly,
spring-cloud-contract-wiremock
uses a really old version of WireMock but it uses WireMock standalone so the version of jetty might not be so important
If you were using Wiremock directly then there would probably be a conflict given Wiremock normally uses jetty 11. That is why we released the jetty 12 version of Wiremock
I don't have a huge amount of experience using
spring-cloud-contract-wiremock
to be honest so not sure how much help I can be. How feasible is it to put a simple demo app together demonstrating the problem?
r
May be I can try to use , `
Copy code
<dependency>
    <groupId>org.wiremock</groupId>
    <artifactId>wiremock-jetty12</artifactId>
    <version>3.9.1</version>
    <scope>test</scope>
</dependency>
@`
l
Not sure that will be compatible with the
spring-cloud-contract-wiremock
r
hmm, that is also there.
l
If the spring version is the only thing that has changed it does seem like it would be a difference in how spring is behaving with WireMock but I am not sure what that would be?
r
Normally the number of http requests to a stubbed url should be same as the number of stubMappings to that url , right?
Copy code
stubFor(get(urlPathEqualTo("/abc/path"))
        .inScenario(scenarioName)
        .whenScenarioStateIs(STARTED)
        .willReturn(aResponse()
                .withStatus(OK.value())
                .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
                .withHeader(HEADER_TRACE_ID, HTTP_HEADERS.getFirst(HEADER_TRACE_ID))
                .withBodyFile("get-international-pending-payments-811-response-200.json"))
        .willSetStateTo(firstSuccessState));

// Second request fails with 4xx error
stubFor(get(urlPathEqualTo("/abc/path"))
        .inScenario(scenarioName)
        .whenScenarioStateIs(firstSuccessState)
        .willReturn(aResponse()
                .withStatus(BAD_REQUEST.value())
                .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
                .withHeader(HEADER_TRACE_ID, HTTP_HEADERS.getFirst(HEADER_TRACE_ID))
                .withBodyFile("get-international-pending-payments-811-response-400.json"))
        .willSetStateTo(secondFailureState));

// Third request fails with 5xx error
stubFor(get(urlPathEqualTo("/abc/path"))
        .inScenario(scenarioName)
        .whenScenarioStateIs(secondFailureState)
        .willReturn(aResponse()
                .withStatus(SERVICE_UNAVAILABLE.value())
                .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
                .withHeader(HEADER_TRACE_ID, HTTP_HEADERS.getFirst(HEADER_TRACE_ID))
                .withBodyFile("get-international-pending-payments-811-response-503.json"))
        .willSetStateTo(STARTED));
l
I think that depends on your tests. I can have 1 stub mapping and many requests to that one stub
r
and I am calling "/abc/path" only once
l
What are the serve events you are seeing?
r
I am seeing 4 events total and 2 events with the first stubMapping
I am verifying the total number of calls to
/abc/path
with this,
Copy code
verify(exactly(3), getRequestedFor(urlPathEqualTo("/abc/path")));
and its failing with an error saying that there are 4 events with the same path and not 3. This was working with out any issue now as part of spring boot 3 migration task I have updated few libraries and it started failing.
l
It would be great to get a little more info on those events if possible
r
Okay, let me take that details
These are the 4 server events
If you see there are 2 events with same
insertionIndex=1
and
stubMapping
id
@Lee Turner Do you think these screenshots are enough ?
It works with springBoot 2.x.x and I can see that there are only 3 server events with the same path and 3 stubMappings
l
So there is more than one request to one of the stubs.
r
yes , there are 2 requests with one of the stub and in application logs also its not visible
Somehow Wiremock is registering this extra event even though its not defined with in the scenario
l
At the moment I have no idea why that would be. Either there is a bug in WireMock and it is registering events without actually receiving them (we certainly haven't seen anything like this) or the update to spring 3.x has changed the way spring interacts with the API (wiremock in this case). I think I would need to look at the code to be of any more help to be honest.
r
Shall I create a sample project and attach it with an issue ?
l
That would be amazing if you can ?
👍 1