From 4c44b91cf93c42bad17d76d0a8a226b457e9cb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Fri, 18 Oct 2024 10:33:32 +0200 Subject: [PATCH 1/2] Speedup WebFlux tests by reducing the interval period In WebFlux, we have various tests using a period of 50 or 100ms. We should use a smaller value like 1ms to speedup tests. Closes gh-33738 --- .../springframework/web/reactive/FlushingIntegrationTests.java | 2 +- .../function/server/SseHandlerFunctionIntegrationTests.java | 2 +- .../method/annotation/JacksonStreamingIntegrationTests.java | 2 +- .../result/method/annotation/ProtobufIntegrationTests.java | 2 +- .../method/annotation/RequestMappingIntegrationTests.java | 2 +- .../reactive/result/method/annotation/SseIntegrationTests.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java index 994a3bdb8c..0a429c67af 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java @@ -127,7 +127,7 @@ class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTests { String path = request.getURI().getPath(); return switch (path) { case "/write-and-flush" -> response.writeAndFlushWith( - testInterval(Duration.ofMillis(50), 2) + testInterval(Duration.ofMillis(1), 2) .map(longValue -> wrap("data" + longValue + "\n", response)) .map(Flux::just) .mergeWith(Flux.never())); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java index a5e65f4612..76333bc929 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java @@ -125,7 +125,7 @@ class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIntegrati private static class SseHandler { - private static final Flux INTERVAL = testInterval(Duration.ofMillis(100), 2); + private static final Flux INTERVAL = testInterval(Duration.ofMillis(1), 2); Mono string(ServerRequest request) { return ServerResponse.ok() diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java index 7cbec1f258..047d334f3f 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java @@ -109,7 +109,7 @@ class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegrationTes @GetMapping(value = "/stream", produces = { APPLICATION_NDJSON_VALUE, "application/stream+x-jackson-smile" }) Flux person() { - return testInterval(Duration.ofMillis(100), 50).map(l -> new Person("foo " + l)); + return testInterval(Duration.ofMillis(1), 50).map(l -> new Person("foo " + l)); } } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ProtobufIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ProtobufIntegrationTests.java index ef8ed31a95..6fd4f3767a 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ProtobufIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ProtobufIntegrationTests.java @@ -168,7 +168,7 @@ class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationTests { @GetMapping(value = "/message-stream", produces = "application/x-protobuf;delimited=true") Flux messageStream() { - return testInterval(Duration.ofMillis(50), 5).map(l -> + return testInterval(Duration.ofMillis(1), 5).map(l -> Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(l.intValue()).build()).build()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java index 34d8a2cd6d..b33e39a399 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java @@ -177,7 +177,7 @@ class RequestMappingIntegrationTests extends AbstractRequestMappingIntegrationTe @GetMapping("/stream") public Publisher stream() { - return testInterval(Duration.ofMillis(50), 5); + return testInterval(Duration.ofMillis(1), 5); } } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java index 205ff217a8..92a82ba71d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java @@ -202,7 +202,7 @@ class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { @RequestMapping("/sse") static class SseController { - private static final Flux INTERVAL = testInterval(Duration.ofMillis(100), 50); + private static final Flux INTERVAL = testInterval(Duration.ofMillis(1), 50); private final Sinks.Empty cancelSink = Sinks.empty(); From 5e28a25a301f188563d20d503030433b3343c6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Fri, 18 Oct 2024 11:11:52 +0200 Subject: [PATCH 2/2] Add a WebFlux integration test This commit adds a WebFlux integration test with a request body and a delayed response in order to test a use case where we found a regression with Undertow 2.3.18.Final. For now, Undertow 2.3.17.Final is still used. Closes gh-33739 --- .../RequestMappingIntegrationTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java index b33e39a399..ca52e7a255 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java @@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import org.reactivestreams.Publisher; +import reactor.core.publisher.Mono; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -34,6 +35,8 @@ import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @@ -116,6 +119,13 @@ class RequestMappingIntegrationTests extends AbstractRequestMappingIntegrationTe assertThat(performGet("/stream", new HttpHeaders(), int[].class).getBody()).isEqualTo(expected); } + @ParameterizedHttpServerTest // gh-33739 + void requestBodyAndDelayedResponse(HttpServer httpServer) throws Exception { + startServer(httpServer); + + assertThat(performPost("/post", new HttpHeaders(), "text", String.class).getBody()).isEqualTo("text"); + } + @Configuration @EnableWebFlux @@ -179,6 +189,12 @@ class RequestMappingIntegrationTests extends AbstractRequestMappingIntegrationTe public Publisher stream() { return testInterval(Duration.ofMillis(1), 5); } + + @PostMapping("/post") + public Mono postDelayedInput(@RequestBody String text) { + return Mono.just(text).delayElement(Duration.ofMillis(1)); + } + }