Skip to content

Commit bf73671

Browse files
authored
Fix the clock resolution to millis in ScheduledEventTests (#38506)
The clock resolution changed from jdk8 to jdk10, hence the test is passing in jdk8 but failing in jdk10. Scheduled events are serialised and deserialised with millisecond precision, making test fail in jdk 10 and higher. Fixes a problem introduced by #38415 and the fix is identical to the one that was made in #38405.
1 parent f8ed6c1 commit bf73671

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/calendars/ScheduledEventTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.time.Clock;
21+
import java.time.Instant;
2122
import java.time.ZoneOffset;
2223
import java.time.ZonedDateTime;
2324
import java.util.EnumSet;
@@ -28,7 +29,7 @@
2829
public class ScheduledEventTests extends AbstractSerializingTestCase<ScheduledEvent> {
2930

3031
public static ScheduledEvent createScheduledEvent(String calendarId) {
31-
ZonedDateTime start = Clock.systemUTC().instant().atZone(ZoneOffset.UTC);
32+
ZonedDateTime start = nowWithMillisResolution();
3233
return new ScheduledEvent(randomAlphaOfLength(10), start, start.plusSeconds(randomIntBetween(1, 10000)),
3334
calendarId, null);
3435
}
@@ -119,4 +120,8 @@ public void testLenientParser() throws IOException {
119120
ScheduledEvent.LENIENT_PARSER.apply(parser, null);
120121
}
121122
}
123+
124+
private static ZonedDateTime nowWithMillisResolution() {
125+
return Instant.ofEpochMilli(Clock.systemUTC().millis()).atZone(ZoneOffset.UTC);
126+
}
122127
}

0 commit comments

Comments
 (0)