get rid of NonBlockingReadActionImpl.cancelAllTasks

callers don't expect NBRA computations to be canceled by factors other than explicitly specified, so such cancellation could break tests or freeze them forever

GitOrigin-RevId: e6e782711f27a8abaa9cd32f00915c9a50ae2138
This commit is contained in:
Peter Gromov
2019-12-27 18:34:09 +00:00
committed by intellij-monorepo-bot
parent d5c96d1dfc
commit 3a8276bd29
4 changed files with 20 additions and 16 deletions
@@ -4,6 +4,7 @@ package com.intellij.openapi.application.impl;
import com.google.common.annotations.VisibleForTesting;
import com.intellij.concurrency.SensitiveProgressWrapper;
import com.intellij.diagnostic.ThreadDumper;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.*;
import com.intellij.openapi.application.constraints.ExpirableConstrainedExecution;
import com.intellij.openapi.application.constraints.Expiration;
@@ -16,6 +17,7 @@ import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.progress.*;
import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ex.ProjectEx;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VirtualFile;
@@ -95,12 +97,12 @@ public class NonBlockingReadActionImpl<T>
@Override
public NonBlockingReadAction<T> inSmartMode(@NotNull Project project) {
return withConstraint(new InSmartMode(project), project);
return withConstraint(new InSmartMode(project), earlyDisposable(project));
}
@Override
public NonBlockingReadAction<T> withDocumentsCommitted(@NotNull Project project) {
return withConstraint(new WithDocumentsCommitted(project, ModalityState.any()), project);
return withConstraint(new WithDocumentsCommitted(project, ModalityState.any()), earlyDisposable(project));
}
@Override
@@ -108,6 +110,17 @@ public class NonBlockingReadActionImpl<T>
return cancelIf(expireCondition);
}
@NotNull
@Override
public NonBlockingReadActionImpl<T> expireWith(@NotNull Disposable parentDisposable) {
return super.expireWith(earlyDisposable(parentDisposable));
}
private static Disposable earlyDisposable(Disposable disposable) {
// account for shared project in tests
return disposable instanceof ProjectEx ? ((ProjectEx)disposable).getEarlyDisposable() : disposable;
}
@Override
public NonBlockingReadAction<T> cancelWith(@NotNull ProgressIndicator progressIndicator) {
LOG.assertTrue(myProgressIndicator == null, "Unspecified behaviour. Outer progress indicator is already set for the action.");
@@ -319,6 +332,7 @@ public class NonBlockingReadActionImpl<T>
}
private void reportCoalescingConflict(NonBlockingReadActionImpl<?>.Submission current) {
ourTasks.remove(this); // the next line will throw in tests and leave this submission hanging forever
LOG.error("Same coalesceBy arguments are already used by " + current.getComputationOrigin() + " so they can cancel each other. " +
"Please make them more unique.");
}
@@ -507,16 +521,6 @@ public class NonBlockingReadActionImpl<T>
}
}
@TestOnly
public static void cancelAllTasks() {
while (!ourTasks.isEmpty()) {
for (CancellablePromise<?> task : ourTasks) {
task.cancel();
}
WriteAction.run(() -> {}); // let background threads complete
}
}
@TestOnly
public static void waitForAsyncTaskCompletion() {
assert !ApplicationManager.getApplication().isWriteAccessAllowed();
@@ -123,7 +123,7 @@ public class ApplicationImplTest extends LightPlatformTestCase {
}
private static void runReadWrites(final int readIterations, final int writeIterations, int expectedMs) {
NonBlockingReadActionImpl.cancelAllTasks(); // someone might've submitted a task depending on app events which we disable now
NonBlockingReadActionImpl.waitForAsyncTaskCompletion(); // someone might've submitted a task depending on app events which we disable now
final ApplicationImpl application = (ApplicationImpl)ApplicationManager.getApplication();
Disposable disposable = Disposer.newDisposable();
application.disableEventsUntil(disposable);
@@ -459,6 +459,8 @@ public abstract class HeavyPlatformTestCase extends UsefulTestCase implements Da
return;
}
NonBlockingReadActionImpl.waitForAsyncTaskCompletion();
UndoManagerImpl globalInstance = (UndoManagerImpl)UndoManager.getGlobalInstance();
if (globalInstance != null) {
globalInstance.dropHistoryInTests();
@@ -477,8 +479,6 @@ public abstract class HeavyPlatformTestCase extends UsefulTestCase implements Da
((PsiManagerImpl)PsiManager.getInstance(defaultProject)).cleanupForNextTest();
}
NonBlockingReadActionImpl.cancelAllTasks();
FileBasedIndex fileBasedIndex = app.getServiceIfCreated(FileBasedIndex.class);
if (fileBasedIndex != null) {
((FileBasedIndexImpl)fileBasedIndex).cleanupForNextTest();
@@ -243,6 +243,7 @@ fun tearDownProjectAndApp(project: Project, appManager: TestApplicationManager?
l.run { LegacyBridgeTestFrameworkUtils.dropCachesOnTeardown(project) }
l.run { (ProjectManager.getInstance() as ProjectManagerImpl).forceCloseProject(project, !isLightProject) }
l.run { NonBlockingReadActionImpl.waitForAsyncTaskCompletion() }
l.run { (appManager ?: TestApplicationManager.getInstanceIfCreated())?.setDataProvider(null) }
l.run { UiInterceptors.clear() }
@@ -346,6 +347,5 @@ fun waitForProjectLeakingThreads(project: Project, timeout: Long = 10, timeUnit:
project.stopServicePreloading()
}
NonBlockingReadActionImpl.cancelAllTasks()
(project.serviceIfCreated<GeneratedSourceFileChangeTracker>() as GeneratedSourceFileChangeTrackerImpl?)?.cancelAllAndWait(timeout, timeUnit)
}