From bef100b46e49af331ab9830be00e096b7c97fe97 Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Fri, 27 Oct 2017 14:08:33 +0300 Subject: [PATCH] AbstractIntentionTest: `isApplicableOnPooled` made run under ProgressIndicator --- .../idea/intentions/AbstractIntentionTest.kt | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt index 4de2a776781..a01372f9620 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt @@ -19,6 +19,10 @@ package org.jetbrains.kotlin.idea.intentions import com.google.common.collect.Lists import com.intellij.codeInsight.intention.IntentionAction import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.progress.ProgressManager +import com.intellij.openapi.progress.Task +import com.intellij.openapi.progress.util.ProgressIndicatorBase import com.intellij.openapi.util.Computable import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.util.io.FileUtil @@ -39,6 +43,8 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import org.junit.Assert import java.io.File import java.util.* +import java.util.concurrent.CompletableFuture +import java.util.concurrent.TimeUnit abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() { protected open fun intentionFileName(): String = ".intention" @@ -124,12 +130,29 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() { } } + private fun computeUnderProgressIndicatorAndWait(compute: () -> T): T { + val result = CompletableFuture() + val progressIndicator = ProgressIndicatorBase() + try { + val task = object : Task.Backgroundable(project, "isApplicable", false) { + override fun run(indicator: ProgressIndicator) { + result.complete(compute()) + } + } + ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, progressIndicator) + return result.get(10, TimeUnit.SECONDS) + } + finally { + progressIndicator.cancel() + } + } + @Throws(Exception::class) private fun doTestFor(mainFilePath: String, pathToFiles: Map, intentionAction: IntentionAction, fileText: String) { val isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// ${isApplicableDirectiveName()}: ") val isApplicableExpected = isApplicableString == null || isApplicableString == "true" - val isApplicableOnPooled = ApplicationManager.getApplication().executeOnPooledThread(java.util.concurrent.Callable { ApplicationManager.getApplication().runReadAction(Computable { intentionAction.isAvailable(project, editor, file) }) }).get() + val isApplicableOnPooled = computeUnderProgressIndicatorAndWait { ApplicationManager.getApplication().runReadAction(Computable { intentionAction.isAvailable(project, editor, file) }) } val isApplicableOnEdt = intentionAction.isAvailable(project, editor, file)