Skip to content

Commit ed473ee

Browse files
committed
Fix hanging test
Make it less harsh and execute it in dedicated thread to avoid hanging. (cherry picked from commit 838cc55)
1 parent 56ca902 commit ed473ee

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/test/java/com/rabbitmq/client/test/server/EffectVisibilityCrossNodeTest.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.junit.Assert.assertEquals;
1919

2020
import java.io.IOException;
21+
import java.util.concurrent.*;
2122

2223
import org.junit.Test;
2324

@@ -46,20 +47,30 @@ protected void releaseResources() throws IOException {
4647
}
4748

4849
private static final int QUEUES = 5;
49-
private static final int BATCHES = 500;
50-
private static final int MESSAGES_PER_BATCH = 10;
50+
private static final int BATCHES = 100;
51+
private static final int MESSAGES_PER_BATCH = 5;
5152

5253
private static final byte[] msg = "".getBytes();
5354

5455
@Test public void effectVisibility() throws Exception {
55-
56-
for (int i = 0; i < BATCHES; i++) {
57-
for (int j = 0; j < MESSAGES_PER_BATCH; j++) {
58-
channel.basicPublish("amq.fanout", "", null, msg);
59-
}
60-
for (int j = 0; j < queues.length ; j++) {
61-
assertEquals(MESSAGES_PER_BATCH, channel.queuePurge(queues[j]).getMessageCount());
62-
}
56+
ExecutorService executorService = Executors.newSingleThreadExecutor();
57+
try {
58+
Future<Void> task = executorService.submit(() -> {
59+
for (int i = 0; i < BATCHES; i++) {
60+
Thread.sleep(10); // to avoid flow control for the connection
61+
for (int j = 0; j < MESSAGES_PER_BATCH; j++) {
62+
channel.basicPublish("amq.fanout", "", null, msg);
63+
}
64+
for (int j = 0; j < queues.length; j++) {
65+
assertEquals(MESSAGES_PER_BATCH, channel.queuePurge(queues[j]).getMessageCount());
66+
}
67+
}
68+
return null;
69+
});
70+
task.get(1, TimeUnit.MINUTES);
71+
} finally {
72+
executorService.shutdownNow();
73+
executorService.awaitTermination(1, TimeUnit.SECONDS);
6374
}
6475
}
6576
}

src/test/java/com/rabbitmq/client/test/server/ServerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Permissions.class,
2727
DurableBindingLifecycle.class,
2828
DeadLetterExchangeDurable.class,
29-
//EffectVisibilityCrossNodeTest.class,
29+
EffectVisibilityCrossNodeTest.class,
3030
ExclusiveQueueDurability.class,
3131
AbsentQueue.class,
3232
AlternateExchangeEquivalence.class,

0 commit comments

Comments
 (0)