diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/IdeaSystemPropertiesForParallelRunConfigurator.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/IdeaSystemPropertiesForParallelRunConfigurator.kt new file mode 100644 index 00000000000..da45a1510f4 --- /dev/null +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/IdeaSystemPropertiesForParallelRunConfigurator.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.test + +import com.intellij.openapi.application.PathManager.PROPERTY_CONFIG_PATH +import com.intellij.openapi.application.PathManager.PROPERTY_SYSTEM_PATH +import com.intellij.openapi.util.io.FileUtil +import java.io.File + +// It's important that this is not created per test, but rather per process. +object IdeaSystemPropertiesForParallelRunConfigurator { + private val GRADLE_WORKER = System.getProperty("org.gradle.test.worker") ?: "" + //TODO: try to remove folder on jvm shutdown (there are some flashing test with deleteOnExit = true) + private val PROCESS_TMP_ROOT_FOLDER = + FileUtil.createTempDirectory(File(System.getProperty("java.io.tmpdir")), "testRoot", GRADLE_WORKER, false).path + private val IDEA_SYSTEM = FileUtil.createTempDirectory(File(PROCESS_TMP_ROOT_FOLDER), "idea-system", "", false).path + private val IDEA_CONFIG = FileUtil.createTempDirectory(File(PROCESS_TMP_ROOT_FOLDER), "idea-config", "", false).path + + init { + // UsefulTestCase temp dir construction could cause folder clash on parallel test execution: + // myTempDir = new File(ORIGINAL_TEMP_DIR, TEMP_DIR_MARKER + testName).getPath(); + // So we need to substitute "java.io.tmpdir" system property to avoid such clashing across different processes. + // IDEA PR: https://github.com/JetBrains/intellij-community/pull/1120 + System.setProperty("java.io.tmpdir", PROCESS_TMP_ROOT_FOLDER) + System.setProperty(PROPERTY_SYSTEM_PATH, IDEA_SYSTEM) + System.setProperty(PROPERTY_CONFIG_PATH, IDEA_CONFIG) + } + + @JvmStatic + fun setProperties() { + //TODO: maybe add check for actual folders + } +} \ No newline at end of file diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/JUnit3RunnerWithInners.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/JUnit3RunnerWithInners.java index c66c1dcc312..805c41ce194 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/JUnit3RunnerWithInners.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/JUnit3RunnerWithInners.java @@ -33,7 +33,7 @@ import java.lang.reflect.Modifier; public class JUnit3RunnerWithInners extends Runner implements Filterable, Sortable { static { - KotlinTestUtils.setIdeaSystemPathProperties(); + IdeaSystemPropertiesForParallelRunConfigurator.setProperties(); } private final Runner delegateRunner; diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index 95ff1f8eb8f..4660630722b 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -115,19 +115,6 @@ public class KotlinTestUtils { private static final List filesToDelete = new ArrayList<>(); - // It's important that this is not created per test, but rather per process. - public static final String IDEA_SYSTEM_PATH; - - static { - try { - IDEA_SYSTEM_PATH = FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), "idea-system", "", false).getPath(); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - - /** * Syntax: * @@ -1324,9 +1311,4 @@ public class KotlinTestUtils { // Several extension if name contains another dot return name.indexOf('.', firstDotIndex + 1) != -1; } - - public static void setIdeaSystemPathProperties() { - System.setProperty(PROPERTY_SYSTEM_PATH, IDEA_SYSTEM_PATH); - System.setProperty(PROPERTY_CONFIG_PATH, IDEA_SYSTEM_PATH + "/config"); - } } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java index d73c084a68b..629ef0f9fee 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java @@ -41,6 +41,8 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.test.IdeaSystemPropertiesForParallelRunConfigurator; +import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.testFramework.MockComponentManagerCreationTracer; import org.jetbrains.kotlin.types.FlexibleTypeImpl; import org.jetbrains.kotlin.utils.ExceptionUtilsKt; @@ -67,6 +69,7 @@ public abstract class KtUsefulTestCase extends TestCase { private Application application; static { + IdeaSystemPropertiesForParallelRunConfigurator.setProperties(); Logger.setFactory(TestLoggerFactory.class); }