Fix intermittent failures in ResourceInitialSelectionTest by waiting for async jobs #3372
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Tests in
ResourceInitialSelectionTestwere failing intermittently on macOS and other platforms during CI builds with assertions like:These failures were reported in issue #1108 and occurred across multiple test runs over several years.
Root Cause
The test pattern was:
However,
dialog.refresh()schedules a chain of asynchronous background jobs that populate the table:FilterHistoryJob- filters history itemsFilterJob- filters workspace resourcesRefreshCacheJob- schedules the UI refreshRefreshJob(UIJob) - updates the table widgetThe 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:This pattern is already successfully used in
ResourceSelectionFilteringDialogTestand eliminates the race condition without requiring any changes to production code.Benefits
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
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 errorunit.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)
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)