TestMonotonicFrameClock
A MonotonicFrameClock with a time source controlled by a kotlinx-coroutines-test TestCoroutineScheduler. This frame clock may be used to consistently drive time under controlled tests.
Calls to withFrameNanos will schedule an upcoming frame frameDelayNanos nanoseconds in the future by launching into coroutineScope if such a frame has not yet been scheduled. The current frame time for withFrameNanos is provided by delayController. It is strongly suggested that coroutineScope contain the test dispatcher controlled by delayController.
Summary
Public constructors |
|
|---|---|
TestMonotonicFrameClock( |
android
|
Public functions |
||
|---|---|---|
open suspend R |
<R : Any?> withFrameNanos(onFrame: (frameTimeNanos: Long) -> R)Schedules |
android
|
Public properties |
||
|---|---|---|
ContinuationInterceptor |
A |
android
|
Long |
The number of nanoseconds to |
android
|
Boolean |
Returns whether there are any awaiters on this clock. |
android
|
Extension properties |
||
|---|---|---|
Long |
The frame delay time for the |
android
|
Inherited functions |
|||||||||
|---|---|---|---|---|---|---|---|---|---|
|
|||||||||
|
Inherited properties |
|||
|---|---|---|---|
|
Public constructors
TestMonotonicFrameClock
TestMonotonicFrameClock(
coroutineScope: CoroutineScope,
frameDelayNanos: Long = DefaultFrameDelay,
onPerformTraversals: (Long) -> Unit = {}
)
| Parameters | |
|---|---|
coroutineScope: CoroutineScope |
The |
frameDelayNanos: Long = DefaultFrameDelay |
The number of nanoseconds to |
onPerformTraversals: (Long) -> Unit = {} |
Called with the frame time of the frame that was just executed, after running all |
Public functions
withFrameNanos
open suspend fun <R : Any?> withFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R
Schedules onFrame to be ran on the next "fake" frame, and schedules the task to actually perform that frame if it hasn't already been scheduled.
Instead of waiting for a vsync message to perform the next frame, it simply calls the coroutine delay function for the test frame time frameDelayMillis (which the underlying test coroutine scheduler will actually complete immediately without waiting), and then run all scheduled tasks.
Public properties
continuationInterceptor
@ExperimentalTestApi
val continuationInterceptor: ContinuationInterceptor
A CoroutineDispatcher that will defer continuation resumptions requested within withFrameNanos calls to until after the frame callbacks have finished running. Resumptions will then be dispatched before resuming the continuations from the withFrameNanos calls themselves.
frameDelayNanos
val frameDelayNanos: Long
The number of nanoseconds to delay between executing frames.
Extension properties
frameDelayMillis
@ExperimentalTestApi
val TestMonotonicFrameClock.frameDelayMillis: Long
The frame delay time for the TestMonotonicFrameClock in milliseconds.