From c0804000eb5ffd4a792824c4155b82301d8f5a8c Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 17 Jul 2019 11:29:08 +0200 Subject: [PATCH] Shorten temp paths used in tests #KT-32490 fixed --- .../kotlin/daemon/CompilerDaemonTest.kt | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt index 687cb9cc1c7..0e05bb02a8c 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.daemon import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.util.io.FileUtilRt import junit.framework.TestCase import org.jetbrains.kotlin.cli.AbstractCliTest import org.jetbrains.kotlin.cli.common.messages.MessageRenderer @@ -67,6 +68,12 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { CompilerId.makeCompilerId(compilerWithScriptingClassPath) } + override fun shouldContainTempFiles(): Boolean = true + + // Using tmpDir from TestCaseWithTmpdir leads to the file paths with >255 chars (see e.g. #KT-32490), while KtUsefulTestCase already + // setups a separate temp dir for each tests, if shouldContainTempFiles() returns true. Therefore current temp dir is used directly + val testTempDir = File(FileUtilRt.getTempDirectory()) + private fun compileOnDaemon(clientAliveFile: File, compilerId: CompilerId, daemonJVMOptions: DaemonJVMOptions, daemonOptions: DaemonOptions, vararg args: String): CompilerResults { val daemon = KotlinCompilerClient.connectToCompileService(compilerId, clientAliveFile, daemonJVMOptions, daemonOptions, DaemonReportingTargets(out = System.err), autostart = true) assertNotNull("failed to connect daemon", daemon) @@ -92,7 +99,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { private fun run(logName: String, vararg args: String): Int = runJava(getTestBaseDir(), logName, *args) fun makeTestDaemonOptions(testName: String, shutdownDelay: Int = 5) = - DaemonOptions(runFilesPath = File(tmpdir, testName).absolutePath, + DaemonOptions(runFilesPath = File(testTempDir, testName).absolutePath, shutdownDelayMilliseconds = shutdownDelay.toLong(), verbose = true, reportPerf = true) @@ -121,7 +128,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { var daemonShotDown = false try { - val jar = tmpdir.absolutePath + File.separator + "hello.jar" + val jar = testTempDir.absolutePath + File.separator + "hello.jar" runDaemonCompilerTwice(flagFile, compilerId, daemonJVMOptions, daemonOptions, "-include-runtime", File(getTestBaseDir(), "hello.kt").absolutePath, "-d", jar) @@ -206,14 +213,14 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { assertTrue(logFile1.length() == 0L && logFile2.length() == 0L) - val jar1 = tmpdir.absolutePath + File.separator + "hello1.jar" + val jar1 = testTempDir.absolutePath + File.separator + "hello1.jar" val res1 = compileOnDaemon(flagFile, compilerId, daemonJVMOptions1, daemonOptions, "-include-runtime", File(getHelloAppBaseDir(), "hello.kt").absolutePath, "-d", jar1) assertEquals("first compilation failed:\n${res1.out}", 0, res1.resultCode) logFile1.assertLogContainsSequence("Starting compilation with args: ") assertEquals("expecting '${logFile2.absolutePath}' to be empty", 0L, logFile2.length()) - val jar2 = tmpdir.absolutePath + File.separator + "hello2.jar" + val jar2 = testTempDir.absolutePath + File.separator + "hello2.jar" val res2 = compileOnDaemon(flagFile, compilerId2, daemonJVMOptions2, daemonOptions, "-include-runtime", File(getHelloAppBaseDir(), "hello.kt").absolutePath, "-d", jar2) assertEquals("second compilation failed:\n${res2.out}", 0, res1.resultCode) @@ -233,7 +240,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonRunError() { withFlagFile(getTestName(true), ".alive") { flagFile -> - val daemonOptions = DaemonOptions(shutdownDelayMilliseconds = 1, verbose = true, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + val daemonOptions = DaemonOptions(shutdownDelayMilliseconds = 1, verbose = true, runFilesPath = File(testTempDir, getTestName(true)).absolutePath) val daemonJVMOptions = configureDaemonJVMOptions("-abracadabra", inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false) @@ -251,7 +258,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { // TODO: find out how to reliably cause the retry fun ignore_testDaemonStartRetry() { withFlagFile(getTestName(true), ".alive") { flagFile -> - val daemonOptions = DaemonOptions(shutdownDelayMilliseconds = 1, verbose = true, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + val daemonOptions = DaemonOptions(shutdownDelayMilliseconds = 1, verbose = true, runFilesPath = File(testTempDir, getTestName(true)).absolutePath) val daemonJVMOptions = configureDaemonJVMOptions(inheritMemoryLimits = false, inheritOtherJvmOptions = false, inheritAdditionalProperties = false) @@ -271,7 +278,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonAutoshutdownOnUnused() { withFlagFile(getTestName(true), ".alive") { flagFile -> - val daemonOptions = DaemonOptions(autoshutdownUnusedSeconds = 1, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + val daemonOptions = DaemonOptions(autoshutdownUnusedSeconds = 1, shutdownDelayMilliseconds = 1, runFilesPath = File(testTempDir, getTestName(true)).absolutePath) withLogFile("kotlin-daemon-test") { logFile -> val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) @@ -295,7 +302,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonAutoshutdownOnIdle() { withFlagFile(getTestName(true), ".alive") { flagFile -> - val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1, shutdownDelayMilliseconds = 1, runFilesPath = File(testTempDir, getTestName(true)).absolutePath) withLogFile("kotlin-daemon-test") { logFile -> val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) @@ -303,7 +310,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { val daemon = KotlinCompilerClient.connectToCompileService(compilerId, flagFile, daemonJVMOptions, daemonOptions, DaemonReportingTargets(out = System.err), autostart = true) assertNotNull("failed to connect daemon", daemon) daemon?.registerClient(flagFile.absolutePath) - val jar = tmpdir.absolutePath + File.separator + "hello1.jar" + val jar = testTempDir.absolutePath + File.separator + "hello1.jar" val strm = ByteArrayOutputStream() val code = KotlinCompilerClient.compile(daemon!!, CompileService.NO_SESSION, CompileService.TargetPlatform.JVM, arrayOf("-include-runtime", File(getHelloAppBaseDir(), "hello.kt").absolutePath, "-d", jar), @@ -327,7 +334,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonGracefulShutdown() { withFlagFile(getTestName(true), ".alive") { flagFile -> - val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1, shutdownDelayMilliseconds = 1, forceShutdownTimeoutMilliseconds = 60000, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1, shutdownDelayMilliseconds = 1, forceShutdownTimeoutMilliseconds = 60000, runFilesPath = File(testTempDir, getTestName(true)).absolutePath) withLogFile("kotlin-daemon-test") { logFile -> val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) @@ -360,7 +367,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { } fun testDaemonExitsOnClientFlagDeletedWithActiveSessions() { - val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(testTempDir, getTestName(true)).absolutePath) val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive") val sessionFlag = FileUtil.createTempFile(getTestName(true), "-session.alive") try { @@ -386,7 +393,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { } fun testDaemonExitsOnClientFlagDeletedWithAllSessionsReleased() { - val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 1, runFilesPath = File(testTempDir, getTestName(true)).absolutePath) val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive") val sessionFlag = FileUtil.createTempFile(getTestName(true), "-session.alive") try { @@ -415,7 +422,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { } fun testDaemonCancelShutdownOnANewClient() { - val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 3000, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1000, shutdownDelayMilliseconds = 3000, runFilesPath = File(testTempDir, getTestName(true)).absolutePath) val clientFlag = FileUtil.createTempFile(getTestName(true), "-client.alive") val clientFlag2 = FileUtil.createTempFile(getTestName(true), "-client.alive") try { @@ -460,7 +467,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonExecutionViaIntermediateProcess() { val clientAliveFile = FileUtil.createTempFile("kotlin-daemon-transitive-run-test", ".run") val daemonOptions = makeTestDaemonOptions(getTestName(true)) - val jar = tmpdir.absolutePath + File.separator + "hello.jar" + val jar = testTempDir.absolutePath + File.separator + "hello.jar" val args = listOf( File(File(System.getProperty("java.home"), "bin"), "java").absolutePath, "-Xmx256m", @@ -517,7 +524,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun runCompile(threadNo: Int) = thread { - val jar = tmpdir.absolutePath + File.separator + "hello.$threadNo.jar" + val jar = testTempDir.absolutePath + File.separator + "hello.$threadNo.jar" val res = KotlinCompilerClient.compile( daemon!!, CompileService.NO_SESSION, @@ -577,7 +584,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { ParallelStartParams.connectionFailedErr } ParallelStartParams.performCompilation -> { - val jar = tmpdir.absolutePath + File.separator + "hello.$threadNo.jar" + val jar = testTempDir.absolutePath + File.separator + "hello.$threadNo.jar" KotlinCompilerClient.compile( compileServiceSession.compileService, compileServiceSession.sessionId, @@ -688,9 +695,9 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { assertNotNull("failed to connect daemon", daemon) daemon?.registerClient(flagFile.absolutePath) - val file = File(tmpdir, "largeKotlinFile.kt") + val file = File(testTempDir, "largeKotlinFile.kt") file.writeText(generateLargeKotlinFile(10)) - val jar = File(tmpdir, "largeKotlinFile.jar").absolutePath + val jar = File(testTempDir, "largeKotlinFile.jar").absolutePath var callbackServices: CompilerCallbackServicesFacadeServer? = null callbackServices = CompilerCallbackServicesFacadeServer(compilationCanceledStatus = object : CompilationCanceledStatus { @@ -804,7 +811,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonReplAutoshutdownOnIdle() { withFlagFile(getTestName(true), ".alive") { flagFile -> - val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1, autoshutdownUnusedSeconds = 1, shutdownDelayMilliseconds = 1, runFilesPath = File(tmpdir, getTestName(true)).absolutePath) + val daemonOptions = DaemonOptions(autoshutdownIdleSeconds = 1, autoshutdownUnusedSeconds = 1, shutdownDelayMilliseconds = 1, runFilesPath = File(testTempDir, getTestName(true)).absolutePath) withLogFile("kotlin-daemon-test") { logFile -> val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)