Skip to content

Commit

Permalink
moved to concurrent package, run tests with sleep only on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmasB committed Feb 1, 2024
1 parent 4c2b422 commit 0da156b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* See LICENSE for details.
*/

package com.almasb.fxgl.core
package com.almasb.fxgl.core.concurrent

import com.almasb.fxgl.core.EngineService
import java.util.concurrent.CompletableFuture

/**
Expand All @@ -22,7 +23,7 @@ abstract class AsyncService<T> : EngineService() {
*/
override fun onGameUpdate(tpf: Double) {
asyncTask?.let { onPostGameUpdateAsync(it.get()) }
asyncTask = CompletableFuture.supplyAsync(){ onGameUpdateAsync(tpf) } // Process until next onGameUpdate
asyncTask = CompletableFuture.supplyAsync() { onGameUpdateAsync(tpf) } // Process until next onGameUpdate
}

/**
Expand All @@ -37,5 +38,4 @@ abstract class AsyncService<T> : EngineService() {
* Service async processing and the main JavaFX thread.
*/
open fun onPostGameUpdateAsync(result: T) { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
* See LICENSE for details.
*/
@file:Suppress("JAVA_MODULE_DOES_NOT_DEPEND_ON_MODULE")
package com.almasb.fxgl.core
package com.almasb.fxgl.core.concurrent

import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.greaterThan
import org.hamcrest.Matchers.lessThan
import org.hamcrest.Matchers.both
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
import kotlin.system.measureTimeMillis

/**
Expand All @@ -23,6 +23,7 @@ import kotlin.system.measureTimeMillis
class AsyncServiceTest {

@Test
@EnabledIfEnvironmentVariable(named = "CI", matches = "true")
fun `Async Service with Unit (Kotlin Void)`() {
val service = object : AsyncService<Unit>() {
override fun onGameUpdateAsync(tpf: Double) {
Expand Down Expand Up @@ -62,6 +63,7 @@ class AsyncServiceTest {
}

@Test
@EnabledIfEnvironmentVariable(named = "CI", matches = "true")
fun `Async Service parallel`() {
val services = listOf(
object : AsyncService<Unit>() {
Expand Down Expand Up @@ -95,5 +97,4 @@ class AsyncServiceTest {
}
}.toDouble(), `is`(both(greaterThan(80.0)).and(lessThan(120.0))))
}

}

0 comments on commit 0da156b

Please sign in to comment.