https://kotlinlang.org logo
Title
p

Paul Woitaschek

10/30/2019, 8:55 PM
Huh, what's happening here?
@Test
  fun experiment() = runBlockingTest {
    PublishProcessor.create<Unit>()
      .replay(1)
      .refCount()
      .asFlow()
      .first()
  }
This fails with
java.lang.IllegalStateException: This job has not completed yet
oO Can someone explan this?
s

streetsofboston

10/30/2019, 9:31 PM
Looks like an issue with the coroutine-test library. You can simplify your failing code like this:
@Test
  fun experiment() = runBlockingTest {
    flow<Unit> {
      suspendCancellableCoroutine<Nothing> {  }
    }
    .first()
  }
The call to
first()
causes it. If you were to emit at least one item, it all works without an exception being thrown
v

voben

10/30/2019, 9:40 PM
Could we just use
runBlocking
instead?
s

streetsofboston

10/30/2019, 9:45 PM
Depends. Sometimes you’d like to use the facilities of the TestCoroutineScope in your tests. For this, you must use
runBlockingTest
.
p

Paul Woitaschek

10/30/2019, 10:23 PM
Lol, I created that first issue 😄
😀 2