7

In most of the integration tests I'm using spring-boot-test(2.1.9.RELEASE) and spring-cloud-contract-wiremock(2.0.2.RELEASE). The test is starting up WireMock server based on : @AutoConfigureWireMock(port = 0), so I'm not using any WireMockRule or other configuration set-up.

Sometime the verifying is failing with a really weird error:

com.github.tomakehurst.wiremock.client.VerificationException:` com.github.tomakehurst.wiremock.client.VerificationException: com.github.tomakehurst.wiremock.client.VerificationException: No requests exactly matched. Most similar request was: expected:< POST /api/id/delete

but was:< POST /api/id/delete

As you can see above the expected endpoint is exactly the same with the actual invocation.

Do you have any ideas ? or Have you seen that before ? There is an open issue here: https://github.com/tomakehurst/wiremock/issues/706 , but the responses are not very helpful.

brebDev
  • 774
  • 10
  • 27
  • Is there a particular reason you're using WireMock version `2.0.2`? The current release is `2.25.1`. See the [WireMock documentation](http://wiremock.org/docs/download-and-installation/) for specific details. – A. Kootstra Jan 16 '20 at 13:25
  • It's spring-cloud-contract-wiremock 2.0.2 version(that include WireMock 2.18.0 version) – brebDev Jan 16 '20 at 15:03

2 Answers2

4

So after months of randomly failing builds, it seems that the only solution was to wait until the stubs got registered. So the new verify wrapper method looks like this:

    public static void verify(int count, RequestPatternBuilder requestPatternBuilder) {
    int maxRetries = 5;
    while (count != WireMock.findAll(requestPatternBuilder)
            .size() && maxRetries > 0) {
        Thread.sleep(1000);
        maxRetries--;
    }
    WireMock.verify(count, requestPatternBuilder);
}

And the callers used it like this:

        WireMockHelper.verify(1, putRequestedFor(urlMatching((URL.BASE_URL.ACTION).replace("%s", ".*"))));

Finally now we can rely on our IT build pipeline. Wish you all only green builds :)

brebDev
  • 774
  • 10
  • 27
2

I have the same issue on the DELETE, but on local it's working (windows + intelliJ) and on Jenkins (linux) fail. And you ?

com.github.tomakehurst.wiremock.client.VerificationException: 
No requests exactly matched. Most similar request was:  expected:<
DELETE
/myAPI/api
> but was:<
DELETE
/myAPI/api
>

Edit:

Solution: I have an asynchronous method in my algorithm and I don't need to wait for it to answer to finish the algo so I have to put a Thread.sleep to be sure that the call is done

    /**
     * Use It when you have a asyc call in your methode
     * @param delay time to wait
     */
    public void waitingForAsycRequest(int delay) {
            try {
                Thread.sleep(delay);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    }
DavidoVitch
  • 61
  • 2
  • 9
  • Most of the times is failing in CI env. We're using Bamboo instead of Jenkins. But surprisingly rarely is failing from the IntelliJ+Ubuntu too. And more often from de cmd when I'm running the whole test pack with Gradle. Still we haven't resolved the issue.. And it's pretty frustrating !!! – brebDev Mar 25 '20 at 10:32
  • Is this the solution to the origianal question or your own problem? – Dharman Mar 25 '20 at 11:29
  • It is the solution to my problem, which resembles its problem because I have the same instability when I run all my unit tests.@brebDev Have you tested the anotation `@RepeatedTest (value = 100)` to see if it goes from time to time? it helped me a lot – DavidoVitch Mar 25 '20 at 13:24