File tree 3 files changed +31
-3
lines changed
3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -325,6 +325,12 @@ impl Command {
325
325
& self . std
326
326
}
327
327
328
+ /// Cheaply convert to a `&mut std::process::Command` for places where the type from the
329
+ /// standard library is expected.
330
+ pub fn as_std_mut ( & mut self ) -> & mut StdCommand {
331
+ & mut self . std
332
+ }
333
+
328
334
/// Adds an argument to pass to the program.
329
335
///
330
336
/// Only one argument can be passed per use. So instead of:
Original file line number Diff line number Diff line change @@ -22,9 +22,11 @@ impl TimeSource {
22
22
pub ( crate ) fn instant_to_tick ( & self , t : Instant ) -> u64 {
23
23
// round up
24
24
let dur: Duration = t. saturating_duration_since ( self . start_time ) ;
25
- let ms = dur. as_millis ( ) ;
26
-
27
- ms. try_into ( ) . unwrap_or ( MAX_SAFE_MILLIS_DURATION )
25
+ let ms = dur
26
+ . as_millis ( )
27
+ . try_into ( )
28
+ . unwrap_or ( MAX_SAFE_MILLIS_DURATION ) ;
29
+ ms. min ( MAX_SAFE_MILLIS_DURATION )
28
30
}
29
31
30
32
pub ( crate ) fn tick_to_duration ( & self , t : u64 ) -> Duration {
@@ -34,4 +36,10 @@ impl TimeSource {
34
36
pub ( crate ) fn now ( & self , clock : & Clock ) -> u64 {
35
37
self . instant_to_tick ( clock. now ( ) )
36
38
}
39
+
40
+ #[ cfg( test) ]
41
+ #[ allow( dead_code) ]
42
+ pub ( super ) fn start_time ( & self ) -> Instant {
43
+ self . start_time
44
+ }
37
45
}
Original file line number Diff line number Diff line change @@ -267,3 +267,17 @@ fn poll_process_levels_targeted() {
267
267
handle. process_at_time ( 0 , 192 ) ;
268
268
handle. process_at_time ( 0 , 192 ) ;
269
269
}
270
+
271
+ #[ test]
272
+ #[ cfg( not( loom) ) ]
273
+ fn instant_to_tick_max ( ) {
274
+ use crate :: runtime:: time:: entry:: MAX_SAFE_MILLIS_DURATION ;
275
+
276
+ let rt = rt ( true ) ;
277
+ let handle = rt. handle ( ) . inner . driver ( ) . time ( ) ;
278
+
279
+ let start_time = handle. time_source . start_time ( ) ;
280
+ let long_future = start_time + std:: time:: Duration :: from_millis ( MAX_SAFE_MILLIS_DURATION + 1 ) ;
281
+
282
+ assert ! ( handle. time_source. instant_to_tick( long_future) <= MAX_SAFE_MILLIS_DURATION ) ;
283
+ }
You can’t perform that action at this time.
0 commit comments