Refactoring test base class to support gradle options and daemon stopping, implementing daemon build test with memory check
(cherry picked from commit a28ce9e)
This commit is contained in:
+39
-7
@@ -27,18 +27,43 @@ abstract class BaseGradleIT {
|
|||||||
deleteRecursively(workingDir)
|
deleteRecursively(workingDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class BuildOptions(val withDaemon: Boolean = false)
|
||||||
|
|
||||||
class Project(val projectName: String, val wrapperVersion: String = "1.4", val minLogLevel: LogLevel = LogLevel.DEBUG)
|
class Project(val projectName: String, val wrapperVersion: String = "1.4", val minLogLevel: LogLevel = LogLevel.DEBUG)
|
||||||
|
|
||||||
class CompiledProject(val project: Project, val output: String, val resultCode: Int)
|
class CompiledProject(val project: Project, val output: String, val resultCode: Int)
|
||||||
|
|
||||||
fun Project.build(vararg tasks: String, check: CompiledProject.() -> Unit) {
|
fun Project.setupWorkingDir() {
|
||||||
copyRecursively(File(resourcesRootFile, "testProject/$projectName"), workingDir)
|
copyRecursively(File(resourcesRootFile, "testProject/$projectName"), workingDir)
|
||||||
val projectDir = File(workingDir, projectName)
|
copyDirRecursively(File(resourcesRootFile, "GradleWrapper-$wrapperVersion"), File(workingDir, projectName))
|
||||||
copyDirRecursively(File(resourcesRootFile, "GradleWrapper-$wrapperVersion"), projectDir)
|
}
|
||||||
val cmd = createCommand(tasks)
|
|
||||||
|
fun Project.build(vararg tasks: String, options: BuildOptions = BuildOptions(), check: CompiledProject.() -> Unit) {
|
||||||
|
val cmd = createBuildCommand(tasks, options)
|
||||||
|
|
||||||
println("<=== Test build: ${this.projectName} $cmd ===>")
|
println("<=== Test build: ${this.projectName} $cmd ===>")
|
||||||
|
|
||||||
|
runAndCheck(cmd, check)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopDaemon(ver: String) {
|
||||||
|
val wrapperDir = File(resourcesRootFile, "GradleWrapper-$ver")
|
||||||
|
val cmd = createGradleCommand(arrayListOf("-stop"))
|
||||||
|
createProcess(cmd, wrapperDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Project.stopDaemon(check: CompiledProject.() -> Unit) {
|
||||||
|
val cmd = createGradleCommand(arrayListOf("-stop"))
|
||||||
|
println("<=== Stop daemon: $cmd ===>")
|
||||||
|
|
||||||
|
runAndCheck(cmd, check)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Project.runAndCheck(cmd: List<String>, check: CompiledProject.() -> Unit) {
|
||||||
|
val projectDir = File(workingDir, projectName)
|
||||||
|
if (!projectDir.exists())
|
||||||
|
setupWorkingDir()
|
||||||
|
|
||||||
val process = createProcess(cmd, projectDir)
|
val process = createProcess(cmd, projectDir)
|
||||||
|
|
||||||
val (output, resultCode) = readOutput(process)
|
val (output, resultCode) = readOutput(process)
|
||||||
@@ -94,14 +119,21 @@ abstract class BaseGradleIT {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Project.createCommand(params: Array<out String>): List<String> {
|
private fun Project.createBuildCommand(params: Array<out String>, options: BuildOptions): List<String> {
|
||||||
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").getAbsolutePath()
|
val pathToKotlinPlugin = "-PpathToKotlinPlugin=" + File("local-repo").getAbsolutePath()
|
||||||
val tailParameters = params.asList() +
|
val tailParameters = params.asList() +
|
||||||
listOf(pathToKotlinPlugin, "--no-daemon", "--${minLogLevel.name().toLowerCase()}", "-Pkotlin.gradle.test=true")
|
listOf( pathToKotlinPlugin,
|
||||||
|
if (options.withDaemon) "--daemon" else "--no-daemon",
|
||||||
|
"--${minLogLevel.name().toLowerCase()}",
|
||||||
|
"-Pkotlin.gradle.test=true")
|
||||||
|
|
||||||
|
return createGradleCommand(tailParameters)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createGradleCommand(tailParameters: List<String>): List<String> {
|
||||||
return if (isWindows())
|
return if (isWindows())
|
||||||
listOf("cmd", "/C", "gradlew.bat") + tailParameters
|
listOf("cmd", "/C", "gradlew.bat") + tailParameters
|
||||||
else
|
else
|
||||||
listOf("/bin/bash", "./gradlew") + tailParameters
|
listOf("/bin/bash", "./gradlew") + tailParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-2
@@ -1,7 +1,8 @@
|
|||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
import org.junit.Test
|
import org.gradle.api.logging.LogLevel
|
||||||
import org.jetbrains.kotlin.gradle.BaseGradleIT.Project
|
import org.jetbrains.kotlin.gradle.BaseGradleIT.Project
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
class KotlinGradleIT: BaseGradleIT() {
|
class KotlinGradleIT: BaseGradleIT() {
|
||||||
|
|
||||||
@@ -35,6 +36,29 @@ class KotlinGradleIT: BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Test fun testKotlinOnlyDaemonMemory() {
|
||||||
|
val project = Project("kotlinProject", "2.4", minLogLevel = LogLevel.DEBUG)
|
||||||
|
|
||||||
|
project.stopDaemon {}
|
||||||
|
|
||||||
|
project.build("build", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i in 1..3)
|
||||||
|
project.build("build", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
||||||
|
assertSuccessful()
|
||||||
|
val matches = "\\[PERF\\] Used memory after build: (\\d+) kb \\(([+-]?\\d+) kb\\)".toRegex().match(output)
|
||||||
|
assert(matches != null && matches.groups.size() == 3, "Used memory after build is not reported by plugin")
|
||||||
|
val reportedGrowth = matches!!.groups.get(2)!!.value.toInt()
|
||||||
|
assert(reportedGrowth <= 1000, "Used memory growth $reportedGrowth > 1000")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.stopDaemon {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Test fun testKotlinClasspath() {
|
Test fun testKotlinClasspath() {
|
||||||
Project("classpathTest", "1.6").build("build") {
|
Project("classpathTest", "1.6").build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
@@ -107,5 +131,4 @@ class KotlinGradleIT: BaseGradleIT() {
|
|||||||
assertFileExists("build/classes/main/example/AncestorClassGenerated.class")
|
assertFileExists("build/classes/main/example/AncestorClassGenerated.class")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user