https://kotlinlang.org logo
#coroutines
Title
# coroutines
r

rafal

07/24/2017, 2:03 PM
Is there somewhere an example of using "virtual time" in
delay
in tests?
e

elizarov

07/24/2017, 2:14 PM
@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

rafal

07/24/2017, 2:27 PM
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

elizarov

07/25/2017, 12:56 PM
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
7 Views