Make gradle daemon thread leak test more thorough
Former test made the following assertion: for any of 3 sequent builds on the same gradle daemon the difference in used memory between build start and finish should not exceed 2500 kb. Current test makes the following assertion: the difference of used memory after first and last of 10 sequent builds on the same daemon should not exceed 200 kb.
This commit is contained in:
-1
@@ -21,7 +21,6 @@ import org.gradle.BuildAdapter
|
|||||||
import org.gradle.BuildResult
|
import org.gradle.BuildResult
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.logging.Logging
|
import org.gradle.api.logging.Logging
|
||||||
import java.util.concurrent.ScheduledExecutorService
|
|
||||||
|
|
||||||
|
|
||||||
private fun comparableVersionStr(version: String) =
|
private fun comparableVersionStr(version: String) =
|
||||||
|
|||||||
+18
-15
@@ -49,6 +49,7 @@ class KotlinGradleIT: BaseGradleIT() {
|
|||||||
val project = Project("kotlinProject", "2.4")
|
val project = Project("kotlinProject", "2.4")
|
||||||
val VARIANT_CONSTANT = "ForTest"
|
val VARIANT_CONSTANT = "ForTest"
|
||||||
val userVariantArg = "-Duser.variant=$VARIANT_CONSTANT"
|
val userVariantArg = "-Duser.variant=$VARIANT_CONSTANT"
|
||||||
|
val MEMORY_GROWTH_LIMIT_KB = 200
|
||||||
|
|
||||||
fun exitTestDaemon() {
|
fun exitTestDaemon() {
|
||||||
project.build(userVariantArg, "exit", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
project.build(userVariantArg, "exit", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
||||||
@@ -57,24 +58,26 @@ class KotlinGradleIT: BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun buildAndGetMemoryAfterBuild(): Int {
|
||||||
|
var reportedMemory: Int? = null
|
||||||
|
|
||||||
|
project.build(userVariantArg, "clean", "build", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
||||||
|
assertSuccessful()
|
||||||
|
val matches = "\\[PERF\\] Used memory after build: (\\d+) kb \\(difference since build start: ([+-]?\\d+) kb\\)".toRegex().find(output)
|
||||||
|
assert(matches != null && matches.groups.size == 3) { "Used memory after build is not reported by plugin" }
|
||||||
|
reportedMemory = matches!!.groupValues[1].toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
return reportedMemory!!
|
||||||
|
}
|
||||||
|
|
||||||
exitTestDaemon()
|
exitTestDaemon()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// build to "warm up" the daemon, if it is not started yet
|
val startMemory = buildAndGetMemoryAfterBuild()
|
||||||
project.build(userVariantArg, "build", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
val endMemory = (1..10).map { buildAndGetMemoryAfterBuild() }.last()
|
||||||
assertSuccessful()
|
val growth = endMemory - startMemory
|
||||||
}
|
assert(growth <= MEMORY_GROWTH_LIMIT_KB) { "Used memory growth $growth kb > $MEMORY_GROWTH_LIMIT_KB kb" }
|
||||||
|
|
||||||
for (i in 1..3) {
|
|
||||||
project.build(userVariantArg, "clean", "build", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
|
||||||
assertSuccessful()
|
|
||||||
val matches = "\\[PERF\\] Used memory after build: (\\d+) kb \\(difference since build start: ([+-]?\\d+) kb\\)".toRegex().find(output)
|
|
||||||
assert(matches != null && matches.groups.size == 3) { "Used memory after build is not reported by plugin on attempt $i" }
|
|
||||||
val reportedGrowth = matches!!.groups.get(2)!!.value.removePrefix("+").toInt()
|
|
||||||
val expectedGrowthLimit = 2500
|
|
||||||
assert(reportedGrowth <= expectedGrowthLimit) { "Used memory growth $reportedGrowth > $expectedGrowthLimit" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// testing that nothing remains locked by daemon, see KT-9440
|
// testing that nothing remains locked by daemon, see KT-9440
|
||||||
project.build(userVariantArg, "clean", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
project.build(userVariantArg, "clean", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user