Skip to content

Commit 10197e7

Browse files
committed
Harden test
Sometimes fails on CI.
1 parent 8cba9ad commit 10197e7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/test/java/com/rabbitmq/stream/impl/StreamConsumerTest.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,14 @@ void duplicatesWhenResubscribeAfterDisconnectionWithLongFlushInterval() throws E
627627
AtomicInteger receivedMessages = new AtomicInteger(0);
628628
int storeEvery = 10_000;
629629
String reference = "ref-1";
630-
CountDownLatch poisonLatch = new CountDownLatch(1);
630+
AtomicBoolean receivedPoison = new AtomicBoolean(false);
631631
environment.consumerBuilder().name(reference).stream(stream)
632632
.offset(OffsetSpecification.first())
633633
.messageHandler(
634634
(context, message) -> {
635635
receivedMessages.incrementAndGet();
636636
if ("poison".equals(new String(message.getBodyAsBinary()))) {
637-
poisonLatch.countDown();
637+
receivedPoison.set(true);
638638
}
639639
})
640640
.autoTrackingStrategy()
@@ -660,9 +660,15 @@ void duplicatesWhenResubscribeAfterDisconnectionWithLongFlushInterval() throws E
660660
Host.killConnection("rabbitmq-stream-consumer-0");
661661

662662
publish.accept(storeEvery * 2);
663-
producer.send(
664-
producer.messageBuilder().addData("poison".getBytes()).build(), confirmationStatus -> {});
665-
latchAssert(poisonLatch).completes();
663+
waitAtMost(
664+
() -> {
665+
producer.send(
666+
producer.messageBuilder().addData("poison".getBytes()).build(),
667+
confirmationStatus -> {});
668+
publishedMessages.incrementAndGet();
669+
return receivedPoison.get();
670+
});
671+
666672
// we have duplicates because the last stored value is behind and the re-subscription uses it
667673
assertThat(receivedMessages).hasValueGreaterThan(publishedMessages.get());
668674
}

0 commit comments

Comments
 (0)