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) {