From a08403419e17e14585f4ce7d126ac89096e40629 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 7 Mar 2024 18:52:42 +0100 Subject: [PATCH] test: HandoverIT-POC - Waiting for the assertion when all messages are sent --- .../kafka/chat/backend/AbstractHandoverIT.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java index 24dd335d..4d245fd3 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java @@ -3,6 +3,7 @@ package de.juplo.kafka.chat.backend; import de.juplo.kafka.chat.backend.api.ChatRoomInfoTo; import de.juplo.kafka.chat.backend.api.MessageTo; import lombok.extern.slf4j.Slf4j; +import org.awaitility.Awaitility; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; @@ -13,6 +14,7 @@ import pl.rzrz.assertj.reactor.Assertions; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import java.time.Duration; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -80,9 +82,16 @@ public abstract class AbstractHandoverIT log.info("Joined TestWriter {}", testWriters[i].user); } - // Yield the work, so that the last messages can be received - Thread.sleep(500); + Awaitility + .await() + .atMost(Duration.ofSeconds(30)) + .untilAsserted(() -> assertAllSentMessagesReceived(testWriters, testListener)); + } + private void assertAllSentMessagesReceived( + TestWriter[] testWriters, + TestListener testListener) + { for (int i = 0; i < NUM_CLIENTS; i++) { TestWriter testWriter = testWriters[i]; -- 2.20.1