Hello, I have problem with my test. When I run sol...
# general
l
Hello, I have problem with my test. When I run solo test it passed but when I run whole package the same test fail. I received error below: Caused by: java.net.SocketException: Software caused connection abort: recv failed I suppose it could be problem with my stub which I using in my test. I tried below solution but it doesn't work: https://stackoverflow.com/questions/68929051/wiremock-sometimes-it-throws-software-caused-connection-abort-recv-failed My code below:
Copy code
public void getList() {

  int XxxId = 1;

  stubPostOperationResponse(XxxId, "YYY");
  mockAuthentication();

  for (int i = 0; i < 2; i++) {
    given()
        .contentType(ContentType.JSON)
        .body(triggerSomethingRequest)
        .port(randomServerPort)
        .when()
        .post("XYZ")
        .then()
        .statusCode(201);
  }

  GetAnalysesResponseDto response = given()
      .port(randomServerPort)
      .when()
      .get("analysis")
      .then()
      .statusCode(200)
      .extract()
      .response()
      .as(GetAnalysesResponseDto.class);

  int responseSize = response.getAnalyses().size();

  assertEquals(2, responseSize);
}

private void stubPostOperationResponse(int operationId, String resourceName) {

  String expectedOutboundRequestBody = TestUtils.readResourceFile(resourceName);

  WireMock.importStubs(
      stubImport()
          .stub(
              post("/xxx/operations")
                  .withRequestBody(equalToJson(expectedOutboundRequestBody, true, false))
                  .willReturn(
                      created()
                          .withHeader(HttpHeaders.CONNECTION, "close")
                          .withHeader("Content-Type", "application/json") 
                          .withBody("{\"id\":" + operationId + "}")))
          .doNotDeleteExistingStubs());
}