From 5ce49709980d9f8d260a58140a2c98770e81dcb7 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Fri, 23 Oct 2026 11:46:44 +0300 Subject: [PATCH] Start the view tests early in a second A view's duration is the difference of two whole-second timestamps, so a view stopped right after it started reports 1 s whenever the two calls fall on either side of a second boundary, and the strict 0.0 duration checks failed on busy runners ("0.0 expected duration, got 1.0"). The view test classes now wait in their setup until the clock is within the first 200 ms of a second. --- .../count/sdk/java/internal/ModuleViewsTests.java | 3 ++- .../count/sdk/java/internal/SessionImplTests.java | 3 ++- .../java/ly/count/sdk/java/internal/TestUtils.java | 14 ++++++++++++++ .../sdk/java/internal/sc_MV_ManualViewTests.java | 3 ++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleViewsTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleViewsTests.java index 2c25479da..07fc1d747 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleViewsTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/ModuleViewsTests.java @@ -17,8 +17,9 @@ public class ModuleViewsTests { @Before - public void beforeTest() { + public void beforeTest() throws InterruptedException { TestUtils.createCleanTestState(); + TestUtils.awaitStartOfSecond(); } @After diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java index 74b38403e..2b903399c 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java @@ -614,13 +614,14 @@ public void view() { * start, stop and next view should be recorded to EQ */ @Test - public void view_stopStartedAndNext() { + public void view_stopStartedAndNext() throws InterruptedException { InternalConfig config = new InternalConfig(TestUtils.getConfigSessions(Config.Feature.Views, Config.Feature.Events).setEventQueueSizeToSend(4)); config.viewIdGenerator = TestUtils.idGenerator(); Countly.instance().init(config); SessionImpl session = (SessionImpl) Countly.session(); TestUtils.validateEQSize(0); + TestUtils.awaitStartOfSecond(); session.view("start"); TestUtils.validateEQSize(1); session.view("next"); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java index 0d558d64b..ebc0d03af 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java @@ -352,6 +352,20 @@ public static Map parseQueryParams(String data) { */ private static final double SLEEP_OVERRUN_TOLERANCE_SECONDS = 2.0; + /** + * Waits for the next second when the clock is past the first 200 ms of the current one. A view + * duration is the difference of two whole-second timestamps, so a view stopped right after it + * started reports 1 s when the two calls fall on either side of a second boundary. + * + * @throws InterruptedException when the wait is interrupted + */ + static void awaitStartOfSecond() throws InterruptedException { + long intoSecond = System.currentTimeMillis() % 1000; + if (intoSecond > 200) { + Thread.sleep(1000 - intoSecond); + } + } + static void validateEvent(EventImpl gonnaValidate, String key, Map segmentation, int count, Double sum, Double duration, String id, String pvid, String cvid, String peid) { Assert.assertEquals(key, gonnaValidate.key); diff --git a/sdk-java/src/test/java/ly/count/sdk/java/internal/sc_MV_ManualViewTests.java b/sdk-java/src/test/java/ly/count/sdk/java/internal/sc_MV_ManualViewTests.java index b94a9eadd..0725a0b3a 100644 --- a/sdk-java/src/test/java/ly/count/sdk/java/internal/sc_MV_ManualViewTests.java +++ b/sdk-java/src/test/java/ly/count/sdk/java/internal/sc_MV_ManualViewTests.java @@ -16,8 +16,9 @@ @RunWith(JUnit4.class) public class sc_MV_ManualViewTests { @Before - public void beforeTest() { + public void beforeTest() throws InterruptedException { TestUtils.createCleanTestState(); + TestUtils.awaitStartOfSecond(); } @After