Skip to content

Commit 0d42a1b

Browse files
committed
Add retry for flaky test (suspected Tomcat issue)
1 parent a7fe6b8 commit 0d42a1b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractWebSocketIntegrationTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525
import java.net.URI;
26-
import java.net.URISyntaxException;
2726
import java.util.LinkedHashMap;
2827
import java.util.Map;
2928
import java.util.stream.Stream;
@@ -156,8 +155,8 @@ private HttpHandler createHttpHandler() {
156155
return WebHttpHandlerBuilder.applicationContext(context).build();
157156
}
158157

159-
protected URI getUrl(String path) throws URISyntaxException {
160-
return new URI("ws://localhost:" + this.port + path);
158+
protected URI getUrl(String path) {
159+
return URI.create("ws://localhost:" + this.port + path);
161160
}
162161

163162
protected abstract Class<?> getWebConfigClass();

spring-webflux/src/test/java/org/springframework/web/reactive/socket/WebSocketIntegrationTests.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import reactor.core.publisher.Mono;
3030
import reactor.core.publisher.MonoProcessor;
3131
import reactor.core.publisher.ReplayProcessor;
32+
import reactor.util.retry.Retry;
3233

3334
import org.springframework.context.annotation.Bean;
3435
import org.springframework.context.annotation.Configuration;
@@ -39,6 +40,7 @@
3940
import org.springframework.web.reactive.socket.client.WebSocketClient;
4041
import org.springframework.web.server.WebFilter;
4142
import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer;
43+
import org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer;
4244

4345
import static org.assertj.core.api.Assertions.assertThat;
4446

@@ -66,18 +68,28 @@ protected Class<?> getWebConfigClass() {
6668
void echo(WebSocketClient client, HttpServer server, Class<?> serverConfigClass) throws Exception {
6769
startServer(client, server, serverConfigClass);
6870

71+
if (server instanceof TomcatHttpServer) {
72+
Mono.fromRunnable(this::testEcho)
73+
.retryWhen(Retry.max(3).filter(ex -> ex instanceof IllegalStateException))
74+
.block();
75+
}
76+
else {
77+
testEcho();
78+
}
79+
}
80+
81+
private void testEcho() {
6982
int count = 100;
7083
Flux<String> input = Flux.range(1, count).map(index -> "msg-" + index);
7184
ReplayProcessor<Object> output = ReplayProcessor.create(count);
72-
7385
this.client.execute(getUrl("/echo"), session -> session
7486
.send(input.map(session::textMessage))
7587
.thenMany(session.receive().take(count).map(WebSocketMessage::getPayloadAsText))
7688
.subscribeWith(output)
7789
.then())
7890
.block(TIMEOUT);
79-
80-
assertThat(output.collectList().block(TIMEOUT)).isEqualTo(input.collectList().block(TIMEOUT));
91+
assertThat(output.isTerminated()).isTrue();
92+
assertThat(output.collectList().block()).isEqualTo(input.collectList().block());
8193
}
8294

8395
@ParameterizedWebSocketTest

0 commit comments

Comments
 (0)