1 /*
2  * Copyright 2016-2019 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.*
8 
9 /**
10  * Test a race between job failure and join.
11  *
12  * See [#1123](https://github.com/Kotlin/kotlinx.coroutines/issues/1123).
13  */
14 class JobStructuredJoinStressTest : TestBase() {
15     private val nRepeats = 1_000 * stressTestMultiplier
16 
17     @Test
18     fun testStress() {
19         repeat(nRepeats) {
20             assertFailsWith<TestException> {
21                 runBlocking {
22                     // launch in background
23                     val job = launch(Dispatchers.Default) {
24                         throw TestException("OK") // crash
25                     }
26                     assertFailsWith<CancellationException> {
27                         job.join()
28                     }
29                 }
30             }
31         }
32     }
33 }