How can I test timings of a `Flow`? I am trying to...
# coroutines
h
How can I test timings of a
Flow
? I am trying to do with turbine and `TestCoroutineScheduler.currentTime`:
Copy code
runTest {
  val myFlow: Flow<Int> = flow<Int> {
    (1..5).forEach {
      delay(100)
      emit(it)
    }
  }
  myFlow.test {
    repeat(5) {
      awaitItem()
      println(testScheduler.currentTime)
    }
    awaitComplete()
  }
}
The described approach does not work: For each run my test prints different/random values, e.g. "300,500,500,500,500 " etc. I have tried using the
myFlow.flowOn()
operator with both test dispatchers available.
a
Are you using the latest version of Turbine? Just asking because IIRC its behavior in
runTest
changed between versions.
h
ohmy! I was on 0.12.0. Seems 0.12.1 fixed: "`await`-prefixed methods no longer interfere with virtual time control from a
TestScheduler
(such as inside
runTest
)." Thank you!