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
This commit is contained in:
Sergei Tachenov
2025-07-14 18:08:34 +00:00
committed by intellij-monorepo-bot
parent 6f568e1cd5
commit 7e61ee8dbd
@@ -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()