Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/org.eclipse.ui.tests.harness/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
}

Expand Down Expand Up @@ -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();
}
}
}
};
Expand All @@ -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();
}
});
}
Expand All @@ -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;
}
Expand Down
Loading