From 9b61ca5ffbe4d8142d35538159f9f8e747b6eb78 Mon Sep 17 00:00:00 2001 From: Simeon Andreev Date: Mon, 25 May 2026 16:17:54 +0300 Subject: [PATCH] Adjust wait for dialog contents in QuickAccessDialogTest, enable debug outputs Adjusted the wait for initial dialog contents in QuickAccessDialogTest.testPreviousChoicesAvailableForExtension(), to rely on QuickAccessDialog.setInfoText() instead of relying on specific dialog contents set during the test. Additionally debug outputs are added when setting dialog contents, the debug outputs are enabled for QuickAccessDialogTest. See: https://github.com/eclipse-platform/eclipse.platform.ui/issues/4009 --- .../org/eclipse/ui/internal/misc/Policy.java | 6 +++ .../quickaccess/QuickAccessContents.java | 9 ++++ .../ui/tests/harness/util/TestRunLogUtil.java | 49 ++++++++++++------- .../quickaccess/QuickAccessDialogTest.java | 37 +++++++++++--- 4 files changed, 78 insertions(+), 23 deletions(-) diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/Policy.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/Policy.java index 4d67b61e5e8..3ddf55cd25d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/Policy.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/misc/Policy.java @@ -112,6 +112,11 @@ public class Policy { */ public static boolean DEBUG_OPERATIONS = DEFAULT; + /** + * Whether to print debugging information for quick access processing. + */ + public static boolean DEBUG_QUICK_ACCESS = DEFAULT; + /** * Whether to print out verbose information about the operation histories, * including all notifications sent. @@ -178,6 +183,7 @@ public class Policy { DEBUG_HANDLERS_PERFORMANCE = getDebugOption("/trace/handlers.performance"); //$NON-NLS-1$ DEBUG_HANDLERS_VERBOSE = getDebugOption("/trace/handlers.verbose"); //$NON-NLS-1$ DEBUG_OPERATIONS = getDebugOption("/trace/operations"); //$NON-NLS-1$ + DEBUG_QUICK_ACCESS = getDebugOption("/trace/quickaccess"); //$NON-NLS-1$ DEBUG_OPERATIONS_VERBOSE = getDebugOption("/trace/operations.verbose"); //$NON-NLS-1$ DEBUG_SHOW_ALL_JOBS = getDebugOption("/debug/showAllJobs"); //$NON-NLS-1$ DEBUG_STALE_JOBS = getDebugOption("/debug/job.stale"); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java index d6a9e57d7db..8f50c81705d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java @@ -36,6 +36,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.eclipse.core.commands.internal.util.Tracing; import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -81,6 +83,7 @@ import org.eclipse.ui.IWorkbenchPreferenceConstants; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.WorkbenchPlugin; +import org.eclipse.ui.internal.misc.Policy; import org.eclipse.ui.keys.IBindingService; import org.eclipse.ui.progress.UIJob; import org.eclipse.ui.quickaccess.QuickAccessElement; @@ -183,6 +186,12 @@ public void done(IJobChangeEvent event) { computingFeedbackJob.cancel(); if (computeProposalsJob == currentComputeEntriesJob && event.getResult().isOK() && !table.isDisposed()) { + if (Policy.DEBUG_QUICK_ACCESS) { + Tracing.printTrace(QuickAccessContents.class.getName(), + "[" + Thread.currentThread().getName() + "] Setting quick access contents: " + //$NON-NLS-1$ //$NON-NLS-2$ + Stream.of(entries.get()).flatMap(List::stream).map(e -> e.element.getId()) + .toList()); + } display.asyncExec(() -> { computingFeedbackJob.cancel(); refreshTable(perfectMatch, entries.get(), filter); diff --git a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/TestRunLogUtil.java b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/TestRunLogUtil.java index 938c56ffb75..78e14acb8e2 100644 --- a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/TestRunLogUtil.java +++ b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/TestRunLogUtil.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.ui.tests.harness.util; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.rules.TestWatcher; import org.junit.runner.Description; @@ -34,23 +37,7 @@ public final class TestRunLogUtil { * * Note: field must be public or JUnit4 will complain. */ - public static TestWatcher LOG_TESTRUN = new TestWatcher() { - @Override - protected void starting(Description description) { - System.out.println(formatTestStartMessage(description.getMethodName())); - } - - @Override - protected void failed(Throwable e, Description description) { - System.out.println(description.getMethodName() + " failed:"); - e.printStackTrace(System.out); - } - - @Override - protected void finished(Description description) { - System.out.println(formatTestFinishedMessage(description.getMethodName())); - } - }; + public static TestWatcher LOG_TESTRUN = new LogTestWatcher(); /** * Create message used to log start of a test. @@ -72,6 +59,34 @@ public static String formatTestFinishedMessage(String testName) { return testName + ": tearDown...\n"; //$NON-NLS-1$ } + private static class LogTestWatcher extends TestWatcher implements BeforeEachCallback, AfterEachCallback { + @Override + protected void starting(Description description) { + System.out.println(formatTestStartMessage(description.getMethodName())); + } + + @Override + protected void failed(Throwable e, Description description) { + System.out.println(description.getMethodName() + " failed:"); + e.printStackTrace(System.out); + } + + @Override + protected void finished(Description description) { + System.out.println(formatTestFinishedMessage(description.getMethodName())); + } + + @Override + public void beforeEach(ExtensionContext context) throws Exception { + System.out.println(formatTestStartMessage(context.getDisplayName())); + } + + @Override + public void afterEach(ExtensionContext context) throws Exception { + System.out.println(formatTestFinishedMessage(context.getDisplayName())); + } + }; + private TestRunLogUtil() { } } diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java index 3352c6246a3..7146c3c6035 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java @@ -45,14 +45,20 @@ import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.internal.misc.Policy; import org.eclipse.ui.internal.quickaccess.QuickAccessDialog; import org.eclipse.ui.internal.quickaccess.QuickAccessMessages; import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension; import org.eclipse.ui.tests.harness.util.DisplayHelper; +import org.eclipse.ui.tests.harness.util.TestRunLogUtil; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.rules.TestWatcher; /** * Tests the quick access UI @@ -63,6 +69,8 @@ public class QuickAccessDialogTest { private class TestQuickAccessDialog extends QuickAccessDialog { + private volatile String infoText; + public TestQuickAccessDialog(IWorkbenchWindow activeWorkbenchWindow, Command command) { super(activeWorkbenchWindow, command); } @@ -71,6 +79,12 @@ public TestQuickAccessDialog(IWorkbenchWindow activeWorkbenchWindow, Command com protected IDialogSettings getDialogSettings() { return dialogSettings; } + + @Override + protected void setInfoText(String text) { + super.setInfoText(text); + infoText = text; + } } private static final int TIMEOUT = 5000; @@ -81,6 +95,18 @@ protected IDialogSettings getDialogSettings() { private IDialogSettings dialogSettings; private IWorkbenchWindow activeWorkbenchWindow; + @RegisterExtension + public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN; + + @BeforeAll + public static void enableDebugOutputs() { + Policy.DEBUG_QUICK_ACCESS = true; + } + + @AfterAll + public static void disableDebugOutputs() { + Policy.DEBUG_QUICK_ACCESS = false; + } @BeforeEach public void setUp() throws Exception { @@ -294,17 +320,16 @@ private void activateCurrentElement(QuickAccessDialog dialog) { @Test public void testPreviousChoicesAvailableForExtension() { // add one selection to history - QuickAccessDialog dialog = new TestQuickAccessDialog(activeWorkbenchWindow, null); + TestQuickAccessDialog dialog = new TestQuickAccessDialog(activeWorkbenchWindow, null); Text text = dialog.getQuickAccessContents().getFilterText(); - text.setText("initial test"); dialog.open(); /* - * wait for the initial dialog contents, to avoid race conditions later on in the test, see: + * wait for the dialog initialization, to avoid race conditions later on in the test, see: * https://github.com/eclipse-platform/eclipse.platform.ui/issues/4009 */ - assertTrue(DisplayHelper.waitForCondition(text.getDisplay(), TIMEOUT, - () -> dialogContains(dialog, "initial test")), - "Unexpected dialog contents: " + getAllEntries(dialog.getQuickAccessContents().getTable())); + assertTrue(DisplayHelper.waitForCondition(text.getDisplay(), TIMEOUT * 1000, + () -> dialog.infoText != null), + "Unexpected dialog info: " + dialog.infoText); text.setText(TestQuickAccessComputer.TEST_QUICK_ACCESS_PROPOSAL_LABEL); final Table firstTable = dialog.getQuickAccessContents().getTable(); assertTrue(DisplayHelper.waitForCondition(text.getDisplay(), TIMEOUT,