From 9740f8eddd9fbc3cb1605ff144a7bd8ca897e1eb Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Tue, 30 Sep 2025 12:57:36 -0400 Subject: [PATCH] Explicitly terminate the Clipboard remote application The old code was unintentionally relying on destroyForcibly alone to terminate the remote process. This had a race condition that when the temp directory needed to be deleted at the end of the test the process may not have completed being terminated. Therefore explicitly destroy/terminate the remote, and add some asserts so that we have explicit test failure if the remote is not finished terminating before `stopRemoteClipboardCommands` returns. Fixes https://github.com/eclipse-platform/eclipse.platform.swt/issues/2568 --- .../junit/Test_org_eclipse_swt_dnd_Clipboard.java | 4 +++- .../data/clipboard/ClipboardCommandsImpl.java | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_dnd_Clipboard.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_dnd_Clipboard.java index e6299b355a..c15eaa7a4f 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_dnd_Clipboard.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_dnd_Clipboard.java @@ -221,9 +221,11 @@ private void stopRemoteClipboardCommands() throws Exception { } finally { if (remoteClipboardProcess != null) { try { - remoteClipboardProcess.waitFor(1, TimeUnit.SECONDS); + remoteClipboardProcess.destroy(); + assertTrue(remoteClipboardProcess.waitFor(10, TimeUnit.SECONDS)); } finally { remoteClipboardProcess.destroyForcibly(); + assertTrue(remoteClipboardProcess.waitFor(10, TimeUnit.SECONDS)); remoteClipboardProcess = null; } } diff --git a/tests/org.eclipse.swt.tests/data/clipboard/ClipboardCommandsImpl.java b/tests/org.eclipse.swt.tests/data/clipboard/ClipboardCommandsImpl.java index 3ada14d862..28123f10fa 100644 --- a/tests/org.eclipse.swt.tests/data/clipboard/ClipboardCommandsImpl.java +++ b/tests/org.eclipse.swt.tests/data/clipboard/ClipboardCommandsImpl.java @@ -43,6 +43,18 @@ public void stop() throws RemoteException { clipboardTest.log("stop()"); clipboardTest.dispose(); }); + // Force the test program to quit, but after a short delay so that + // the return value of stop can make it back to the caller and + // the JUnit test may destroy the process before this sleep + // expires anyway + SwingUtilities.invokeLater(() -> { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + Thread.interrupted(); + } + System.exit(0); + }); } @Override