From 209e0ddef0f76cb1ee91ddf724bd08b467e5b3ee Mon Sep 17 00:00:00 2001 From: Joao Duarte Date: Tue, 20 Oct 2026 14:57:25 +0100 Subject: [PATCH] Fix flaky WireLoggerTest connection open/close assertion ListAppender#getMessages returns a snapshot copy, so awaiting on the size of a list captured once never observed the "Closing connection" message that the server event loop logs asynchronously after the client closes. Re-read the messages on every poll and await the actual assertions. Co-Authored-By: Claude Opus 5.5 --- .../plugins/inputs/http/util/WireLoggerTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/logstash/plugins/inputs/http/util/WireLoggerTest.java b/src/test/java/org/logstash/plugins/inputs/http/util/WireLoggerTest.java index f0ff6db..877cc6d 100644 --- a/src/test/java/org/logstash/plugins/inputs/http/util/WireLoggerTest.java +++ b/src/test/java/org/logstash/plugins/inputs/http/util/WireLoggerTest.java @@ -106,13 +106,15 @@ void wireLoggerLogsOpeningAndClosingConnectionAroundHttpRequest() throws Excepti } // Implicit close of auto-closeable client so that "Closing connection" is logged before we assert. - List messages = logSpy.getMessages(); + // "Closing connection" is logged asynchronously by the server's event loop, and + // ListAppender#getMessages returns a snapshot, so re-read the messages on each poll. Awaitility.await() .atMost(5, TimeUnit.SECONDS) - .until(() -> messages.size() >= 4); - - assertThat(messages, hasItem(matchesPattern("Opening connection .*" + HOST + ":\\d+"))); - assertThat(messages, hasItem(matchesPattern("Closing connection .*" + HOST + ":\\d+"))); + .untilAsserted(() -> { + List messages = logSpy.getMessages(); + assertThat(messages, hasItem(matchesPattern("Opening connection .*" + HOST + ":\\d+"))); + assertThat(messages, hasItem(matchesPattern("Closing connection .*" + HOST + ":\\d+"))); + }); } @Test