blob: 8d48aa43b31afde1e9e9632f59705340c83f9d2f [file] [log] [blame]
Steve Elliottca095be2022-07-25 14:26:10 +00001/*
2 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5package kotlinx.coroutines
6
7import org.junit.Test
8import java.util.concurrent.*
9import kotlin.coroutines.*
10import kotlin.test.*
11
12class LimitedParallelismUnhandledExceptionTest : TestBase() {
13
14 @Test
15 fun testUnhandledException() = runTest {
16 var caughtException: Throwable? = null
17 val executor = Executors.newFixedThreadPool(
18 1
19 ) {
20 Thread(it).also {
21 it.uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { _, e -> caughtException = e }
22 }
23 }.asCoroutineDispatcher()
24 val view = executor.limitedParallelism(1)
25 view.dispatch(EmptyCoroutineContext, Runnable { throw TestException() })
26 withContext(view) {
27 // Verify it is in working state and establish happens-before
28 }
29 assertTrue { caughtException is TestException }
30 executor.close()
31 }
32}