From 83cf551fb0142f7a5d042bd54e0cf3c1e47ed419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Faria?= Date: Fri, 9 Jun 2023 10:05:47 +0100 Subject: [PATCH] Fix flaky test (cherry picked from commit f5c26a7975b22a8b73cbde98be9b8cb63c233275) Conflicts: src/test/java/com/rabbitmq/client/test/ChannelNTest.java --- .../rabbitmq/client/test/ChannelNTest.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/rabbitmq/client/test/ChannelNTest.java b/src/test/java/com/rabbitmq/client/test/ChannelNTest.java index f557e5f3d..372acbc18 100644 --- a/src/test/java/com/rabbitmq/client/test/ChannelNTest.java +++ b/src/test/java/com/rabbitmq/client/test/ChannelNTest.java @@ -25,10 +25,12 @@ import org.mockito.Mockito; import java.io.IOException; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicReference;import java.util.stream.Stream; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -116,17 +118,16 @@ public void confirmSelectOnlySendsRPCCallOnce() throws Exception { ChannelN channel = new ChannelN(connection, 1, consumerWorkService); - Future future = executorService.submit(() -> { + new Thread(() -> { try { - return channel.confirmSelect(); - } catch (IOException e) { + Thread.sleep(15); + channel.handleCompleteInboundCommand(new AMQCommand(new AMQImpl.Confirm.SelectOk())); + } catch (Exception e) { throw new RuntimeException(e); } - }); + }).start(); - channel.handleCompleteInboundCommand(new AMQCommand(new AMQImpl.Confirm.SelectOk())); - - assertNotNull(future.get(1, TimeUnit.SECONDS)); + assertNotNull(channel.confirmSelect()); assertNotNull(channel.confirmSelect()); Mockito.verify(trafficListener, Mockito.times(1)).write(Mockito.any(Command.class)); }