Skip to content

Commit

Permalink
add exceptionInLifetimeCoroutineScopeTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliya-usov committed Aug 16, 2023
1 parent 03a3382 commit f66c08e
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.fail
import java.time.Duration
import kotlin.coroutines.CoroutineContext
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
import kotlin.test.*

class CoroutineTest : CoroutineTestBase() {

Expand Down Expand Up @@ -671,5 +669,32 @@ class CoroutineTest : CoroutineTestBase() {
}
}

@Test
fun exceptionInLifetimeCoroutineScopeTest() {
val def = LifetimeDefinition()
runBlocking {
val coroutineScope = def.coroutineScope
val job = coroutineScope.async {
throw IllegalStateException()
}

job.join()
val exception = job.getCompletionExceptionOrNull()
assertIs<java.lang.IllegalStateException>(exception)
assertTrue(job.isCompleted)

assertTrue(def.isAlive)
assertTrue(def.coroutineScope.isActive)
assertSame(coroutineScope, def.coroutineScope)

var called = false
coroutineScope.launch {
called = true
}.join()

assertTrue(called)
}
}

private class TestException : Exception()
}

0 comments on commit f66c08e

Please sign in to comment.