[platform] Handle exceptions in junit5 fixtures

GitOrigin-RevId: 891f6f19b2563f64547e81d75f3878e4c1a0c389
This commit is contained in:
Konstantin.Nisht
2025-01-03 18:44:39 +00:00
committed by intellij-monorepo-bot
parent b00f652930
commit 4b66658d03
@@ -40,10 +40,7 @@ internal class TestFixtureExtension : BeforeAllCallback,
val fixture = field.get(testInstance) as TestFixtureImpl<*>
pendingFixtures.add(fixture.init(testScope, context.uniqueId))
}
@Suppress("SSBasedInspection")
runBlocking {
pendingFixtures.awaitAll()
}
awaitFixtureInitialization(testScope, pendingFixtures)
context.getStore(ExtensionContext.Namespace.GLOBAL).put("TestFixtureExtension", testScope)
}
@@ -63,3 +60,21 @@ internal class TestFixtureExtension : BeforeAllCallback,
}
}
}
private fun awaitFixtureInitialization(cleanupScope: CoroutineScope, pendingFixtures: List<Deferred<*>>) {
@Suppress("SSBasedInspection")
runBlocking {
try {
pendingFixtures.awaitAll()
}
catch (e: Throwable) {
try {
cleanupScope.coroutineContext.job.cancelAndJoin()
}
catch (exceptionDuringCleanup: Throwable) {
e.addSuppressed(Throwable("Exception during cleanup of test fixture", exceptionDuringCleanup))
}
throw e
}
}
}