From 4e3f387cec74ad92c2753330915a85034a1740af Mon Sep 17 00:00:00 2001 From: Davy Landman Date: Wed, 22 Apr 2026 17:41:00 +0200 Subject: [PATCH 1/2] Properly cancel the rpc futures as to stop the client&server in the tests --- .../test/rpc/IValueOverJsonTests.java | 69 ++++++++++++++----- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/test/org/rascalmpl/test/rpc/IValueOverJsonTests.java b/test/org/rascalmpl/test/rpc/IValueOverJsonTests.java index 417dadbe87d..162c81e67b8 100644 --- a/test/org/rascalmpl/test/rpc/IValueOverJsonTests.java +++ b/test/org/rascalmpl/test/rpc/IValueOverJsonTests.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -15,12 +16,14 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import org.checkerframework.checker.nullness.qual.Nullable; import org.eclipse.lsp4j.jsonrpc.Launcher; import org.eclipse.lsp4j.jsonrpc.messages.ResponseError; import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode; @@ -74,6 +77,8 @@ public class IValueOverJsonTests { private final PipedInputStream is0, is1; private final PipedOutputStream os0, os1; private final ExecutorService exec = Executors.newCachedThreadPool(); + private final TestThread server; + private final TestClient client; @Parameters(name="{0}") public static Iterable modesAndConfig() { @@ -94,31 +99,43 @@ public IValueOverJsonTests(ComplexTypeMode complexTypeMode, Consumer { + try { + close(is0); + close(is1); + close(os0); + close(os1); + exec.shutdown(); + } + catch (IOException ignored) { + System.err.println("Closing the streams failed with: " + ignored.getMessage()); + ignored.printStackTrace(); + + } + }); } - class TestClient { + class TestClient implements Closeable { + private final Future connection; public TestClient(InputStream is, OutputStream os, Consumer gsonConfig) { Launcher clientLauncher = new Launcher.Builder() .setLocalService(this) @@ -133,16 +150,23 @@ public TestClient(InputStream is, OutputStream os, Consumer gsonCon .setExecutorService(exec) .create(); - clientLauncher.startListening(); + connection = clientLauncher.startListening(); testServer = clientLauncher.getRemoteProxy(); } + @Override + public void close() throws IOException { + if (connection != null) { + connection.cancel(true); + } + } } - static class TestThread extends Thread { + static class TestThread extends Thread implements Closeable { private final InputStream is; private final OutputStream os; private final Consumer gsonConfig; private final ExecutorService exec; + private volatile Future socket; public TestThread(InputStream is, OutputStream os, Consumer gsonConfig, ExecutorService exec) { this.is = is; @@ -167,7 +191,14 @@ public void run() { .setExecutorService(exec) .create(); - serverLauncher.startListening(); + socket = serverLauncher.startListening(); + } + + @Override + public void close() throws IOException { + if (socket != null) { + socket.cancel(true); + } } } From a7bad44fb40c66b3a07e7f1aeb56e980a9436f77 Mon Sep 17 00:00:00 2001 From: Davy Landman Date: Thu, 23 Apr 2026 13:10:40 +0200 Subject: [PATCH 2/2] Fixed spacing & comment --- test/org/rascalmpl/test/rpc/IValueOverJsonTests.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/org/rascalmpl/test/rpc/IValueOverJsonTests.java b/test/org/rascalmpl/test/rpc/IValueOverJsonTests.java index 162c81e67b8..0bcf0df7d90 100644 --- a/test/org/rascalmpl/test/rpc/IValueOverJsonTests.java +++ b/test/org/rascalmpl/test/rpc/IValueOverJsonTests.java @@ -117,7 +117,7 @@ static void close(@Nullable Closeable cl) throws IOException { public void teardown() throws IOException { close(client); close(server); - // give the json rpc server a bit of time to actually close everything before we jank away the streams + // give the JSON-RPC server a bit of time to actually close everything before we jank away the streams CompletableFuture.delayedExecutor(100, TimeUnit.MILLISECONDS).execute(() -> { try { close(is0); @@ -129,7 +129,6 @@ public void teardown() throws IOException { catch (IOException ignored) { System.err.println("Closing the streams failed with: " + ignored.getMessage()); ignored.printStackTrace(); - } }); }