blob: b5d1c262bfa7499ef7483b98ad538e9ac2c2664a [file] [log] [blame]
Vsevolod Tolstopyatov2bdd4602019-02-20 17:00:57 +03001/*
2 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5import kotlinx.coroutines.*
6import kotlinx.coroutines.debug.junit4.*
7import org.junit.*
8
9@Ignore // do not run it on CI
10class TestRuleExample {
11
12 @JvmField
13 @Rule
14 public val timeout = CoroutinesTimeout.seconds(1)
15
16 private suspend fun someFunctionDeepInTheStack() {
17 withContext(Dispatchers.IO) {
18 delay(Long.MAX_VALUE)
19 println("This line is never executed")
20 }
21
22 println("This line is never executed as well")
23 }
24
25 @Test
26 fun hangingTest() = runBlocking {
27 val job = launch {
28 someFunctionDeepInTheStack()
29 }
30
31 println("Doing some work...")
32 job.join()
33 }
34
35 @Test
36 fun successfulTest() = runBlocking {
37 launch {
38 delay(10)
39 }.join()
40 }
41
42}