From a45c3a9d409327a17906ce05e97e65dac285acaf Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:01:12 -0400 Subject: [PATCH] fix: Test for proper clock settings before running clock tests (#5932) Clock tests occasionally fail when the system clock is improperly set. Test the system clock's setting before performing more tests. This does not resolve the problem, but it provides clear evidence of the root cause of intermittent clock test failures. --- .../src/test/java/io/deephaven/time/TestDateTimeUtils.java | 7 +++++++ .../deephaven/time/calendar/TestStaticCalendarMethods.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/engine/time/src/test/java/io/deephaven/time/TestDateTimeUtils.java b/engine/time/src/test/java/io/deephaven/time/TestDateTimeUtils.java index 7dcad0ad771..585cde2f96a 100644 --- a/engine/time/src/test/java/io/deephaven/time/TestDateTimeUtils.java +++ b/engine/time/src/test/java/io/deephaven/time/TestDateTimeUtils.java @@ -1933,6 +1933,13 @@ public Instant instantMillis() { TestCase.assertEquals(Instant.ofEpochSecond(0, (nanos / DateTimeUtils.MILLI) * DateTimeUtils.MILLI), DateTimeUtils.nowMillisResolution()); + // Occasionally tests fail because of invalid clocks on the test system + final LocalDate startDate = LocalDate.of(1990, 1, 1); + final LocalDate currentDate = DateTimeUtils.toLocalDate( + DateTimeUtils.epochNanosToInstant(Clock.system().currentTimeNanos()), DateTimeUtils.timeZone()); + assertTrue("Checking for a valid date on the test system: currentDate=" + currentDate, + currentDate.isAfter(startDate)); + TestCase.assertTrue(Math.abs(Clock.system().currentTimeNanos() - DateTimeUtils.epochNanos(DateTimeUtils.nowSystem())) < 1_000_000L); TestCase.assertTrue(Math.abs(Clock.system().currentTimeNanos() diff --git a/engine/time/src/test/java/io/deephaven/time/calendar/TestStaticCalendarMethods.java b/engine/time/src/test/java/io/deephaven/time/calendar/TestStaticCalendarMethods.java index 4140b66cf34..47f6ed9ef5a 100644 --- a/engine/time/src/test/java/io/deephaven/time/calendar/TestStaticCalendarMethods.java +++ b/engine/time/src/test/java/io/deephaven/time/calendar/TestStaticCalendarMethods.java @@ -3,6 +3,7 @@ // package io.deephaven.time.calendar; +import io.deephaven.base.clock.Clock; import io.deephaven.base.testing.BaseArrayTestCase; import io.deephaven.time.DateTimeUtils; @@ -107,6 +108,12 @@ public void testAll() { excludes.add("firstValidDate"); excludes.add("lastValidDate"); + // Occasionally tests fail because of invalid clocks on the test system + final LocalDate startDate = LocalDate.of(1990, 1, 1); + final LocalDate currentDate = DateTimeUtils.todayLocalDate(); + assertTrue("Checking for a valid date on the test system: currentDate=" + currentDate, + currentDate.isAfter(startDate)); + for (Method m1 : BusinessCalendar.class.getMethods()) { if (m1.getDeclaringClass() == Object.class || Modifier.isStatic(m1.getModifiers()) ||