1 /*
2  * Copyright 2016-2018 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 kotlin.test.*
9 
10 class WithTimeoutChildDispatchStressTest : TestBase() {
11     private val N_REPEATS = 10_000 * stressTestMultiplier
12 
13     /**
14      * This stress-test makes sure that dispatching resumption from within withTimeout
15      * works appropriately (without additional dispatch) despite the presence of
16      * children coroutine in a different dispatcher.
17      */
18     @Test
<lambda>null19     fun testChildDispatch() = runBlocking {
20         repeat(N_REPEATS) {
21             val result = withTimeout(5000) {
22                 // child in different dispatcher
23                 val job = launch(Dispatchers.Default) {
24                     // done nothing, but dispatches to join from another thread
25                 }
26                 job.join()
27                 "DONE"
28             }
29             assertEquals("DONE", result)
30         }
31     }
32 }