File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 1
1
use std:: time:: { Duration , Instant } ;
2
2
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
+
3
11
fn test_sleep ( ) {
4
12
let before = Instant :: now ( ) ;
5
13
std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
@@ -20,9 +28,7 @@ fn main() {
20
28
let diff = now2. duration_since ( now1) ;
21
29
assert_eq ! ( now1 + diff, now2) ;
22
30
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) ;
26
32
27
33
test_sleep ( ) ;
28
34
}
You can’t perform that action at this time.
0 commit comments