Handle exception during intention background computation in tests

Our test infrastructure (in particular, muting mechanics) rely on
thrown exception during doTestFor function call. But if the
exception happened on background thread, then here we'll get only
TimeOutException but the actual exception won't be reported during
doTestFor call. It would be reported later by the common IDEA test
framework and bypass our mute mechanics
This commit is contained in:
Stanislav Erokhin
2021-05-07 18:06:39 +02:00
committed by teamcityserver
parent 7ac599520e
commit d2f831b635
@@ -139,16 +139,22 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
private fun <T> computeUnderProgressIndicatorAndWait(compute: () -> T): T {
val result = CompletableFuture<T>()
val progressIndicator = ProgressIndicatorBase()
var exceptionDuringCompute: Throwable? = null
try {
val task = object : Task.Backgroundable(project, "isApplicable", false) {
override fun run(indicator: ProgressIndicator) {
result.complete(compute())
try {
result.complete(compute())
} catch(e: Throwable) {
exceptionDuringCompute = e
}
}
}
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, progressIndicator)
return result.get(10, TimeUnit.SECONDS)
} finally {
progressIndicator.cancel()
exceptionDuringCompute?.let { throw it }
}
}