From 7e61ee8dbd6ca0b08b22100909aff2ba7ca3960a Mon Sep 17 00:00:00 2001 From: Sergei Tachenov Date: Mon, 14 Jul 2025 13:39:46 +0300 Subject: [PATCH] IJPL-196231 Add Unconfined+launchOnShow test This covers the recent fix of the issue when a long-running unconfined EDT coroutine would prevent executing the job. The test can be checked by setting ide.ui.coroutine.scopes.unconfined.fix to false, it fails then. GitOrigin-RevId: c448be818a87daf888b438a6ab1a8b71b46ae6ae --- .../application/impl/LaunchOnShowTest.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/LaunchOnShowTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/LaunchOnShowTest.kt index 2ac3515426c3..4aaa0449ba02 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/LaunchOnShowTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/application/impl/LaunchOnShowTest.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.application.EDT import com.intellij.platform.ide.progress.ModalTaskOwner import com.intellij.platform.ide.progress.TaskCancellation import com.intellij.platform.ide.progress.withModalProgress +import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.common.timeoutRunBlocking import com.intellij.testFramework.junit5.TestApplication import com.intellij.ui.ComponentUtil.forceMarkAsShowing @@ -114,6 +115,24 @@ class LaunchOnShowTest { assertTrue(awaitValue(true) { executed }) } + @Test + fun `launch works in a long-running unconfined EDT coroutine`(): Unit = edtTest { + var executed = false + withContext(Dispatchers.Unconfined) { + container.launchOnShow("test") { + executed = true + } + var eventuallyExecuted = false + // not using awaitValue because it's important to not let go of this unconfined thing, + // and therefore we must not suspend the coroutine + repeat(10) { + PlatformTestUtil.dispatchAllEventsInIdeEventQueue() + eventuallyExecuted = executed + } + assertTrue(eventuallyExecuted) + } + } + @Test fun `launch once without adding it to hierarchy is GCed with component`(): Unit = edtTest { var component: Component? = JLabel()