From 7f7cf7cb03fefe789e8982fbea1650d0dab06a72 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 29 Sep 2026 13:26:30 +0200 Subject: [PATCH] [CI] Wait for the flush in testBatchSizeFromConfig instead of sleeping 4 s The 200th line starts the flush on another thread and the request goes to the real ingesting endpoint. The test slept a fixed 4 s and then required exactly one API call and a 202 response, so it failed whenever the request took longer (a bare AssertionError from isOk()) or had failed and been retried by the appender by then (expected:<1> but was:<2>) - six times since 2026-09-08, hidden by the retry wrapper in the Java Build workflow. Wait for the flush with LogtailAppenderDecorator.awaitFlushCompletion() instead, and count the calls the endpoint accepted rather than all calls, so the test still checks that the batch went out in exactly one request while the appender's retries do their job. Co-Authored-By: Claude Opus 5.5 --- .../logback/LogtailAppenderBatchConfigSizeTest.java | 7 +++++-- .../java/com/logtail/logback/LogtailAppenderDecorator.java | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/logtail/logback/LogtailAppenderBatchConfigSizeTest.java b/src/test/java/com/logtail/logback/LogtailAppenderBatchConfigSizeTest.java index 25ef39c..c9af9bf 100644 --- a/src/test/java/com/logtail/logback/LogtailAppenderBatchConfigSizeTest.java +++ b/src/test/java/com/logtail/logback/LogtailAppenderBatchConfigSizeTest.java @@ -60,10 +60,13 @@ public void testBatchSizeFromConfig() throws Exception { MDC.put("requestId", "testErrorLog"); MDC.put("requestTime", 199 + ""); this.logger.info(batchRunId + " Custom batch size Final Batch Groot "); - Thread.sleep(4000); - assertEquals(1, this.appender.apiCalls); + + // The 200th line sends the batch on another thread. Wait for that flush instead of a fixed time: a request to + // the real endpoint now and then takes several seconds, or fails and is retried by the appender + this.appender.awaitFlushCompletion(); isOk(); + assertEquals(1, this.appender.acceptedCalls); } private void isOk() { diff --git a/src/test/java/com/logtail/logback/LogtailAppenderDecorator.java b/src/test/java/com/logtail/logback/LogtailAppenderDecorator.java index 77f0040..99fb8eb 100644 --- a/src/test/java/com/logtail/logback/LogtailAppenderDecorator.java +++ b/src/test/java/com/logtail/logback/LogtailAppenderDecorator.java @@ -9,12 +9,17 @@ public class LogtailAppenderDecorator extends LogtailAppender { private Exception exception; private LogtailResponse response; protected int apiCalls = 0; + // Calls answered with 202, i.e. apiCalls without the failed ones the appender retried + protected int acceptedCalls = 0; @Override protected LogtailResponse callHttpURLConnection(int flushedSize) throws IOException { try { apiCalls++; this.response = super.callHttpURLConnection(flushedSize); + if (isOK()) { + acceptedCalls++; + } return this.response; } catch (Exception e) {