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)" {...@@ -1354,7 +1354,7 @@ test "timeout (after a relative time)" {
1354 .flags = 0,1354 .flags = 0,
1355 }, cqe);1355 }, 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.
1358 if (!std.math.approxEqAbs(f64, ms, @intToFloat(f64, stopped - started), margin)) return error.SkipZigTest;1358 if (!std.math.approxEqAbs(f64, ms, @intToFloat(f64, stopped - started), margin)) return error.SkipZigTest;
1359}1359}
13601360
lib/std/time.zig+6-2
...@@ -271,7 +271,9 @@ test "timestamp" {...@@ -271,7 +271,9 @@ test "timestamp" {
271 sleep(ns_per_ms);271 sleep(ns_per_ms);
272 const time_1 = milliTimestamp();272 const time_1 = milliTimestamp();
273 const interval = time_1 - time_0;273 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;
275}277}
276278
277test "Timer" {279test "Timer" {
...@@ -280,7 +282,9 @@ test "Timer" {...@@ -280,7 +282,9 @@ test "Timer" {
280 var timer = try Timer.start();282 var timer = try Timer.start();
281 sleep(10 * ns_per_ms);283 sleep(10 * ns_per_ms);
282 const time_0 = timer.read();284 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
285 const time_1 = timer.lap();289 const time_1 = timer.lap();
286 testing.expect(time_1 >= time_0);290 testing.expect(time_1 >= time_0);