• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines
6 
7 import org.junit.Test
8 import java.util.concurrent.*
9 import kotlin.coroutines.*
10 import kotlin.test.*
11 
12 class 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 }
33