-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathJavaFxDispatcherTest.kt
67 lines (59 loc) · 1.83 KB
/
JavaFxDispatcherTest.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines.javafx
import javafx.application.*
import kotlinx.coroutines.*
import org.junit.*
import org.junit.Test
import kotlin.test.*
class JavaFxDispatcherTest : TestBase() {
@Before
fun setup() {
ignoreLostThreads("JavaFX Application Thread", "Thread-", "QuantumRenderer-", "InvokeLaterDispatcher")
}
@Test
fun testDelay() {
if (!initPlatform()) {
println("Skipping JavaFxTest in headless environment")
return // ignore test in headless environments
}
runBlocking {
expect(1)
val job = launch(Dispatchers.JavaFx) {
check(Platform.isFxApplicationThread())
expect(2)
delay(100)
check(Platform.isFxApplicationThread())
expect(3)
}
job.join()
finish(4)
}
}
@Test
fun testImmediateDispatcherYield() {
if (!initPlatform()) {
println("Skipping JavaFxTest in headless environment")
return // ignore test in headless environments
}
runBlocking(Dispatchers.JavaFx) {
expect(1)
check(Platform.isFxApplicationThread())
// launch in the immediate dispatcher
launch(Dispatchers.JavaFx.immediate) {
expect(2)
yield()
expect(4)
}
expect(3) // after yield
yield() // yield back
finish(5)
}
}
@Test
fun testMainDispatcherToString() {
assertEquals("Dispatchers.Main", Dispatchers.Main.toString())
assertEquals("Dispatchers.Main.immediate", Dispatchers.Main.immediate.toString())
}
}