From e1457ffea09be865ad8016d947e358968a6352f7 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Sat, 27 May 2017 20:37:45 +0300 Subject: [PATCH] Limit max number of active Gradle processes for the test run This is needed to avoid retaining memory by each Gradle version which is critical for running tests on CI server. --- .../org/jetbrains/kotlin/gradle/BaseGradleIT.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt index e849e996b03..5e3b2249e90 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt @@ -53,6 +53,7 @@ abstract class BaseGradleIT { // gradle wrapper version to wrapper directory private val gradleWrappers = hashMapOf() private const val MAX_DAEMON_RUNS = 30 + private const val MAX_ACTIVE_GRADLE_PROCESSES = 1 private fun getEnvJDK_18() = System.getenv()["JDK_18"] @@ -82,6 +83,16 @@ abstract class BaseGradleIT { ): File { val wrapperDir = gradleWrappers.getOrPut(version) { createNewWrapperDir(version) } + // Even if gradle is run with --no-daemon, we should check, + // that common active process count does not exceed the threshold, + // to avoid retaining too much memory (which is critical for CI) + val activeDaemonsCount = daemonRunCount.keys.size + val nonDaemonCount = if (!withDaemon) 1 else 0 + if (activeDaemonsCount + nonDaemonCount > MAX_ACTIVE_GRADLE_PROCESSES) { + println("Too many Gradle active processes (max is $MAX_ACTIVE_GRADLE_PROCESSES). Stopping all daemons") + stopAllDaemons(environmentVariables) + } + if (withDaemon) { val timesDaemonUsed = daemonRunCount[version] ?: 0 if (timesDaemonUsed >= MAX_DAEMON_RUNS) {