From a97b1daf368e4ac308e92a89984636cca146c99b Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Tue, 16 Jul 2024 12:12:50 +0200 Subject: [PATCH 1/2] Improve and add assertions for random failing HoverTest #926 #1808 This contributes to fixing the randomly failing HoverTests: - Removes unnecessary focus enforcing: The code checks for the text editor having focus and afterwards uses different methods to force focus to the widget's shell again. This is unnecessary and is only prone to introduce further problems. - Introduces further assertions: in order to better locate the cause of the failing tests, assertions are added for the conditions, on which the execution waits, to be actually fulfilled. - Adds a retry functionality for simulating the hover event. Contributes to https://github.com/eclipse-platform/eclipse.platform.ui/issues/926 Contributes to https://github.com/eclipse-platform/eclipse.platform.ui/issues/1808 --- .../ui/genericeditor/tests/HoverTest.java | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java b/tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java index 2c77c6097cc..e225db29124 100644 --- a/tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java +++ b/tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java @@ -65,6 +65,8 @@ */ public class HoverTest extends AbstratGenericEditorTest { + private static final int MAXIMUM_HOVER_RETRY_COUNT = 5; + @Rule public TestName testName= new TestName(); @@ -227,38 +229,43 @@ private Object getHoverData(AbstractInformationControlManager manager) { } private AbstractInformationControlManager triggerCompletionAndRetrieveInformationControlManager() { - final int caretLocation= 2; - this.editor.selectAndReveal(caretLocation, 0); - final StyledText editorTextWidget= (StyledText) this.editor.getAdapter(Control.class); - new DisplayHelper() { - @Override - protected boolean condition() { - return editorTextWidget.isFocusControl() && editorTextWidget.getSelection().x == caretLocation; - } - }.waitForCondition(editorTextWidget.getDisplay(), 3000); - // sending event to trigger hover computation - editorTextWidget.getShell().forceActive(); - editorTextWidget.getShell().setActive(); - editorTextWidget.getShell().setFocus(); - editorTextWidget.getShell().getDisplay().wake(); - Event hoverEvent= new Event(); - hoverEvent.widget= editorTextWidget; - hoverEvent.type= SWT.MouseHover; - hoverEvent.x= editorTextWidget.getClientArea().x + 5; - hoverEvent.y= editorTextWidget.getClientArea().y + 5; - hoverEvent.display= editorTextWidget.getDisplay(); - hoverEvent.doit= true; - editorTextWidget.getDisplay().setCursorLocation(editorTextWidget.toDisplay(hoverEvent.x, hoverEvent.y)); - editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent); + boolean foundHoverData = false; + int attemptNumber = 0; + ITextViewer viewer= (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]); AbstractInformationControlManager textHoverManager= (AbstractInformationControlManager) new Accessor(viewer, TextViewer.class).get("fTextHoverManager"); - // retrieving hover content - new DisplayHelper() { - @Override - protected boolean condition() { - return getHoverData(textHoverManager) != null; - } - }.waitForCondition(hoverEvent.display, 6000); + + while (!foundHoverData && attemptNumber++ < MAXIMUM_HOVER_RETRY_COUNT) { + final int caretLocation= 2; + editor.setFocus(); + this.editor.selectAndReveal(caretLocation, 0); + final StyledText editorTextWidget= (StyledText) this.editor.getAdapter(Control.class); + new DisplayHelper() { + @Override + protected boolean condition() { + return editorTextWidget.isFocusControl() && editorTextWidget.getSelection().x == caretLocation; + } + }.waitForCondition(editorTextWidget.getDisplay(), 3000); + assertTrue("editor does not have focus", editorTextWidget.isFocusControl()); + // sending event to trigger hover computation + Event hoverEvent= new Event(); + hoverEvent.widget= editorTextWidget; + hoverEvent.type= SWT.MouseHover; + hoverEvent.x= editorTextWidget.getClientArea().x + 5; + hoverEvent.y= editorTextWidget.getClientArea().y + 5; + hoverEvent.display= editorTextWidget.getDisplay(); + hoverEvent.doit= true; + editorTextWidget.getDisplay().setCursorLocation(editorTextWidget.toDisplay(hoverEvent.x, hoverEvent.y)); + editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent); + // retrieving hover content + foundHoverData = new DisplayHelper() { + @Override + protected boolean condition() { + return getHoverData(textHoverManager) != null; + } + }.waitForCondition(hoverEvent.display, 6000); + } + assertTrue("hover data not found", foundHoverData); return textHoverManager; } } From ba6a578bd958df1aabf59158e716f9e761f75298 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Tue, 16 Jul 2024 12:45:05 +0200 Subject: [PATCH 2/2] Bump version of org.eclipse.ui.genericeditor.tests for 4.34 stream --- tests/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF index f95c0ce33f8..a3dd34a3a53 100644 --- a/tests/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Plugin.name Bundle-SymbolicName: org.eclipse.ui.genericeditor.tests;singleton:=true -Bundle-Version: 1.3.500.qualifier +Bundle-Version: 1.3.600.qualifier Bundle-Vendor: %Plugin.providerName Bundle-Localization: plugin Export-Package: org.eclipse.ui.genericeditor.tests,