https://kotlinlang.org logo
Title
p

Paul Woitaschek

05/17/2019, 9:39 AM
Why does this fail immediately with
java.lang.IllegalStateException: This job has not completed yet
?
kotlin
  @Test
  fun remoteConfigWorks() = runBlockingTest {
    val remoteConfig = FirebaseRemoteConfig.getInstance()
    val worked = suspendCoroutine<Boolean> { cont ->
      remoteConfig.fetch().addOnCompleteListener {
        if (it.isSuccessful) {
          cont.resume(true)
        } else {
          cont.resumeWithException(it.exception ?: AssertionError("Fetching was not succssfull"))
        }
      }
    }
    assertThat(worked).isTrue()
  }
e

elizarov

05/17/2019, 11:57 AM
Can you post a bit larger piece of the stack-trace, please?
p

Paul Woitaschek

05/17/2019, 2:26 PM
Exception in thread "main" java.lang.IllegalStateException: This job has not completed yet at kotlinx.coroutines.JobSupport.getCompletionExceptionOrNull(JobSupport.kt:1114) at kotlinx.coroutines.test.TestBuildersKt.runBlockingTest(TestBuilders.kt:53) at kotlinx.coroutines.test.TestBuildersKt.runBlockingTest$default(TestBuilders.kt:45) at SamplKt.main(Sampl.kt:8) at SamplKt.main(Sampl.kt)
A reproducer is actually pretty simple
runBlockingTest {
    suspendCancellableCoroutine<Unit> { cont ->
      thread {
        Thread.sleep(1000)
        cont.resume(Unit)
      }
    }
  }
@elizarov
e

elizarov

05/17/2019, 2:44 PM
Can you, please, file an issue to http://github.com/kotlin/kotlinx.coroutines/issues Thanks in advance!