diff --git a/quic/s2n-quic-core/src/time/clock.rs b/quic/s2n-quic-core/src/time/clock.rs index 30885dc46b..cf31a46d9b 100644 --- a/quic/s2n-quic-core/src/time/clock.rs +++ b/quic/s2n-quic-core/src/time/clock.rs @@ -2,7 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 use crate::time::timestamp::Timestamp; -use core::time::Duration; +use core::{ + task::{Context, Poll}, + time::Duration, +}; + +#[cfg(any(test, feature = "std"))] +mod std; +#[cfg(any(test, feature = "testing"))] +pub mod testing; + +#[cfg(any(test, feature = "std"))] +pub use self::std::*; /// A `Clock` is a source of [`Timestamp`]s. pub trait Clock { @@ -10,93 +21,30 @@ pub trait Clock { fn get_time(&self) -> Timestamp; } -/// A clock which always returns a Timestamp of value 1us -#[derive(Clone, Copy, Debug)] -pub struct NoopClock; +pub trait ClockWithTimer: Clock { + type Timer: Timer; -impl Clock for NoopClock { - fn get_time(&self) -> Timestamp { - unsafe { Timestamp::from_duration(Duration::from_micros(1)) } - } + fn timer(&self) -> Self::Timer; } -#[cfg(any(test, feature = "std"))] -mod std_clock { - use super::*; - use std::time::Instant; - - impl Clock for &'static std::thread::LocalKey { - fn get_time(&self) -> Timestamp { - self.with(|clock| clock.get_time()) - } +pub trait Timer: Sized { + #[inline] + fn ready(&mut self) -> TimerReady { + TimerReady(self) } - #[derive(Clone, Copy, Debug)] - pub struct StdClock { - epoch: Instant, - } - - impl Default for StdClock { - fn default() -> Self { - Self { - epoch: Instant::now(), - } - } - } - - impl StdClock { - /// Creates a new `StdClock` with the given epoch - pub const fn new(epoch: Instant) -> Self { - Self { epoch } - } - } - - impl Clock for StdClock { - fn get_time(&self) -> Timestamp { - unsafe { Timestamp::from_duration(self.epoch.elapsed()) } - } - } - - #[test] - #[cfg_attr(miri, ignore)] // time isn't queryable in miri - fn monotonicity_test() { - let clock = StdClock::default(); - let ts1 = clock.get_time(); - ::std::thread::sleep(Duration::from_millis(50)); - let ts2 = clock.get_time(); - assert!(ts2 - ts1 >= Duration::from_millis(50)); - } + fn poll_ready(&mut self, cx: &mut Context) -> Poll<()>; + fn update(&mut self, timestamp: Timestamp); } -#[cfg(any(test, feature = "std"))] -pub use std_clock::*; - -#[cfg(any(test, feature = "testing"))] -pub mod testing { - use super::{Duration, Timestamp}; - - #[derive(Clone, Copy, Debug)] - pub struct Clock { - current_timestamp: Timestamp, - } - - impl Default for Clock { - fn default() -> Self { - Self { - current_timestamp: unsafe { Timestamp::from_duration(Duration::from_micros(1)) }, - } - } - } +impl_ready_future!(Timer, TimerReady, ()); - impl super::Clock for Clock { - fn get_time(&self) -> Timestamp { - self.current_timestamp - } - } +/// A clock which always returns a Timestamp of value 1us +#[derive(Clone, Copy, Debug)] +pub struct NoopClock; - impl Clock { - pub fn inc_by(&mut self, duration: Duration) { - self.current_timestamp += duration - } +impl Clock for NoopClock { + fn get_time(&self) -> Timestamp { + unsafe { Timestamp::from_duration(Duration::from_micros(1)) } } } diff --git a/quic/s2n-quic-core/src/time/clock/std.rs b/quic/s2n-quic-core/src/time/clock/std.rs new file mode 100644 index 0000000000..cd1e284108 --- /dev/null +++ b/quic/s2n-quic-core/src/time/clock/std.rs @@ -0,0 +1,47 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +use super::*; +use ::std::time::Instant; + +impl Clock for &'static ::std::thread::LocalKey { + fn get_time(&self) -> Timestamp { + self.with(|clock| clock.get_time()) + } +} + +#[derive(Clone, Copy, Debug)] +pub struct StdClock { + epoch: Instant, +} + +impl Default for StdClock { + fn default() -> Self { + Self { + epoch: Instant::now(), + } + } +} + +impl StdClock { + /// Creates a new `StdClock` with the given epoch + pub const fn new(epoch: Instant) -> Self { + Self { epoch } + } +} + +impl Clock for StdClock { + fn get_time(&self) -> Timestamp { + unsafe { Timestamp::from_duration(self.epoch.elapsed()) } + } +} + +#[test] +#[cfg_attr(miri, ignore)] // time isn't queryable in miri +fn monotonicity_test() { + let clock = StdClock::default(); + let ts1 = clock.get_time(); + ::std::thread::sleep(Duration::from_millis(50)); + let ts2 = clock.get_time(); + assert!(ts2 - ts1 >= Duration::from_millis(50)); +} diff --git a/quic/s2n-quic-core/src/time/clock/testing.rs b/quic/s2n-quic-core/src/time/clock/testing.rs new file mode 100644 index 0000000000..57f8efb479 --- /dev/null +++ b/quic/s2n-quic-core/src/time/clock/testing.rs @@ -0,0 +1,46 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +use crate::time::{Duration, Timestamp}; +use core::cell::Cell; + +fn initial() -> Timestamp { + unsafe { + // Safety: the timestamp is non-zero + Timestamp::from_duration(Duration::from_micros(1)) + } +} + +thread_local! { + static CLOCK: Cell = Cell::new(initial()); +} + +pub fn now() -> Timestamp { + CLOCK.with(|c| c.get()) +} + +pub fn reset() { + CLOCK.with(|c| c.set(initial())); +} + +pub fn advance(duration: Duration) { + CLOCK.with(|c| { + let next = c.get() + duration; + c.set(next); + }); +} + +#[derive(Clone, Copy, Debug, Default)] +pub struct Clock(()); + +impl super::Clock for Clock { + fn get_time(&self) -> Timestamp { + now() + } +} + +impl Clock { + pub fn inc_by(&mut self, duration: Duration) { + advance(duration); + } +} diff --git a/quic/s2n-quic-core/src/time/mod.rs b/quic/s2n-quic-core/src/time/mod.rs index 23aa4633a6..bc827d6b79 100644 --- a/quic/s2n-quic-core/src/time/mod.rs +++ b/quic/s2n-quic-core/src/time/mod.rs @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -mod clock; +pub mod clock; pub mod timer; mod timestamp; diff --git a/quic/s2n-quic-platform/src/io/testing.rs b/quic/s2n-quic-platform/src/io/testing.rs index cb2a876ca3..8bfd17ea20 100644 --- a/quic/s2n-quic-platform/src/io/testing.rs +++ b/quic/s2n-quic-platform/src/io/testing.rs @@ -9,6 +9,7 @@ use s2n_quic_core::{ event::{self, EndpointPublisher as _}, inet::SocketAddress, path::MaxMtu, + time::clock::Timer as _, }; type Error = std::io::Error; @@ -301,12 +302,14 @@ impl> Instance { let mut wakeups = endpoint.wakeups(&clock); let mut wakeups = Pin::new(&mut wakeups); + let timer_ready = timer.ready(); + let select::Outcome { rx_result, tx_result, timeout_expired, application_wakeup, - } = if let Ok(res) = Select::new(io_task, empty_task, &mut wakeups, &mut timer).await { + } = if let Ok(res) = Select::new(io_task, empty_task, &mut wakeups, timer_ready).await { res } else { // The endpoint has shut down diff --git a/quic/s2n-quic-platform/src/io/testing/time.rs b/quic/s2n-quic-platform/src/io/testing/time.rs index 28a8f46754..e855dc4010 100644 --- a/quic/s2n-quic-platform/src/io/testing/time.rs +++ b/quic/s2n-quic-platform/src/io/testing/time.rs @@ -9,7 +9,7 @@ use core::{ time::Duration, }; use futures::ready; -use s2n_quic_core::time::Timestamp; +use s2n_quic_core::time::{clock, Timestamp}; pub fn now() -> Timestamp { unsafe { Timestamp::from_duration(time::now()) } @@ -27,12 +27,20 @@ pub fn delay_until(deadline: Timestamp) -> Timer { #[derive(Debug, Default)] pub(crate) struct Clock(()); -impl s2n_quic_core::time::Clock for Clock { +impl clock::Clock for Clock { fn get_time(&self) -> Timestamp { now() } } +impl clock::ClockWithTimer for Clock { + type Timer = Timer; + + fn timer(&self) -> Timer { + Default::default() + } +} + #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct Timer { timer: scheduler::Timer, @@ -58,23 +66,14 @@ impl Timer { } } - pub fn update(&mut self, deadline: Timestamp) { - if self.deadline != Some(deadline) { - self.cancel(); - *self = delay_until(deadline); - } - } - pub fn cancel(&mut self) { self.deadline = None; self.timer.cancel() } } -impl Future for Timer { - type Output = (); - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { +impl clock::Timer for Timer { + fn poll_ready(&mut self, cx: &mut Context) -> Poll<()> { if self.deadline.is_none() { return Poll::Pending; } @@ -84,4 +83,19 @@ impl Future for Timer { self.deadline = None; Poll::Ready(()) } + + fn update(&mut self, deadline: Timestamp) { + if self.deadline != Some(deadline) { + self.cancel(); + *self = delay_until(deadline); + } + } +} + +impl Future for Timer { + type Output = (); + + fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<()> { + clock::Timer::poll_ready(&mut *self, cx) + } } diff --git a/quic/s2n-quic-platform/src/io/tokio.rs b/quic/s2n-quic-platform/src/io/tokio.rs index 5c33f582b9..cbc3a330cd 100644 --- a/quic/s2n-quic-platform/src/io/tokio.rs +++ b/quic/s2n-quic-platform/src/io/tokio.rs @@ -9,7 +9,10 @@ use s2n_quic_core::{ event::{self, EndpointPublisher as _}, inet::{self, SocketAddress}, path::MaxMtu, - time::Clock as ClockTrait, + time::{ + clock::{ClockWithTimer as _, Timer as _}, + Clock as ClockTrait, + }, }; use std::{convert::TryInto, io, io::ErrorKind}; use tokio::{net::UdpSocket, runtime::Handle}; @@ -383,12 +386,14 @@ impl> Instance { // pin the wakeups future so we don't have to move it into the Select future. tokio::pin!(wakeups); + let timer_ready = timer.ready(); + let select::Outcome { rx_result, tx_result, timeout_expired, application_wakeup, - } = if let Ok(res) = Select::new(rx_task, tx_task, &mut wakeups, &mut timer).await { + } = if let Ok(res) = Select::new(rx_task, tx_task, &mut wakeups, timer_ready).await { res } else { // The endpoint has shut down diff --git a/quic/s2n-quic-platform/src/io/tokio/clock.rs b/quic/s2n-quic-platform/src/io/tokio/clock.rs index dd559cc29d..185aa6c2cc 100644 --- a/quic/s2n-quic-platform/src/io/tokio/clock.rs +++ b/quic/s2n-quic-platform/src/io/tokio/clock.rs @@ -7,7 +7,7 @@ use core::{ task::{Context, Poll}, time::Duration, }; -use s2n_quic_core::time::{self, Clock as ClockTrait, Timestamp}; +use s2n_quic_core::time::{self, Timestamp}; use tokio::time::{sleep_until, Instant, Sleep}; #[derive(Clone, Debug)] @@ -23,13 +23,10 @@ impl Clock { pub fn new() -> Self { Self(Instant::now()) } - - pub fn timer(&self) -> Timer { - Timer::new(self.clone()) - } } -impl ClockTrait for Clock { +impl time::Clock for Clock { + #[inline] fn get_time(&self) -> time::Timestamp { let duration = self.0.elapsed(); unsafe { @@ -39,6 +36,15 @@ impl ClockTrait for Clock { } } +impl time::ClockWithTimer for Clock { + type Timer = Timer; + + #[inline] + fn timer(&self) -> Timer { + Timer::new(self.clone()) + } +} + #[derive(Debug)] pub struct Timer { /// A reference to the current clock @@ -63,9 +69,28 @@ impl Timer { sleep, } } +} + +impl time::clock::Timer for Timer { + #[inline] + fn poll_ready(&mut self, cx: &mut Context) -> Poll<()> { + // Only poll the inner timer if we have a target set + if self.target.is_none() { + return Poll::Pending; + } + + let res = self.sleep.as_mut().poll(cx); + + if res.is_ready() { + // clear the target after it fires, otherwise we'll endlessly wake up the task + self.target = None; + } - /// Modifies the target expiration timestamp for the timer - pub fn update(&mut self, timestamp: Timestamp) { + res + } + + #[inline] + fn update(&mut self, timestamp: Timestamp) { let delay = unsafe { // Safety: the same clock epoch is being used timestamp.as_duration() @@ -87,23 +112,3 @@ impl Timer { self.target = Some(next_time); } } - -impl Future for Timer { - type Output = (); - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - // Only poll the inner timer if we have a target set - if self.target.is_none() { - return Poll::Pending; - } - - let res = self.sleep.as_mut().poll(cx); - - if res.is_ready() { - // clear the target after it fires, otherwise we'll endlessly wake up the task - self.target = None; - } - - res - } -} diff --git a/quic/s2n-quic-platform/src/io/turmoil.rs b/quic/s2n-quic-platform/src/io/turmoil.rs index efd54ba9f0..aacbb06f8a 100644 --- a/quic/s2n-quic-platform/src/io/turmoil.rs +++ b/quic/s2n-quic-platform/src/io/turmoil.rs @@ -8,7 +8,10 @@ use s2n_quic_core::{ event::{self, EndpointPublisher as _}, inet::SocketAddress, path::MaxMtu, - time::Clock as ClockTrait, + time::{ + clock::{ClockWithTimer as _, Timer as _}, + Clock as ClockTrait, + }, }; use std::{convert::TryInto, io, io::ErrorKind}; use tokio::runtime::Handle; @@ -221,12 +224,14 @@ impl> Instance { // pin the wakeups future so we don't have to move it into the Select future. tokio::pin!(wakeups); + let timer_ready = timer.ready(); + let select::Outcome { rx_result, tx_result, timeout_expired, application_wakeup, - } = if let Ok(res) = Select::new(rx_task, tx_task, &mut wakeups, &mut timer).await { + } = if let Ok(res) = Select::new(rx_task, tx_task, &mut wakeups, timer_ready).await { res } else { // The endpoint has shut down diff --git a/quic/s2n-quic-transport/Cargo.toml b/quic/s2n-quic-transport/Cargo.toml index 0ffd993f0e..8cb567d15c 100644 --- a/quic/s2n-quic-transport/Cargo.toml +++ b/quic/s2n-quic-transport/Cargo.toml @@ -32,4 +32,3 @@ futures-test = "0.3" # For testing Waker interactions insta = { version = "1", features = ["json"] } s2n-codec = { path = "../../common/s2n-codec", features = ["testing"] } s2n-quic-core = { path = "../s2n-quic-core", features = ["testing"] } -s2n-quic-platform = { path = "../s2n-quic-platform", features = ["testing"] } diff --git a/quic/s2n-quic-transport/src/ack/ack_manager.rs b/quic/s2n-quic-transport/src/ack/ack_manager.rs index 5963c12ce7..090cd4f6e0 100644 --- a/quic/s2n-quic-transport/src/ack/ack_manager.rs +++ b/quic/s2n-quic-transport/src/ack/ack_manager.rs @@ -415,7 +415,7 @@ mod tests { frame::{ack_elicitation::AckElicitation, ping, Frame}, inet::{DatagramInfo, ExplicitCongestionNotification}, path, - time::{Clock, NoopClock}, + time::{clock::testing as time, Clock, NoopClock}, }; #[test] @@ -541,7 +541,7 @@ mod tests { AckManager::new(PacketNumberSpace::ApplicationData, ack::Settings::default()); let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -607,7 +607,7 @@ mod tests { AckManager::new(PacketNumberSpace::ApplicationData, ack::Settings::default()); let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, diff --git a/quic/s2n-quic-transport/src/ack/tests/environment.rs b/quic/s2n-quic-transport/src/ack/tests/environment.rs index f378d5755a..dfba06e1d9 100644 --- a/quic/s2n-quic-transport/src/ack/tests/environment.rs +++ b/quic/s2n-quic-transport/src/ack/tests/environment.rs @@ -2,7 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 use crate::contexts::testing::{MockWriteContext, OutgoingFrameBuffer}; -use s2n_quic_core::{endpoint, time::Timestamp, transmission}; +use s2n_quic_core::{ + endpoint, + time::{clock::testing as time, Timestamp}, + transmission, +}; #[derive(Clone, Debug)] pub struct TestEnvironment { @@ -27,7 +31,7 @@ impl TestEnvironment { Self { sent_frames, - current_time: s2n_quic_platform::time::now(), + current_time: time::now(), transmission_constraint: transmission::Constraint::None, transmission_mode: transmission::Mode::Normal, local_endpoint_type: endpoint::Type::Server, diff --git a/quic/s2n-quic-transport/src/ack/tests/simulation.rs b/quic/s2n-quic-transport/src/ack/tests/simulation.rs index 9b69fe098a..f8d1686a42 100644 --- a/quic/s2n-quic-transport/src/ack/tests/simulation.rs +++ b/quic/s2n-quic-transport/src/ack/tests/simulation.rs @@ -4,7 +4,7 @@ use super::{generator::gen_duration, Network, NetworkEvent, Report}; use alloc::collections::VecDeque; use bolero::generator::*; -use s2n_quic_core::time::Duration; +use s2n_quic_core::time::{clock::testing as time, Duration}; #[derive(Clone, Debug, TypeGenerator)] pub struct Simulation { @@ -20,7 +20,7 @@ impl Simulation { let delay = self.delay; let mut report = Report::default(); - self.network.init(s2n_quic_platform::time::now()); + self.network.init(time::now()); while let Some(now) = self.network.next_tick() { self.network.tick(now, &mut events, delay, &mut report); diff --git a/quic/s2n-quic-transport/src/connection/close_sender.rs b/quic/s2n-quic-transport/src/connection/close_sender.rs index 2c998e077d..f189593d81 100644 --- a/quic/s2n-quic-transport/src/connection/close_sender.rs +++ b/quic/s2n-quic-transport/src/connection/close_sender.rs @@ -322,7 +322,7 @@ mod tests { event::testing::Publisher, io::tx::Message as _, path::MINIMUM_MTU, - time::{testing::Clock, timer::Provider as _, Clock as _}, + time::{clock::testing as time, testing::Clock, timer::Provider as _, Clock as _}, }; static PACKET: Bytes = Bytes::from_static(b"CLOSE"); @@ -362,7 +362,7 @@ mod tests { // transmit an initial packet assert!(sender.can_transmit(path.transmission_constraint())); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let _ = sender .transmission(&mut path, now, &mut publisher) .write_payload(tx::PayloadBuffer::new(&mut buffer), 0); diff --git a/quic/s2n-quic-transport/src/connection/local_id_registry/tests.rs b/quic/s2n-quic-transport/src/connection/local_id_registry/tests.rs index 649ce8421a..5a9dfb6d05 100644 --- a/quic/s2n-quic-transport/src/connection/local_id_registry/tests.rs +++ b/quic/s2n-quic-transport/src/connection/local_id_registry/tests.rs @@ -8,7 +8,7 @@ use s2n_quic_core::{ packet::number::PacketNumberRange, random, stateless_reset::token::testing::*, - time::timer::Provider as _, + time::{clock::testing as time, timer::Provider as _}, varint::VarInt, }; @@ -68,7 +68,7 @@ fn minimum_lifetime() { let ext_id_1 = id(b"id01"); let ext_id_2 = id(b"id02"); - let expiration = s2n_quic_platform::time::now() + MIN_LIFETIME; + let expiration = time::now() + MIN_LIFETIME; let (_mapper, mut reg1) = mapper(ext_id_1, Some(expiration), TEST_TOKEN_1); reg1.set_active_connection_id_limit(3); @@ -144,7 +144,7 @@ fn connection_mapper_test() { let ext_id_3 = id(b"id03"); let ext_id_4 = id(b"id04"); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let handshake_id_expiration_time = now + Duration::from_secs(60); let mut reg1 = mapper.create_local_id_registry( @@ -240,7 +240,7 @@ fn on_retire_connection_id() { let ext_id_1 = id(b"id01"); let ext_id_2 = id(b"id02"); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let (mapper, mut reg1) = mapper(ext_id_1, None, TEST_TOKEN_1); reg1.set_active_connection_id_limit(2); @@ -321,7 +321,7 @@ fn on_retire_connection_id_pending_removal() { let ext_id_1 = id(b"id01"); let ext_id_2 = id(b"id02"); - let now = s2n_quic_platform::time::now() + Duration::from_secs(60); + let now = time::now() + Duration::from_secs(60); let (_, mut reg1) = mapper(ext_id_1, None, TEST_TOKEN_1); reg1.set_active_connection_id_limit(2); @@ -460,7 +460,7 @@ fn endpoint_may_exceed_limit_temporarily() { let ext_id_2 = id(b"id02"); let ext_id_3 = id(b"id03"); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let (_, mut reg1) = mapper(ext_id_1, None, TEST_TOKEN_1); reg1.set_active_connection_id_limit(2); @@ -510,7 +510,7 @@ fn on_transmit() { let ext_id_2 = id(b"id02"); let ext_id_3 = id(b"id03"); - let now = s2n_quic_platform::time::now() + Duration::from_secs(60); + let now = time::now() + Duration::from_secs(60); let (_, mut reg1) = mapper(ext_id_1, None, TEST_TOKEN_1); @@ -532,7 +532,7 @@ fn on_transmit() { let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -627,7 +627,7 @@ fn on_transmit_constrained() { let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::RetransmissionOnly, transmission::Mode::Normal, @@ -684,7 +684,7 @@ fn on_packet_ack_and_loss() { let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -732,7 +732,7 @@ fn timers() { // No timer set for the handshake connection ID assert_eq!(0, reg1.armed_timer_count()); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let expiration = now + Duration::from_secs(60); assert!(reg1 @@ -774,7 +774,7 @@ fn on_timeout() { let ext_id_2 = id(b"id02"); let ext_id_3 = id(b"id03"); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let handshake_expiration = now + Duration::from_secs(60); let (_, mut reg1) = mapper(ext_id_1, Some(handshake_expiration), TEST_TOKEN_1); @@ -840,7 +840,7 @@ fn retire_handshake_connection_id() { let ext_id_2 = id(b"id02"); let ext_id_3 = id(b"id03"); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let handshake_expiration = now + Duration::from_secs(60); let (_, mut reg1) = mapper(ext_id_1, Some(handshake_expiration), TEST_TOKEN_1); diff --git a/quic/s2n-quic-transport/src/connection/peer_id_registry/tests.rs b/quic/s2n-quic-transport/src/connection/peer_id_registry/tests.rs index 6e1aa11d58..12f043adee 100644 --- a/quic/s2n-quic-transport/src/connection/peer_id_registry/tests.rs +++ b/quic/s2n-quic-transport/src/connection/peer_id_registry/tests.rs @@ -30,6 +30,7 @@ use s2n_quic_core::{ packet::number::PacketNumberRange, random, stateless_reset::token::testing::*, + time::clock::testing as time, transport, varint::VarInt, }; @@ -253,7 +254,7 @@ fn retire_connection_id_when_retire_prior_to_increases() { let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, diff --git a/quic/s2n-quic-transport/src/endpoint/version.rs b/quic/s2n-quic-transport/src/endpoint/version.rs index 7bc7c600ae..e6dc0e9835 100644 --- a/quic/s2n-quic-transport/src/endpoint/version.rs +++ b/quic/s2n-quic-transport/src/endpoint/version.rs @@ -320,6 +320,7 @@ mod tests { zero_rtt::ZeroRtt, }, path::RemoteAddress, + time::clock::testing as time, varint::VarInt, }; @@ -334,7 +335,7 @@ mod tests { ( RemoteAddress::from(SocketAddress::default()), DatagramInfo { - timestamp: s2n_quic_platform::time::now(), + timestamp: time::now(), payload_len, ecn: Default::default(), destination_connection_id: connection::LocalId::TEST_ID, diff --git a/quic/s2n-quic-transport/src/path/ecn/tests.rs b/quic/s2n-quic-transport/src/path/ecn/tests.rs index 011a585a9c..f3fe30cd20 100644 --- a/quic/s2n-quic-transport/src/path/ecn/tests.rs +++ b/quic/s2n-quic-transport/src/path/ecn/tests.rs @@ -3,7 +3,7 @@ use super::*; use s2n_quic_core::{ event::{builder::Path, testing::Publisher}, - time::timer::Provider, + time::{clock::testing as time, timer::Provider}, varint::VarInt, }; use std::ops::Deref; @@ -59,7 +59,7 @@ fn restart_already_in_testing_0() { fn on_timeout_failed() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); controller.fail(now, Path::test(), &mut publisher); if let State::Failed(timer) = &controller.state { @@ -106,7 +106,7 @@ fn on_timeout_failed() { fn on_timeout_capable() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let rtt = Duration::from_millis(50); let ce_suppression_time = now + *CE_SUPPRESSION_TESTING_RTT_MULTIPLIER.start() as u32 * rtt; let mut ce_suppression_timer = Timer::default(); @@ -153,7 +153,7 @@ fn on_timeout_capable() { #[test] fn ecn() { let mut publisher = Publisher::snapshot(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); for &transmission_mode in &[ transmission::Mode::Normal, @@ -183,7 +183,7 @@ fn ecn() { //# If validation fails, then the endpoint MUST disable ECN. It stops setting the ECT //# codepoint in IP packets that it sends, assuming that either the network path or //# the peer does not support ECN. - controller.fail(s2n_quic_platform::time::now(), Path::test(), &mut publisher); + controller.fail(time::now(), Path::test(), &mut publisher); assert!(!controller.ecn(transmission_mode, now).using_ecn()); controller.state = State::Unknown; @@ -193,7 +193,7 @@ fn ecn() { #[test] fn ecn_ce_suppression() { - let now = s2n_quic_platform::time::now(); + let now = time::now(); for &transmission_mode in &[ transmission::Mode::Normal, @@ -219,7 +219,7 @@ fn ecn_ce_suppression() { #[test] fn ecn_loss_recovery_probing() { - let now = s2n_quic_platform::time::now(); + let now = time::now(); for state in vec![ State::Capable(Timer::default()), @@ -262,7 +262,7 @@ fn is_capable() { fn validate_already_failed() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); controller.fail(now, Path::test(), &mut publisher); let outcome = controller.validate( EcnCounts::default(), @@ -298,7 +298,7 @@ fn validate_already_failed() { fn validate_ecn_counts_not_in_ack() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let expected_ecn_counts = helper_ecn_counts(1, 0, 0); let outcome = controller.validate( expected_ecn_counts, @@ -324,7 +324,7 @@ fn validate_ecn_counts_not_in_ack() { fn validate_ecn_ce_remarking() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let expected_ecn_counts = helper_ecn_counts(1, 0, 0); let sent_packet_ecn_counts = helper_ecn_counts(1, 0, 0); let outcome = controller.validate( @@ -350,7 +350,7 @@ fn validate_ecn_ce_remarking() { fn validate_ect_0_remarking() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let expected_ecn_counts = helper_ecn_counts(1, 0, 0); let sent_packet_ecn_counts = helper_ecn_counts(1, 0, 0); let ack_frame_ecn_counts = helper_ecn_counts(1, 1, 0); @@ -373,7 +373,7 @@ fn validate_ect_0_remarking() { fn validate_ect_0_remarking_after_restart() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let expected_ecn_counts = helper_ecn_counts(1, 0, 0); let ack_frame_ecn_counts = helper_ecn_counts(0, 3, 0); let baseline_ecn_counts = helper_ecn_counts(0, 2, 0); @@ -400,7 +400,7 @@ fn validate_no_ecn_counts() { state: State::Unknown, ..Default::default() }; - let now = s2n_quic_platform::time::now(); + let now = time::now(); let outcome = controller.validate( EcnCounts::default(), EcnCounts::default(), @@ -420,7 +420,7 @@ fn validate_no_ecn_counts() { fn validate_ecn_decrease() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let baseline_ecn_counts = helper_ecn_counts(1, 0, 0); let outcome = controller.validate( EcnCounts::default(), @@ -449,7 +449,7 @@ fn validate_no_marked_packets_acked() { state: State::Unknown, ..Default::default() }; - let now = s2n_quic_platform::time::now(); + let now = time::now(); let outcome = controller.validate( EcnCounts::default(), EcnCounts::default(), @@ -476,7 +476,7 @@ fn validate_no_marked_packets_acked() { fn validate_ce_suppression_remarked_to_not_ect() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); // We sent one ECT0 and one CE let newly_acked_ecn_counts = helper_ecn_counts(1, 0, 1); let sent_packet_ecn_counts = helper_ecn_counts(1, 0, 1); @@ -508,7 +508,7 @@ fn validate_ce_suppression_remarked_to_not_ect() { fn validate_ce_suppression_remarked_to_ect0() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); // We sent one ECT0 and one CE let newly_acked_ecn_counts = helper_ecn_counts(1, 0, 1); let sent_packet_ecn_counts = helper_ecn_counts(1, 0, 1); @@ -536,7 +536,7 @@ fn validate_capable() { state: State::Unknown, ..Default::default() }; - let now = s2n_quic_platform::time::now(); + let now = time::now(); let expected_ecn_counts = helper_ecn_counts(2, 0, 0); let ack_frame_ecn_counts = helper_ecn_counts(2, 0, 0); let sent_packet_ecn_counts = helper_ecn_counts(2, 0, 0); @@ -569,7 +569,7 @@ fn validate_capable_congestion_experienced() { state: State::Unknown, ..Default::default() }; - let now = s2n_quic_platform::time::now(); + let now = time::now(); let expected_ecn_counts = helper_ecn_counts(2, 0, 5); let ack_frame_ecn_counts = helper_ecn_counts(1, 0, 12); let sent_packet_ecn_counts = helper_ecn_counts(2, 0, 5); @@ -605,7 +605,7 @@ fn validate_capable_ce_suppression_test() { state: State::Unknown, ..Default::default() }; - let now = s2n_quic_platform::time::now(); + let now = time::now(); let expected_ecn_counts = helper_ecn_counts(2, 0, 1); let ack_frame_ecn_counts = helper_ecn_counts(2, 0, 1); let sent_packet_ecn_counts = helper_ecn_counts(2, 0, 1); @@ -646,7 +646,7 @@ fn validate_capable_not_in_unknown_state() { state, ..Default::default() }; - let now = s2n_quic_platform::time::now(); + let now = time::now(); let expected_ecn_counts = helper_ecn_counts(1, 0, 0); let ack_frame_ecn_counts = helper_ecn_counts(1, 0, 0); let sent_packet_ecn_counts = helper_ecn_counts(1, 0, 0); @@ -674,7 +674,7 @@ fn validate_capable_lost_ack_frame() { state: State::Unknown, ..Default::default() }; - let now = s2n_quic_platform::time::now(); + let now = time::now(); // We sent three ECT0 packets let sent_packet_ecn_counts = helper_ecn_counts(3, 0, 0); @@ -714,7 +714,7 @@ fn validate_capable_after_restart() { state: State::Unknown, ..Default::default() }; - let now = s2n_quic_platform::time::now(); + let now = time::now(); let sent_packet_ecn_counts = helper_ecn_counts(2, 0, 0); let expected_ecn_counts = helper_ecn_counts(2, 0, 0); // The Ect1 markings would normally fail validation, but since they are included @@ -775,7 +775,7 @@ fn on_packet_loss() { state, ..Default::default() }; - let now = s2n_quic_platform::time::now(); + let now = time::now(); let time_sent = now + Duration::from_secs(1); controller.last_acked_ecn_packet_timestamp = Some(now); @@ -810,7 +810,7 @@ fn on_packet_loss() { fn on_packet_loss_already_failed() { let mut publisher = Publisher::snapshot(); let mut controller = Controller::default(); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let time_sent = now + Duration::from_secs(1); controller.last_acked_ecn_packet_timestamp = Some(now); @@ -843,7 +843,7 @@ fn on_packet_loss_already_failed() { #[test] fn fuzz_validate() { - let now = s2n_quic_platform::time::now(); + let now = time::now(); bolero::check!() .with_type::<(EcnCounts, EcnCounts, EcnCounts, Option, Duration)>() diff --git a/quic/s2n-quic-transport/src/path/mtu.rs b/quic/s2n-quic-transport/src/path/mtu.rs index 57407755bc..e777b4e1d9 100644 --- a/quic/s2n-quic-transport/src/path/mtu.rs +++ b/quic/s2n-quic-transport/src/path/mtu.rs @@ -467,11 +467,14 @@ mod test { use super::*; use crate::contexts::testing::{MockWriteContext, OutgoingFrameBuffer}; use s2n_quic_core::{ - endpoint, event::testing::Publisher, frame::Frame, packet::number::PacketNumberSpace, + endpoint, + event::testing::Publisher, + frame::Frame, + packet::number::PacketNumberSpace, recovery::congestion_controller::testing::mock::CongestionController, - time::timer::Provider as _, varint::VarInt, + time::{clock::testing::now, timer::Provider as _}, + varint::VarInt, }; - use s2n_quic_platform::time::now; use std::{convert::TryInto, net::SocketAddr}; /// Creates a new mtu::Controller with an IPv4 address and the given `max_mtu` diff --git a/quic/s2n-quic-transport/src/recovery/manager/tests.rs b/quic/s2n-quic-transport/src/recovery/manager/tests.rs index 891edb991c..f343bb776e 100644 --- a/quic/s2n-quic-transport/src/recovery/manager/tests.rs +++ b/quic/s2n-quic-transport/src/recovery/manager/tests.rs @@ -26,7 +26,7 @@ use s2n_quic_core::{ }, DEFAULT_INITIAL_RTT, }, - time::{timer::Provider as _, Clock, NoopClock}, + time::{clock::testing as time, timer::Provider as _, Clock, NoopClock}, varint::VarInt, }; use std::{collections::HashSet, net::SocketAddr}; @@ -46,7 +46,7 @@ fn one_second_pto_when_no_previous_rtt_available() { let space = PacketNumberSpace::Handshake; let max_ack_delay = Duration::from_millis(0); let mut manager = Manager::new(space); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let path = Path::new( Default::default(), @@ -74,7 +74,7 @@ fn one_second_pto_when_no_previous_rtt_available() { #[test] fn on_packet_sent() { let max_ack_delay = Duration::from_millis(100); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let mut time_sent = now; let ecn = ExplicitCongestionNotification::Ect0; let space = PacketNumberSpace::ApplicationData; @@ -215,7 +215,7 @@ fn on_packet_sent_across_multiple_paths() { // let space = PacketNumberSpace::ApplicationData; let max_ack_delay = Duration::from_millis(100); // let mut manager = Manager::new(space, max_ack_delay); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let ecn = ExplicitCongestionNotification::default(); let mut time_sent = now; let mut publisher = Publisher::snapshot(); @@ -343,7 +343,7 @@ fn on_ack_frame() { // Start the pto backoff at 2 so we can tell if it was reset context.path_mut().pto_backoff = 2; - let time_sent = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_sent = time::now() + Duration::from_secs(10); // Send packets 1 to 10 for i in 1..=10 { @@ -555,7 +555,7 @@ fn process_new_acked_packets_update_pto_timer() { helper_generate_multi_path_manager(space, &mut publisher); let mut context = MockContext::new(&mut path_manager); let ecn = ExplicitCongestionNotification::default(); - let time_sent = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_sent = time::now() + Duration::from_secs(10); // Send packets 1 on first_path manager.on_packet_sent( @@ -672,7 +672,7 @@ fn process_new_acked_packets_congestion_controller() { let ecn = ExplicitCongestionNotification::default(); let mut context = MockContext::new(&mut path_manager); - let time_sent = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_sent = time::now() + Duration::from_secs(10); // Send packets 1 on first_path manager.on_packet_sent( @@ -800,7 +800,7 @@ fn process_new_acked_packets_pto_timer() { helper_generate_multi_path_manager(space, &mut publisher); let mut context = MockContext::new(&mut path_manager); let ecn = ExplicitCongestionNotification::default(); - let time_sent = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_sent = time::now() + Duration::from_secs(10); // Send packets 1 on first_path manager.on_packet_sent( @@ -916,7 +916,7 @@ fn process_new_acked_packets_process_ecn() { let packet_bytes = 128; let mut path_manager = helper_generate_path_manager(Duration::from_millis(10)); let mut context = MockContext::new(&mut path_manager); - let time_sent = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_sent = time::now() + Duration::from_secs(10); let mut publisher = Publisher::snapshot(); // Send 10 ECT0 marked packets @@ -1018,7 +1018,7 @@ fn process_new_acked_packets_failed_ecn_validation_does_not_cause_congestion_eve let packet_bytes = 128; let mut path_manager = helper_generate_path_manager(Duration::from_millis(10)); let mut context = MockContext::new(&mut path_manager); - let time_sent = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_sent = time::now() + Duration::from_secs(10); let mut publisher = Publisher::snapshot(); // Send 10 ECT0 marked packets @@ -1078,7 +1078,7 @@ fn no_rtt_update_when_not_acknowledging_the_largest_acknowledged_packet() { let mut context = MockContext::new(&mut path_manager); let mut publisher = Publisher::snapshot(); - let time_sent = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_sent = time::now() + Duration::from_secs(10); // Send 2 packets manager.on_packet_sent( @@ -1171,7 +1171,7 @@ fn no_rtt_update_when_receiving_packet_on_different_path() { let ecn = ExplicitCongestionNotification::default(); let mut context = MockContext::new(&mut path_manager); - let time_sent = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_sent = time::now() + Duration::from_secs(10); // Send packet manager.on_packet_sent( @@ -1286,7 +1286,7 @@ fn rtt_update_when_receiving_ack_from_multiple_paths() { let mut context = MockContext::new(&mut path_manager); // Trigger: - let time_sent = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_sent = time::now() + Duration::from_secs(10); let sent_time = time_sent + Duration::from_millis(300); let ack_receive_time = time_sent + Duration::from_millis(1000); @@ -1371,7 +1371,7 @@ fn rtt_update_when_receiving_ack_from_multiple_paths() { fn detect_and_remove_lost_packets() { let space = PacketNumberSpace::ApplicationData; let mut manager = Manager::new(space); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let mut path_manager = helper_generate_path_manager(Duration::from_millis(10)); let ecn = ExplicitCongestionNotification::default(); let mut context = MockContext::new(&mut path_manager); @@ -1380,7 +1380,7 @@ fn detect_and_remove_lost_packets() { manager.largest_acked_packet = Some(space.new_packet_number(VarInt::from_u8(10))); - let mut time_sent = s2n_quic_platform::time::now(); + let mut time_sent = time::now(); let outcome = transmission::Outcome { ack_elicitation: AckElicitation::Eliciting, is_congestion_controlled: true, @@ -1537,7 +1537,7 @@ fn detect_lost_packets_persistent_congestion_path_aware() { let ecn = ExplicitCongestionNotification::default(); let mut context = MockContext::new(&mut path_manager); - let mut now = s2n_quic_platform::time::now(); + let mut now = time::now(); manager.largest_acked_packet = Some(space.new_packet_number(VarInt::from_u8(20))); // create first rtt samples so they can enter enter persistent_congestion @@ -1664,7 +1664,7 @@ fn remove_lost_packets_persistent_congestion_path_aware() { helper_generate_multi_path_manager(space, &mut publisher); let ecn = ExplicitCongestionNotification::default(); let mut context = MockContext::new(&mut path_manager); - let mut now = s2n_quic_platform::time::now(); + let mut now = time::now(); let random = &mut random::testing::Generator::default(); assert_eq!( @@ -1793,7 +1793,7 @@ fn detect_and_remove_lost_packets_nothing_lost() { let mut publisher = Publisher::snapshot(); let random = &mut random::testing::Generator::default(); - let time_sent = s2n_quic_platform::time::now(); + let time_sent = time::now(); let outcome = transmission::Outcome { ack_elicitation: AckElicitation::Eliciting, is_congestion_controlled: true, @@ -1846,7 +1846,7 @@ fn detect_and_remove_lost_packets_mtu_probe() { let mut publisher = Publisher::snapshot(); let random = &mut random::testing::Generator::default(); - let time_sent = s2n_quic_platform::time::now(); + let time_sent = time::now(); let outcome = transmission::Outcome { ack_elicitation: AckElicitation::Eliciting, is_congestion_controlled: true, @@ -1896,14 +1896,14 @@ fn persistent_congestion() { let mut context = MockContext::new(&mut path_manager); let mut publisher = Publisher::snapshot(); - let time_zero = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_zero = time::now() + Duration::from_secs(10); // The RFC doesn't mention it, but it is implied that the first RTT sample has already // been received when this example begins, otherwise packet #2 would not be considered // part of the persistent congestion period. context.path_mut().rtt_estimator.update_rtt( Duration::from_millis(10), Duration::from_millis(700), - s2n_quic_platform::time::now(), + time::now(), true, space, ); @@ -2068,7 +2068,7 @@ fn persistent_congestion_multiple_periods() { let mut path_manager = helper_generate_path_manager(Duration::from_millis(10)); let ecn = ExplicitCongestionNotification::default(); let mut context = MockContext::new(&mut path_manager); - let time_zero = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_zero = time::now() + Duration::from_secs(10); let mut publisher = Publisher::snapshot(); let outcome = transmission::Outcome { @@ -2203,7 +2203,7 @@ fn persistent_congestion_period_does_not_start_until_rtt_sample() { let mut path_manager = helper_generate_path_manager(Duration::from_millis(10)); let ecn = ExplicitCongestionNotification::default(); let mut context = MockContext::new(&mut path_manager); - let time_zero = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_zero = time::now() + Duration::from_secs(10); let mut publisher = Publisher::snapshot(); let outcome = transmission::Outcome { @@ -2283,11 +2283,11 @@ fn persistent_congestion_not_ack_eliciting() { let mut context = MockContext::new(&mut path_manager); let mut publisher = Publisher::snapshot(); - let time_zero = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_zero = time::now() + Duration::from_secs(10); context.path_mut().rtt_estimator.update_rtt( Duration::from_millis(10), Duration::from_millis(700), - s2n_quic_platform::time::now(), + time::now(), true, space, ); @@ -2371,11 +2371,11 @@ fn persistent_congestion_mtu_probe() { let mut context = MockContext::new(&mut path_manager); let mut publisher = Publisher::snapshot(); - let time_zero = s2n_quic_platform::time::now() + Duration::from_secs(10); + let time_zero = time::now() + Duration::from_secs(10); context.path_mut().rtt_estimator.update_rtt( Duration::from_millis(10), Duration::from_millis(700), - s2n_quic_platform::time::now(), + time::now(), true, space, ); @@ -2449,7 +2449,7 @@ fn persistent_congestion_mtu_probe() { fn update_pto_timer() { let space = PacketNumberSpace::ApplicationData; let mut manager = Manager::new(space); - let now = s2n_quic_platform::time::now() + Duration::from_secs(10); + let now = time::now() + Duration::from_secs(10); let is_handshake_confirmed = true; let mut path_manager = helper_generate_path_manager(Duration::from_millis(10)); let ecn = ExplicitCongestionNotification::default(); @@ -2579,7 +2579,7 @@ fn update_pto_timer() { fn pto_armed_if_handshake_not_confirmed() { let space = PacketNumberSpace::Handshake; let mut manager = Manager::new(space); - let now = s2n_quic_platform::time::now() + Duration::from_secs(10); + let now = time::now() + Duration::from_secs(10); let is_handshake_confirmed = false; let mut path = Path::new( @@ -2608,7 +2608,7 @@ fn pto_must_be_at_least_k_granularity() { let space = PacketNumberSpace::Handshake; let max_ack_delay = Duration::from_millis(0); let mut manager = Manager::new(space); - let now = s2n_quic_platform::time::now(); + let now = time::now(); let mut path = Path::new( Default::default(), @@ -2643,7 +2643,7 @@ fn pto_must_be_at_least_k_granularity() { fn on_timeout() { let space = PacketNumberSpace::ApplicationData; let mut manager = Manager::new(space); - let now = s2n_quic_platform::time::now() + Duration::from_secs(10); + let now = time::now() + Duration::from_secs(10); manager.largest_acked_packet = Some(space.new_packet_number(VarInt::from_u8(10))); let mut path_manager = helper_generate_path_manager(Duration::from_millis(10)); let ecn = ExplicitCongestionNotification::default(); @@ -2762,8 +2762,8 @@ fn on_timeout() { fn timers() { let space = PacketNumberSpace::ApplicationData; let mut manager = Manager::new(space); - let loss_time = s2n_quic_platform::time::now() + Duration::from_secs(5); - let pto_time = s2n_quic_platform::time::now() + Duration::from_secs(10); + let loss_time = time::now() + Duration::from_secs(5); + let pto_time = time::now() + Duration::from_secs(10); // No timer is set assert_eq!(manager.armed_timer_count(), 0); @@ -2792,7 +2792,7 @@ fn on_transmit() { let mut manager = Manager::new(space); let mut frame_buffer = OutgoingFrameBuffer::new(); let mut context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::CongestionLimited, // Recovery manager ignores constraints transmission::Mode::LossRecoveryProbing, @@ -2858,7 +2858,7 @@ fn on_transmit_normal_transmission_mode() { let mut manager = Manager::new(space); let mut frame_buffer = OutgoingFrameBuffer::new(); let mut context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::CongestionLimited, // Recovery manager ignores constraints transmission::Mode::Normal, @@ -2989,7 +2989,7 @@ fn probe_packets_count_towards_bytes_in_flight() { manager.on_packet_sent( space.new_packet_number(VarInt::from_u8(1)), outcome, - s2n_quic_platform::time::now(), + time::now(), ecn, transmission::Mode::Normal, None, @@ -3027,7 +3027,7 @@ fn time_threshold_multiplier_equals_nine_eighths() { rtt_estimator.update_rtt( Duration::from_millis(10), Duration::from_secs(1), - s2n_quic_platform::time::now(), + time::now(), true, PacketNumberSpace::Initial, ); @@ -3049,7 +3049,7 @@ fn timer_granularity() { rtt_estimator.update_rtt( Duration::from_millis(0), Duration::from_nanos(1), - s2n_quic_platform::time::now(), + time::now(), true, PacketNumberSpace::Initial, ); @@ -3071,7 +3071,7 @@ fn packet_declared_lost_less_than_1_ms_from_loss_threshold() { let ecn = ExplicitCongestionNotification::default(); let mut context = MockContext::new(&mut path_manager); let mut publisher = Publisher::snapshot(); - let sent_time = s2n_quic_platform::time::now() + Duration::from_secs(10); + let sent_time = time::now() + Duration::from_secs(10); let outcome = transmission::Outcome { ack_elicitation: AckElicitation::Eliciting, is_congestion_controlled: true, diff --git a/quic/s2n-quic-transport/src/space/handshake_status.rs b/quic/s2n-quic-transport/src/space/handshake_status.rs index cee977e3a5..8fb3dd54df 100644 --- a/quic/s2n-quic-transport/src/space/handshake_status.rs +++ b/quic/s2n-quic-transport/src/space/handshake_status.rs @@ -209,8 +209,7 @@ mod fuzz_target; mod tests { use super::*; use crate::{contexts::testing::*, transmission::interest::Provider}; - use s2n_quic_core::{endpoint, event::testing::Publisher}; - use s2n_quic_platform::time; + use s2n_quic_core::{endpoint, event::testing::Publisher, time::clock::testing as time}; #[test] fn server_test() { diff --git a/quic/s2n-quic-transport/src/space/handshake_status/fuzz_target.rs b/quic/s2n-quic-transport/src/space/handshake_status/fuzz_target.rs index 18d671086e..224b4695ca 100644 --- a/quic/s2n-quic-transport/src/space/handshake_status/fuzz_target.rs +++ b/quic/s2n-quic-transport/src/space/handshake_status/fuzz_target.rs @@ -8,8 +8,7 @@ use crate::{ transmission::{self, interest::Provider}, }; use bolero::{check, generator::*}; -use s2n_quic_core::{ack, event::testing::Publisher, packet}; -use s2n_quic_platform::time; +use s2n_quic_core::{ack, event::testing::Publisher, packet, time::clock::testing as time}; #[derive(Debug)] struct Oracle { diff --git a/quic/s2n-quic-transport/src/stream/manager/tests.rs b/quic/s2n-quic-transport/src/stream/manager/tests.rs index 4b18f30df7..8eaa734fe5 100644 --- a/quic/s2n-quic-transport/src/stream/manager/tests.rs +++ b/quic/s2n-quic-transport/src/stream/manager/tests.rs @@ -41,6 +41,7 @@ use s2n_quic_core::{ packet::number::{PacketNumberRange, PacketNumberSpace}, stream::{ops, StreamId, StreamType}, time::{ + clock::testing as time, timer::{self, Provider as _}, Timestamp, }, @@ -761,7 +762,7 @@ fn peer_closing_streams_transmits_max_streams() { let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -842,7 +843,7 @@ fn send_streams_blocked_frame_when_blocked_by_peer() { let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -1001,7 +1002,7 @@ where let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -1069,7 +1070,7 @@ fn send_data_blocked_frame_when_blocked_by_connection_flow_limits() { let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -1247,7 +1248,7 @@ fn blocked_on_local_concurrent_stream_limit() { let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -2329,7 +2330,7 @@ fn on_transmit_queries_streams_for_data() { assert_eq!([stream_5], *manager.streams_waiting_for_retransmission()); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -2381,7 +2382,7 @@ fn on_transmit_queries_streams_for_data() { frame_buffer.set_error_write_after_n_frames(15); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -2415,7 +2416,7 @@ fn on_transmit_queries_streams_for_data() { frame_buffer.set_error_write_after_n_frames(15); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -2440,7 +2441,7 @@ fn on_transmit_queries_streams_for_data() { frame_buffer.set_error_write_after_n_frames(5); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -2465,7 +2466,7 @@ fn on_transmit_queries_streams_for_data() { frame_buffer.set_error_write_after_n_frames(5); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -2487,7 +2488,7 @@ fn on_transmit_queries_streams_for_data() { frame_buffer.set_error_write_after_n_frames(11); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, @@ -3085,7 +3086,7 @@ fn stream_transmission_fairness_test() { let mut frame_buffer = OutgoingFrameBuffer::new(); let mut write_context = MockWriteContext::new( - s2n_quic_platform::time::now(), + time::now(), &mut frame_buffer, transmission::Constraint::None, transmission::Mode::Normal, diff --git a/quic/s2n-quic-transport/src/stream/testing.rs b/quic/s2n-quic-transport/src/stream/testing.rs index 351dc2c642..314a601779 100644 --- a/quic/s2n-quic-transport/src/stream/testing.rs +++ b/quic/s2n-quic-transport/src/stream/testing.rs @@ -20,7 +20,7 @@ use s2n_quic_core::{ frame::{stream::Stream as StreamFrame, Frame, ResetStream, StreamDataBlocked}, packet::number::{PacketNumber, PacketNumberSpace}, stream::{ops, StreamError, StreamId, StreamType}, - time::Timestamp, + time::{clock::testing as time, Timestamp}, transport, varint::VarInt, }; @@ -560,7 +560,7 @@ pub fn setup_stream_test_env_with_config(config: TestEnvironmentConfig) -> TestE tx_connection_flow_controller, wake_counter, waker, - current_time: s2n_quic_platform::time::now(), + current_time: time::now(), transmission_constraint: config.transmission_constraint, endpoint: config.local_endpoint_type, } diff --git a/quic/s2n-quic-transport/src/sync/data_sender.rs b/quic/s2n-quic-transport/src/sync/data_sender.rs index b7ca97f114..035e8dafd5 100644 --- a/quic/s2n-quic-transport/src/sync/data_sender.rs +++ b/quic/s2n-quic-transport/src/sync/data_sender.rs @@ -541,7 +541,7 @@ mod tests { transmission::{self, interest::Provider as _}, }; use bolero::{check, generator::*}; - use s2n_quic_core::{endpoint, frame, stream::testing as stream}; + use s2n_quic_core::{endpoint, frame, stream::testing as stream, time::clock::testing as time}; use std::collections::HashSet; #[derive(Clone, Copy, Debug, TypeGenerator)] @@ -588,7 +588,7 @@ mod tests { let mut total_len = 0; let mut frame_buffer = OutgoingFrameBuffer::new(); let mut context = MockWriteContext { - current_time: s2n_quic_platform::time::now(), + current_time: time::now(), frame_buffer: &mut frame_buffer, transmission_constraint: transmission::Constraint::None, transmission_mode: transmission::Mode::Normal, diff --git a/quic/s2n-quic-transport/src/sync/flag.rs b/quic/s2n-quic-transport/src/sync/flag.rs index 1d7110b643..ec9d146982 100644 --- a/quic/s2n-quic-transport/src/sync/flag.rs +++ b/quic/s2n-quic-transport/src/sync/flag.rs @@ -185,8 +185,7 @@ impl Writer for PingWriter { mod tests { use super::*; use crate::{contexts::testing::*, transmission::interest::Provider}; - use s2n_quic_core::endpoint; - use s2n_quic_platform::time; + use s2n_quic_core::{endpoint, time::clock::testing as time}; #[test] fn ping_test() {