From bdad3cace9a31fc2ec8bd23e9bfb9a7b38551d9e Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 26 Mar 2019 15:19:03 +0300 Subject: [PATCH] Revert "Allow tests to be run in parallel." This reverts commit 21d81f35 --- compiler/build.gradle.kts | 4 ---- ...nAnnotationsNoAnnotationInClasspathTest.kt | 6 +----- .../checkers/KotlinMultiFileTestWithJava.java | 7 +++++++ .../kotlin/test/KotlinTestUtils.java | 21 +++++++++++++++++-- .../test/testFramework/KtUsefulTestCase.java | 13 ++++++------ .../kotlin/daemon/CompilerDaemonTest.kt | 19 ++++++++--------- js/js.tests/build.gradle.kts | 4 ---- 7 files changed, 43 insertions(+), 31 deletions(-) diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts index 63acedd52b1..9d5c588b6ab 100644 --- a/compiler/build.gradle.kts +++ b/compiler/build.gradle.kts @@ -3,10 +3,6 @@ import org.gradle.api.tasks.bundling.Jar import org.jetbrains.kotlin.gradle.dsl.KotlinCompile import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile -tasks.withType { - maxParallelForks = Math.max(Runtime.getRuntime().availableProcessors() / 2, 1) -} - plugins { kotlin("jvm") id("jps-compatible") diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsNoAnnotationInClasspathTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsNoAnnotationInClasspathTest.kt index 9bc6d7868c4..cbbc9e92e47 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsNoAnnotationInClasspathTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsNoAnnotationInClasspathTest.kt @@ -22,11 +22,7 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File abstract class AbstractForeignAnnotationsNoAnnotationInClasspathTest : AbstractForeignAnnotationsTest() { - // This should be executed after setUp runs, since setUp changes the root folder - // for temporary files. - private val compiledJavaPath by lazy { - KotlinTestUtils.tmpDir("java-compiled-files") - } + private val compiledJavaPath = KotlinTestUtils.tmpDir("java-compiled-files") override fun getExtraClasspath(): List { val foreignAnnotations = createJarWithForeignAnnotations() diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/KotlinMultiFileTestWithJava.java b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/KotlinMultiFileTestWithJava.java index 6443065d860..eb309934198 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/KotlinMultiFileTestWithJava.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/KotlinMultiFileTestWithJava.java @@ -43,6 +43,13 @@ public abstract class KotlinMultiFileTestWithJava extends KtUsefulTestCase coroutinesPackage = ""; } + @Override + protected void tearDown() throws Exception { + if (javaFilesDir != null) FileUtil.delete(javaFilesDir); + if (kotlinSourceRoot != null) FileUtil.delete(kotlinSourceRoot); + super.tearDown(); + } + public class ModuleAndDependencies { final M module; final List dependencies; 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 55c6d919805..ad08302ef0d 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -413,7 +413,9 @@ public class KotlinTestUtils { @NotNull 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 @@ -423,7 +425,10 @@ public class KotlinTestUtils { @NotNull 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 { @@ -433,6 +438,18 @@ public class KotlinTestUtils { 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 public static KtFile createFile(@NotNull @NonNls String name, @NotNull String text, @NotNull Project project) { String shortName = name.substring(name.lastIndexOf('/') + 1); 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..12ef0a01a81 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 @@ -76,7 +76,7 @@ public abstract class KtUsefulTestCase extends TestCase { private static final String ourPathToKeep = null; private final List myPathsToKeep = new ArrayList<>(); - private File myTempDir; + private String myTempDir; static { // 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)); if (StringUtil.isEmptyOrSpaces(testName)) testName = ""; testName = new File(testName).getName(); // in case the test name contains file separators - myTempDir = FileUtil.createTempDirectory(TEMP_DIR_MARKER, testName, false); - FileUtil.resetCanonicalTempPathCache(myTempDir.getPath()); + myTempDir = new File(ORIGINAL_TEMP_DIR, TEMP_DIR_MARKER + testName).getPath(); + FileUtil.resetCanonicalTempPathCache(myTempDir); boolean isStressTest = isStressTest(); ApplicationInfoImpl.setInStressTest(isStressTest); // turn off Disposer debugging for performance tests @@ -119,7 +119,7 @@ public abstract class KtUsefulTestCase extends TestCase { Disposer.setDebugMode(oldDisposerDebug); FileUtil.resetCanonicalTempPathCache(ORIGINAL_TEMP_DIR); if (hasTmpFilesToKeep()) { - File[] files = myTempDir.listFiles(); + File[] files = new File(myTempDir).listFiles(); if (files != null) { for (File file : files) { if (!shouldKeepTmpFile(file)) { @@ -127,8 +127,9 @@ public abstract class KtUsefulTestCase extends TestCase { } } } - } else { - FileUtil.delete(myTempDir); + } + else { + FileUtil.delete(new File(myTempDir)); } } diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt index db3f4a6f304..d6bf2fad863 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.daemon -import com.intellij.openapi.util.io.FileUtil import junit.framework.TestCase import org.jetbrains.kotlin.cli.AbstractCliTest import org.jetbrains.kotlin.cli.common.messages.MessageRenderer @@ -358,8 +357,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonExitsOnClientFlagDeletedWithActiveSessions() { val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) - val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive") - val sessionFlag = FileUtil.createTempFile(getTestName(true), "-session.alive") + val clientFlag = createTempFile(getTestName(true), "-client.alive") + val sessionFlag = createTempFile(getTestName(true), "-session.alive") try { withLogFile("kotlin-daemon-test") { logFile -> val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) @@ -384,8 +383,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonExitsOnClientFlagDeletedWithAllSessionsReleased() { val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) - val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive") - val sessionFlag = FileUtil.createTempFile(getTestName(true), "-session.alive") + val clientFlag = createTempFile(getTestName(true), "-client.alive") + val sessionFlag = createTempFile(getTestName(true), "-session.alive") try { withLogFile("kotlin-daemon-test") { logFile -> val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) @@ -413,8 +412,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonCancelShutdownOnANewClient() { val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 3000, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) - val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive") - val clientFlag2 = FileUtil.createTempFile(getTestName(true), "-client.alive") + val clientFlag = createTempFile(getTestName(true), "-client.alive") + val clientFlag2 = createTempFile(getTestName(true), "-client.alive") try { withLogFile("kotlin-daemon-test") { logFile -> val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) @@ -455,7 +454,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { * (the same solution is used in kotlin daemon client - see next commit) */ 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 jar = tmpdir.absolutePath + File.separator + "hello.jar" 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) { - val file = FileUtil.createTempFile(prefix, suffix) + val file = createTempFile(prefix, suffix) try { 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) { - val logFile = FileUtil.createTempFile(prefix, suffix) + val logFile = createTempFile(prefix, suffix) try { body(logFile) } diff --git a/js/js.tests/build.gradle.kts b/js/js.tests/build.gradle.kts index 73821266db9..c9600b14b49 100644 --- a/js/js.tests/build.gradle.kts +++ b/js/js.tests/build.gradle.kts @@ -2,10 +2,6 @@ import com.moowork.gradle.node.NodeExtension import com.moowork.gradle.node.npm.NpmTask import org.gradle.internal.os.OperatingSystem -tasks.withType { - maxParallelForks = Math.max(Runtime.getRuntime().availableProcessors() / 2, 1) -} - plugins { kotlin("jvm") id("jps-compatible")