Skip to content

Commit 47bc499

Browse files
committed
Stabilize QuickAccessDialogTest UI-responsiveness check
testLongRunningComputerDoesntFreezeUI measured UI blocking via the DisplayHelper.waitForCondition tick, whose loop parks in Display.sleep() when idle. While the second dialog restored a previous pick on the worker thread the UI thread was idle, not frozen, but the idle interval was counted as a block and intermittently exceeded the 3s threshold on macOS. Probe responsiveness with a self-rescheduling Display.timerExec instead: the timer keeps firing while the UI thread can dispatch events, so idle waiting registers as short gaps while a genuine freeze still produces a large one.
1 parent 55ec079 commit 47bc499

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,32 @@ public void testLongRunningComputerDoesntFreezeUI() {
216216
QuickAccessDialog secondDialog = new TestQuickAccessDialog(activeWorkbenchWindow, null);
217217
secondDialog.open();
218218
assertTrue(System.currentTimeMillis() - duration < TestLongRunningQuickAccessComputer.DELAY);
219-
AtomicLong tick = new AtomicLong(System.currentTimeMillis());
219+
// Probe UI responsiveness with a self-rescheduling timer: it keeps firing
220+
// while the UI thread can dispatch, so only a real freeze yields a large gap.
221+
// The waitForCondition tick cannot tell a freeze from an idle Display.sleep().
222+
Display display = secondDialog.getShell().getDisplay();
223+
AtomicLong lastTick = new AtomicLong(System.currentTimeMillis());
220224
AtomicLong maxBlockedUIThread = new AtomicLong();
221-
assertTrue(DisplayHelper.waitForCondition(
222-
secondDialog.getShell().getDisplay(), TestLongRunningQuickAccessComputer.DELAY + TIMEOUT, () -> {
223-
long currentTick = System.currentTimeMillis();
224-
long previousTick = tick.getAndSet(currentTick);
225-
long currentDelayInUIThread = currentTick - previousTick;
226-
maxBlockedUIThread.set(Math.max(maxBlockedUIThread.get(), currentDelayInUIThread));
227-
return dialogContains(secondDialog,
228-
TestLongRunningQuickAccessComputer.THE_ELEMENT.getLabel());
229-
}), "Missing contributed element as previous pick");
230-
assertTrue(maxBlockedUIThread.get() < TestLongRunningQuickAccessComputer.DELAY);
225+
boolean[] monitoring = { true };
226+
Runnable[] responsivenessProbe = new Runnable[1];
227+
responsivenessProbe[0] = () -> {
228+
long now = System.currentTimeMillis();
229+
maxBlockedUIThread.set(Math.max(maxBlockedUIThread.get(), now - lastTick.getAndSet(now)));
230+
if (monitoring[0]) {
231+
display.timerExec(50, responsivenessProbe[0]);
232+
}
233+
};
234+
display.timerExec(50, responsivenessProbe[0]);
235+
try {
236+
assertTrue(DisplayHelper.waitForCondition(display, TestLongRunningQuickAccessComputer.DELAY + TIMEOUT,
237+
() -> dialogContains(secondDialog, TestLongRunningQuickAccessComputer.THE_ELEMENT.getLabel())),
238+
"Missing contributed element as previous pick");
239+
} finally {
240+
monitoring[0] = false;
241+
display.timerExec(-1, responsivenessProbe[0]);
242+
}
243+
assertTrue(maxBlockedUIThread.get() < TestLongRunningQuickAccessComputer.DELAY,
244+
"UI thread blocked for " + maxBlockedUIThread.get() + "ms while restoring a previous pick");
231245
}
232246

233247
/**

0 commit comments

Comments
 (0)