TestCoroutineScheduler

This is a scheduler for coroutines used in tests, providing the delay-skipping behavior.

Test dispatchers are parameterized with a scheduler. Several dispatchers can share the same scheduler, in which case their knowledge about the virtual time will be synchronized. When the dispatchers require scheduling an event at a later point in time, they notify the scheduler, which will establish the order of the tasks.

The scheduler can be queried to advance the time (via advanceTimeBy), run all the scheduled tasks advancing the virtual time as needed (via advanceUntilIdle), or run the tasks that are scheduled to run as soon as possible but haven't yet been dispatched (via runCurrent).

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The current virtual time in milliseconds.

Link copied to clipboard

Returns the TimeSource representation of the virtual time of this scheduler.

Functions

Link copied to clipboard
fun advanceTimeBy(delayTime: Duration)

Moves the virtual clock of this dispatcher forward by the specified amount, running the scheduled tasks in the meantime.

Link copied to clipboard

Runs the enqueued tasks in the specified order, advancing the virtual time as needed until there are no more tasks associated with the dispatchers linked to this scheduler.

Link copied to clipboard

Runs the tasks that are scheduled to execute at this moment of virtual time.