mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
no swing event pumping under write action in tests
This commit is contained in:
@@ -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 '<caret> 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 {
|
||||
{
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
-8
@@ -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 {
|
||||
|
||||
@@ -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<String>
|
||||
get() = ModuleRootManager.getInstance(this).contentRootUrls
|
||||
|
||||
fun ProjectRule.createModule(path: Path) = runWriteAction { ModuleManager.getInstance(project).newModule(path.systemIndependentPath, ModuleTypeId.JAVA_MODULE) }
|
||||
fun ProjectRule.createModule(path: Path): Module {
|
||||
val p = project
|
||||
return runWriteAction { ModuleManager.getInstance(p).newModule(path.systemIndependentPath, ModuleTypeId.JAVA_MODULE) }
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
+29
-36
@@ -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> 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> 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) {
|
||||
|
||||
+1
-7
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
-3
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user