Add heap-dumps collection to BaseGradleIT.kt for TC investigations

Disable in daemon tests that checks defaults of -XX:MaxMetaspaceSize as
it looks like settings any jvm options reset defaults.
This commit is contained in:
Nikolay Krasko
2021-03-11 12:49:57 +03:00
committed by TeamCityServer
parent 48f2db51d2
commit da6440c59e
2 changed files with 58 additions and 6 deletions
@@ -157,7 +157,7 @@ abstract class BaseGradleIT {
// enableFeaturePreview("GRADLE_METADATA") is no longer needed when building with Gradle 5.4 or above
if (GradleVersion.version(wrapperVersion) >= GradleVersion.version("5.4")) {
settingsScript.apply {
if(exists()) {
if (exists()) {
modify {
it.replace("enableFeaturePreview('GRADLE_METADATA')", "//")
}
@@ -249,7 +249,8 @@ abstract class BaseGradleIT {
val projectName: String,
val gradleVersionRequirement: GradleVersionRequired = defaultGradleVersion,
directoryPrefix: String? = null,
val minLogLevel: LogLevel = LogLevel.DEBUG
val minLogLevel: LogLevel = LogLevel.DEBUG,
val addHeapDumpOptions: Boolean = true
) {
internal val testCase = this@BaseGradleIT
@@ -258,8 +259,59 @@ abstract class BaseGradleIT {
val projectDir = File(workingDir.canonicalFile, projectName)
open fun setupWorkingDir() {
if (!projectDir.isDirectory || projectDir.listFiles().isEmpty())
if (!projectDir.isDirectory || projectDir.listFiles().isEmpty()) {
copyRecursively(this.resourcesRoot, workingDir)
if (addHeapDumpOptions) {
addHeapDumpOptionsToPropertiesFile()
}
}
}
private fun addHeapDumpOptionsToPropertiesFile() {
val propertiesFile = File(projectDir, "gradle.properties")
propertiesFile.createNewFile()
val heapDumpOutOfErrorStr = "-XX:+HeapDumpOnOutOfMemoryError"
val heapDumpPathStr = "-XX:HeapDumpPath=\"${System.getProperty("user.dir")}${File.separatorChar}build\""
val gradlePropertiesText = propertiesFile.readText()
val presentJvmArgsLine = gradlePropertiesText
.lines()
.singleOrNull { it.contains("org.gradle.jvmargs") } // Can't write back if there are several lines with jvmargs
val updated: Boolean
val updatedJvmArgsLine = if (presentJvmArgsLine == null) {
updated = true
"org.gradle.jvmargs=$heapDumpOutOfErrorStr $heapDumpPathStr"
} else {
val options = buildString {
if (!presentJvmArgsLine.contains("HeapDumpOnOutOfMemoryError")) {
append(" $heapDumpOutOfErrorStr")
}
if (!presentJvmArgsLine.contains("HeapDumpPath")) {
append(" $heapDumpPathStr")
}
}
if (options.isEmpty()) {
// All options are already present
updated = false
presentJvmArgsLine
} else {
updated = true
"$presentJvmArgsLine$options"
}
}
if (!updated) {
return
}
val lines = listOf("# modified in addHeapDumpOptionsToPropertiesFile", updatedJvmArgsLine) +
gradlePropertiesText.lines().filter { !it.contains("org.gradle.jvmargs") }
propertiesFile.writeText(lines.joinToString(separator = "\n"))
}
fun relativize(files: Iterable<File>): List<String> =
@@ -45,7 +45,7 @@ class ExecutionStrategyJvmIT : ExecutionStrategyIT() {
abstract class ExecutionStrategyIT : BaseGradleIT() {
@Test
fun testDaemon() {
doTestExecutionStrategy("daemon")
doTestExecutionStrategy("daemon", addHeapDumpOptions = false)
}
@Test
@@ -58,8 +58,8 @@ abstract class ExecutionStrategyIT : BaseGradleIT() {
doTestExecutionStrategy("out-of-process")
}
private fun doTestExecutionStrategy(executionStrategy: String) {
val project = Project("kotlinBuiltins")
private fun doTestExecutionStrategy(executionStrategy: String, addHeapDumpOptions: Boolean = true) {
val project = Project("kotlinBuiltins", addHeapDumpOptions = addHeapDumpOptions)
setupProject(project)
val strategyCLIArg = "-Dkotlin.compiler.execution.strategy=$executionStrategy"