| ... | ... | @@ -74,15 +74,11 @@ pub fn nanoTimestamp() i128 { |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | test milliTimestamp { |
| 77 | | const margin = ns_per_ms * 50; |
| 78 | | |
| 79 | 77 | const time_0 = milliTimestamp(); |
| 80 | 78 | std.Thread.sleep(ns_per_ms); |
| 81 | 79 | const time_1 = milliTimestamp(); |
| 82 | 80 | const interval = time_1 - time_0; |
| 83 | 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 | 84 | // Divisions of a nanosecond. |
| ... | ... | @@ -277,20 +273,14 @@ pub const Timer = struct { |
| 277 | 273 | }; |
| 278 | 274 | |
| 279 | 275 | test Timer { |
| 280 | | const margin = ns_per_ms * 150; |
| 281 | | |
| 282 | 276 | var timer = try Timer.start(); |
| 277 | |
| 283 | 278 | std.Thread.sleep(10 * ns_per_ms); |
| 284 | 279 | const time_0 = timer.read(); |
| 285 | 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 | 282 | const time_1 = timer.lap(); |
| 290 | 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 | 286 | test { |