Skip to content

Commit 8f9028f

Browse files
committed
Fix Race in Test
1 parent 70fd4ce commit 8f9028f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

spring-kafka/src/test/java/org/springframework/kafka/listener/KafkaMessageListenerContainerTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,12 +2772,14 @@ public void rePausePartitionAfterRebalance() throws Exception {
27722772
return null;
27732773
}).given(consumer).pause(any());
27742774
given(consumer.paused()).willReturn(pausedParts);
2775+
CountDownLatch firstPoll = new CountDownLatch(1);
27752776
given(consumer.poll(any(Duration.class))).willAnswer(i -> {
27762777
if (paused.get()) {
27772778
pauseLatch1.countDown();
27782779
// hold up the consumer thread while we revoke/assign partitions on the test thread
27792780
suspendConsumerThread.await(10, TimeUnit.SECONDS);
27802781
}
2782+
firstPoll.countDown();
27812783
Thread.sleep(50);
27822784
return ConsumerRecords.empty();
27832785
});
@@ -2801,6 +2803,7 @@ public void rePausePartitionAfterRebalance() throws Exception {
28012803
new KafkaMessageListenerContainer<>(cf, containerProps);
28022804
container.start();
28032805
InOrder inOrder = inOrder(consumer);
2806+
assertThat(firstPoll.await(10, TimeUnit.SECONDS)).isNotNull();
28042807
container.pausePartition(tp0);
28052808
container.pausePartition(tp1);
28062809
assertThat(pauseLatch1.await(10, TimeUnit.SECONDS)).isTrue();

0 commit comments

Comments
 (0)