Skip to content

Commit

Permalink
fix: Test for proper clock settings before running clock tests (#5932)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chipkent authored Aug 13, 2024
1 parent e53433f commit a45c3a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()) ||
Expand Down

0 comments on commit a45c3a9

Please sign in to comment.