Skip to content

Commit e1457ff

Browse files
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.
1 parent 2fa8a11 commit e1457ff

File tree

1 file changed

+11
-0
lines changed
  • libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle

1 file changed

+11
-0
lines changed

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ abstract class BaseGradleIT {
5353
// gradle wrapper version to wrapper directory
5454
private val gradleWrappers = hashMapOf<String, File>()
5555
private const val MAX_DAEMON_RUNS = 30
56+
private const val MAX_ACTIVE_GRADLE_PROCESSES = 1
5657

5758
private fun getEnvJDK_18() = System.getenv()["JDK_18"]
5859

@@ -82,6 +83,16 @@ abstract class BaseGradleIT {
8283
): File {
8384
val wrapperDir = gradleWrappers.getOrPut(version) { createNewWrapperDir(version) }
8485

86+
// Even if gradle is run with --no-daemon, we should check,
87+
// that common active process count does not exceed the threshold,
88+
// to avoid retaining too much memory (which is critical for CI)
89+
val activeDaemonsCount = daemonRunCount.keys.size
90+
val nonDaemonCount = if (!withDaemon) 1 else 0
91+
if (activeDaemonsCount + nonDaemonCount > MAX_ACTIVE_GRADLE_PROCESSES) {
92+
println("Too many Gradle active processes (max is $MAX_ACTIVE_GRADLE_PROCESSES). Stopping all daemons")
93+
stopAllDaemons(environmentVariables)
94+
}
95+
8596
if (withDaemon) {
8697
val timesDaemonUsed = daemonRunCount[version] ?: 0
8798
if (timesDaemonUsed >= MAX_DAEMON_RUNS) {

0 commit comments

Comments
 (0)