File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 1+ #![ feature( thread_sleep_until) ]
2+
13use std:: sync:: { Arc , Mutex } ;
24use std:: thread;
3- use std:: time:: Duration ;
5+ use std:: time:: { Duration , Instant } ;
46
57#[ test]
68#[ cfg_attr( target_os = "emscripten" , ignore) ]
@@ -14,3 +16,19 @@ fn sleep() {
1416 thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
1517 assert_eq ! ( * finished. lock( ) . unwrap( ) , false ) ;
1618}
19+
20+ #[ test]
21+ fn sleep_until ( ) {
22+ let now = Instant :: now ( ) ;
23+ let period = Duration :: from_millis ( 100 ) ;
24+ let deadline = now + period;
25+ thread:: sleep_until ( deadline) ;
26+
27+ let margin = Duration :: from_micros ( 100 ) ;
28+ let elapsed = now. elapsed ( ) ;
29+ assert ! (
30+ ( period..period + margin) . contains( & elapsed) ,
31+ "elapsed: {} microseconds, expected 100_000 to 100_100" ,
32+ elapsed. as_micros( )
33+ ) ;
34+ }
You can’t perform that action at this time.
0 commit comments