diff --git a/pom.xml b/pom.xml index 4ccf9ca..d3ea2e2 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,13 @@ org.junit.jupiter junit-jupiter - 5.10.2 + 5.11.3 + test + + + org.awaitility + awaitility + 4.2.2 test diff --git a/src/main/java/com/fathzer/jchess/uci/BackgroundTaskManager.java b/src/main/java/com/fathzer/jchess/uci/BackgroundTaskManager.java index 3fc2f45..c0d524c 100644 --- a/src/main/java/com/fathzer/jchess/uci/BackgroundTaskManager.java +++ b/src/main/java/com/fathzer/jchess/uci/BackgroundTaskManager.java @@ -30,6 +30,7 @@ boolean doBackground(Task task) { task.run.run(); this.current.set(null); } catch (Exception e) { + task.logger.accept(e); stop(); } }); diff --git a/src/test/java/com/fathzer/jchess/uci/UCITest.java b/src/test/java/com/fathzer/jchess/uci/UCITest.java index 9720a70..a90cd13 100644 --- a/src/test/java/com/fathzer/jchess/uci/UCITest.java +++ b/src/test/java/com/fathzer/jchess/uci/UCITest.java @@ -1,8 +1,11 @@ package com.fathzer.jchess.uci; + import static org.junit.jupiter.api.Assertions.*; +import static org.awaitility.Awaitility.*; import java.util.Arrays; import java.util.Collection; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.BeforeAll; @@ -127,4 +130,22 @@ void testPositionAndNewGame() { //TODO Test move related things } + + @Test + void bug20241123() { + // Exceptions thrown by engine during the go command were not reported by the logger + uci.post("ucinewgame", 10); + assertFalse(uci.isPositionSet()); + engine.setPositionConsumer(s -> {}); + assertTrue(uci.post("position fen toto", 10)); + + engine.setGoFunction(s -> new LongRunningTask<>() { + @Override + public GoReply get() { + throw new UnsupportedOperationException("I'm a buggy engine"); + } + }); + uci.post("go", 10); + await().atMost(200, TimeUnit.MILLISECONDS).until(() -> uci.getExceptions().getOrDefault("go", new IllegalArgumentException()).getClass()==UnsupportedOperationException.class); + } } diff --git a/src/test/java/com/fathzer/jchess/uci/util/InstrumentedUCI.java b/src/test/java/com/fathzer/jchess/uci/util/InstrumentedUCI.java index 2c52bcd..329c110 100644 --- a/src/test/java/com/fathzer/jchess/uci/util/InstrumentedUCI.java +++ b/src/test/java/com/fathzer/jchess/uci/util/InstrumentedUCI.java @@ -102,4 +102,8 @@ public void clear() { public List out() { return output; } + + public Map getExceptions() { + return exceptions; + } } \ No newline at end of file