Skip to main content

TestScheduler

Struct TestScheduler 

Source
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

Source

pub fn new() -> Self

A scheduler with its clock at zero.

Source

pub fn scheduler(&self) -> Rc<dyn IScheduler>

The scheduler as the handle operators take.

Source

pub fn schedule_absolute_action( &self, due_time: i64, action: impl FnOnce() + 'static, ) -> Rc<dyn IDisposable>

Schedules an action at an absolute virtual time.

Source

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)).

Source

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)).

Source

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>>)).

Source

pub fn run(&self)

Runs the queued work (VirtualTimeScheduler.Start()).

Source

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).

Source

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).

Source

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>>§

Source

pub fn clock(&self) -> <C as VirtualTimeClock>::Absolute

The current time of the clock (Clock).

Source

pub fn set_clock(&self, clock: <C as VirtualTimeClock>::Absolute)

Sets the clock (Clock’s protected setter), for derived schedulers.

Source

pub fn is_enabled(&self) -> bool

Whether the scheduler is running work (IsEnabled).

Source

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).

Source

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).

Source

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).

Source

pub fn stop(&self)

Stops the scheduler after the work that runs (Stop).

Source

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.

Source

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).

Source

pub fn sleep(&self, time: <C as VirtualTimeClock>::Relative)

Moves the clock by time without running work (Sleep).

Trait Implementations§

Source§

impl Clone for TestScheduler

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for TestScheduler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for TestScheduler

Source§

type Target = VirtualTimeScheduler<TestTime>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.