From 43e7b0425d42f657d5f3a5a5bcd24d6d3729dc45 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 5 Jun 2018 18:30:01 +0300 Subject: [PATCH] Test: move Gradle daemon memory test to separate class --- .../kotlin/gradle/GradleDaemonMemoryIT.kt | 69 +++++++++++++++++++ .../kotlin/gradle/KotlinGradlePluginIT.kt | 58 ---------------- 2 files changed, 69 insertions(+), 58 deletions(-) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/GradleDaemonMemoryIT.kt diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/GradleDaemonMemoryIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/GradleDaemonMemoryIT.kt new file mode 100644 index 00000000000..4923f2325db --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/GradleDaemonMemoryIT.kt @@ -0,0 +1,69 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle + +import org.junit.Test +import kotlin.test.assertTrue + +class GradleDaemonMemoryIT : BaseGradleIT() { + // 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 testGradleDaemonMemory() { + val project = Project("kotlinProject") + val VARIANT_CONSTANT = "ForTest" + val userVariantArg = "-Duser.variant=$VARIANT_CONSTANT" + val MEMORY_MAX_GROWTH_LIMIT_KB = 500 + val BUILD_COUNT = 15 + val reportMemoryUsage = "-Dkotlin.gradle.test.report.memory.usage=true" + val options = BaseGradleIT.BuildOptions(withDaemon = true) + + fun exitTestDaemon() { + project.build(userVariantArg, reportMemoryUsage, "exit", options = options) { + assertFailed() + assertContains("The daemon has exited normally or was terminated in response to a user interrupt.") + } + } + + fun buildAndGetMemoryAfterBuild(): Int { + var reportedMemory: Int? = null + + project.build(userVariantArg, reportMemoryUsage, "clean", "build", options = options) { + assertSuccessful() + val matches = "\\[KOTLIN\\]\\[PERF\\] Used memory after build: (\\d+) kb \\(difference since build start: ([+-]?\\d+) kb\\)" + .toRegex().find(output) + assert(matches != null && matches.groups.size == 3) { "Used memory after build is not reported by plugin" } + reportedMemory = matches!!.groupValues[1].toInt() + } + + return reportedMemory!! + } + + exitTestDaemon() + + try { + val usedMemory = (1..BUILD_COUNT).map { buildAndGetMemoryAfterBuild() } + + // ensure that the maximum of the used memory established after several first builds doesn't raise significantly in the subsequent builds + val establishedMaximum = usedMemory.take(5).max()!! + val totalMaximum = usedMemory.max()!! + + val maxGrowth = totalMaximum - establishedMaximum + assertTrue( + maxGrowth <= MEMORY_MAX_GROWTH_LIMIT_KB, + "Maximum used memory over series of builds growth $maxGrowth (from $establishedMaximum to $totalMaximum) kb > $MEMORY_MAX_GROWTH_LIMIT_KB kb" + ) + + // testing that nothing remains locked by daemon, see KT-9440 + project.build(userVariantArg, "clean", options = BaseGradleIT.BuildOptions(withDaemon = true)) { + assertSuccessful() + } + } finally { + exitTestDaemon() + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt index 5353fa213df..a89ddc6e711 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt @@ -92,64 +92,6 @@ class KotlinGradleIT : BaseGradleIT() { } } - // 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") - val VARIANT_CONSTANT = "ForTest" - val userVariantArg = "-Duser.variant=$VARIANT_CONSTANT" - val MEMORY_MAX_GROWTH_LIMIT_KB = 500 - val BUILD_COUNT = 15 - val reportMemoryUsage = "-Dkotlin.gradle.test.report.memory.usage=true" - val options = BaseGradleIT.BuildOptions(withDaemon = true) - - fun exitTestDaemon() { - project.build(userVariantArg, reportMemoryUsage, "exit", options = options) { - assertFailed() - assertContains("The daemon has exited normally or was terminated in response to a user interrupt.") - } - } - - fun buildAndGetMemoryAfterBuild(): Int { - var reportedMemory: Int? = null - - project.build(userVariantArg, reportMemoryUsage, "clean", "build", options = options) { - assertSuccessful() - val matches = "\\[KOTLIN\\]\\[PERF\\] Used memory after build: (\\d+) kb \\(difference since build start: ([+-]?\\d+) kb\\)" - .toRegex().find(output) - assert(matches != null && matches.groups.size == 3) { "Used memory after build is not reported by plugin" } - reportedMemory = matches!!.groupValues[1].toInt() - } - - return reportedMemory!! - } - - exitTestDaemon() - - try { - val usedMemory = (1..BUILD_COUNT).map { buildAndGetMemoryAfterBuild() } - - // ensure that the maximum of the used memory established after several first builds doesn't raise significantly in the subsequent builds - val establishedMaximum = usedMemory.take(5).max()!! - val totalMaximum = usedMemory.max()!! - - val maxGrowth = totalMaximum - establishedMaximum - assertTrue( - maxGrowth <= MEMORY_MAX_GROWTH_LIMIT_KB, - "Maximum used memory over series of builds growth $maxGrowth (from $establishedMaximum to $totalMaximum) kb > $MEMORY_MAX_GROWTH_LIMIT_KB kb" - ) - - // testing that nothing remains locked by daemon, see KT-9440 - project.build(userVariantArg, "clean", options = BaseGradleIT.BuildOptions(withDaemon = true)) { - assertSuccessful() - } - } finally { - exitTestDaemon() - } - } - @Test fun testLogLevelForceGC() { val debugProject = Project("simpleProject", minLogLevel = LogLevel.LIFECYCLE)