authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2021-04-07 05:25:59-04:00
committergravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2021-04-07 08:33:32-04:00
log2871d32be727fc729ba4be0c615cb5fe97591391
tree4eb9ae33ffda30c058431e9f2fc591de25b506a7
parentf253822415304fc069f68452f7f4abbded58a24e

test: fix std.time timing tests to skip on failure


2 files changed, 7 insertions(+), 3 deletions(-)

lib/std/os/linux/io_uring.zig+1-1
......@@ -1354,7 +1354,7 @@ test "timeout (after a relative time)" {
13541354 .flags = 0,
13551355 }, cqe);
13561356
1357 // Tests should not depend on timings: skip test (result) if outside margin.
1357 // Tests should not depend on timings: skip test if outside margin.
13581358 if (!std.math.approxEqAbs(f64, ms, @intToFloat(f64, stopped - started), margin)) return error.SkipZigTest;
13591359}
13601360
lib/std/time.zig+6-2
......@@ -271,7 +271,9 @@ test "timestamp" {
271271 sleep(ns_per_ms);
272272 const time_1 = milliTimestamp();
273273 const interval = time_1 - time_0;
274 testing.expect(interval > 0 and interval < margin);
274 testing.expect(interval > 0);
275 // Tests should not depend on timings: skip test if outside margin.
276 if (!(interval < margin)) return error.SkipZigTest;
275277}
276278
277279test "Timer" {
......@@ -280,7 +282,9 @@ test "Timer" {
280282 var timer = try Timer.start();
281283 sleep(10 * ns_per_ms);
282284 const time_0 = timer.read();
283 testing.expect(time_0 > 0 and time_0 < margin);
285 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;
284288
285289 const time_1 = timer.lap();
286290 testing.expect(time_1 >= time_0);