diff --git a/tests/org.eclipse.ui.tests.harness/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests.harness/META-INF/MANIFEST.MF index 259fee3e993..8cdb2f2c5fb 100644 --- a/tests/org.eclipse.ui.tests.harness/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ui.tests.harness/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Harness Plug-in Bundle-SymbolicName: org.eclipse.ui.tests.harness;singleton:=true -Bundle-Version: 1.10.600.qualifier +Bundle-Version: 1.10.700.qualifier Eclipse-BundleShape: dir Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, diff --git a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/RCPTestWorkbenchAdvisor.java b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/RCPTestWorkbenchAdvisor.java index 670ed8276af..5f5f19feeca 100644 --- a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/RCPTestWorkbenchAdvisor.java +++ b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/RCPTestWorkbenchAdvisor.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.ui.tests.harness.util; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWTException; import org.eclipse.swt.widgets.Display; @@ -44,6 +47,10 @@ public class RCPTestWorkbenchAdvisor extends WorkbenchAdvisor { private static boolean started = false; + // CountDownLatch to wait for async/sync operations with DisplayAccess to complete + // We need to wait for 2 operations: asyncWithDisplayAccess and syncWithDisplayAccess + private static CountDownLatch displayAccessLatch = null; + public static boolean isSTARTED() { synchronized (RCPTestWorkbenchAdvisor.class) { return started; @@ -122,12 +129,13 @@ public void eventLoopIdle(final Display display) { public void preStartup() { super.preStartup(); final Display display = Display.getCurrent(); + + // Initialize the latch to wait for 2 operations with DisplayAccess + displayAccessLatch = new CountDownLatch(2); + if (display != null) { display.asyncExec(() -> { - if (isSTARTED()) - asyncDuringStartup = Boolean.FALSE; - else - asyncDuringStartup = Boolean.TRUE; + asyncDuringStartup = !isSTARTED(); }); } @@ -158,17 +166,23 @@ public void run() { DisplayAccess.accessDisplayDuringStartup(); try { display.syncExec(() -> { - synchronized (RCPTestWorkbenchAdvisor.class) { - if (callDisplayAccess) - syncWithDisplayAccess = !isSTARTED() ? Boolean.TRUE : Boolean.FALSE; - else - syncWithoutDisplayAccess = !isSTARTED() ? Boolean.TRUE : Boolean.FALSE; + if (callDisplayAccess) { + syncWithDisplayAccess = !isSTARTED(); + // Count down after the runnable executes + if (displayAccessLatch != null) { + displayAccessLatch.countDown(); + } + } else { + syncWithoutDisplayAccess = !isSTARTED(); } }); } catch (SWTException e) { // this can happen because we shut down the workbench just // as soon as we're initialized - ie: when we're trying to // run this runnable in the deferred case. + if (callDisplayAccess && displayAccessLatch != null) { + displayAccessLatch.countDown(); + } } } }; @@ -183,11 +197,14 @@ public void run() { if (callDisplayAccess) DisplayAccess.accessDisplayDuringStartup(); display.asyncExec(() -> { - synchronized (RCPTestWorkbenchAdvisor.class) { - if (callDisplayAccess) - asyncWithDisplayAccess = !isSTARTED() ? Boolean.TRUE : Boolean.FALSE; - else - asyncWithoutDisplayAccess = !isSTARTED() ? Boolean.TRUE : Boolean.FALSE; + if (callDisplayAccess) { + asyncWithDisplayAccess = !isSTARTED(); + // Count down after the runnable executes + if (displayAccessLatch != null) { + displayAccessLatch.countDown(); + } + } else { + asyncWithoutDisplayAccess = !isSTARTED(); } }); } @@ -199,6 +216,24 @@ public void run() { @Override public void postStartup() { super.postStartup(); + + // Wait for async/sync operations with DisplayAccess to complete execution + if (displayAccessLatch != null) { + try { + // Wait up to 5 seconds for operations with DisplayAccess to complete + // This ensures they execute BEFORE we mark started = true + boolean completed = displayAccessLatch.await(5, TimeUnit.SECONDS); + if (!completed) { + System.err.println("WARNING: Timeout waiting for async/sync operations with DisplayAccess"); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + System.err.println("WARNING: Interrupted while waiting for async/sync operations"); + } + } + + // Now mark as started - operations with DisplayAccess should have completed + // Operations without DisplayAccess should still be pending (deferred) synchronized (RCPTestWorkbenchAdvisor.class) { started = true; }