-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathSetTimeoutDispatcherTest.kt
53 lines (48 loc) · 1.2 KB
/
SetTimeoutDispatcherTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines
import kotlin.test.*
class SetTimeoutDispatcherTest : TestBase() {
@Test
fun testDispatch() = runTest {
launch(SetTimeoutDispatcher) {
expect(1)
launch {
expect(3)
}
expect(2)
yield()
expect(4)
}.join()
finish(5)
}
@Test
fun testDelay() = runTest {
withContext(SetTimeoutDispatcher) {
val job = launch(SetTimeoutDispatcher) {
expect(2)
delay(100)
expect(4)
}
expect(1)
yield() // Yield uses microtask, so should be in the same context
expect(3)
job.join()
finish(5)
}
}
@Test
fun testWithTimeout() = runTest {
withContext(SetTimeoutDispatcher) {
val result = withTimeoutOrNull(10) {
expect(1)
delay(100)
expectUnreached()
42
}
assertNull(result)
finish(2)
}
}
}