dsgryazin
03/17/2018, 3:25 PMTestScheduler
in Rx, making time shifting in test a breeze.
I'd expect a special CoroutineDispatcher
for testing reasons.
I've looked through the tests in coroutines-core
repository, but did not find examples there. Moreover it's full of realtime delays delay(100)
.
The case is testing UI-sensitive code, where delays can be impermissibly long.elizarov
03/17/2018, 6:47 PMstreetsofboston
03/18/2018, 2:00 PMThis [CoroutineContext] dispatcher can be used to simulate virtual time to speed up
code, especially tests, that deal with delays and timeouts.
Specify an instance of this context when calling the *non-blocking* [kotlinx.coroutines.experimental.launch]
or [kotlinx.coroutines.experimental.async] and then advance time or trigger the actions
to make the co-routines execute.
This works much like the *TestScheduler* in RxJava, which allows to speed up tests that deal
with non-blocking Rx chains that contain delays or timeouts.
This dispatcher can also handle *blocking* coroutines that are started by
[kotlinx.coroutines.experimental.runBlocking]. This dispatcher's virtual time will be automatically
advanced based based on the delayed actions within the coroutine(s).
elizarov
03/18/2018, 5:34 PMkotlinx.coroutines
will be welcome.streetsofboston
03/19/2018, 8:19 PMkotlinx.coroutines
should this class be added?elizarov
03/20/2018, 2:09 PMkotlinx-coroutines-core
module is for JVM. The package does not matter much, as different modules can have slightly varying APIs in the same packages. Moreover, I don't see a big problem to port this class to other platforms in the future, toostreetsofboston
03/20/2018, 2:14 PMtest
(like the TestScheduler
on Rx Java 2).elizarov
03/20/2018, 2:14 PMstreetsofboston
03/21/2018, 9:21 PM