pub struct TestScheduler { /* private fields */ }Expand description
A virtual-time scheduler for tests, whose clock counts ticks (TestScheduler). It dereferences to
the virtual-time scheduler (clock, start, advance_to, advance_by, sleep,
schedule_absolute, …).
Implementations§
Source§impl TestScheduler
impl TestScheduler
Sourcepub fn scheduler(&self) -> Rc<dyn IScheduler>
pub fn scheduler(&self) -> Rc<dyn IScheduler>
The scheduler as the handle operators take.
Sourcepub fn schedule_absolute_action(
&self,
due_time: i64,
action: impl FnOnce() + 'static,
) -> Rc<dyn IDisposable>
pub fn schedule_absolute_action( &self, due_time: i64, action: impl FnOnce() + 'static, ) -> Rc<dyn IDisposable>
Schedules an action at an absolute virtual time.
Sourcepub fn start_with<T: Clone + 'static>(
&self,
create: impl FnOnce() -> Rc<dyn IObservable<T>> + 'static,
created: i64,
subscribed: i64,
disposed: i64,
) -> Rc<MockObserver<T>>
pub fn start_with<T: Clone + 'static>( &self, create: impl FnOnce() -> Rc<dyn IObservable<T>> + 'static, created: i64, subscribed: i64, disposed: i64, ) -> Rc<MockObserver<T>>
Creates the sequence at created, subscribes an observer at subscribed and disposes the
subscription at disposed, runs the scheduler, and returns the observer with what it
recorded (Start(Func<IObservable<T>>, long, long, long)).
Sourcepub fn start_disposed<T: Clone + 'static>(
&self,
create: impl FnOnce() -> Rc<dyn IObservable<T>> + 'static,
disposed: i64,
) -> Rc<MockObserver<T>>
pub fn start_disposed<T: Clone + 'static>( &self, create: impl FnOnce() -> Rc<dyn IObservable<T>> + 'static, disposed: i64, ) -> Rc<MockObserver<T>>
start_with at the default times, created at 100, subscribed at 200 and
disposed at disposed (Start(Func<IObservable<T>>, long)).
Sourcepub fn start<T: Clone + 'static>(
&self,
create: impl FnOnce() -> Rc<dyn IObservable<T>> + 'static,
) -> Rc<MockObserver<T>>
pub fn start<T: Clone + 'static>( &self, create: impl FnOnce() -> Rc<dyn IObservable<T>> + 'static, ) -> Rc<MockObserver<T>>
start_with at the default times: created at 100, subscribed at 200,
disposed at 1000 (Start(Func<IObservable<T>>)).
Sourcepub fn create_hot_observable<T: Clone + 'static>(
&self,
messages: Vec<Recorded<Notification<T>>>,
) -> Rc<HotObservable<T>>
pub fn create_hot_observable<T: Clone + 'static>( &self, messages: Vec<Recorded<Notification<T>>>, ) -> Rc<HotObservable<T>>
A sequence that notifies its messages at their absolute times to the observers subscribed
then (CreateHotObservable).
Sourcepub fn create_cold_observable<T: Clone + 'static>(
&self,
messages: Vec<Recorded<Notification<T>>>,
) -> Rc<ColdObservable<T>>
pub fn create_cold_observable<T: Clone + 'static>( &self, messages: Vec<Recorded<Notification<T>>>, ) -> Rc<ColdObservable<T>>
A sequence that notifies its messages at their times relative to each subscription
(CreateColdObservable).
Sourcepub fn create_observer<T: 'static>(&self) -> Rc<MockObserver<T>>
pub fn create_observer<T: 'static>(&self) -> Rc<MockObserver<T>>
An observer that records what it receives with the time (CreateObserver).
Methods from Deref<Target = VirtualTimeScheduler<TestTime>>§
Sourcepub fn clock(&self) -> <C as VirtualTimeClock>::Absolute
pub fn clock(&self) -> <C as VirtualTimeClock>::Absolute
The current time of the clock (Clock).
Sourcepub fn set_clock(&self, clock: <C as VirtualTimeClock>::Absolute)
pub fn set_clock(&self, clock: <C as VirtualTimeClock>::Absolute)
Sets the clock (Clock’s protected setter), for derived schedulers.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether the scheduler is running work (IsEnabled).
Sourcepub fn schedule_absolute(
&self,
due_time: <C as VirtualTimeClock>::Absolute,
action: Box<dyn FnOnce(&Rc<dyn IScheduler>) -> Rc<dyn IDisposable>>,
) -> Rc<dyn IDisposable>
pub fn schedule_absolute( &self, due_time: <C as VirtualTimeClock>::Absolute, action: Box<dyn FnOnce(&Rc<dyn IScheduler>) -> Rc<dyn IDisposable>>, ) -> Rc<dyn IDisposable>
Schedules work at an absolute virtual time (ScheduleAbsolute).
Sourcepub fn schedule_relative(
&self,
due_time: <C as VirtualTimeClock>::Relative,
action: Box<dyn FnOnce(&Rc<dyn IScheduler>) -> Rc<dyn IDisposable>>,
) -> Rc<dyn IDisposable>
pub fn schedule_relative( &self, due_time: <C as VirtualTimeClock>::Relative, action: Box<dyn FnOnce(&Rc<dyn IScheduler>) -> Rc<dyn IDisposable>>, ) -> Rc<dyn IDisposable>
Schedules work at a virtual time relative to the clock (ScheduleRelative).
Sourcepub fn start(&self)
pub fn start(&self)
Runs the queued work, moving the clock to the due time of each, until there is none or the
scheduler is stopped (Start).
Sourcepub fn advance_to(&self, time: <C as VirtualTimeClock>::Absolute)
pub fn advance_to(&self, time: <C as VirtualTimeClock>::Absolute)
Runs the work due up to time and moves the clock to it (AdvanceTo). Panics when time
is before the clock or the scheduler is running, where upstream throws.
Sourcepub fn advance_by(&self, time: <C as VirtualTimeClock>::Relative)
pub fn advance_by(&self, time: <C as VirtualTimeClock>::Relative)
Runs the work due within time from the clock and moves the clock by it (AdvanceBy).
Sourcepub fn sleep(&self, time: <C as VirtualTimeClock>::Relative)
pub fn sleep(&self, time: <C as VirtualTimeClock>::Relative)
Moves the clock by time without running work (Sleep).