From d2f831b6351468f01ac4598f6b8b5e48dde13532 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Fri, 7 May 2021 18:06:39 +0200 Subject: [PATCH] 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 --- .../kotlin/idea/intentions/AbstractIntentionTest.kt | 8 +++++++- 1 file changed, 7 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 0f6c6b125db..b649941ff2f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt @@ -139,16 +139,22 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() { private fun computeUnderProgressIndicatorAndWait(compute: () -> T): T { val result = CompletableFuture() 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 } } }