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
+
1
3
use std:: sync:: { Arc , Mutex } ;
2
4
use std:: thread;
3
- use std:: time:: Duration ;
5
+ use std:: time:: { Duration , Instant } ;
4
6
5
7
#[ test]
6
8
#[ cfg_attr( target_os = "emscripten" , ignore) ]
@@ -14,3 +16,19 @@ fn sleep() {
14
16
thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
15
17
assert_eq ! ( * finished. lock( ) . unwrap( ) , false ) ;
16
18
}
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