From f42a589ddce77b58e3d03161b64818597ff5e454 Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Mon, 17 Aug 2015 22:00:17 +0300 Subject: [PATCH] enable testKotlinOnlyDaemonMemory --- .../kotlin/gradle/KotlinGradlePluginIT.kt | 53 +++++++++++-------- .../testProject/kotlinProject/build.gradle | 4 ++ 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt index 851faa80ea9..9daf4f582c6 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt @@ -1,8 +1,6 @@ package org.jetbrains.kotlin.gradle -import org.gradle.api.logging.LogLevel import org.jetbrains.kotlin.gradle.BaseGradleIT.Project -import org.junit.Ignore import org.junit.Test class KotlinGradleIT: BaseGradleIT() { @@ -37,31 +35,42 @@ class KotlinGradleIT: BaseGradleIT() { } } - // This test isn't safe enough: gradle daemon is a singleton process (for a chosen version) and stopping it may - // affect the build environment in an unpredictable way. Therefore it is now disabled. - // TODO research the possibility to run isolated daemon build - Ignore Test fun testKotlinOnlyDaemonMemory() { + // For corresponding documentation, see https://docs.gradle.org/current/userguide/gradle_daemon.html + // Setting user.variant to different value implies a new daemon process will be created. + // In order to stop daemon process, special exit task is used ( System.exit(0) ). + Test fun testKotlinOnlyDaemonMemory() { val project = Project("kotlinProject", "2.4") + val VARIANT_CONSTANT = "ForTest" + val userVariantArg = "-Duser.variant=$VARIANT_CONSTANT" - project.stopDaemon {} - - // build to "warm up" the daemon, if it is not started yet - project.build("build", options = BaseGradleIT.BuildOptions(withDaemon = true)) { - assertSuccessful() - } - - for (i in 1..3) { - project.build("build", options = BaseGradleIT.BuildOptions(withDaemon = true)) { - assertSuccessful() - val matches = "\\[PERF\\] Used memory after build: (\\d+) kb \\(([+-]?\\d+) kb\\)".toRegex().match(output) - assert(matches != null && matches.groups.size() == 3, "Used memory after build is not reported by plugin") - val reportedGrowth = matches!!.groups.get(2)!!.value.toInt() - assert(reportedGrowth <= 500, "Used memory growth $reportedGrowth > 500") + fun exitTestDaemon() { + project.build(userVariantArg, "exit", options = BaseGradleIT.BuildOptions(withDaemon = true)) { + assertFailed() + assertContains("The daemon has exited normally or was terminated in response to a user interrupt.") } } - project.stopDaemon { - assertSuccessful() + exitTestDaemon() + + try { + // build to "warm up" the daemon, if it is not started yet + project.build(userVariantArg, "build", options = BaseGradleIT.BuildOptions(withDaemon = true)) { + assertSuccessful() + } + + for (i in 1..3) { + project.build(userVariantArg, "build", options = BaseGradleIT.BuildOptions(withDaemon = true)) { + assertSuccessful() + val matches = "\\[PERF\\] Used memory after build: (\\d+) kb \\(([+-]?\\d+) kb\\)".toRegex().match(output) + assert(matches != null && matches.groups.size() == 3, "Used memory after build is not reported by plugin") + val reportedGrowth = matches!!.groups.get(2)!!.value.removePrefix("+").toInt() + assert(reportedGrowth <= 700, "Used memory growth $reportedGrowth > 700") + } + } + + } + finally { + exitTestDaemon() } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinProject/build.gradle b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinProject/build.gradle index db2fe7e0341..66e939cad54 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinProject/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinProject/build.gradle @@ -43,3 +43,7 @@ compileKotlin { task wrapper(type: Wrapper) { gradleVersion="1.4" } + +task exit << { + System.exit(0) +}