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 11use 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+
311fn 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}
You can’t perform that action at this time.
0 commit comments