Struct netstack3_base::testutil::FakeTimerCtx
source · pub struct FakeTimerCtx<Id> {
pub instant: FakeInstantCtx,
pub timers: BinaryHeap<InstantAndData<FakeTimer<Id>>>,
/* private fields */
}
Expand description
A fake TimerContext
which stores time as a FakeInstantCtx
.
Fields§
§instant: FakeInstantCtx
The instant context within this fake timer context.
timers: BinaryHeap<InstantAndData<FakeTimer<Id>>>
The timer heap kept by the fake implementation.
Implementations§
source§impl<Id: Clone> FakeTimerCtx<Id>
impl<Id: Clone> FakeTimerCtx<Id>
sourcepub fn timers(&self) -> Vec<(FakeInstant, Id)>
pub fn timers(&self) -> Vec<(FakeInstant, Id)>
Get an ordered list of all currently-scheduled timers.
source§impl<Id: Debug + Clone + Hash + Eq> FakeTimerCtx<Id>
impl<Id: Debug + Clone + Hash + Eq> FakeTimerCtx<Id>
sourcepub fn assert_timers_installed<I: IntoIterator<Item = (Id, FakeInstant)>>(
&self,
timers: I
)
pub fn assert_timers_installed<I: IntoIterator<Item = (Id, FakeInstant)>>( &self, timers: I )
Asserts that self
contains exactly the timers in timers
.
§Panics
Panics if timers
contains the same ID more than once or if self
does not contain exactly the timers in timers
.
sourcepub fn assert_timers_installed_range<R: RangeBounds<FakeInstant> + Debug, I: IntoIterator<Item = (Id, R)>>(
&self,
timers: I
)
pub fn assert_timers_installed_range<R: RangeBounds<FakeInstant> + Debug, I: IntoIterator<Item = (Id, R)>>( &self, timers: I )
Like [assert_timers_installed
] but receives a range instants to
match.
Each timer must be present, and its deadline must fall into the specified range.
sourcepub fn assert_some_timers_installed<I: IntoIterator<Item = (Id, FakeInstant)>>(
&self,
timers: I
)
pub fn assert_some_timers_installed<I: IntoIterator<Item = (Id, FakeInstant)>>( &self, timers: I )
Asserts that self
contains at least the timers in timers
.
Like [assert_timers_installed
], but only asserts that timers
is
a subset of the timers installed; other timers may be installed in
addition to those in timers
.
sourcepub fn assert_some_timers_installed_range<R: RangeBounds<FakeInstant> + Debug, I: IntoIterator<Item = (Id, R)>>(
&self,
timers: I
)
pub fn assert_some_timers_installed_range<R: RangeBounds<FakeInstant> + Debug, I: IntoIterator<Item = (Id, R)>>( &self, timers: I )
Like [assert_some_timers_installed
] but receives instant ranges
to match like [assert_timers_installed_range
].
sourcepub fn assert_no_timers_installed(&self)
pub fn assert_no_timers_installed(&self)
Trait Implementations§
source§impl<Id, Event: Debug, State, FrameMeta> AsMut<FakeTimerCtx<Id>> for FakeBindingsCtx<Id, Event, State, FrameMeta>
impl<Id, Event: Debug, State, FrameMeta> AsMut<FakeTimerCtx<Id>> for FakeBindingsCtx<Id, Event, State, FrameMeta>
source§fn as_mut(&mut self) -> &mut FakeTimerCtx<Id>
fn as_mut(&mut self) -> &mut FakeTimerCtx<Id>
source§impl<Id> AsRef<FakeInstantCtx> for FakeTimerCtx<Id>
impl<Id> AsRef<FakeInstantCtx> for FakeTimerCtx<Id>
source§fn as_ref(&self) -> &FakeInstantCtx
fn as_ref(&self) -> &FakeInstantCtx
source§impl<Id, Event: Debug, State, FrameMeta> AsRef<FakeTimerCtx<Id>> for FakeBindingsCtx<Id, Event, State, FrameMeta>
impl<Id, Event: Debug, State, FrameMeta> AsRef<FakeTimerCtx<Id>> for FakeBindingsCtx<Id, Event, State, FrameMeta>
source§fn as_ref(&self) -> &FakeTimerCtx<Id>
fn as_ref(&self) -> &FakeTimerCtx<Id>
source§impl<Id> Default for FakeTimerCtx<Id>
impl<Id> Default for FakeTimerCtx<Id>
source§fn default() -> FakeTimerCtx<Id>
fn default() -> FakeTimerCtx<Id>
source§impl<Id: Debug + Clone + Send + Sync> TimerBindingsTypes for FakeTimerCtx<Id>
impl<Id: Debug + Clone + Send + Sync> TimerBindingsTypes for FakeTimerCtx<Id>
§type Timer = FakeTimer<Id>
type Timer = FakeTimer<Id>
TimerContext
.§type DispatchId = Id
type DispatchId = Id
source§impl<Id: PartialEq + Debug + Clone + Send + Sync> TimerContext for FakeTimerCtx<Id>
impl<Id: PartialEq + Debug + Clone + Send + Sync> TimerContext for FakeTimerCtx<Id>
source§fn new_timer(&mut self, dispatch_id: Self::DispatchId) -> Self::Timer
fn new_timer(&mut self, dispatch_id: Self::DispatchId) -> Self::Timer
id
back to core when fired. Read moresource§fn schedule_timer_instant(
&mut self,
time: Self::Instant,
timer: &mut Self::Timer
) -> Option<Self::Instant>
fn schedule_timer_instant( &mut self, time: Self::Instant, timer: &mut Self::Timer ) -> Option<Self::Instant>
source§fn cancel_timer(&mut self, timer: &mut Self::Timer) -> Option<Self::Instant>
fn cancel_timer(&mut self, timer: &mut Self::Timer) -> Option<Self::Instant>
source§impl<TimerId> WithFakeTimerContext<TimerId> for FakeTimerCtx<TimerId>
impl<TimerId> WithFakeTimerContext<TimerId> for FakeTimerCtx<TimerId>
source§fn with_fake_timer_ctx<O, F: FnOnce(&FakeTimerCtx<TimerId>) -> O>(
&self,
f: F
) -> O
fn with_fake_timer_ctx<O, F: FnOnce(&FakeTimerCtx<TimerId>) -> O>( &self, f: F ) -> O
FakeTimerCtx
.source§fn with_fake_timer_ctx_mut<O, F: FnOnce(&mut FakeTimerCtx<TimerId>) -> O>(
&mut self,
f: F
) -> O
fn with_fake_timer_ctx_mut<O, F: FnOnce(&mut FakeTimerCtx<TimerId>) -> O>( &mut self, f: F ) -> O
FakeTimerCtx
.Auto Trait Implementations§
impl<Id> Freeze for FakeTimerCtx<Id>
impl<Id> RefUnwindSafe for FakeTimerCtx<Id>where
Id: RefUnwindSafe,
impl<Id> Send for FakeTimerCtx<Id>where
Id: Send,
impl<Id> Sync for FakeTimerCtx<Id>where
Id: Sync,
impl<Id> Unpin for FakeTimerCtx<Id>where
Id: Unpin,
impl<Id> UnwindSafe for FakeTimerCtx<Id>where
Id: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Id, Ctx> FakeTimerCtxExt<Id> for Ctxwhere
Id: Clone,
Ctx: WithFakeTimerContext<Id>,
impl<Id, Ctx> FakeTimerCtxExt<Id> for Ctxwhere
Id: Clone,
Ctx: WithFakeTimerContext<Id>,
source§fn trigger_next_timer<H>(&mut self, handler: &mut H) -> Option<Id>where
H: TimerHandler<Ctx, Id>,
fn trigger_next_timer<H>(&mut self, handler: &mut H) -> Option<Id>where
H: TimerHandler<Ctx, Id>,
Triggers the next timer, if any, by calling f
on it.
trigger_next_timer
triggers the next timer, if any, advances the
internal clock to the timer’s scheduled time, and returns its ID.
source§fn trigger_timers_until_instant<H>(
&mut self,
instant: FakeInstant,
handler: &mut H
) -> Vec<Id>where
H: TimerHandler<Ctx, Id>,
fn trigger_timers_until_instant<H>(
&mut self,
instant: FakeInstant,
handler: &mut H
) -> Vec<Id>where
H: TimerHandler<Ctx, Id>,
Skips the current time forward until instant
, triggering all timers
until then, inclusive, by giving them to handler
.
Returns the timers which were triggered.
§Panics
Panics if instant
is in the past.
source§fn trigger_timers_for<H>(
&mut self,
duration: Duration,
handler: &mut H
) -> Vec<Id>where
H: TimerHandler<Ctx, Id>,
fn trigger_timers_for<H>(
&mut self,
duration: Duration,
handler: &mut H
) -> Vec<Id>where
H: TimerHandler<Ctx, Id>,
Skips the current time forward by duration
, triggering all timers
until then, inclusive, by calling f
on them.
Returns the timers which were triggered.
source§fn trigger_timers_and_expect_unordered<I, H>(
&mut self,
timers: I,
handler: &mut H
)
fn trigger_timers_and_expect_unordered<I, H>( &mut self, timers: I, handler: &mut H )
Triggers timers and expects them to be the given timers.
The number of timers to be triggered is taken to be the number of
timers produced by timers
. Timers may be triggered in any order.
§Panics
Panics under the following conditions:
- Fewer timers could be triggered than expected
- Timers were triggered that were not expected
- Timers that were expected were not triggered
source§fn trigger_timers_until_and_expect_unordered<I, H>(
&mut self,
instant: FakeInstant,
timers: I,
handler: &mut H
)
fn trigger_timers_until_and_expect_unordered<I, H>( &mut self, instant: FakeInstant, timers: I, handler: &mut H )
Triggers timers until instant
and expects them to be the given
timers.
Like trigger_timers_and_expect_unordered
, except that timers will
only be triggered until instant
(inclusive).
source§fn trigger_timers_for_and_expect<I, H>(
&mut self,
duration: Duration,
timers: I,
handler: &mut H
)
fn trigger_timers_for_and_expect<I, H>( &mut self, duration: Duration, timers: I, handler: &mut H )
Triggers timers for duration
and expects them to be the given
timers.
Like trigger_timers_and_expect_unordered
, except that timers will
only be triggered for duration
(inclusive).