From 61570fc4b8ad5e683da82676a6dafe4dee9afde6 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Tue, 25 Apr 2017 17:16:01 +0200 Subject: [PATCH] Improve daemon client diagnostic and run failure detection Removing prefiltering of the daemon client reporting - filtering should be performed on the receiver site. And put daemon process output during executioninto INFO category. May make daemon usage more talkative, but will not eat important error messages anymore. Add test with failure condition. Also failed daemon start should not cause timeout anymore. --- .../daemon/client/KotlinCompilerClient.kt | 7 ++++--- .../kotlin/daemon/CompilerDaemonTest.kt | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt index 8801f708583..efdcf2f18cd 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt @@ -339,7 +339,6 @@ object KotlinCompilerClient { } private fun DaemonReportingTargets.report(category: DaemonReportCategory, message: String, source: String = "daemon client") { - if (category == DaemonReportCategory.DEBUG && !verboseReporting) return out?.println("[$source] ${category.name}: $message") messages?.add(DaemonReportMessage(category, "[$source] $message")) messageCollector?.let { @@ -421,19 +420,21 @@ object KotlinCompilerClient { daemon.inputStream .reader() .forEachLine { - reportingTargets.report(DaemonReportCategory.DEBUG, it, "daemon") - if (it == COMPILE_DAEMON_IS_READY_MESSAGE) { reportingTargets.report(DaemonReportCategory.DEBUG, "Received the message signalling that the daemon is ready") isEchoRead.release() return@forEachLine } + else { + reportingTargets.report(DaemonReportCategory.INFO, it, "daemon") + } } } finally { daemon.inputStream.close() daemon.outputStream.close() daemon.errorStream.close() + isEchoRead.release() } } try { diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt index 5777cc9ed96..110d4abb491 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt @@ -208,6 +208,26 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { } } + fun testDaemonRunError() { + withFlagFile(getTestName(true), ".alive") { flagFile -> + val daemonOptions = DaemonOptions(shutdownDelayMilliseconds = 1, verbose = true, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + + KotlinCompilerClient.shutdownCompileService(compilerId, daemonOptions) + + val daemonJVMOptions = configureDaemonJVMOptions("-abracadabra", inheritMemoryLimits = false, inheritAdditionalProperties = false) + + val messageCollector = TestMessageCollector() + + val daemon = KotlinCompilerClient.connectToCompileService(compilerId, flagFile, daemonJVMOptions, daemonOptions, + DaemonReportingTargets(messageCollector = messageCollector), autostart = true) + + assertNull(daemon) + + assertTrue("Expecting error message, actual:\n${messageCollector.messages.joinToString("\n") { it.message }}", + messageCollector.messages.any { it.message == "Unrecognized option: --abracadabra" }) + } + } + fun testDaemonAutoshutdownOnUnused() { withFlagFile(getTestName(true), ".alive") { flagFile -> val daemonOptions = DaemonOptions(autoshutdownUnusedSeconds = 1, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath)