Fix Daemon compiler tests on Windows
In 202 platform tearDown tries to remove temporary directory, but this fails on Windows, because while Daemon is active directory can't be deleted.
This commit is contained in:
+5
-20
@@ -16,23 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jps.build
|
package org.jetbrains.kotlin.jps.build
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
|
||||||
import org.jetbrains.jps.builders.CompileScopeTestBuilder
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
|
||||||
import org.jetbrains.jps.builders.JpsBuildTestCase
|
import org.jetbrains.jps.builders.JpsBuildTestCase
|
||||||
import org.jetbrains.jps.builders.logging.BuildLoggingManager
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
||||||
import org.jetbrains.kotlin.config.LanguageVersion
|
import org.jetbrains.kotlin.config.LanguageVersion
|
||||||
import kotlin.reflect.KMutableProperty1
|
|
||||||
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS
|
|
||||||
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_ENABLED_PROPERTY
|
|
||||||
import org.jetbrains.kotlin.daemon.common.isDaemonEnabled
|
import org.jetbrains.kotlin.daemon.common.isDaemonEnabled
|
||||||
import org.jetbrains.kotlin.incremental.LookupSymbol
|
|
||||||
import org.jetbrains.kotlin.jps.build.fixtures.EnableICFixture
|
import org.jetbrains.kotlin.jps.build.fixtures.EnableICFixture
|
||||||
import org.jetbrains.kotlin.jps.model.kotlinCommonCompilerArguments
|
import org.jetbrains.kotlin.jps.model.kotlinCommonCompilerArguments
|
||||||
import org.jetbrains.kotlin.jps.model.kotlinCompilerArguments
|
import org.jetbrains.kotlin.jps.model.kotlinCompilerArguments
|
||||||
import org.junit.Assert
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import kotlin.reflect.KMutableProperty1
|
||||||
|
|
||||||
class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
||||||
private val enableICFixture = EnableICFixture()
|
private val enableICFixture = EnableICFixture()
|
||||||
@@ -77,19 +70,11 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
|||||||
assertCompiled(KotlinBuilder.KOTLIN_BUILDER_NAME, "src/main.kt", "src/Foo.kt")
|
assertCompiled(KotlinBuilder.KOTLIN_BUILDER_NAME, "src/main.kt", "src/Foo.kt")
|
||||||
}
|
}
|
||||||
|
|
||||||
val daemonHome = FileUtil.createTempDirectory("daemon-home", "testJpsDaemonIC")
|
withDaemon {
|
||||||
try {
|
withSystemProperty(JpsKotlinCompilerRunner.FAIL_ON_FALLBACK_PROPERTY, "true") {
|
||||||
withSystemProperty(COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS, daemonHome.absolutePath) {
|
testImpl()
|
||||||
withSystemProperty(COMPILE_DAEMON_ENABLED_PROPERTY, "true") {
|
|
||||||
withSystemProperty(JpsKotlinCompilerRunner.FAIL_ON_FALLBACK_PROPERTY, "true") {
|
|
||||||
testImpl()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
daemonHome.deleteRecursively()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testManyFiles() {
|
fun testManyFiles() {
|
||||||
|
|||||||
+6
-10
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jps.build
|
package org.jetbrains.kotlin.jps.build
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
|
||||||
import com.intellij.util.PathUtil
|
import com.intellij.util.PathUtil
|
||||||
import org.jetbrains.jps.model.java.JpsJavaExtensionService
|
import org.jetbrains.jps.model.java.JpsJavaExtensionService
|
||||||
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
||||||
import org.jetbrains.kotlin.daemon.common.*
|
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY
|
||||||
|
import org.jetbrains.kotlin.daemon.common.OSKind
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -68,14 +68,10 @@ class SimpleKotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
|
|
||||||
// TODO: add JS tests
|
// TODO: add JS tests
|
||||||
fun testDaemon() {
|
fun testDaemon() {
|
||||||
val daemonHome = FileUtil.createTempDirectory("daemon-home", "testJpsDaemonIC")
|
withDaemon {
|
||||||
|
withSystemProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "true") {
|
||||||
withSystemProperty(COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS, daemonHome.absolutePath) {
|
withSystemProperty(JpsKotlinCompilerRunner.FAIL_ON_FALLBACK_PROPERTY, "true") {
|
||||||
withSystemProperty(COMPILE_DAEMON_ENABLED_PROPERTY, "true") {
|
testLoadingKotlinFromDifferentModules()
|
||||||
withSystemProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "true") {
|
|
||||||
withSystemProperty(JpsKotlinCompilerRunner.FAIL_ON_FALLBACK_PROPERTY, "true") {
|
|
||||||
testLoadingKotlinFromDifferentModules()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jps.build
|
package org.jetbrains.kotlin.jps.build
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
||||||
|
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS
|
||||||
|
import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_ENABLED_PROPERTY
|
||||||
|
|
||||||
inline fun withSystemProperty(property: String, newValue: String?, fn: ()->Unit) {
|
inline fun withSystemProperty(property: String, newValue: String?, fn: ()->Unit) {
|
||||||
val backup = System.getProperty(property)
|
val backup = System.getProperty(property)
|
||||||
setOrClearSysProperty(property, newValue)
|
setOrClearSysProperty(property, newValue)
|
||||||
@@ -38,3 +43,32 @@ inline fun setOrClearSysProperty(property: String, newValue: String?) {
|
|||||||
System.clearProperty(property)
|
System.clearProperty(property)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun withDaemon(fn: () -> Unit) {
|
||||||
|
val daemonHome = FileUtil.createTempDirectory("daemon-home", "testJpsDaemonIC")
|
||||||
|
|
||||||
|
withSystemProperty(COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS, daemonHome.absolutePath) {
|
||||||
|
withSystemProperty(COMPILE_DAEMON_ENABLED_PROPERTY, "true") {
|
||||||
|
try {
|
||||||
|
fn()
|
||||||
|
} finally {
|
||||||
|
JpsKotlinCompilerRunner.shutdownDaemon()
|
||||||
|
|
||||||
|
// Try to force directory deletion to prevent test failure later in tearDown().
|
||||||
|
// Working Daemon can prevent folder deletion on Windows, because Daemon shutdown
|
||||||
|
// is asynchronous.
|
||||||
|
var attempts = 0
|
||||||
|
daemonHome.deleteRecursively()
|
||||||
|
while (daemonHome.exists() && attempts < 100) {
|
||||||
|
daemonHome.deleteRecursively()
|
||||||
|
attempts++
|
||||||
|
Thread.sleep(50)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (daemonHome.exists()) {
|
||||||
|
error("Couldn't delete Daemon home directory")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,6 +54,16 @@ class JpsKotlinCompilerRunner {
|
|||||||
private var _jpsCompileServiceSession: CompileServiceSession? = null
|
private var _jpsCompileServiceSession: CompileServiceSession? = null
|
||||||
|
|
||||||
@TestOnly
|
@TestOnly
|
||||||
|
fun shutdownDaemon() {
|
||||||
|
_jpsCompileServiceSession?.let {
|
||||||
|
try {
|
||||||
|
it.compileService.shutdown()
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_jpsCompileServiceSession = null
|
||||||
|
}
|
||||||
|
|
||||||
fun releaseCompileServiceSession() {
|
fun releaseCompileServiceSession() {
|
||||||
_jpsCompileServiceSession?.let {
|
_jpsCompileServiceSession?.let {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user