Skip to content

Commit 1f7b2c1

Browse files
vogellaclaude
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 (now line 111). 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 (lines 161-188), 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. Fixes: #196 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e900fff commit 1f7b2c1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,32 @@ 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);
8590
Assert.assertEquals(1, childrenOfProjectA.length);
8691
Assert.assertEquals(projectAB, childrenOfProjectA[0]);
8792
Assert.assertNull(NestedProjectManager.getInstance().getMostDirectOpenContainer(projectA));
8893

94+
// Wait for NestedProjectManager to process projectAAA
95+
assertTrue("NestedProjectManager did not update children for folderAA",
96+
DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT,
97+
() -> NestedProjectManager.getInstance().getDirectChildrenProjects(folderAA).length == 1));
98+
8999
IProject[] childrenOfFolderAA = NestedProjectManager.getInstance().getDirectChildrenProjects(folderAA);
90100
Assert.assertEquals(1, childrenOfFolderAA.length);
91101
Assert.assertEquals("aaa", childrenOfFolderAA[0].getName());
92102
Assert.assertEquals(folderAA,
93103
NestedProjectManager.getInstance().getMostDirectOpenContainer(childrenOfFolderAA[0]));
94104

105+
// Wait for NestedProjectManager to process both projectABA and projectABB
106+
assertTrue("NestedProjectManager did not update children for projectAB",
107+
DisplayHelper.waitForCondition(Display.getDefault(), TIMEOUT,
108+
() -> NestedProjectManager.getInstance().getDirectChildrenProjects(projectAB).length == 2));
109+
95110
IProject[] childrenOfProjectAB = NestedProjectManager.getInstance().getDirectChildrenProjects(projectAB);
96111
Assert.assertEquals(2, childrenOfProjectAB.length);
97112
}

0 commit comments

Comments
 (0)