From 31e7c95bd20801c6cb0cfbc47074333754f82ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 21 Feb 2025 01:01:52 +0100 Subject: [PATCH] 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 --- lib/std/time.zig | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/std/time.zig b/lib/std/time.zig index 3b6abfdb7b..b4fd271205 100644 --- a/lib/std/time.zig +++ b/lib/std/time.zig @@ -74,15 +74,11 @@ pub fn nanoTimestamp() i128 { } test milliTimestamp { - const margin = ns_per_ms * 50; - const time_0 = milliTimestamp(); std.Thread.sleep(ns_per_ms); const time_1 = milliTimestamp(); const interval = time_1 - time_0; try testing.expect(interval > 0); - // Tests should not depend on timings: skip test if outside margin. - if (!(interval < margin)) return error.SkipZigTest; } // Divisions of a nanosecond. @@ -277,20 +273,14 @@ pub const Timer = struct { }; test Timer { - const margin = ns_per_ms * 150; - var timer = try Timer.start(); + std.Thread.sleep(10 * ns_per_ms); const time_0 = timer.read(); try testing.expect(time_0 > 0); - // Tests should not depend on timings: skip test if outside margin. - if (!(time_0 < margin)) return error.SkipZigTest; const time_1 = timer.lap(); try testing.expect(time_1 >= time_0); - - timer.reset(); - try testing.expect(timer.read() < time_1); } test {