From d1a25edd73f434c0d8eb2444b505e78ad1165ff3 Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Fri, 1 Sep 2023 18:55:58 +0300 Subject: [PATCH] [test] Fix flaky test From time to time HttpServerTests#testSniSupportHandshakeTimeout fails on CI with HttpServerTests > testSniSupportHandshakeTimeout() FAILED java.lang.AssertionError: Expecting actual not to be null at reactor.netty.http.server.HttpServerTests.testSniSupportHandshakeTimeout(HttpServerTests.java:2259) --- .../reactor/netty/http/server/HttpServerTests.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/reactor-netty-http/src/test/java/reactor/netty/http/server/HttpServerTests.java b/reactor-netty-http/src/test/java/reactor/netty/http/server/HttpServerTests.java index 1b81677b38..17f59b6992 100644 --- a/reactor-netty-http/src/test/java/reactor/netty/http/server/HttpServerTests.java +++ b/reactor-netty-http/src/test/java/reactor/netty/http/server/HttpServerTests.java @@ -117,6 +117,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.publisher.SignalType; +import reactor.core.publisher.Sinks; import reactor.netty.BaseHttpTest; import reactor.netty.ByteBufFlux; import reactor.netty.ChannelBindException; @@ -2220,7 +2221,7 @@ void testSniSupportHandshakeTimeout() { Http11SslContextSpec.forClient() .configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE)); - AtomicReference error = new AtomicReference<>(); + Sinks.One error = Sinks.one(); disposableServer = createServer() .childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(64)) @@ -2234,7 +2235,7 @@ void testSniSupportHandshakeTimeout() { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (evt instanceof SniCompletionEvent) { - error.set(((SniCompletionEvent) evt).cause()); + error.tryEmitValue(((SniCompletionEvent) evt).cause()); } ctx.fireUserEventTriggered(evt); } @@ -2253,7 +2254,10 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { .expectError() .verify(Duration.ofSeconds(5)); - assertThat(error.get()).isNotNull().isInstanceOf(SslHandshakeTimeoutException.class); + StepVerifier.create(error.asMono()) + .expectNextMatches(t -> t instanceof SslHandshakeTimeoutException) + .expectComplete() + .verify(Duration.ofSeconds(10)); } @Test