diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy index df341563b0d7..792af508a0a2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy @@ -786,7 +786,7 @@ class A {{ template.addVariable("V3", "", "", true) final Editor editor = getEditor() - writeCommand { startTemplate(template) } + startTemplate(template) final TemplateState state = getState() @@ -828,7 +828,7 @@ class A {{ template.addVariable("V1", "", "", true) template.addVariable("V2", "", '"239"', true) - writeCommand { startTemplate(template) } + startTemplate(template) myFixture.checkResult ' var = 239;' @@ -1129,7 +1129,7 @@ class Foo { ((TemplateImpl)template).templateContext.setEnabled(contextType(JavaCodeContextType.class), true) CodeInsightTestUtil.addTemplate(template, testRootDisposable) - writeCommand { startTemplate(template) } + startTemplate(template) myFixture.checkResult """\ class Foo { { @@ -1137,7 +1137,7 @@ class Foo { } } """ - writeCommand { myFixture.type '42' } + myFixture.type '42' myFixture.checkResult """\ class Foo { { @@ -1146,7 +1146,7 @@ class Foo { } """ - writeCommand { myFixture.type '\b\b' } + myFixture.type '\b\b' myFixture.checkResult """\ class Foo { { diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java index 69dfe4931f94..cbcfd1028399 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java @@ -28,6 +28,7 @@ import com.intellij.refactoring.introduceParameter.Util; import com.intellij.refactoring.util.occurrences.ExpressionOccurrenceManager; import com.intellij.testFramework.TestDataPath; import com.intellij.util.ObjectUtils; +import com.intellij.util.ui.UIUtil; import gnu.trove.TIntArrayList; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -366,12 +367,14 @@ public class IntroduceParameterTest extends LightRefactoringTestCase { public void testCodeDuplicates() { configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java"); perform(true, 0, "anObject", false, true, true, false, 0, true); + UIUtil.dispatchAllInvocationEvents(); checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java"); } public void testCodeDuplicatesFromConstructor() { configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java"); perform(true, 0, "anObject", false, true, true, false, 0, true); + UIUtil.dispatchAllInvocationEvents(); checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java"); } diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt index c6bc835c5d87..65aca91ca031 100644 --- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt +++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt @@ -36,7 +36,6 @@ import com.intellij.project.isDirectoryBased import com.intellij.psi.search.scope.packageSet.NamedScopeManager import com.intellij.psi.search.scope.packageSet.NamedScopesHolder import com.intellij.util.loadElement -import com.intellij.util.ui.UIUtil import com.intellij.util.xmlb.Accessor import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters import com.intellij.util.xmlb.XmlSerializer @@ -179,13 +178,6 @@ class ProjectInspectionProfileManager(val project: Project, initialLoadSchemesFuture.done { currentProfile.initInspectionTools(project) fireProfilesInitialized() - - val app = ApplicationManager.getApplication() - if (app.isUnitTestMode && app.isDispatchThread) { - // do not restart daemon in the middle of the test - //noinspection TestOnlyProblems - UIUtil.dispatchAllInvocationEvents() - } } scopeListener = NamedScopesHolder.ScopeListener { diff --git a/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt b/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt index adc7486bd6ec..4290a60c3647 100644 --- a/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt @@ -43,7 +43,10 @@ class ModuleStoreTest { } } - private fun VirtualFile.loadModule() = runWriteAction { ModuleManager.getInstance(projectRule.project).loadModule(path) } + private fun VirtualFile.loadModule(): Module { + val project = projectRule.project + return runWriteAction { ModuleManager.getInstance(project).loadModule(path) } + } fun Path.createModule() = projectRule.createModule(this) } @@ -158,4 +161,7 @@ class ModuleStoreTest { val Module.contentRootUrls: Array get() = ModuleRootManager.getInstance(this).contentRootUrls -fun ProjectRule.createModule(path: Path) = runWriteAction { ModuleManager.getInstance(project).newModule(path.systemIndependentPath, ModuleTypeId.JAVA_MODULE) } \ No newline at end of file +fun ProjectRule.createModule(path: Path): Module { + val p = project + return runWriteAction { ModuleManager.getInstance(p).newModule(path.systemIndependentPath, ModuleTypeId.JAVA_MODULE) } +} \ No newline at end of file diff --git a/platform/diff-impl/tests/com/intellij/diff/merge/MergeTestBase.kt b/platform/diff-impl/tests/com/intellij/diff/merge/MergeTestBase.kt index cbc7155a0e57..132870446311 100644 --- a/platform/diff-impl/tests/com/intellij/diff/merge/MergeTestBase.kt +++ b/platform/diff-impl/tests/com/intellij/diff/merge/MergeTestBase.kt @@ -19,12 +19,10 @@ import com.intellij.diff.DiffContentFactoryImpl import com.intellij.diff.DiffTestCase import com.intellij.diff.contents.DocumentContent import com.intellij.diff.merge.MergeTestBase.SidesState.* -import com.intellij.diff.merge.TextMergeViewer import com.intellij.diff.merge.TextMergeViewer.MyThreesideViewer import com.intellij.diff.util.DiffUtil import com.intellij.diff.util.Side import com.intellij.diff.util.TextDiffType -import com.intellij.diff.util.ThreeSide import com.intellij.openapi.actionSystem.ActionPlaces import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent @@ -144,7 +142,6 @@ abstract class MergeTestBase : DiffTestCase() { fun write(f: () -> Unit): Unit { ApplicationManager.getApplication().runWriteAction({ CommandProcessor.getInstance().executeCommand(project, f, null, null) }) - UIUtil.dispatchAllInvocationEvents() } fun Int.ignore(side: Side, modifier: Boolean = false) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java index e7bbd4aaced4..3a67137e7ece 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java @@ -539,11 +539,6 @@ public abstract class BaseRefactoringProcessor implements Runnable { if (ApplicationManager.getApplication().isUnitTestMode()) { ApplicationManager.getApplication().assertIsDispatchThread(); NonProjectFileWritingAccessProvider.disableChecksDuring(this::doRun); - - //noinspection TestOnlyProblems - UIUtil.dispatchAllInvocationEvents(); - //noinspection TestOnlyProblems - UIUtil.dispatchAllInvocationEvents(); return; } if (ApplicationManager.getApplication().isWriteAccessAllowed()) { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/ApplicationImplTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/ApplicationImplTest.java index 7bc8a47028c8..641d2e350e91 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/ApplicationImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/ApplicationImplTest.java @@ -636,45 +636,38 @@ public class ApplicationImplTest extends LightPlatformTestCase { } public void testPooledThreadsStartedAfterQuickSuspendedWriteActionDontGetReadPrivileges() { + for (int i = 0; i < 1000; i++) { + safeWrite(() -> checkPooledThreadsDontGetWrongPrivileges()); + } + } + + private static void checkPooledThreadsDontGetWrongPrivileges() { ApplicationImpl app = (ApplicationImpl)ApplicationManager.getApplication(); - safeWrite(new Runnable() { - @Override - public void run() { - for (int i = 0; i < 1000; i++) { - checkPooledThreadsDontGetWrongPrivileges(); - UIUtil.dispatchAllInvocationEvents(); - } + Ref future = Ref.create(); + + Disposable disableStderrDumping = Disposer.newDisposable(); + LoggedErrorProcessor.getInstance().disableStderrDumping(disableStderrDumping); + + Semaphore mayFinish = new Semaphore(); + mayFinish.down(); + try { + app.executeSuspendingWriteAction(ourProject, "", () -> + future.set(app.executeOnPooledThread( + () -> assertTrue(mayFinish.waitFor(1000))))); + } + catch (AssertionError e) { + if (!isEscapingThreadAssertion(e)) { + e.printStackTrace(); + throw e; } + } + finally { + Disposer.dispose(disableStderrDumping); + } - private void checkPooledThreadsDontGetWrongPrivileges() { - Ref future = Ref.create(); - - Disposable disableStderrDumping = Disposer.newDisposable(); - LoggedErrorProcessor.getInstance().disableStderrDumping(disableStderrDumping); - - Semaphore mayFinish = new Semaphore(); - mayFinish.down(); - try { - app.executeSuspendingWriteAction(ourProject, "", () -> - future.set(app.executeOnPooledThread( - () -> assertTrue(mayFinish.waitFor(1000))))); - } - catch (AssertionError e) { - if (!isEscapingThreadAssertion(e)) { - e.printStackTrace(); - throw e; - } - } - finally { - Disposer.dispose(disableStderrDumping); - } - - app.executeSuspendingWriteAction(ourProject, "", () -> {}); - mayFinish.up(); - waitForFuture(future.get()); - } - - }); + app.executeSuspendingWriteAction(ourProject, "", () -> {}); + mayFinish.up(); + waitForFuture(future.get()); } private static boolean isEscapingThreadAssertion(AssertionError e) { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestUtil.java index febe381dbdff..708e37ce9c88 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestUtil.java @@ -104,13 +104,7 @@ public class CodeInsightTestUtil { if (intentionAction == null) { Assert.fail("Action not found: " + action + " in place: " + fixture.getElementAtCaret() + " among " + availableIntentions); } - new WriteCommandAction(fixture.getProject()) { - @Override - protected void run(@NotNull Result result) { - fixture.launchAction(intentionAction); - } - }.execute(); - UIUtil.dispatchAllInvocationEvents(); + fixture.launchAction(intentionAction); fixture.checkResultByFile(after, false); } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy index d9e5f69513d1..d7d55daec92e 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy @@ -25,12 +25,10 @@ import com.intellij.psi.PsiClass import com.intellij.psi.PsiFile import com.intellij.psi.impl.source.PostprocessReformattingAspect import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase -import com.intellij.util.ui.UIUtil import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable import org.jetbrains.plugins.groovy.actions.generate.constructors.GroovyGenerateConstructorHandler import org.jetbrains.plugins.groovy.util.TestUtils - /** * @author peter */ @@ -381,7 +379,6 @@ class GrImportStatementStub { return members } }.invoke(project, myFixture.editor, myFixture.file) - UIUtil.dispatchAllInvocationEvents() PostprocessReformattingAspect.getInstance(project).doPostponedFormatting() } }.execute()