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 moreTestSchedulertest 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
initialClockThe VirtualTime at which the scheduler will start
maxClockThe VirtualTime ceiling after which the scheduler will cease to process tasks
-
Schedules the creation and subscription of an arbitrary
Publisherto 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.defaultfor the subscriber configuration.
Declaration
Swift
public func start<P>(configuration: Configuration = .default, create: @escaping () -> P) -> TestableSubscriber<P.Output, P.Failure> where P : PublisherParameters
configurationThe parameters of the test subscription including scheduling details
createA factory function that returns the publisher to be subscribed to
Return Value
A
TestableSubscriberthat contains, or is scheduled to contain, the output of the publisher subscription. - Creates the publisher (executes the supplied publisher factory) at
-
Initialises a
TestablePublisherwith events scheduled in absolute time.Creates a
TestablePublisherand schedules the suppliedTestSequenceto 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
TestSequenceincludes aSignal.subscriptionelement. 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 : ErrorParameters
sequenceThe sequence of values the publisher should produce
Return Value
A
TestablePublisherloaded with the suppliedTestSequence. -
Initialises a
TestablePublisherwith events scheduled in relative time.Creates a
TestablePublisherand schedules the suppliedTestSequenceto occur in absolute time.Warning
This method will produce an assertion failure if the supplied
TestSequenceincludes aSignal.subscriptionelement. 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 : ErrorParameters
sequenceThe sequence of values the publisher should produce
Return Value
A
TestablePublisherloaded with the suppliedTestSequence. -
Produces a
TestableSubscriberpre-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 : ErrorParameters
inputTypeThe
Inputassociated type for the producedSubscriberfailureTypeThe
Failureassociated type for the producedSubscriberoptionsBehavior options for the produced
SubscriberReturn 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
View on GitHub
TestScheduler Class Reference