jeudi 20 septembre 2018

Sporadic java.net.SocketTimeoutException issue with junit5 pact consumer test

We have two junit5 pact tests in our system. Those work pretty well, however, now and then (especially on the pipeline) we get a SocketTimeoutException (attached below)

The code is executed in a Docker instance based on ubuntu:16.04 and jre: openjdk-8-jdk with pact library au.com.dius:pact-jvm-consumer-junit5_2.12:3.5.22.

The tests looks like this:

@Pact(provider = "http-health-status", consumer = "heartbeat-status-client")
fun `query for a healthy endpoint`(builder: PactDslWithProvider): RequestResponsePact {
    return builder
        .given("a healthy service")
        .uponReceiving("A health api query")
        .matchPath(".*\\/health\$", "/some-service/health")
        .method("GET")
        .willRespondWith()
        .headers(mapOf(HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_UTF8_VALUE))
        .body("""{"status":"UP"}""")
        .status(200)
        .toPact()
}


@Test
@PactTestFor(providerName = "http-health-status", pactMethod = "query for a healthy endpoint")
fun `query for a healthy endpoint`(mockServer: MockServer) {
    val httpResponse = subject.query(mockServer.getUrl() + "/some-other-service/health")
   assertThat(httpResponse).isEqualTo(StatusCode.UP)
}

Is there any known issue with our setup?

com.v.hb.api.clients.HttpStatusClientTest > query for a healthy endpoint(MockServer) FAILED
    org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://127.0.0.1:43796/some-other-service/health": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:732)
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:680)
        at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:359)
        at com.v.hb.api.clients.HttpStatusClient.query(HttpStatusClient.kt:48)
        at com.v.hb.api.clients.HttpStatusClientTest.query for a healthy endpoint(HttpStatusClientTest.kt:49)

        Caused by:
        java.net.SocketTimeoutException: Read timed out
            at java.net.SocketInputStream.socketRead0(Native Method)
            at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
            at java.net.SocketInputStream.read(SocketInputStream.java:171)
            at java.net.SocketInputStream.read(SocketInputStream.java:141)
            at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
            [...]
            at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:108)
            at com.v.hb.api.common.logging.RestTemplateLoggingInterceptor.intercept(RestTemplateLoggingInterceptor.kt:24)
            at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
            at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:76)
            at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
            at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
            at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:723)
            ... 4 more

com.v.hb.api.clients.HttpStatusClientTest > query for a down endpoint(MockServer) STANDARD_OUT
    2018-09-20 09:23:31.358 ERROR 2528 --- [      Thread-21] a.com.dius.pact.consumer.BaseMockServer  : Failed to generate response

    java.io.IOException: stream is closed
        at sun.net.httpserver.Request$WriteStream.write(Request.java:380) ~[na:1.8.0_181]
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) ~[na:1.8.0_181]
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) ~[na:1.8.0_181]
        at sun.net.httpserver.ExchangeImpl.sendResponseHeaders(ExchangeImpl.java:261) ~[na:1.8.0_181]
        at sun.net.httpserver.HttpExchangeImpl.sendResponseHeaders(HttpExchangeImpl.java:86) ~[na:1.8.0_181]
        at au.com.dius.pact.consumer.BaseMockServer.pactResponseToHttpExchange(MockHttpServer.kt:102) ~[pact-jvm-consumer_2.12-3.5.22.jar:3.5.22]
        at au.com.dius.pact.consumer.BaseMockServer.handle(MockHttpServer.kt:85) ~[pact-jvm-consumer_2.12-3.5.22.jar:3.5.22]
        [...]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]

Aucun commentaire:

Enregistrer un commentaire