Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 2, 2025

Problem

Tests in ResourceInitialSelectionTest were failing intermittently on macOS and other platforms during CI builds with assertions like:

  • "One file should be selected by default"
  • "Two files should be selected by default"
  • "The first file should be selected by default"

These failures were reported in issue #1108 and occurred across multiple test runs over several years.

Root Cause

The test pattern was:

dialog.open();
dialog.refresh();
List<Object> selected = getSelectedItems(dialog);
// Assert on selected items

However, dialog.refresh() schedules a chain of asynchronous background jobs that populate the table:

  1. FilterHistoryJob - filters history items
  2. FilterJob - filters workspace resources
  3. RefreshCacheJob - schedules the UI refresh
  4. RefreshJob (UIJob) - updates the table widget

The test was immediately checking the selection before these jobs completed, creating a race condition that manifested intermittently depending on system load and job scheduling timing.

Solution

Added DisplayHelper.waitForCondition() calls to all 13 test methods to wait up to 3 seconds for the expected state before proceeding with assertions:

// For tests expecting specific selections
Display display = PlatformUI.getWorkbench().getDisplay();
DisplayHelper.waitForCondition(display, 3000,
    () -> expectedSelection.equals(getSelectedItems(dialog)));
// For tests expecting empty selections (wait for table to be populated first)
DisplayHelper.waitForCondition(display, 3000, () -> {
    Table table = (Table) ((Composite) ((Composite) ((Composite) dialog.getShell().getChildren()[0])
            .getChildren()[0]).getChildren()[0]).getChildren()[3];
    return table.getItemCount() > 0;
});

This pattern is already successfully used in ResourceSelectionFilteringDialogTest and eliminates the race condition without requiring any changes to production code.

Benefits

  • ✅ Eliminates race condition between test execution and background jobs
  • ✅ Makes tests deterministic and stable across all platforms
  • ✅ No production code changes required
  • ✅ Consistent with existing test patterns in the codebase
  • ✅ Tests complete quickly when jobs finish fast (no fixed delays)
  • ✅ Low risk - test-only changes

Testing

The fix addresses timing issues without changing test logic. All assertions remain the same, only the timing of when they execute has been adjusted to wait for a stable state.

Fixes #1108

Original prompt

This section details on the original issue you should resolve

<issue_title>Some ResourceInitialSelectionTest tests fail intermittently</issue_title>
<issue_description>The tests

  • org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest.testMultiSelectionAndOneInitialSelectionWithInitialPattern
One file should be selected by default expected:<[L/org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest_1661392833486/foo.txt]> but was:<[]>

junit.framework.AssertionFailedError: One file should be selected by default expected:<[L/org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest_1661392833486/foo.txt]> but was:<[]>
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.Assert.failNotEquals(Assert.java:329)
at junit.framework.Assert.assertEquals(Assert.java:78)
at junit.framework.TestCase.assertEquals(TestCase.java:238)
at org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest.testMultiSelectionAndOneInitialSelectionWithInitialPattern(ResourceInitialSelectionTest.java:227)
  • org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest.testSingleSelectionAndNoInitialSelectionWithInitialPattern
One file should be selected by default

junit.framework.AssertionFailedError: One file should be selected by default
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.Assert.assertTrue(Assert.java:22)
at junit.framework.Assert.assertFalse(Assert.java:39)
at junit.framework.TestCase.assertFalse(TestCase.java:208)
at org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest.testSingleSelectionAndNoInitialSelectionWithInitialPattern(ResourceInitialSelectionTest.java:98) 

failed in I-Build I20220824-1800 on Mac

</issue_description>

<agent_instructions>This test is randomly failing on macOS during the verification build. Try to identify the reason and stabilize the test</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@ktatavarthi This issues is created as a follow up to [Bug 576361](https://bugs.eclipse.org/bugs/show_bug.cgi?id=576361) @ktatavarthi The test org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest.testMultiSelectionAndTwoInitialFilteredSelections fails on [MacM1](https://download.eclipse.org/eclipse/downloads/drops4/I20220928-1800/testresults/html/org.eclipse.ui.tests_ep426I-unit-macM1-java17_macosx.cocoa.aarch64_17.html) with the below error
Two files should be selected by default 

junit.framework.AssertionFailedError: Two files should be selected by default
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.Assert.assertTrue(Assert.java:22)
at junit.framework.TestCase.assertTrue(TestCase.java:192)
at org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest.testMultiSelectionAndTwoInitialFilteredSelections(ResourceInitialSelectionTest.java:331)
```</body></comment_new>
<comment_new><author>@HeikoKlare</author><body>
Test failure still occurs: https://github.com/eclipse-platform/eclipse.platform.ui/pull/970/checks?check_run_id=15356957783</body></comment_new>
<comment_new><author>@jukzi</author><body>
also

unit.framework.AssertionFailedError: Two files should be selected by default
at junit.framework.TestCase.assertTrue(TestCase.java:192)
at org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest.testMultiSelectionAndTwoInitialSelectionsWithInitialPattern(ResourceInitialSelectionTest.java:306)

https://github.com/eclipse-platform/eclipse.platform.ui/pull/1384/checks?check_run_id=19379975992</body></comment_new>
<comment_new><author>@jukzi</author><body>
https://download.eclipse.org/eclipse/downloads/drops4/I20240619-1800/testresults/html/org.eclipse.ui.tests_ep433I-unit-mac64-java17_macosx.cocoa.x86_64_17.html

junit.framework.AssertionFailedError: The first file should be selected by default expected:<[L/org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest_1718858209743/foo.txt]> but was:<[]>
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.Assert.failNotEquals(Assert.java:329)
at junit.framework.Assert.assertEquals(Assert.java:78)
at junit.framework.TestCase.assertEquals(TestCase.java:238)
at org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest.testSingleSelectionAndTwoInitialSelectionsWithInitialPattern(ResourceInitialSelectionTest.java:189)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)

<comment_new><author>@HeikoKlare</author><body>
The title originally stated that tests fail in I-Builds, but they also fail in GH Actions builds quite often. I changed the title accordingly.</body></comment_new>...

</details>
Fixes eclipse-platform/eclipse.platform.ui#294

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 2 commits October 2, 2025 16:45
…nc jobs

Add DisplayHelper.waitForCondition() calls to wait for background jobs
(FilterHistoryJob, FilterJob) to complete before checking the selection.
This prevents intermittent test failures on macOS where the table hasn't
been populated yet when getSelectedItems() is called.

Fixes: #1108

Co-authored-by: vogella <[email protected]>
Also add DisplayHelper.waitForCondition() to tests that check for empty
selection to ensure the table is fully populated before the assertion.
This prevents race conditions where the table hasn't been initialized yet.

Co-authored-by: vogella <[email protected]>
Copilot AI changed the title [WIP] Some ResourceInitialSelectionTest tests fail intermittently Fix intermittent failures in ResourceInitialSelectionTest by waiting for async jobs Oct 2, 2025
Copilot AI requested a review from vogella October 2, 2025 16:50
@vogella vogella closed this Oct 2, 2025
@laeubi
Copy link
Contributor

laeubi commented Oct 2, 2025

@vogella whats wrong with this approach?

@vogella
Copy link
Contributor

vogella commented Oct 2, 2025

#3373 looks IMHO better as it "only" modifiy the teardown method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants