blob: 9bfd3a1602c4cff58584b3e804065fd059e86f3d [file] [log] [blame]
Roman Elizarovaa461cf2018-04-11 13:20:29 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarovaa461cf2018-04-11 13:20:29 +03003 */
4
5package kotlinx.coroutines.experimental
6
Vsevolod Tolstopyatov06f57aa2018-07-24 19:51:21 +03007import java.io.*
Roman Elizarovaa461cf2018-04-11 13:20:29 +03008import kotlin.test.*
9
10class WithTimeoutOrNullJvmTest : TestBase() {
Roman Elizarovaa461cf2018-04-11 13:20:29 +030011 @Test
12 fun testOuterTimeoutFiredBeforeInner() = runTest {
13 val result = withTimeoutOrNull(100) {
14 Thread.sleep(200) // wait enough for outer timeout to fire
15 withContext(NonCancellable) { yield() } // give an event loop a chance to run and process that cancellation
16 withTimeoutOrNull(100) {
17 yield() // will cancel because of outer timeout
18 expectUnreached()
19 }
20 expectUnreached() // should not be reached, because it is outer timeout
21 }
22 // outer timeout results in null
23 assertEquals(null, result)
24 }
25}