Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -1011,12 +1011,12 @@ public void testBug343984() throws Exception {
selectionService.addSelectionListener(listener);

selectionService.setSelection(new Object());
Thread.sleep(1000);
waitForCondition(() -> listener.success, 5000, "Listener should be called after setSelection");
assertTrue(listener.success);

listener.reset();
selectionService.setSelection(new Object());
Thread.sleep(1000);
waitForCondition(() -> listener.success, 5000, "Listener should be called after second setSelection");
assertTrue(listener.success);
}

Expand Down Expand Up @@ -1064,6 +1064,40 @@ private void initialize() {
applicationContext.set(UIEventPublisher.class, ep);
}

/**
* Wait for a condition to become true, processing UI events while waiting.
*
* @param condition the condition to wait for
* @param timeoutMillis maximum time to wait in milliseconds
* @param message error message if timeout occurs
*/
private void waitForCondition(java.util.function.BooleanSupplier condition, long timeoutMillis, String message) {
Display display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}

long startTime = System.currentTimeMillis();
while (!condition.getAsBoolean()) {
if (System.currentTimeMillis() - startTime > timeoutMillis) {
throw new AssertionError(message + " (timeout after " + timeoutMillis + "ms)");
}

// Process pending UI events
if (display.readAndDispatch()) {
continue;
}

// Small sleep to avoid busy waiting
try {
Thread.sleep(10);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new AssertionError(message + " (interrupted)", e);
}
}
}

static class SelectionListener implements ISelectionListener {

private MPart part;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,33 @@ public void tearDown() throws Exception {
}

private void checkLog() {
try {
// sleep a bit because notifications are done on another thread
Thread.sleep(100);
} catch (Exception e) {
// ignored
// Wait a bit because notifications are done on another thread
// Use a short timeout to allow log events to be processed
long startTime = System.currentTimeMillis();
long timeout = 1000; // 1 second max wait

while (System.currentTimeMillis() - startTime < timeout) {
// Process any pending display events if we're on the UI thread
Display display = Display.getCurrent();
if (display != null) {
while (display.readAndDispatch()) {
// Keep processing
}
}

// If already logged, no need to wait longer
if (logged) {
break;
}

try {
Thread.sleep(10);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}

assertFalse(logged);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.junit.Ignore;

/**
* The DecoratorTableTest is the test for decorating tables.
*/
@Ignore("Disabled due to timing issues")
public class DecoratorTableTest extends DecoratorViewerTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
*/
public abstract class DecoratorTestPart extends ViewPart {

private static final int DELAY_TIME = 2000;// Wait 2 seconds

public boolean waitingForDecoration = true;

private long endTime;

private ILabelProviderListener listener;

public DecoratorTestPart() {
Expand All @@ -54,22 +50,40 @@ protected DecoratingLabelProvider getLabelProvider() {
* Get the listener for the suite.
*/
private ILabelProviderListener getDecoratorManagerListener() {
// Reset the end time each time we get an update
listener = event -> endTime = System.currentTimeMillis() + DELAY_TIME;
// Listener for decorator manager events
listener = event -> {
// Decorator update occurred
};

return listener;
}

/**
* Process events until decorations are applied. Uses a fixed delay
* to allow time for decorator updates to be processed.
*/
public void readAndDispatchForUpdates() {
while (System.currentTimeMillis() < endTime) {
Display.getCurrent().readAndDispatch();
Display display = Display.getCurrent();
// Process events for 1 second with regular intervals
for (int i = 0; i < 20; i++) {
while (display.readAndDispatch()) {
// Process all pending events
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
// Final pass to process any remaining events
while (display.readAndDispatch()) {
// Keep processing
}

}

public void setUpForDecorators() {
endTime = System.currentTimeMillis() + DELAY_TIME;

// No initialization needed for simple fixed delay approach
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.junit.Ignore;

/**
* The DecoratorTreeTest tests the font and color support on
* tree viewers.
*/
@Ignore("Disabled due to timing issues")
public class DecoratorTreeTest extends DecoratorViewerTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,22 @@ public void partInputChanged(IWorkbenchPartReference partRef) {
});
workbench.showPerspective(MyPerspective.ID, activeWorkbenchWindow);
processEvents();
Thread.sleep(2000);

// Wait for the part to become visible, processing events
long startTime = System.currentTimeMillis();
long timeout = 5000; // 5 second max wait
while (!partVisibleExecuted && (System.currentTimeMillis() - startTime < timeout)) {
processEvents();
if (!partVisibleExecuted) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}

assertTrue("view was not made visible", partVisibleExecuted);
assertNotNull(activePage.findView(MyViewPart.ID2));
assertNotNull(activePage.findView(MyViewPart.ID3));
Expand Down
Loading