Fix: radical overhaul of Game UI tests to fix CI pipeline failures

This commit is contained in:
Julian Kropff
2026-04-26 23:04:45 +02:00
parent 52ad32a100
commit ddb3e221ac
2 changed files with 18 additions and 33 deletions
@@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import ch.unibas.dmi.dbis.cs108.casono.client.ui.gameui.gameuicomponents.TaskbarController; import ch.unibas.dmi.dbis.cs108.casono.client.ui.gameui.gameuicomponents.TaskbarController;
import java.net.URL; import java.net.URL;
import java.util.concurrent.CountDownLatch;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
@@ -17,31 +16,17 @@ class TaskbarControllerSmokeTest {
private static boolean started = false; private static boolean started = false;
@BeforeAll @BeforeAll
static void initJavaFX() throws Exception { static void initJavaFX() {
if (started) { if (started) {
return; return;
} }
CountDownLatch latch = new CountDownLatch(1);
Thread t =
new Thread(
() -> {
try { try {
Platform.startup( Platform.startup(() -> {});
() -> {
Platform.setImplicitExit(false);
latch.countDown();
});
} catch (IllegalStateException ignored) { } catch (IllegalStateException ignored) {
latch.countDown(); // already started
} }
});
t.setDaemon(true);
t.start();
latch.await();
started = true; started = true;
} }
@@ -22,25 +22,17 @@ class TaskbarControllerInputValidationTest {
private static boolean started = false; private static boolean started = false;
@BeforeAll @BeforeAll
static void initJavaFX() throws Exception { static void initJavaFX() {
if (started) { if (started) {
return; return;
} }
CountDownLatch latch = new CountDownLatch(1);
try { try {
Platform.startup( Platform.startup(() -> {});
() -> { } catch (IllegalStateException ignored) {
Platform.setImplicitExit(false); // already started
latch.countDown();
});
} catch (IllegalStateException e) {
// JavaFX already started → CI safe
latch.countDown();
} }
assertTrue(latch.await(10, TimeUnit.SECONDS));
started = true; started = true;
} }
@@ -107,6 +99,10 @@ class TaskbarControllerInputValidationTest {
}); });
assertTrue(latch.await(5, TimeUnit.SECONDS)); assertTrue(latch.await(5, TimeUnit.SECONDS));
CountDownLatch fxLatch = new CountDownLatch(1);
Platform.runLater(fxLatch::countDown);
assertTrue(fxLatch.await(5, TimeUnit.SECONDS));
} }
private GameState createGameState() { private GameState createGameState() {
@@ -133,6 +129,10 @@ class TaskbarControllerInputValidationTest {
root.applyCss(); root.applyCss();
root.layout(); root.layout();
CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(latch::countDown);
assertTrue(latch.await(5, TimeUnit.SECONDS));
TaskbarController controller = loader.getController(); TaskbarController controller = loader.getController();
TextField input = get(controller, "taskbarInput", TextField.class); TextField input = get(controller, "taskbarInput", TextField.class);