Skip to content

Commit

Permalink
Bug fix : Exceptions thrown by engine in go command were not logged
Browse files Browse the repository at this point in the history
  • Loading branch information
fathzer committed Nov 23, 2024
1 parent d56318a commit 331970e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ boolean doBackground(Task task) {
task.run.run();
this.current.set(null);
} catch (Exception e) {
task.logger.accept(e);
stop();
}
});
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/fathzer/jchess/uci/UCITest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,8 @@ public void clear() {
public List<String> out() {
return output;
}

public Map<String, Throwable> getExceptions() {
return exceptions;
}
}

0 comments on commit 331970e

Please sign in to comment.