Allow tests to be run in parallel.

This commit is contained in:
Steven Schäfer
2019-03-19 18:10:32 +01:00
committed by max-kammerer
parent ca0e66bafc
commit 21d81f353c
7 changed files with 31 additions and 43 deletions
+4
View File
@@ -3,6 +3,10 @@ import org.gradle.api.tasks.bundling.Jar
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
tasks.withType<Test> {
maxParallelForks = Math.max(Runtime.getRuntime().availableProcessors() / 2, 1)
}
plugins {
kotlin("jvm")
id("jps-compatible")
@@ -22,7 +22,11 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
abstract class AbstractForeignAnnotationsNoAnnotationInClasspathTest : AbstractForeignAnnotationsTest() {
private val compiledJavaPath = KotlinTestUtils.tmpDir("java-compiled-files")
// 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")
}
override fun getExtraClasspath(): List<File> {
val foreignAnnotations = createJarWithForeignAnnotations()
@@ -43,13 +43,6 @@ public abstract class KotlinMultiFileTestWithJava<M, F> 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<String> dependencies;
@@ -413,9 +413,7 @@ public class KotlinTestUtils {
@NotNull
public static File tmpDirForTest(@NotNull String testClassName, @NotNull String testName) throws IOException {
File answer = normalizeFile(FileUtil.createTempDirectory(testClassName, testName));
deleteOnShutdown(answer);
return answer;
return normalizeFile(FileUtil.createTempDirectory(testClassName, testName, false));
}
@NotNull
@@ -425,10 +423,7 @@ public class KotlinTestUtils {
@NotNull
public static File tmpDir(String name) throws IOException {
// 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;
return normalizeFile(FileUtil.createTempDirectory(name, "", false));
}
private static File normalizeFile(File file) throws IOException {
@@ -438,18 +433,6 @@ 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);
@@ -76,7 +76,7 @@ public abstract class KtUsefulTestCase extends TestCase {
private static final String ourPathToKeep = null;
private final List<String> myPathsToKeep = new ArrayList<>();
private String myTempDir;
private File 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 = new File(ORIGINAL_TEMP_DIR, TEMP_DIR_MARKER + testName).getPath();
FileUtil.resetCanonicalTempPathCache(myTempDir);
myTempDir = FileUtil.createTempDirectory(TEMP_DIR_MARKER, testName, false);
FileUtil.resetCanonicalTempPathCache(myTempDir.getPath());
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 = new File(myTempDir).listFiles();
File[] files = myTempDir.listFiles();
if (files != null) {
for (File file : files) {
if (!shouldKeepTmpFile(file)) {
@@ -127,9 +127,8 @@ public abstract class KtUsefulTestCase extends TestCase {
}
}
}
}
else {
FileUtil.delete(new File(myTempDir));
} else {
FileUtil.delete(myTempDir);
}
}
@@ -16,6 +16,7 @@
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
@@ -357,8 +358,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
fun testDaemonExitsOnClientFlagDeletedWithActiveSessions() {
val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath)
val clientFlag = createTempFile(getTestName(true), "-client.alive")
val sessionFlag = createTempFile(getTestName(true), "-session.alive")
val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive")
val sessionFlag = FileUtil.createTempFile(getTestName(true), "-session.alive")
try {
withLogFile("kotlin-daemon-test") { logFile ->
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
@@ -383,8 +384,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
fun testDaemonExitsOnClientFlagDeletedWithAllSessionsReleased() {
val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath)
val clientFlag = createTempFile(getTestName(true), "-client.alive")
val sessionFlag = createTempFile(getTestName(true), "-session.alive")
val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive")
val sessionFlag = FileUtil.createTempFile(getTestName(true), "-session.alive")
try {
withLogFile("kotlin-daemon-test") { logFile ->
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
@@ -412,8 +413,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
fun testDaemonCancelShutdownOnANewClient() {
val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 3000, runFilesPath = File(tmpdir, getTestName(true)).absolutePath)
val clientFlag = createTempFile(getTestName(true), "-client.alive")
val clientFlag2 = createTempFile(getTestName(true), "-client.alive")
val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive")
val clientFlag2 = FileUtil.createTempFile(getTestName(true), "-client.alive")
try {
withLogFile("kotlin-daemon-test") { logFile ->
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
@@ -454,7 +455,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
* (the same solution is used in kotlin daemon client - see next commit)
*/
fun testDaemonExecutionViaIntermediateProcess() {
val clientAliveFile = createTempFile("kotlin-daemon-transitive-run-test", ".run")
val clientAliveFile = FileUtil.createTempFile("kotlin-daemon-transitive-run-test", ".run")
val daemonOptions = makeTestDaemonOptions(getTestName(true))
val jar = tmpdir.absolutePath + File.separator + "hello.jar"
val args = listOf(
@@ -911,7 +912,7 @@ fun restoreSystemProperty(propertyName: String, backupValue: String?) {
}
internal inline fun withFlagFile(prefix: String, suffix: String? = null, body: (File) -> Unit) {
val file = createTempFile(prefix, suffix)
val file = FileUtil.createTempFile(prefix, suffix)
try {
body(file)
}
@@ -921,7 +922,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 = createTempFile(prefix, suffix)
val logFile = FileUtil.createTempFile(prefix, suffix)
try {
body(logFile)
}
+4
View File
@@ -2,6 +2,10 @@ import com.moowork.gradle.node.NodeExtension
import com.moowork.gradle.node.npm.NpmTask
import org.gradle.internal.os.OperatingSystem
tasks.withType<Test> {
maxParallelForks = Math.max(Runtime.getRuntime().availableProcessors() / 2, 1)
}
plugins {
kotlin("jvm")
id("jps-compatible")