Skip to content

Commit 5ba4ba5

Browse files
committed
use interval for test
1 parent be90f65 commit 5ba4ba5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tests/pass/shims/time-with-isolation.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
use std::time::{Duration, Instant};
22

3+
fn duration_sanity(diff: Duration) {
4+
// The virtual clock is deterministic and I got 29us on a 64-bit Linux machine. However, this
5+
// changes according to the platform so we use an interval to be safe. This should be updated
6+
// if `NANOSECONDS_PER_BASIC_BLOCK` changes.
7+
assert!(diff.as_micros() > 10);
8+
assert!(diff.as_micros() < 40);
9+
}
10+
311
fn test_sleep() {
412
let before = Instant::now();
513
std::thread::sleep(Duration::from_millis(100));
@@ -20,9 +28,7 @@ fn main() {
2028
let diff = now2.duration_since(now1);
2129
assert_eq!(now1 + diff, now2);
2230
assert_eq!(now2 - diff, now1);
23-
// The virtual clock is deterministic and I got 29us. This should be updated if
24-
// `NANOSECONDS_PER_BASIC_BLOCK` changes.
25-
assert_eq!(diff.as_micros(), 29);
31+
duration_sanity(diff);
2632

2733
test_sleep();
2834
}

0 commit comments

Comments
 (0)