Is there somewhere an example of using "virtual ti...
# coroutines
r
Is there somewhere an example of using "virtual time" in
delay
in tests?
e
@rafal Basically, all examples in coroutines guide are runnable tests. See, this example: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/src/test/kotlin/guide/example-basic-02.kt When you run it from IDE it takes 2 secs of real-time to run, however the same example is also run as a test here https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/src/test/kotlin/guide/test/GuideTest.kt and it runs instantaneously, because it works under virtual (test) time source
r
Thanks Roman, I'll definitely look into those tests soon 🙂
@elizarov Hmm... I dug into those test and found out that
TimeSource
is
internal
. Do this fact and
(this feature is not available outside of the library)
mean that I cannot use virtual time in my tests?
e
Exactly. That was the point.
TestTimeSource
implementation is also private. You are welcome to clone the repo, implement some kind of public API for test that you’re comfortable with and contribute it via pull request. Right now there are simply not enough use-cases, all it is tightly-coupled to the infrastructure that runs coroutines guide tests