Skip to content

Commit 83cf551

Browse files
sergio91ptacogoluegnes
authored andcommitted
Fix flaky test
(cherry picked from commit f5c26a7) Conflicts: src/test/java/com/rabbitmq/client/test/ChannelNTest.java
1 parent 0dc9ea2 commit 83cf551

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/test/java/com/rabbitmq/client/test/ChannelNTest.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import org.mockito.Mockito;
2626

2727
import java.io.IOException;
28-
import java.util.concurrent.*;
29-
import java.util.concurrent.atomic.AtomicReference;import java.util.stream.Stream;
28+
import java.util.concurrent.atomic.AtomicReference;
29+
import java.util.stream.Stream;
3030

3131
import static org.assertj.core.api.Assertions.assertThat;
32+
import java.util.concurrent.ExecutorService;
33+
import java.util.concurrent.Executors;
3234
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3335
import static org.junit.jupiter.api.Assertions.assertNotNull;
3436

@@ -116,17 +118,16 @@ public void confirmSelectOnlySendsRPCCallOnce() throws Exception {
116118

117119
ChannelN channel = new ChannelN(connection, 1, consumerWorkService);
118120

119-
Future<AMQImpl.Confirm.SelectOk> future = executorService.submit(() -> {
121+
new Thread(() -> {
120122
try {
121-
return channel.confirmSelect();
122-
} catch (IOException e) {
123+
Thread.sleep(15);
124+
channel.handleCompleteInboundCommand(new AMQCommand(new AMQImpl.Confirm.SelectOk()));
125+
} catch (Exception e) {
123126
throw new RuntimeException(e);
124127
}
125-
});
128+
}).start();
126129

127-
channel.handleCompleteInboundCommand(new AMQCommand(new AMQImpl.Confirm.SelectOk()));
128-
129-
assertNotNull(future.get(1, TimeUnit.SECONDS));
130+
assertNotNull(channel.confirmSelect());
130131
assertNotNull(channel.confirmSelect());
131132
Mockito.verify(trafficListener, Mockito.times(1)).write(Mockito.any(Command.class));
132133
}

0 commit comments

Comments
 (0)