Skip to content

Commit bfb48af

Browse files
committed
Fix random failing MMenuItemTest.testElementHierarchyInContext_HandledItem
The test testElementHierarchyInContext_HandledItem was failing randomly because the handler registration is asynchronous and might not be complete when the menu item execution is triggered. This change adds a wait loop that checks for the menu item enablement, which is a reliable indicator that the handler is registered and the command is ready. It also increases the robustness of testElementHierarchyInContext_DirectItem by spinning the event loop multiple times. Fixes #1737
1 parent 9f29191 commit bfb48af

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MMenuItemTest.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,14 @@ public void execute(MUIElement uiElement, MMenuItem menuItem,
764764
inactivePart.getContext().set("key", "inactive");
765765

766766
// Ensure all pending UI events are processed before triggering the menu item
767-
contextRule.spinEventLoop();
767+
for (int i = 0; i < 10; i++) {
768+
contextRule.spinEventLoop();
769+
try {
770+
Thread.sleep(5);
771+
} catch (InterruptedException e) {
772+
// ignore
773+
}
774+
}
768775

769776
assertFalse(executed[0]);
770777

@@ -841,7 +848,17 @@ public void execute(MUIElement uiElement, MMenuItem menuItem,
841848

842849
// Ensure all pending UI events are processed before triggering the menu item
843850
// This prevents race conditions where the handler may not be fully registered yet
844-
contextRule.spinEventLoop();
851+
for (int i = 0; i < 50; i++) {
852+
contextRule.spinEventLoop();
853+
if (((MenuItem) menuItem.getWidget()).getEnabled()) {
854+
break;
855+
}
856+
try {
857+
Thread.sleep(5);
858+
} catch (InterruptedException e) {
859+
// ignore
860+
}
861+
}
845862

846863
assertFalse(executed[0]);
847864
assertEquals(activePart, window.getContext().get(EPartService.class)

0 commit comments

Comments
 (0)