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) {