Skip to content

Commit 31e7c95

Browse files
committed
std.time: Make tests less flaky.
For the Timer decltest in particular, the margin check is not going to help if the kernel just decides not to schedule the thread for a while after we call timer.reset(). Failure observed here: https://github.com/ziglang/zig/actions/runs/13443634035/job/37563803341?pr=22909
1 parent 8d9bb97 commit 31e7c95

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

lib/std/time.zig

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,11 @@ pub fn nanoTimestamp() i128 {
7474
}
7575

7676
test milliTimestamp {
77-
const margin = ns_per_ms * 50;
78-
7977
const time_0 = milliTimestamp();
8078
std.Thread.sleep(ns_per_ms);
8179
const time_1 = milliTimestamp();
8280
const interval = time_1 - time_0;
8381
try testing.expect(interval > 0);
84-
// Tests should not depend on timings: skip test if outside margin.
85-
if (!(interval < margin)) return error.SkipZigTest;
8682
}
8783

8884
// Divisions of a nanosecond.
@@ -277,20 +273,14 @@ pub const Timer = struct {
277273
};
278274

279275
test Timer {
280-
const margin = ns_per_ms * 150;
281-
282276
var timer = try Timer.start();
277+
283278
std.Thread.sleep(10 * ns_per_ms);
284279
const time_0 = timer.read();
285280
try testing.expect(time_0 > 0);
286-
// Tests should not depend on timings: skip test if outside margin.
287-
if (!(time_0 < margin)) return error.SkipZigTest;
288281

289282
const time_1 = timer.lap();
290283
try testing.expect(time_1 >= time_0);
291-
292-
timer.reset();
293-
try testing.expect(timer.read() < time_1);
294284
}
295285

296286
test {

0 commit comments

Comments
 (0)