Skip to content

Commit 9dee7b7

Browse files
vogellaclaude
authored andcommitted
Fix race condition in NestedResourcesTests.testProjectHierarchy
This commit fixes the intermittent test failure reported in GitHub issue #196 where testProjectHierarchy randomly fails with "expected:<2> but was:<1>" at line 96. Root cause: The NestedProjectManager uses an asynchronous IResourceChangeListener that responds to POST_CHANGE events to update its internal project hierarchy map (locationsToProjects). When projects are created and opened in rapid succession, the test may query getDirectChildrenProjects() before the manager has finished processing all resource change events, leading to incomplete results. The specific failure occurred at the assertion checking that projectAB has 2 children (projectABA and projectABB). The test would sometimes only see 1 child because the second project's creation event hadn't been processed yet. Solution: Added DisplayHelper.waitForCondition() calls at three critical synchronization points to wait for NestedProjectManager to process all resource changes before making assertions: 1. Wait for projectA to show 1 child (projectAB) 2. Wait for folderAA to show 1 child (projectAAA) 3. Wait for projectAB to show 2 children (projectABA and projectABB) This approach follows the same pattern already used successfully in the testProblemDecoration() method in the same test file, which also waits for asynchronous marker updates to propagate. The 2-second timeout (TIMEOUT constant) provides sufficient time for event processing while still failing quickly if assertions are genuinely incorrect. Since the waitForCondition() calls already verify the array lengths, the redundant Assert.assertEquals calls for array lengths have been removed per code review feedback. Fixes: #196 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f86e59e commit 9dee7b7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/resources/NestedResourcesTests.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,29 @@ public void testProjectHierarchy() throws Exception {
8181
testProjects.add(projectABA);
8282
testProjects.add(projectABB);
8383

84+
// Wait for NestedProjectManager to process all resource changes
85+
assertTrue("NestedProjectManager did not update children for projectA",
86+
DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT,
87+
() -> NestedProjectManager.getInstance().getDirectChildrenProjects(projectA).length == 1));
88+
8489
IProject[] childrenOfProjectA = NestedProjectManager.getInstance().getDirectChildrenProjects(projectA);
85-
Assert.assertEquals(1, childrenOfProjectA.length);
8690
Assert.assertEquals(projectAB, childrenOfProjectA[0]);
8791
Assert.assertNull(NestedProjectManager.getInstance().getMostDirectOpenContainer(projectA));
8892

93+
// Wait for NestedProjectManager to process projectAAA
94+
assertTrue("NestedProjectManager did not update children for folderAA",
95+
DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT,
96+
() -> NestedProjectManager.getInstance().getDirectChildrenProjects(folderAA).length == 1));
97+
8998
IProject[] childrenOfFolderAA = NestedProjectManager.getInstance().getDirectChildrenProjects(folderAA);
90-
Assert.assertEquals(1, childrenOfFolderAA.length);
9199
Assert.assertEquals("aaa", childrenOfFolderAA[0].getName());
92100
Assert.assertEquals(folderAA,
93101
NestedProjectManager.getInstance().getMostDirectOpenContainer(childrenOfFolderAA[0]));
94102

95-
IProject[] childrenOfProjectAB = NestedProjectManager.getInstance().getDirectChildrenProjects(projectAB);
96-
Assert.assertEquals(2, childrenOfProjectAB.length);
103+
// Wait for NestedProjectManager to process both projectABA and projectABB
104+
assertTrue("NestedProjectManager did not update children for projectAB",
105+
DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT,
106+
() -> NestedProjectManager.getInstance().getDirectChildrenProjects(projectAB).length == 2));
97107
}
98108

99109
@Test

0 commit comments

Comments
 (0)