From 6d152bd043941fe1989546f6faeb9f5c4fb0ec48 Mon Sep 17 00:00:00 2001 From: David Venable Date: Wed, 12 Jul 2023 16:37:36 -0500 Subject: [PATCH] Using awaitility to improve the consistency of the RSSSourceTest. Signed-off-by: David Venable --- .../dataprepper/plugins/source/rss/RSSSourceTest.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/data-prepper-plugins/rss-source/src/test/java/org/opensearch/dataprepper/plugins/source/rss/RSSSourceTest.java b/data-prepper-plugins/rss-source/src/test/java/org/opensearch/dataprepper/plugins/source/rss/RSSSourceTest.java index 60c5151ad1..a6ae918089 100644 --- a/data-prepper-plugins/rss-source/src/test/java/org/opensearch/dataprepper/plugins/source/rss/RSSSourceTest.java +++ b/data-prepper-plugins/rss-source/src/test/java/org/opensearch/dataprepper/plugins/source/rss/RSSSourceTest.java @@ -18,6 +18,7 @@ import java.time.Duration; +import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.atLeast; @@ -62,9 +63,15 @@ public void tearDown() { @Test void test_ExecutorService_keep_writing_Events_to_Buffer() throws Exception { rssSource.start(buffer); - Thread.sleep(pollingFrequency.toMillis()); + await().atMost(pollingFrequency.multipliedBy(2)) + .untilAsserted(() -> { + verify(buffer, atLeastOnce()).writeAll(anyCollection(), anyInt()); + }); verify(buffer, atLeastOnce()).writeAll(anyCollection(), anyInt()); - Thread.sleep(pollingFrequency.toMillis()); + await().atMost(pollingFrequency.multipliedBy(2)) + .untilAsserted(() -> { + verify(buffer, atLeast(2)).writeAll(anyCollection(), anyInt()); + }); verify(buffer, atLeast(2)).writeAll(anyCollection(), anyInt()); } }