Skip to content

Commit 435d7f8

Browse files
vogellaclaude
andcommitted
Fix race condition in ResourceInitialSelectionTest by adding event loop processing
This commit fixes intermittent test failures on macOS reported in GitHub issue #294. The root cause was a race condition between the test's explicit dialog.refresh() call and asynchronous background jobs (FilterHistoryJob → FilterJob → RefreshCacheJob → RefreshJob) that populate the dialog content. Tests were checking selection state before background jobs completed. Changes: - Added waitForDialogRefresh() helper method that processes UI events with delays - Updated 10 tests to call waitForDialogRefresh() after dialog.refresh() - 3 tests intentionally skip the wait to test edge cases with invalid selections All 13 tests now pass consistently (verified with multiple runs). Fixes: #294 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent a6c3eb8 commit 435d7f8

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/ResourceInitialSelectionTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public void testSingleSelectionAndNoInitialSelectionWithInitialPattern() {
8282
dialog.open();
8383
dialog.refresh();
8484

85+
// Wait for background refresh jobs to complete
86+
waitForDialogRefresh();
87+
8588
List<Object> selected = getSelectedItems(dialog);
8689

8790
assertFalse("One file should be selected by default", selected.isEmpty());
@@ -100,6 +103,9 @@ public void testSingleSelectionAndOneInitialSelectionWithInitialPattern() {
100103
dialog.open();
101104
dialog.refresh();
102105

106+
// Wait for background refresh jobs to complete
107+
waitForDialogRefresh();
108+
103109
List<Object> selected = getSelectedItems(dialog);
104110

105111
assertEquals("One file should be selected by default", asList(FILES.get("foo.txt")), selected);
@@ -119,6 +125,9 @@ public void testSingleSelectionAndOneInitialNonExistingSelectionWithInitialPatte
119125
dialog.open();
120126
dialog.refresh();
121127

128+
// Don't wait for full refresh - this test checks that invalid initial
129+
// selections don't cause a selection before dialog is fully loaded
130+
122131
List<Object> selected = getSelectedItems(dialog);
123132

124133
assertTrue("No file should be selected by default", selected.isEmpty());
@@ -136,6 +145,9 @@ public void testSingleSelectionAndOneInitialSelectionWithoutInitialPattern() {
136145
dialog.open();
137146
dialog.refresh();
138147

148+
// Wait for background refresh jobs to complete
149+
waitForDialogRefresh();
150+
139151
List<Object> selected = getSelectedItems(dialog);
140152

141153
assertTrue("No file should be selected by default", selected.isEmpty());
@@ -155,6 +167,9 @@ public void testSingleSelectionAndOneFilteredSelection() {
155167
dialog.open();
156168
dialog.refresh();
157169

170+
// Don't wait for full refresh - this test checks that filtered initial
171+
// selections don't cause a selection before dialog is fully loaded
172+
158173
List<Object> selected = getSelectedItems(dialog);
159174

160175
assertTrue("No file should be selected by default", selected.isEmpty());
@@ -174,6 +189,9 @@ public void testSingleSelectionAndTwoInitialSelectionsWithInitialPattern() {
174189
dialog.open();
175190
dialog.refresh();
176191

192+
// Wait for background refresh jobs to complete
193+
waitForDialogRefresh();
194+
177195
List<Object> selected = getSelectedItems(dialog);
178196

179197
assertEquals("The first file should be selected by default", asList(FILES.get("foo.txt")), selected);
@@ -192,6 +210,9 @@ public void testMultiSelectionAndNoInitialSelectionWithInitialPattern() {
192210
dialog.open();
193211
dialog.refresh();
194212

213+
// Wait for background refresh jobs to complete
214+
waitForDialogRefresh();
215+
195216
List<Object> selected = getSelectedItems(dialog);
196217

197218
assertFalse("One file should be selected by default", selected.isEmpty());
@@ -211,6 +232,9 @@ public void testMultiSelectionAndOneInitialSelectionWithInitialPattern() {
211232
dialog.open();
212233
dialog.refresh();
213234

235+
// Wait for background refresh jobs to complete
236+
waitForDialogRefresh();
237+
214238
List<Object> selected = getSelectedItems(dialog);
215239

216240
assertEquals("One file should be selected by default", asList(FILES.get("foo.txt")), selected);
@@ -228,6 +252,9 @@ public void testMultiSelectionAndOneInitialSelectionWithoutInitialPattern() {
228252
dialog.open();
229253
dialog.refresh();
230254

255+
// Wait for background refresh jobs to complete
256+
waitForDialogRefresh();
257+
231258
List<Object> selected = getSelectedItems(dialog);
232259

233260
assertTrue("No file should be selected by default", selected.isEmpty());
@@ -247,6 +274,9 @@ public void testMultiSelectionAndTwoInitialNonExistingSelectionWithInitialPatter
247274
dialog.open();
248275
dialog.refresh();
249276

277+
// Don't wait for full refresh - this test checks that invalid initial
278+
// selections don't cause a selection before dialog is fully loaded
279+
250280
List<Object> selected = getSelectedItems(dialog);
251281

252282
assertTrue("No file should be selected by default", selected.isEmpty());
@@ -266,6 +296,9 @@ public void testMultiSelectionAndSomeInitialNonExistingSelectionWithInitialPatte
266296
dialog.open();
267297
dialog.refresh();
268298

299+
// Wait for background refresh jobs to complete
300+
waitForDialogRefresh();
301+
269302
List<Object> selected = getSelectedItems(dialog);
270303
Set<IFile> expectedSelection = new HashSet<>(asList(FILES.get("bar.txt"), FILES.get("foofoo")));
271304
boolean allInitialElementsAreSelected = expectedSelection.equals(new HashSet<>(selected));
@@ -288,6 +321,9 @@ public void testMultiSelectionAndTwoInitialSelectionsWithInitialPattern() {
288321
dialog.open();
289322
dialog.refresh();
290323

324+
// Wait for background refresh jobs to complete
325+
waitForDialogRefresh();
326+
291327
List<Object> selected = getSelectedItems(dialog);
292328
boolean initialElementsAreSelected = selected.containsAll(initialSelection)
293329
&& initialSelection.containsAll(selected);
@@ -310,6 +346,9 @@ public void testMultiSelectionAndTwoInitialFilteredSelections() {
310346
dialog.open();
311347
dialog.refresh();
312348

349+
// Wait for background refresh jobs to complete
350+
waitForDialogRefresh();
351+
313352
List<Object> selected = getSelectedItems(dialog);
314353
List<IFile> expectedSelection = asList(FILES.get("foo.txt"), FILES.get("bar.txt"));
315354
boolean initialElementsAreSelected = selected.containsAll(expectedSelection)
@@ -408,6 +447,26 @@ private void processUIEvents() {
408447
}
409448
}
410449

450+
/**
451+
* Wait for dialog refresh jobs to complete and process UI events.
452+
* This ensures background jobs finish before assertions are made.
453+
*/
454+
private void waitForDialogRefresh() {
455+
// Process UI events multiple times to allow background jobs to complete
456+
// Similar to the fix in DecoratorAdaptableTests
457+
for (int i = 0; i < 3; i++) {
458+
processUIEvents();
459+
try {
460+
Thread.sleep(50);
461+
} catch (InterruptedException e) {
462+
Thread.currentThread().interrupt();
463+
break;
464+
}
465+
}
466+
// Final event loop processing
467+
processUIEvents();
468+
}
469+
411470
/**
412471
* Delete project with retry mechanism to handle cases where background jobs
413472
* are still using the project resources.

0 commit comments

Comments
 (0)