Skip to content

Commit 9c446c0

Browse files
committed
Skip JavaFxTest in headless environment
1 parent 1cc8608 commit 9c446c0

File tree

2 files changed

+24
-12
lines changed
  • ui/kotlinx-coroutines-javafx/src
    • main/kotlin/kotlinx/coroutines/experimental/javafx
    • test/kotlin/kotlinx/coroutines/experimental/javafx

2 files changed

+24
-12
lines changed

ui/kotlinx-coroutines-javafx/src/main/kotlin/kotlinx/coroutines/experimental/javafx/JavaFx.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ import java.util.concurrent.CopyOnWriteArrayList
3030
import java.util.concurrent.TimeUnit
3131
import kotlin.coroutines.experimental.CoroutineContext
3232

33-
3433
/**
3534
* Dispatches execution onto JavaFx application thread and provides native [delay] support.
3635
*/
3736
object JavaFx : CoroutineDispatcher(), Delay {
3837
init {
3938
// :kludge: to make sure Toolkit is initialized if we use JavaFx dispatcher outside of JavaFx app
40-
PlatformImpl.startup {}
39+
initPlatform()
4140
}
4241

4342
private val pulseTimer by lazy {
@@ -93,3 +92,7 @@ object JavaFx : CoroutineDispatcher(), Delay {
9392

9493
override fun toString() = "JavaFx"
9594
}
95+
96+
internal fun initPlatform() {
97+
PlatformImpl.startup {}
98+
}

ui/kotlinx-coroutines-javafx/src/test/kotlin/kotlinx/coroutines/experimental/javafx/JavaFxTest.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,25 @@ class JavaFxTest : TestBase() {
3232
}
3333

3434
@Test
35-
fun testDelay() = runBlocking {
36-
expect(1)
37-
val job = launch(JavaFx) {
38-
check(Platform.isFxApplicationThread())
39-
expect(2)
40-
delay(100)
41-
check(Platform.isFxApplicationThread())
42-
expect(3)
35+
fun testDelay() {
36+
try {
37+
initPlatform()
38+
} catch (e: UnsupportedOperationException) {
39+
println("Skipping JavaFxTest in headless environment")
40+
return // ignore test in headless environments
41+
}
42+
43+
runBlocking {
44+
expect(1)
45+
val job = launch(JavaFx) {
46+
check(Platform.isFxApplicationThread())
47+
expect(2)
48+
delay(100)
49+
check(Platform.isFxApplicationThread())
50+
expect(3)
51+
}
52+
job.join()
53+
finish(4)
4354
}
44-
job.join()
45-
finish(4)
4655
}
4756
}

0 commit comments

Comments
 (0)