TestScheduler
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public class TestScheduler
extension TestScheduler: Scheduler
A Scheduler
thats uses VirtualTime
to schedule its tasks.
A special, non thread-safe scheduler for testing operators that require a scheduler without introducing real concurrency. Faciliates a recreatable sequence of tasks executed within ‘virtual time’.
-
Configuration values for a
See moreTestScheduler
test run.Declaration
Swift
public struct Configuration
-
Initialises the scheduler with the given commencement time
Declaration
Swift
public init(initialClock: VirtualTime = 0, maxClock: VirtualTime = 100_000)
Parameters
initialClock
The VirtualTime at which the scheduler will start
maxClock
The VirtualTime ceiling after which the scheduler will cease to process tasks
-
Schedules the creation and subscription of an arbitrary
Publisher
to aTestableSubscriber
, and finally the subscription’s subsequent cancellation.The default
Configuration
:- Creates the publisher (executes the supplied publisher factory) at
100
- Subscribes to the publisher at
200
- Cancels the subscription at
900
- Starts the scheduler immediately.
Uses
TestableSubscriberOptions.default
for the subscriber configuration.
Declaration
Swift
public func start<P>(configuration: Configuration = .default, create: @escaping () -> P) -> TestableSubscriber<P.Output, P.Failure> where P : Publisher
Parameters
configuration
The parameters of the test subscription including scheduling details
create
A factory function that returns the publisher to be subscribed to
Return Value
A
TestableSubscriber
that contains, or is scheduled to contain, the output of the publisher subscription. - Creates the publisher (executes the supplied publisher factory) at
-
Initialises a
TestablePublisher
with events scheduled in absolute time.Creates a
TestablePublisher
and schedules the suppliedTestSequence
to occur in absolute time. Sequence elements with virtual times in the ‘past’ will be ignored.Warning
This method will produce an assertion failure if the supplied
TestSequence
includes aSignal.subscription
element. Subscription time is dictated by the subscriber and can not be predetermined by the publisher.Declaration
Swift
public func createAbsoluteTestablePublisher<Value, Failure>(_ sequence: TestSequence<Value, Failure>) -> TestablePublisher<Value, Failure> where Failure : Error
Parameters
sequence
The sequence of values the publisher should produce
Return Value
A
TestablePublisher
loaded with the suppliedTestSequence
. -
Initialises a
TestablePublisher
with events scheduled in relative time.Creates a
TestablePublisher
and schedules the suppliedTestSequence
to occur in absolute time.Warning
This method will produce an assertion failure if the supplied
TestSequence
includes aSignal.subscription
element. Subscription time is dictated by the subscriber and can not be predetermined by the publisher.Declaration
Swift
public func createRelativeTestablePublisher<Value, Failure>(_ sequence: TestSequence<Value, Failure>) -> TestablePublisher<Value, Failure> where Failure : Error
Parameters
sequence
The sequence of values the publisher should produce
Return Value
A
TestablePublisher
loaded with the suppliedTestSequence
. -
Produces a
TestableSubscriber
pre-populated with this scheduler.Declaration
Swift
public func createTestableSubscriber<Input, Failure>(_ inputType: Input.Type, _ failureType: Failure.Type, options: TestableSubscriberOptions = .default) -> TestableSubscriber<Input, Failure> where Failure : Error
Parameters
inputType
The
Input
associated type for the producedSubscriber
failureType
The
Failure
associated type for the producedSubscriber
options
Behavior options for the produced
Subscriber
Return Value
A configured
TestableSubscriber
. -
Performs all the actions in the scheduler’s queue, in time order followed by submission order, until no more actions remain.
Declaration
Swift
public func resume()
-
Declaration
Swift
public typealias SchedulerTimeType = VirtualTime
-
Declaration
Swift
public typealias SchedulerOptions = Never
-
Declaration
Swift
public var now: VirtualTime { get }
-
Declaration
Swift
public var minimumTolerance: VirtualTimeInterval { get }
-
Declaration
Swift
public func schedule(options: Never?, _ action: @escaping () -> Void)
-
Declaration
Swift
public func schedule(after date: VirtualTime, tolerance: VirtualTimeInterval, options: Never?, _ action: @escaping () -> Void)
-
Declaration
Swift
public func schedule(after date: VirtualTime, interval: VirtualTimeInterval, tolerance: VirtualTimeInterval, options: Never?, _ action: @escaping () -> Void) -> Cancellable