• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package kotlinx.coroutines
2 
3 import kotlinx.coroutines.testing.*
4 import org.junit.Test
5 import kotlin.test.*
6 
7 class WithTimeoutChildDispatchStressTest : TestBase() {
8     private val N_REPEATS = 10_000 * stressTestMultiplier
9 
10     /**
11      * This stress-test makes sure that dispatching resumption from within withTimeout
12      * works appropriately (without additional dispatch) despite the presence of
13      * children coroutine in a different dispatcher.
14      */
15     @Test
<lambda>null16     fun testChildDispatch() = runBlocking {
17         repeat(N_REPEATS) {
18             val result = withTimeout(5000) {
19                 // child in different dispatcher
20                 val job = launch(Dispatchers.Default) {
21                     // done nothing, but dispatches to join from another thread
22                 }
23                 job.join()
24                 "DONE"
25             }
26             assertEquals("DONE", result)
27         }
28     }
29 }