1 package kotlinx.coroutines.debug.junit4 2 3 import kotlinx.coroutines.testing.* 4 import kotlinx.coroutines.* 5 import org.junit.* 6 import org.junit.runners.model.* 7 8 class CoroutinesTimeoutTest : TestBase(disableOutCheck = true) { 9 10 @Rule 11 @JvmField 12 public val validation = TestFailureValidation( 13 1000, false, true, 14 TestResultSpec("throwingTest", error = RuntimeException::class.java), 15 TestResultSpec("successfulTest"), 16 TestResultSpec( 17 "hangingTest", expectedOutParts = listOf( 18 "Coroutines dump", 19 "Test hangingTest timed out after 1 seconds", 20 "BlockingCoroutine{Active}", 21 "runBlocking", 22 "at kotlinx.coroutines.debug.junit4.CoroutinesTimeoutTest.suspendForever", 23 "at kotlinx.coroutines.debug.junit4.CoroutinesTimeoutTest\$hangingTest\$1.invokeSuspend"), 24 notExpectedOutParts = listOf("delay", "throwingTest"), 25 error = TestTimedOutException::class.java) 26 ) 27 28 @Test <lambda>null29 fun hangingTest() = runBlocking<Unit> { 30 suspendForever() 31 expectUnreached() 32 } 33 suspendForevernull34 private suspend fun suspendForever() { 35 delay(Long.MAX_VALUE) 36 expectUnreached() 37 } 38 39 @Test <lambda>null40 fun throwingTest() = runBlocking<Unit> { 41 throw RuntimeException() 42 } 43 44 @Test <lambda>null45 fun successfulTest() = runBlocking { 46 val job = launch { 47 yield() 48 } 49 50 job.join() 51 } 52 } 53