Skip to content

Commit 9f9dcc7

Browse files
committed
fix(tests): make EventCorrelatorTest timestamps deterministic
Avoid relying on Thread.sleep(100) to produce distinct timestamps. The sleep was removed because the test only requires timestamp ordering, not elapsed time. However, the Windows Bazel build showed that OffsetDateTime.now() can return identical timestamps in consecutive calls depending on the environment clock resolution. Advance the timestamp explicitly instead, keeping the test deterministic across different platforms.
1 parent 0ec504c commit 9f9dcc7

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

‎extended/src/test/java/io/kubernetes/client/extended/event/EventCorrelatorTest.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,16 @@ void eventCorrelate(
144144
Boolean expectedSkip)
145145
throws Exception {
146146
EventCorrelator correlator = new EventCorrelator();
147+
OffsetDateTime now = OffsetDateTime.now();
147148
for (CoreV1Event event : previousEvents) {
148-
OffsetDateTime now = OffsetDateTime.now();
149149
event.setFirstTimestamp(now);
150150
event.setLastTimestamp(now);
151151
Optional<MutablePair<CoreV1Event, V1Patch>> result = correlator.correlate(event);
152152
if (result.isEmpty()) {
153153
correlator.updateState(event);
154154
}
155155
}
156-
Thread.sleep(100);
157-
OffsetDateTime now = OffsetDateTime.now();
156+
now = now.plusNanos(10);
158157
newEvent.setFirstTimestamp(now);
159158
newEvent.setLastTimestamp(now);
160159
Optional<MutablePair<CoreV1Event, V1Patch>> result = correlator.correlate(newEvent);

0 commit comments

Comments
 (0)