[terminal] IJPL-173788 Wait for prompt before performing test logic

GitOrigin-RevId: 12a9af54bf7974e74a0633899828272cf38d71c2
This commit is contained in:
Konstantin Hudyakov
2025-01-17 17:42:10 +00:00
committed by intellij-monorepo-bot
parent ac01965768
commit de2d3dd1c3
@@ -9,6 +9,7 @@ import com.intellij.testFramework.RuleChain
import com.intellij.testFramework.common.timeoutRunBlocking
import com.jediterm.core.util.TermSize
import com.jediterm.terminal.TerminalKeyEncoder
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
@@ -181,13 +182,19 @@ internal class ShellIntegrationTest(private val shellPath: Path) {
val session = TerminalSessionTestUtil.startTestTerminalSession(shellPath.toString(), projectRule.project, childScope("TerminalSession"), size)
val outputEvents = mutableListOf<TerminalOutputEvent>()
val promptFinishedEventDeferred = CompletableDeferred(false)
launch {
for (events in session.outputChannel) {
outputEvents.addAll(events)
if (events.any { it is TerminalPromptFinishedEvent }) {
promptFinishedEventDeferred.complete(true)
}
}
}
delay(1000) // Wait for prompt initialization
// Wait for prompt initialization before going further
promptFinishedEventDeferred.await()
block(session.inputChannel)
delay(1000) // Wait for the shell to handle input sent in `block`