Skip to content

Commit a7ad5ae

Browse files
vogellaclaude
andcommitted
Fix race condition in MMenuItemTest by adding event loop processing
Fixes #1737 The test testElementHierarchyInContext_HandledItem was experiencing intermittent failures due to a race condition. After creating handler processing addons and activating parts, the handler registration may not have completed before the test triggered the menu item selection. This commit adds calls to contextRule.spinEventLoop() in both testElementHierarchyInContext_DirectItem and testElementHierarchyInContext_HandledItem to ensure all pending UI events are processed before triggering menu item selection. This is a standard pattern for preventing race conditions in Eclipse UI tests. The spinEventLoop() method processes all pending events in the Display event queue, ensuring that handler registration and context updates have completed before the test proceeds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 126085a commit a7ad5ae

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,9 @@ public void execute(MUIElement uiElement, MMenuItem menuItem,
763763
activePart.getContext().set("key", "active");
764764
inactivePart.getContext().set("key", "inactive");
765765

766+
// Ensure all pending UI events are processed before triggering the menu item
767+
contextRule.spinEventLoop();
768+
766769
assertFalse(executed[0]);
767770

768771
Object widget1 = menuItem.getWidget();
@@ -836,6 +839,10 @@ public void execute(MUIElement uiElement, MMenuItem menuItem,
836839
activePart.getContext().set("key", "active");
837840
inactivePart.getContext().set("key", "inactive");
838841

842+
// Ensure all pending UI events are processed before triggering the menu item
843+
// This prevents race conditions where the handler may not be fully registered yet
844+
contextRule.spinEventLoop();
845+
839846
assertFalse(executed[0]);
840847
assertEquals(activePart, window.getContext().get(EPartService.class)
841848
.getActivePart());

0 commit comments

Comments
 (0)