Skip to content

Commit ef09467

Browse files
vogellaclaude
andcommitted
Fix flaky DecoratorAdaptableTests by waiting for decorator jobs
The previous fix in commit 9c171a0 added UITestUtil.processEvents() to wait for decorator enablement, but this only processes the event queue and doesn't wait for asynchronous jobs to complete. The DecoratorManager.setEnabled() method triggers updateForEnablementChange() which uses fireListenersInUIThread() to schedule WorkbenchJob instances. These jobs may not complete before tests check decoration results, causing intermittent failures. This fix introduces waitForDecoratorJobs() which uses Job.getJobManager().join() to wait for all FAMILY_DECORATE jobs to complete before proceeding with tests. Fixes: #868 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 337f3ad commit ef09467

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/decorators/DecoratorAdaptableTests.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.core.resources.IWorkspace;
2121
import org.eclipse.core.resources.ResourcesPlugin;
2222
import org.eclipse.core.runtime.CoreException;
23+
import org.eclipse.core.runtime.jobs.Job;
2324
import org.eclipse.ui.PlatformUI;
2425
import org.eclipse.ui.internal.WorkbenchPlugin;
2526
import org.eclipse.ui.internal.decorators.DecorationResult;
@@ -44,6 +45,21 @@ private String getDecorationTextFor(Object object) {
4445
return result.decorateWithText("Default label");
4546
}
4647

48+
/**
49+
* Waits for all decorator-related jobs to complete.
50+
* This ensures that decorator enablement changes have been fully processed
51+
* before tests check decoration results.
52+
*/
53+
private void waitForDecoratorJobs() {
54+
try {
55+
Job.getJobManager().join(DecoratorManager.FAMILY_DECORATE, null);
56+
} catch (InterruptedException e) {
57+
Thread.currentThread().interrupt();
58+
}
59+
// Also process any pending UI events
60+
UITestUtil.processEvents();
61+
}
62+
4763
private void assertDecorated(String testSubName, String[] expectedSuffixes, Object[] elements,
4864
boolean shouldHaveMatches) {
4965
for (Object object : elements) {
@@ -65,9 +81,9 @@ public void doSetUp() throws Exception {
6581
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestResourceDecoratorContributor.ID, true);
6682
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestResourceMappingDecoratorContributor.ID, true);
6783

68-
// Process all pending UI events to ensure decorator enablement has completed
69-
// This prevents race conditions where decorators may not be fully registered yet
70-
UITestUtil.processEvents();
84+
// Wait for all decorator jobs to complete after enabling decorators
85+
// This prevents race conditions where decorators may not be fully initialized yet
86+
waitForDecoratorJobs();
7187
}
7288

7389
@After
@@ -77,8 +93,8 @@ public void doTearDown() throws Exception {
7793
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestResourceDecoratorContributor.ID, false);
7894
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestResourceMappingDecoratorContributor.ID, false);
7995

80-
// Process all pending UI events to ensure clean state for next test
81-
UITestUtil.processEvents();
96+
// Wait for all decorator jobs to complete to ensure clean state for next test
97+
waitForDecoratorJobs();
8298
}
8399

84100
/**

0 commit comments

Comments
 (0)