From ee07d6c3cad62216789287535214dc32ffa49d48 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 23 Jul 2021 13:02:23 +0100 Subject: [PATCH] Increase response timeout for server-bound WebTestClients Closes gh-27472 --- .../CloudFoundryWebFluxEndpointIntegrationTests.java | 6 ++++-- .../CloudFoundryMvcWebEndpointIntegrationTests.java | 7 ++++--- .../MappingsEndpointReactiveDocumentationTests.java | 5 +++-- .../MappingsEndpointServletDocumentationTests.java | 5 +++-- .../integrationtest/JerseyEndpointIntegrationTests.java | 7 +++++-- .../WebMvcEndpointExposureIntegrationTests.java | 5 +++-- .../servlet/AbstractEndpointRequestIntegrationTests.java | 6 ++++-- .../annotation/AbstractWebEndpointIntegrationTests.java | 4 ++-- .../ControllerEndpointHandlerMappingIntegrationTests.java | 4 ++-- .../ControllerEndpointHandlerMappingIntegrationTests.java | 4 ++-- .../test/WebEndpointTestInvocationContextProvider.java | 4 ++-- .../rsocket/RSocketWebSocketNettyRouteProviderTests.java | 5 +++-- ...SpringBootTestEmbeddedReactiveWebEnvironmentTests.java | 8 +++++--- 13 files changed, 42 insertions(+), 28 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryWebFluxEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryWebFluxEndpointIntegrationTests.java index ceb011459d..7b1d3ad033 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryWebFluxEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryWebFluxEndpointIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.Map; @@ -151,7 +152,8 @@ class CloudFoundryWebFluxEndpointIntegrationTests { return (context) -> { int port = ((AnnotationConfigReactiveWebServerApplicationContext) context.getSourceApplicationContext()) .getWebServer().getPort(); - clientConsumer.accept(WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build()); + clientConsumer.accept(WebTestClient.bindToServer().baseUrl("http://localhost:" + port) + .responseTimeout(Duration.ofMinutes(5)).build()); }; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java index 8af1637510..a7affad6a0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.Map; @@ -146,8 +147,8 @@ class CloudFoundryMvcWebEndpointIntegrationTests { BiConsumer consumer = (context, client) -> clientConsumer.accept(client); try (AnnotationConfigServletWebServerApplicationContext context = createApplicationContext(configuration, CloudFoundryMvcConfiguration.class)) { - consumer.accept(context, - WebTestClient.bindToServer().baseUrl("http://localhost:" + getPort(context)).build()); + consumer.accept(context, WebTestClient.bindToServer().baseUrl("http://localhost:" + getPort(context)) + .responseTimeout(Duration.ofMinutes(5)).build()); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java index 9be633f7db..89b853d355 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -73,7 +74,7 @@ class MappingsEndpointReactiveDocumentationTests extends AbstractEndpointDocumen void webTestClient(RestDocumentationContextProvider restDocumentation) { this.client = WebTestClient.bindToServer() .filter(documentationConfiguration(restDocumentation).snippets().withDefaults()) - .baseUrl("http://localhost:" + this.port).build(); + .baseUrl("http://localhost:" + this.port).responseTimeout(Duration.ofMinutes(5)).build(); } @Test diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java index b4c5c6b4e2..ab73bbb62f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -72,7 +73,7 @@ class MappingsEndpointServletDocumentationTests extends AbstractEndpointDocument @BeforeEach void webTestClient(RestDocumentationContextProvider restDocumentation) { this.client = WebTestClient.bindToServer().filter(documentationConfiguration(restDocumentation)) - .baseUrl("http://localhost:" + this.port).build(); + .baseUrl("http://localhost:" + this.port).responseTimeout(Duration.ofMinutes(5)).build(); } @Test diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JerseyEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JerseyEndpointIntegrationTests.java index 7ac15241b8..cfa5d51e86 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JerseyEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JerseyEndpointIntegrationTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.integrationtest; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -69,7 +70,8 @@ class JerseyEndpointIntegrationTests { contextRunner.run((context) -> { int port = context.getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) .getWebServer().getPort(); - WebTestClient client = WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build(); + WebTestClient client = WebTestClient.bindToServer().baseUrl("http://localhost:" + port) + .responseTimeout(Duration.ofMinutes(5)).build(); client.get().uri("/actuator").exchange().expectStatus().isUnauthorized(); }); @@ -79,7 +81,8 @@ class JerseyEndpointIntegrationTests { getContextRunner(userConfigurations, getAutoconfigurations()).run((context) -> { int port = context.getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) .getWebServer().getPort(); - WebTestClient client = WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build(); + WebTestClient client = WebTestClient.bindToServer().baseUrl("http://localhost:" + port) + .responseTimeout(Duration.ofMinutes(5)).build(); client.get().uri("/actuator").exchange().expectStatus().isOk().expectBody().jsonPath("_links.beans") .isNotEmpty().jsonPath("_links.restcontroller").doesNotExist().jsonPath("_links.controller") .doesNotExist(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointExposureIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointExposureIntegrationTests.java index 61dd70d553..48fa77900d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointExposureIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointExposureIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.integrationtest; import java.io.IOException; +import java.time.Duration; import java.util.function.Supplier; import javax.servlet.ServletException; @@ -168,7 +169,7 @@ class WebMvcEndpointExposureIntegrationTests { ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() .codecs((configurer) -> configurer.defaultCodecs().maxInMemorySize(-1)).build(); return WebTestClient.bindToServer().baseUrl("http://localhost:" + port).exchangeStrategies(exchangeStrategies) - .build(); + .responseTimeout(Duration.ofMinutes(5)).build(); } private boolean isExposed(WebTestClient client, HttpMethod method, String path) throws Exception { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java index 6283f91b2a..67dcf86f57 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.security.servlet; +import java.time.Duration; import java.util.Base64; import java.util.function.Supplier; @@ -90,7 +91,8 @@ abstract class AbstractEndpointRequestIntegrationTests { protected WebTestClient getWebTestClient(AssertableWebApplicationContext context) { int port = context.getSourceApplicationContext(AnnotationConfigServletWebServerApplicationContext.class) .getWebServer().getPort(); - return WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build(); + return WebTestClient.bindToServer().baseUrl("http://localhost:" + port).responseTimeout(Duration.ofMinutes(5)) + .build(); } String getBasicAuth() { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java index 409f14b7c3..0afb46250e 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ import static org.mockito.Mockito.verify; */ public abstract class AbstractWebEndpointIntegrationTests { - private static final Duration TIMEOUT = Duration.ofMinutes(6); + private static final Duration TIMEOUT = Duration.ofMinutes(5); private static final String ACTUATOR_MEDIA_TYPE_PATTERN = "application/vnd.test\\+json(;charset=UTF-8)?"; diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingIntegrationTests.java index bcbffcee65..1b7517b661 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ class ControllerEndpointHandlerMappingIntegrationTests { private WebTestClient createWebTestClient(int port) { DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory("http://localhost:" + port); uriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE); - return WebTestClient.bindToServer().uriBuilderFactory(uriBuilderFactory).responseTimeout(Duration.ofMinutes(2)) + return WebTestClient.bindToServer().uriBuilderFactory(uriBuilderFactory).responseTimeout(Duration.ofMinutes(5)) .build(); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMappingIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMappingIntegrationTests.java index ef42dc9783..bf8b98b736 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMappingIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMappingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,7 +95,7 @@ class ControllerEndpointHandlerMappingIntegrationTests { private WebTestClient createWebTestClient(int port) { DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory("http://localhost:" + port); uriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE); - return WebTestClient.bindToServer().uriBuilderFactory(uriBuilderFactory).responseTimeout(Duration.ofMinutes(2)) + return WebTestClient.bindToServer().uriBuilderFactory(uriBuilderFactory).responseTimeout(Duration.ofMinutes(5)) .build(); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebEndpointTestInvocationContextProvider.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebEndpointTestInvocationContextProvider.java index ef16fe1047..2d12bdbdfa 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebEndpointTestInvocationContextProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebEndpointTestInvocationContextProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,7 +127,7 @@ class WebEndpointTestInvocationContextProvider implements TestTemplateInvocation static class WebEndpointsInvocationContext implements TestTemplateInvocationContext, BeforeEachCallback, AfterEachCallback, ParameterResolver { - private static final Duration TIMEOUT = Duration.ofMinutes(6); + private static final Duration TIMEOUT = Duration.ofMinutes(5); private final String name; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketWebSocketNettyRouteProviderTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketWebSocketNettyRouteProviderTests.java index d81d5c3bd1..2b8a3fb87d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketWebSocketNettyRouteProviderTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketWebSocketNettyRouteProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,7 +79,8 @@ class RSocketWebSocketNettyRouteProviderTests { } private WebTestClient createWebTestClient(WebServer server) { - return WebTestClient.bindToServer().baseUrl("http://localhost:" + server.getPort()).build(); + return WebTestClient.bindToServer().baseUrl("http://localhost:" + server.getPort()) + .responseTimeout(Duration.ofMinutes(5)).build(); } private RSocketRequester createRSocketRequester(ApplicationContext context, WebServer server) { diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java index b868f702a5..2aa871007d 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.boot.test.context; +import java.time.Duration; + import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -67,8 +69,8 @@ abstract class AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests { @Test void runAndTestHttpEndpoint() { assertThat(this.port).isNotEqualTo(8080).isNotEqualTo(0); - WebTestClient.bindToServer().baseUrl("http://localhost:" + this.port).build().get().uri("/").exchange() - .expectBody(String.class).isEqualTo("Hello World"); + WebTestClient.bindToServer().baseUrl("http://localhost:" + this.port).responseTimeout(Duration.ofMinutes(5)) + .build().get().uri("/").exchange().expectBody(String.class).isEqualTo("Hello World"); } @Test