Skip to content

Commit 1c6578d

Browse files
committed
Fix ResourceInitialSelectionTest teardown failure
The test testSingleSelectionAndOneInitialSelectionWithInitialPattern was intermittently failing with ResourceException during project deletion in doTearDown() due to background jobs holding project locks. Changes: - Add comprehensive UI event processing before/after cleanup - Wait for additional job families (FAMILY_MANUAL_REFRESH, FAMILY_AUTO_REFRESH) - Implement retry mechanism with proper NullProgressMonitor (5 retries, 1s delay) - Preserve existing exception chaining for debugging - Follow established Eclipse test patterns (ResourceHelper, ResourceActionTest) This resolves intermittent test failures in CI/CD environments where decorator and resource refresh jobs interfere with project deletion. Fixes: ResourceException: Problems encountered while deleting resources
1 parent 8ce2da8 commit 1c6578d

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

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

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,24 @@ public void doTearDown() throws Exception {
365365
dialog.close();
366366
}
367367
if (project != null) {
368+
// Process any pending UI events before cleanup
369+
processUIEvents();
370+
368371
try {
372+
// Wait for decorator jobs to finish
369373
Job.getJobManager().wakeUp(DecoratorManager.FAMILY_DECORATE);
370374
Job.getJobManager().join(DecoratorManager.FAMILY_DECORATE, null);
371-
project.delete(true, null);
375+
376+
// Wait for any resource jobs that might be running
377+
Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_REFRESH, null);
378+
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, null);
379+
380+
// Process UI events again after joining jobs
381+
processUIEvents();
382+
383+
// Try to delete with proper progress monitor and retry mechanism
384+
deleteProjectWithRetry(project);
385+
372386
} catch (Exception e) {
373387
// try to get a stacktrace which jobs still has project open so that it can not
374388
// be deleted:
@@ -381,4 +395,49 @@ public void doTearDown() throws Exception {
381395
}
382396
}
383397
}
398+
399+
/**
400+
* Process any pending UI events.
401+
*/
402+
private void processUIEvents() {
403+
Display display = Display.getCurrent();
404+
if (display != null) {
405+
while (display.readAndDispatch()) {
406+
// Process all pending events
407+
}
408+
}
409+
}
410+
411+
/**
412+
* Delete project with retry mechanism to handle cases where background jobs
413+
* are still using the project resources.
414+
*/
415+
private void deleteProjectWithRetry(IProject projectToDelete) throws CoreException {
416+
final int MAX_RETRY = 5;
417+
CoreException lastException = null;
418+
419+
for (int i = 0; i < MAX_RETRY; i++) {
420+
try {
421+
projectToDelete.delete(true, true, new NullProgressMonitor());
422+
return; // Success
423+
} catch (CoreException e) {
424+
lastException = e;
425+
if (i < MAX_RETRY - 1) {
426+
// Process UI events and wait before retrying
427+
processUIEvents();
428+
try {
429+
Thread.sleep(1000); // Wait 1 second before retry
430+
} catch (InterruptedException ie) {
431+
Thread.currentThread().interrupt();
432+
break;
433+
}
434+
}
435+
}
436+
}
437+
438+
// If we get here, all retries failed
439+
if (lastException != null) {
440+
throw lastException;
441+
}
442+
}
384443
}

0 commit comments

Comments
 (0)