• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.debug.junit4
6 
7 import kotlinx.coroutines.*
8 import org.junit.*
9 import org.junit.runners.model.*
10 
11 class CoroutinesTimeoutEagerTest : TestBase() {
12 
13     @Rule
14     @JvmField
15     public val validation = TestFailureValidation(
16         500, true, true,
17         TestResultSpec(
18             "hangingTest", expectedOutParts = listOf(
19                 "Coroutines dump",
20                 "Test hangingTest timed out after 500 milliseconds",
21                 "BlockingCoroutine{Active}",
22                 "runBlocking",
23                 "at kotlinx.coroutines.debug.junit4.CoroutinesTimeoutEagerTest.hangForever",
24                 "at kotlinx.coroutines.debug.junit4.CoroutinesTimeoutEagerTest.waitForHangJob"),
25             error = TestTimedOutException::class.java)
26     )
27 
<lambda>null28     private val job = GlobalScope.launch(Dispatchers.Unconfined) { hangForever() }
29 
hangForevernull30     private suspend fun hangForever() {
31         suspendCancellableCoroutine<Unit> {  }
32         expectUnreached()
33     }
34 
35     @Test
<lambda>null36     fun hangingTest() = runBlocking<Unit> {
37         waitForHangJob()
38         expectUnreached()
39     }
40 
waitForHangJobnull41     private suspend fun waitForHangJob() {
42         job.join()
43         expectUnreached()
44     }
45 
46 }
47