spring-cloud-gateway
spring-cloud-gateway copied to clipboard
Timeouts return Http "ok" (200) response
Set a global or a per-route timeout. Create a test that delays the response from the stubbed downstream service in order to trigger a timeout. This will log a ResponseStatusException with a message containing "504 GATEWAY_TIMEOUT". However, the resultant response from the spring-cloud-gateway service has a status of 200. Ideally, it should have a status of 504.
Spring-cloud-gateway version: "2021.0.3"
In the config:
cloud:
gateway:
httpclient:
connect-timeout: 3000
response-timeout: 15s
In the test:
@ActiveProfiles("test")
@AutoConfigureWireMock(port = WIRE_MOCK_PORT)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = {PortalGatewayApplication.class})
@AutoConfigureWebTestClient(timeout = "20000")
public class AdvertsIntegrationTest {
@Test
public void shouldProxyRequestsToAdvertsService() {
stubFor(get(urlEqualTo("/api/")).withHost(equalTo("localhost")).withPort(WIRE_MOCK_PORT)
.withHeader("someHeader", equalTo("someHeaderValue"))
.willReturn(status(ok())
.withFixedDelay(50000))
);
webClient.get().uri("/advert/")
.exchange()
.expectStatus().isOk(); // This passes, although ideally the status wouldn't be "ok".
}
}