Skip to content

Commit

Permalink
Wait for FAMILY_SNAPSHOT jobs after creating projects/teardown
Browse files Browse the repository at this point in the history
org.eclipse.core.internal.resources.DelayedSnapshotJob.run(IProgressMonitor)
is triggered both periodically and on few special cases. Special cases
are project deletion and creation, options change...

This job may create change events coming to JDT from non-UI thread, see
org.eclipse.jdt.internal.core.DeltaProcessor.resourceChanged(IResourceChangeEvent).

To avoid sporadic test fails we should also wait for that job.

Note: we can't unconditionally call waitForSnapShot(), it should be
always done outside of the code that holds workspace rule, otherwise we
will run in deadlocks with other jobs...

See #2716
  • Loading branch information
iloveeclipse committed Aug 6, 2024
1 parent 45f50f7 commit 57bcdfc
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4107,6 +4107,7 @@ public void waitForManualRefresh() {
try {
Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_MANUAL_REFRESH);
Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_REFRESH, null);
waitForSnapShot();
JavaModelManager.getIndexManager().waitForIndex(isIndexDisabledForTest(), null);
wasInterrupted = false;
} catch (OperationCanceledException e) {
Expand All @@ -4127,6 +4128,27 @@ public static boolean isTouchJobRunning() {
return false;
}

public void waitForSnapShot() {
if (isWorkspaceRuleAlreadyInUse(getWorkspaceRoot())){
// Don't wait holding workspace lock on FAMILY_SNAPSHOT, because
// we might deadlock with DelayedSnapshotJob
System.out.println("\n\nAborted waitForSnapShot() because running with the workspace rule\n\n");
return;
}
boolean wasInterrupted = false;
do {
try {
Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_SNAPSHOT);
Job.getJobManager().join(ResourcesPlugin.FAMILY_SNAPSHOT, null);
wasInterrupted = false;
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (InterruptedException e) {
wasInterrupted = true;
}
} while (wasInterrupted);
}

public void waitUntilIndexesReady() {
// dummy query for waiting until the indexes are ready
SearchEngine engine = new SearchEngine();
Expand Down

0 comments on commit 57bcdfc

Please sign in to comment.