in skiko/src/awtTest/kotlin/org/jetbrains/skiko/LibraryLoadStressTest.kt [70:106]
suspend fun launchProcess(
command: String, skikoDataDir: Path
) = withContext(Dispatchers.IO) {
val process = ProcessBuilder(
ProcessHandle.current().info().command().get(),
"-cp", System.getProperty("java.class.path"),
"-Dskiko.data.path=${skikoDataDir.toAbsolutePath()}",
"-Xmx256m", "-Xms64m",
StressTestMain::class.java.name, command
).start()
coroutineContext.job.invokeOnCompletion {
process.destroyForcibly()
}
launch(Dispatchers.IO) {
process.inputStream.bufferedReader().forEachLine { line ->
println("$command: $line")
}
}
val errorOut = async(Dispatchers.IO) {
process.errorStream.bufferedReader().readText()
}
select {
process.onExit().asDeferred().onAwait { }
onTimeout(15.seconds) {
process.destroyForcibly()
fail("Timeout waiting on '$command' to finish")
}
}
if (process.exitValue() != 0) {
fail("Process ($command) exited with code ${process.exitValue()}: ${errorOut.await()}")
}
}