Test: turn off thread leaks assertion for android gradle tests
ThreadTracker compares active threads before and after compilation. In test mode if those sets are different, it was throwing an exception. By some reason that is not obviously linked with kotlin, the exception was thrown for every android test. As a temporary solution I added a property 'kotlin.gradle.test.assertThreadLeaks' that controls this assertion and turned it off for android tests only.
This commit is contained in:
+8
-8
@@ -1,22 +1,18 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.junit.Assert
|
||||
import java.util.HashSet
|
||||
import java.util.*
|
||||
|
||||
public class ThreadTracker {
|
||||
class ThreadTracker {
|
||||
val log = Logging.getLogger(this.javaClass)
|
||||
private var before: Collection<Thread>? = getThreads()
|
||||
|
||||
private fun getThreads(): Collection<Thread> = Thread.getAllStackTraces().keys
|
||||
|
||||
public fun checkThreadLeak(gradle: Gradle?) {
|
||||
fun checkThreadLeak(gradle: Gradle?) {
|
||||
try {
|
||||
val testThreads = gradle != null &&
|
||||
gradle.rootProject.hasProperty("kotlin.gradle.test") &&
|
||||
!gradle.rootProject.hasProperty("kotlin.gradle.noThreadTest")
|
||||
val testThreads = gradle != null && gradle.rootProject.hasProperty(ASSERT_THREAD_LEAKS_PROPERTY)
|
||||
|
||||
Thread.sleep(if (testThreads) 200L else 50L)
|
||||
|
||||
@@ -39,4 +35,8 @@ public class ThreadTracker {
|
||||
before = null
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ASSERT_THREAD_LEAKS_PROPERTY = "kotlin.gradle.test.assertThreadLeaks"
|
||||
}
|
||||
}
|
||||
+23
-12
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.gradle
|
||||
import com.google.common.io.Files
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.jetbrains.kotlin.gradle.plugin.ThreadTracker
|
||||
import org.jetbrains.kotlin.gradle.util.createGradleCommand
|
||||
import org.jetbrains.kotlin.gradle.util.runProcess
|
||||
import org.junit.After
|
||||
@@ -66,7 +67,14 @@ abstract class BaseGradleIT {
|
||||
}
|
||||
|
||||
// the second parameter is for using with ToolingAPI, that do not like --daemon/--no-daemon options at all
|
||||
data class BuildOptions(val withDaemon: Boolean = false, val daemonOptionSupported: Boolean = true)
|
||||
data class BuildOptions(
|
||||
val withDaemon: Boolean = false,
|
||||
val daemonOptionSupported: Boolean = true,
|
||||
/**
|
||||
* @see [ThreadTracker]
|
||||
*/
|
||||
val assertThreadLeaks: Boolean = true
|
||||
)
|
||||
|
||||
open inner class Project(val projectName: String, val wrapperVersion: String = "1.4", val minLogLevel: LogLevel = LogLevel.DEBUG) {
|
||||
open val resourcesRoot = File(resourcesRootFile, "testProject/$projectName")
|
||||
@@ -193,17 +201,20 @@ abstract class BaseGradleIT {
|
||||
private fun Project.createBuildCommand(params: Array<out String>, options: BuildOptions): List<String> =
|
||||
createGradleCommand(createGradleTailParameters(options, params))
|
||||
|
||||
protected fun Project.createGradleTailParameters(options: BuildOptions, params: Array<out String> = arrayOf()): List<String> =
|
||||
params.asList() +
|
||||
listOf("-PpathToKotlinPlugin=" + File("local-repo").absolutePath,
|
||||
if (options.daemonOptionSupported)
|
||||
if (options.withDaemon) "--daemon"
|
||||
else "--no-daemon"
|
||||
else null,
|
||||
"--stacktrace",
|
||||
"--${minLogLevel.name.toLowerCase()}",
|
||||
"-Pkotlin.gradle.test=true")
|
||||
.filterNotNull()
|
||||
protected fun Project.createGradleTailParameters(options: BuildOptions, tasks: Array<out String> = arrayOf()): List<String> =
|
||||
tasks.toMutableList().apply {
|
||||
add("--stacktrace")
|
||||
add("--${minLogLevel.name.toLowerCase()}")
|
||||
if (options.daemonOptionSupported) {
|
||||
add(if (options.withDaemon) "--daemon" else "--no-daemon")
|
||||
}
|
||||
|
||||
add("-PpathToKotlinPlugin=" + File("local-repo").absolutePath)
|
||||
if (options.assertThreadLeaks) {
|
||||
add("-P${ThreadTracker.ASSERT_THREAD_LEAKS_PROPERTY}=true")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun String.normalize() = this.lineSequence().joinToString(SYSTEM_LINE_SEPARATOR)
|
||||
|
||||
|
||||
+4
-2
@@ -1,12 +1,14 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.Ignore
|
||||
import org.jetbrains.kotlin.gradle.BaseGradleIT.Project
|
||||
import org.junit.Test
|
||||
|
||||
@Ignore("Requires Android SDK")
|
||||
class KotlinAndroidGradleIT: BaseGradleIT() {
|
||||
|
||||
override fun defaultBuildOptions() =
|
||||
BuildOptions(withDaemon = true, assertThreadLeaks = false)
|
||||
|
||||
@Test
|
||||
fun testSimpleCompile() {
|
||||
val project = Project("AndroidProject", "2.3")
|
||||
|
||||
Reference in New Issue
Block a user