diff --git a/platform/testFramework/junit5/src/fixture/TestFixtureExtension.kt b/platform/testFramework/junit5/src/fixture/TestFixtureExtension.kt index 66f9aec5278a..f4461978e6b1 100644 --- a/platform/testFramework/junit5/src/fixture/TestFixtureExtension.kt +++ b/platform/testFramework/junit5/src/fixture/TestFixtureExtension.kt @@ -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>) { + @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 + } + } +} \ No newline at end of file