From ddda382194e894c5f69c47788634385832bfc675 Mon Sep 17 00:00:00 2001 From: Simeon Andreev Date: Sun, 17 May 2026 11:34:31 +0300 Subject: [PATCH] Wait for process to terminate in InstanceMainMethodsTests Currently tests in InstanceMainMethodsTests don't wait for process termination, but check the process exit value. This can result in fails. Fixes: https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/953 --- .../launching/InstanceMainMethodsTests.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/launching/InstanceMainMethodsTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/launching/InstanceMainMethodsTests.java index e66878564c..8d2acdafea 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/launching/InstanceMainMethodsTests.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/launching/InstanceMainMethodsTests.java @@ -17,6 +17,8 @@ import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.debug.core.IJavaDebugTarget; import org.eclipse.jdt.debug.tests.AbstractDebugTest; +import org.eclipse.jdt.debug.tests.TestUtil; +import org.eclipse.swt.widgets.Display; public class InstanceMainMethodsTests extends AbstractDebugTest { @@ -41,8 +43,7 @@ public void testStaticMainWithoutArgs() throws Exception { terminateAndRemove(target); } } - assertNotNull("Missing VM process.", process); - assertEquals("Process finished with error code", 0, process.getExitValue()); + waitForExit(process, 10_000L); } public void testDefaultMainWithoutArgs() throws Exception { @@ -57,7 +58,18 @@ public void testDefaultMainWithoutArgs() throws Exception { terminateAndRemove(target); } } + waitForExit(process, 10_000L); + } + + private static void waitForExit(IProcess process, long timeoutMs) throws Exception { assertNotNull("Missing VM process.", process); + long start = System.currentTimeMillis(); + while (!process.isTerminated() && System.currentTimeMillis() - start < timeoutMs) { + if (Display.getCurrent() != null) { + TestUtil.runEventLoop(); + } + Thread.sleep(50L); + } assertEquals("Process finished with error code", 0, process.getExitValue()); }