Skip to content

Commit 9bd345a

Browse files
authored
Merge branch 'tokio-rs:master' into master
2 parents af34861 + 8fca6f6 commit 9bd345a

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

tokio/src/process/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ impl Command {
325325
&self.std
326326
}
327327

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+
328334
/// Adds an argument to pass to the program.
329335
///
330336
/// Only one argument can be passed per use. So instead of:

tokio/src/runtime/time/source.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ impl TimeSource {
2222
pub(crate) fn instant_to_tick(&self, t: Instant) -> u64 {
2323
// round up
2424
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)
2830
}
2931

3032
pub(crate) fn tick_to_duration(&self, t: u64) -> Duration {
@@ -34,4 +36,10 @@ impl TimeSource {
3436
pub(crate) fn now(&self, clock: &Clock) -> u64 {
3537
self.instant_to_tick(clock.now())
3638
}
39+
40+
#[cfg(test)]
41+
#[allow(dead_code)]
42+
pub(super) fn start_time(&self) -> Instant {
43+
self.start_time
44+
}
3745
}

tokio/src/runtime/time/tests/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,17 @@ fn poll_process_levels_targeted() {
267267
handle.process_at_time(0, 192);
268268
handle.process_at_time(0, 192);
269269
}
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+
}

0 commit comments

Comments
 (0)