From 3873bf23f87ad4fd69691f3dbce2cad7357ab233 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Fri, 23 Oct 2026 10:35:11 +0300 Subject: [PATCH] Wait for a sent log batch to be handed over before asserting it The networking removes a sent log batch and only then lets the logger queue the next one, so the tests' wait for sent batches could end in between and find lines still held ("expected:<0> but was:<475>" on CI). It now also waits for the networking task that sent the batch, for which DefaultNetworking.tasks is package-private. --- .../count/sdk/java/internal/DefaultNetworking.java | 3 ++- .../sdk/java/internal/SdkLogGatheringTests.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/DefaultNetworking.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/DefaultNetworking.java index 10b00aab..f1e9ee22 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/DefaultNetworking.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/DefaultNetworking.java @@ -19,7 +19,8 @@ public class DefaultNetworking implements Networking { private Log L = null; private Transport transport; - private Tasks tasks; + //package-private so tests can wait until a sent request was handled + Tasks tasks; private volatile boolean shutdown; private volatile boolean backedOff; diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/SdkLogGatheringTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/SdkLogGatheringTests.java index 94a7db3d..fd502a1a 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/SdkLogGatheringTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/SdkLogGatheringTests.java @@ -896,6 +896,8 @@ private static void awaitSentBatches() throws Exception { for (int round = 0; round < 200; round++) { awaitLogDelivery(); Assert.assertTrue("a queued batch never reached the server", TestUtils.waitFor(30_000, () -> storedBatchCount() == 0)); + //the networking removes a sent batch before it lets the logger queue the next one + awaitNetworking(); awaitLogDelivery(); if (storedBatchCount() == 0) { return; @@ -904,6 +906,17 @@ private static void awaitSentBatches() throws Exception { Assert.fail("the logger kept queueing batches"); } + /** + * Waits until the networking finished the task it was running, the handling of a sent request + * included. + */ + private static void awaitNetworking() { + SDKCore core = SDKCore.instance; + if (core != null && core.networking instanceof DefaultNetworking) { + ((DefaultNetworking) core.networking).tasks.await(); + } + } + /** * The log batches stored on disk, read straight from the request files, which works once the * SDK stopped too.