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 CoroutinesTimeoutTest : TestBase(disableOutCheck = true) { 12 13 @Rule 14 @JvmField 15 public val validation = TestFailureValidation( 16 1000, false, true, 17 TestResultSpec("throwingTest", error = RuntimeException::class.java), 18 TestResultSpec("successfulTest"), 19 TestResultSpec( 20 "hangingTest", expectedOutParts = listOf( 21 "Coroutines dump", 22 "Test hangingTest timed out after 1 seconds", 23 "BlockingCoroutine{Active}", 24 "runBlocking", 25 "at kotlinx.coroutines.debug.junit4.CoroutinesTimeoutTest.suspendForever", 26 "at kotlinx.coroutines.debug.junit4.CoroutinesTimeoutTest\$hangingTest\$1.invokeSuspend"), 27 notExpectedOutParts = listOf("delay", "throwingTest"), 28 error = TestTimedOutException::class.java) 29 ) 30 31 @Test <lambda>null32 fun hangingTest() = runBlocking<Unit> { 33 suspendForever() 34 expectUnreached() 35 } 36 suspendForevernull37 private suspend fun suspendForever() { 38 delay(Long.MAX_VALUE) 39 expectUnreached() 40 } 41 42 @Test <lambda>null43 fun throwingTest() = runBlocking<Unit> { 44 throw RuntimeException() 45 } 46 47 @Test <lambda>null48 fun successfulTest() = runBlocking { 49 val job = launch { 50 yield() 51 } 52 53 job.join() 54 } 55 } 56