| ... | @@ -74,15 +74,11 @@ pub fn nanoTimestamp() i128 { | ... | @@ -74,15 +74,11 @@ pub fn nanoTimestamp() i128 { |
| 74 | } | 74 | } |
| 75 | | 75 | |
| 76 | test milliTimestamp { | 76 | test milliTimestamp { |
| 77 | const margin = ns_per_ms * 50; | | |
| 78 | | | |
| 79 | const time_0 = milliTimestamp(); | 77 | const time_0 = milliTimestamp(); |
| 80 | std.Thread.sleep(ns_per_ms); | 78 | std.Thread.sleep(ns_per_ms); |
| 81 | const time_1 = milliTimestamp(); | 79 | const time_1 = milliTimestamp(); |
| 82 | const interval = time_1 - time_0; | 80 | const interval = time_1 - time_0; |
| 83 | try testing.expect(interval > 0); | 81 | try testing.expect(interval > 0); |
| 84 | // Tests should not depend on timings: skip test if outside margin. | | |
| 85 | if (!(interval < margin)) return error.SkipZigTest; | | |
| 86 | } | 82 | } |
| 87 | | 83 | |
| 88 | // Divisions of a nanosecond. | 84 | // Divisions of a nanosecond. |
| ... | @@ -277,20 +273,14 @@ pub const Timer = struct { | ... | @@ -277,20 +273,14 @@ pub const Timer = struct { |
| 277 | }; | 273 | }; |
| 278 | | 274 | |
| 279 | test Timer { | 275 | test Timer { |
| 280 | const margin = ns_per_ms * 150; | | |
| 281 | | | |
| 282 | var timer = try Timer.start(); | 276 | var timer = try Timer.start(); |
| | 277 | |
| 283 | std.Thread.sleep(10 * ns_per_ms); | 278 | std.Thread.sleep(10 * ns_per_ms); |
| 284 | const time_0 = timer.read(); | 279 | const time_0 = timer.read(); |
| 285 | try testing.expect(time_0 > 0); | 280 | 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; | | |
| 288 | | 281 | |
| 289 | const time_1 = timer.lap(); | 282 | const time_1 = timer.lap(); |
| 290 | try testing.expect(time_1 >= time_0); | 283 | try testing.expect(time_1 >= time_0); |
| 291 | | | |
| 292 | timer.reset(); | | |
| 293 | try testing.expect(timer.read() < time_1); | | |
| 294 | } | 284 | } |
| 295 | | 285 | |
| 296 | test { | 286 | test { |