Move parallelization utils to separate file, set test root for each process

This commit is contained in:
Mikhael Bogdanov
2019-04-13 20:34:28 +02:00
parent c6d177b467
commit 51bc979edb
4 changed files with 40 additions and 19 deletions
@@ -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
}
}
@@ -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;
@@ -115,19 +115,6 @@ public class KotlinTestUtils {
private static final List<File> 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");
}
}
@@ -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);
}