Skip to content

Commit

Permalink
Fix flaky test
Browse files Browse the repository at this point in the history
(cherry picked from commit f5c26a7)

Conflicts:
	src/test/java/com/rabbitmq/client/test/ChannelNTest.java
  • Loading branch information
sergio91pt authored and acogoluegnes committed Jun 13, 2023
1 parent 0dc9ea2 commit 83cf551
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/test/java/com/rabbitmq/client/test/ChannelNTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

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

Future<AMQImpl.Confirm.SelectOk> 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));
}
Expand Down

0 comments on commit 83cf551

Please sign in to comment.