Revert "Allow tests to be run in parallel."

This reverts commit 21d81f35
This commit is contained in:
Zalim Bashorov
2019-03-26 15:19:03 +03:00
parent 37de9a0a26
commit bdad3cace9
7 changed files with 43 additions and 31 deletions
-4
View File
@@ -3,10 +3,6 @@ import org.gradle.api.tasks.bundling.Jar
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
tasks.withType<Test> {
maxParallelForks = Math.max(Runtime.getRuntime().availableProcessors() / 2, 1)
}
plugins { plugins {
kotlin("jvm") kotlin("jvm")
id("jps-compatible") id("jps-compatible")
@@ -22,11 +22,7 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File import java.io.File
abstract class AbstractForeignAnnotationsNoAnnotationInClasspathTest : AbstractForeignAnnotationsTest() { abstract class AbstractForeignAnnotationsNoAnnotationInClasspathTest : AbstractForeignAnnotationsTest() {
// This should be executed after setUp runs, since setUp changes the root folder private val compiledJavaPath = KotlinTestUtils.tmpDir("java-compiled-files")
// for temporary files.
private val compiledJavaPath by lazy {
KotlinTestUtils.tmpDir("java-compiled-files")
}
override fun getExtraClasspath(): List<File> { override fun getExtraClasspath(): List<File> {
val foreignAnnotations = createJarWithForeignAnnotations() val foreignAnnotations = createJarWithForeignAnnotations()
@@ -43,6 +43,13 @@ public abstract class KotlinMultiFileTestWithJava<M, F> extends KtUsefulTestCase
coroutinesPackage = ""; coroutinesPackage = "";
} }
@Override
protected void tearDown() throws Exception {
if (javaFilesDir != null) FileUtil.delete(javaFilesDir);
if (kotlinSourceRoot != null) FileUtil.delete(kotlinSourceRoot);
super.tearDown();
}
public class ModuleAndDependencies { public class ModuleAndDependencies {
final M module; final M module;
final List<String> dependencies; final List<String> dependencies;
@@ -413,7 +413,9 @@ public class KotlinTestUtils {
@NotNull @NotNull
public static File tmpDirForTest(@NotNull String testClassName, @NotNull String testName) throws IOException { public static File tmpDirForTest(@NotNull String testClassName, @NotNull String testName) throws IOException {
return normalizeFile(FileUtil.createTempDirectory(testClassName, testName, false)); File answer = normalizeFile(FileUtil.createTempDirectory(testClassName, testName));
deleteOnShutdown(answer);
return answer;
} }
@NotNull @NotNull
@@ -423,7 +425,10 @@ public class KotlinTestUtils {
@NotNull @NotNull
public static File tmpDir(String name) throws IOException { public static File tmpDir(String name) throws IOException {
return normalizeFile(FileUtil.createTempDirectory(name, "", false)); // We should use this form. otherwise directory will be deleted on each test.
File answer = normalizeFile(FileUtil.createTempDirectory(new File(System.getProperty("java.io.tmpdir")), name, ""));
deleteOnShutdown(answer);
return answer;
} }
private static File normalizeFile(File file) throws IOException { private static File normalizeFile(File file) throws IOException {
@@ -433,6 +438,18 @@ public class KotlinTestUtils {
return file.getCanonicalFile(); return file.getCanonicalFile();
} }
private static void deleteOnShutdown(File file) {
if (filesToDelete.isEmpty()) {
ShutDownTracker.getInstance().registerShutdownTask(() -> {
for (File victim : filesToDelete) {
FileUtil.delete(victim);
}
});
}
filesToDelete.add(file);
}
@NotNull @NotNull
public static KtFile createFile(@NotNull @NonNls String name, @NotNull String text, @NotNull Project project) { public static KtFile createFile(@NotNull @NonNls String name, @NotNull String text, @NotNull Project project) {
String shortName = name.substring(name.lastIndexOf('/') + 1); String shortName = name.substring(name.lastIndexOf('/') + 1);
@@ -76,7 +76,7 @@ public abstract class KtUsefulTestCase extends TestCase {
private static final String ourPathToKeep = null; private static final String ourPathToKeep = null;
private final List<String> myPathsToKeep = new ArrayList<>(); private final List<String> myPathsToKeep = new ArrayList<>();
private File myTempDir; private String myTempDir;
static { static {
// Radar #5755208: Command line Java applications need a way to launch without a Dock icon. // Radar #5755208: Command line Java applications need a way to launch without a Dock icon.
@@ -100,8 +100,8 @@ public abstract class KtUsefulTestCase extends TestCase {
String testName = FileUtil.sanitizeFileName(getTestName(true)); String testName = FileUtil.sanitizeFileName(getTestName(true));
if (StringUtil.isEmptyOrSpaces(testName)) testName = ""; if (StringUtil.isEmptyOrSpaces(testName)) testName = "";
testName = new File(testName).getName(); // in case the test name contains file separators testName = new File(testName).getName(); // in case the test name contains file separators
myTempDir = FileUtil.createTempDirectory(TEMP_DIR_MARKER, testName, false); myTempDir = new File(ORIGINAL_TEMP_DIR, TEMP_DIR_MARKER + testName).getPath();
FileUtil.resetCanonicalTempPathCache(myTempDir.getPath()); FileUtil.resetCanonicalTempPathCache(myTempDir);
boolean isStressTest = isStressTest(); boolean isStressTest = isStressTest();
ApplicationInfoImpl.setInStressTest(isStressTest); ApplicationInfoImpl.setInStressTest(isStressTest);
// turn off Disposer debugging for performance tests // turn off Disposer debugging for performance tests
@@ -119,7 +119,7 @@ public abstract class KtUsefulTestCase extends TestCase {
Disposer.setDebugMode(oldDisposerDebug); Disposer.setDebugMode(oldDisposerDebug);
FileUtil.resetCanonicalTempPathCache(ORIGINAL_TEMP_DIR); FileUtil.resetCanonicalTempPathCache(ORIGINAL_TEMP_DIR);
if (hasTmpFilesToKeep()) { if (hasTmpFilesToKeep()) {
File[] files = myTempDir.listFiles(); File[] files = new File(myTempDir).listFiles();
if (files != null) { if (files != null) {
for (File file : files) { for (File file : files) {
if (!shouldKeepTmpFile(file)) { if (!shouldKeepTmpFile(file)) {
@@ -127,8 +127,9 @@ public abstract class KtUsefulTestCase extends TestCase {
} }
} }
} }
} else { }
FileUtil.delete(myTempDir); else {
FileUtil.delete(new File(myTempDir));
} }
} }
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.daemon package org.jetbrains.kotlin.daemon
import com.intellij.openapi.util.io.FileUtil
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.cli.AbstractCliTest import org.jetbrains.kotlin.cli.AbstractCliTest
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
@@ -358,8 +357,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
fun testDaemonExitsOnClientFlagDeletedWithActiveSessions() { fun testDaemonExitsOnClientFlagDeletedWithActiveSessions() {
val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath)
val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive") val clientFlag = createTempFile(getTestName(true), "-client.alive")
val sessionFlag = FileUtil.createTempFile(getTestName(true), "-session.alive") val sessionFlag = createTempFile(getTestName(true), "-session.alive")
try { try {
withLogFile("kotlin-daemon-test") { logFile -> withLogFile("kotlin-daemon-test") { logFile ->
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
@@ -384,8 +383,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
fun testDaemonExitsOnClientFlagDeletedWithAllSessionsReleased() { fun testDaemonExitsOnClientFlagDeletedWithAllSessionsReleased() {
val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath)
val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive") val clientFlag = createTempFile(getTestName(true), "-client.alive")
val sessionFlag = FileUtil.createTempFile(getTestName(true), "-session.alive") val sessionFlag = createTempFile(getTestName(true), "-session.alive")
try { try {
withLogFile("kotlin-daemon-test") { logFile -> withLogFile("kotlin-daemon-test") { logFile ->
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
@@ -413,8 +412,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
fun testDaemonCancelShutdownOnANewClient() { fun testDaemonCancelShutdownOnANewClient() {
val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 3000, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 3000, runFilesPath = File(tmpdir, getTestName(true)).absolutePath)
val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive") val clientFlag = createTempFile(getTestName(true), "-client.alive")
val clientFlag2 = FileUtil.createTempFile(getTestName(true), "-client.alive") val clientFlag2 = createTempFile(getTestName(true), "-client.alive")
try { try {
withLogFile("kotlin-daemon-test") { logFile -> withLogFile("kotlin-daemon-test") { logFile ->
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
@@ -455,7 +454,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
* (the same solution is used in kotlin daemon client - see next commit) * (the same solution is used in kotlin daemon client - see next commit)
*/ */
fun testDaemonExecutionViaIntermediateProcess() { fun testDaemonExecutionViaIntermediateProcess() {
val clientAliveFile = FileUtil.createTempFile("kotlin-daemon-transitive-run-test", ".run") val clientAliveFile = createTempFile("kotlin-daemon-transitive-run-test", ".run")
val daemonOptions = makeTestDaemonOptions(getTestName(true)) val daemonOptions = makeTestDaemonOptions(getTestName(true))
val jar = tmpdir.absolutePath + File.separator + "hello.jar" val jar = tmpdir.absolutePath + File.separator + "hello.jar"
val args = listOf( val args = listOf(
@@ -912,7 +911,7 @@ fun restoreSystemProperty(propertyName: String, backupValue: String?) {
} }
internal inline fun withFlagFile(prefix: String, suffix: String? = null, body: (File) -> Unit) { internal inline fun withFlagFile(prefix: String, suffix: String? = null, body: (File) -> Unit) {
val file = FileUtil.createTempFile(prefix, suffix) val file = createTempFile(prefix, suffix)
try { try {
body(file) body(file)
} }
@@ -922,7 +921,7 @@ internal inline fun withFlagFile(prefix: String, suffix: String? = null, body: (
} }
internal inline fun withLogFile(prefix: String, suffix: String = ".log", printLogOnException: Boolean = true, body: (File) -> Unit) { internal inline fun withLogFile(prefix: String, suffix: String = ".log", printLogOnException: Boolean = true, body: (File) -> Unit) {
val logFile = FileUtil.createTempFile(prefix, suffix) val logFile = createTempFile(prefix, suffix)
try { try {
body(logFile) body(logFile)
} }
-4
View File
@@ -2,10 +2,6 @@ import com.moowork.gradle.node.NodeExtension
import com.moowork.gradle.node.npm.NpmTask import com.moowork.gradle.node.npm.NpmTask
import org.gradle.internal.os.OperatingSystem import org.gradle.internal.os.OperatingSystem
tasks.withType<Test> {
maxParallelForks = Math.max(Runtime.getRuntime().availableProcessors() / 2, 1)
}
plugins { plugins {
kotlin("jvm") kotlin("jvm")
id("jps-compatible") id("jps-compatible")