I encountered a very strange situation when using Spring and Wiremock for integration testing: suddenly, one specific test started failing intermittently. A snippet of the error below:
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:10314/my/endpoint": Software caused connection abort: recv failed; nested exception is java.net.SocketException: Software caused connection abort: recv failed
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785) ~[spring-web-5.3.7.jar:5.3.7]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711) ~[spring-web-5.3.7.jar:5.3.7]
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:468) ~[spring-web-5.3.7.jar:5.3.7]
... more logs here ...
The context is as follows: I have added a new test that uses wiremock to stub responses:
wireMockServer.stubFor(WireMock.post("/my/endpoint")
.withRequestBody(containing(aJsonRequestBodyHere))
.willReturn(aResponse()
.withBody(aJsonResponseHere)
.withStatus(HttpStatus.OK.value())
.withHeader(HttpHeader.CONTENT_TYPE.toString(), CONTENT_TYPE_APPLICATION_JSON)));
The call to this stub endpoint is made as follows:
given()
.when()
.get("my/endpoint")
.then()
.body(containsString(theExpectedJsonResponse)))
.statusCode(200);
The strange part:
- the same test runs without any problems on my local machine - if run alone
- when running all the tests on my machine, sometimes, the same test fails, sometimes does not
- only this test is failing each time; no other test fails
- when tests are run on Jenkins, it fails 100%