Skip to content

Commit e339117

Browse files
committed
Rewrite parallel daemon start test to make it tougher but more robust
1 parent 4c6b9b6 commit e339117

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
401401

402402
fun testParallelDaemonStart() {
403403

404-
val PARALLEL_THREADS_TO_START = 10
404+
val PARALLEL_THREADS_TO_START = 16
405405

406406
val doneLatch = CountDownLatch(PARALLEL_THREADS_TO_START)
407407

@@ -417,14 +417,17 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
417417
runFilesPath = File(tmpdir, getTestName(true)).absolutePath,
418418
verbose = true)
419419
val logFile = createTempFile("kotlin-daemon-test", ".log")
420+
logFiles[threadNo] = logFile
420421
val daemonJVMOptions =
421422
configureDaemonJVMOptions(DaemonJVMOptions(maxMemory = "2048m"),
422423
"D$COMPILE_DAEMON_LOG_PATH_PROPERTY=\"${logFile.loggerCompatiblePath}\"",
423424
inheritMemoryLimits = false, inheritAdditionalProperties = false)
424425
val daemonWithSession = KotlinCompilerClient.connectAndLease(compilerId, flagFile, daemonJVMOptions, daemonOptions,
425426
DaemonReportingTargets(out = System.err), autostart = true,
426427
leaseSession = true, sessionAliveFlagFile = sessionFlagFile)
427-
assertNotNull("failed to connect daemon", daemonWithSession?.first)
428+
if (daemonWithSession?.first == null) {
429+
fail("failed to connect daemon:\n${logFile.readLines().joinToString("\n")}\n------")
430+
}
428431
val jar = tmpdir.absolutePath + File.separator + "hello.$threadNo.jar"
429432
val res = KotlinCompilerClient.compile(
430433
daemonWithSession!!.first,
@@ -433,7 +436,6 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
433436
arrayOf(File(getHelloAppBaseDir(), "hello.kt").absolutePath, "-d", jar),
434437
outStreams[threadNo])
435438
resultCodes[threadNo] = res
436-
logFiles[threadNo] = logFile
437439
}
438440
}
439441
}
@@ -442,23 +444,32 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
442444
}
443445
}
444446

445-
(1..PARALLEL_THREADS_TO_START).forEach { connectThread(it - 1) }
447+
System.setProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "true")
448+
System.setProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY, "100000")
449+
450+
val succeeded = try {
451+
(1..PARALLEL_THREADS_TO_START).forEach { connectThread(it - 1) }
452+
doneLatch.await(PARALLEL_WAIT_TIMEOUT_S, TimeUnit.SECONDS)
453+
}
454+
finally {
455+
System.clearProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY)
456+
System.clearProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY)
457+
}
446458

447-
val succeeded = doneLatch.await(PARALLEL_WAIT_TIMEOUT_S, TimeUnit.SECONDS)
448459
assertTrue("parallel daemons start failed to complete in $PARALLEL_WAIT_TIMEOUT_S s, ${doneLatch.count} unfinished threads", succeeded)
449460

450461
Thread.sleep(100) // Wait for processes to finish and close log files
451462

452-
val electionLogs = logFiles.map { it to it?.readLines()?.find { it.contains(LOG_PREFIX_ASSUMING_OTHER_DAEMONS_HAVE) } }
463+
val electionLogs = (0..(PARALLEL_THREADS_TO_START - 1)).map {
464+
val logContents = logFiles[it]?.readLines()
465+
assertEquals("Compilation on thread $it failed:\n${outStreams[it]}\n\n------- daemon log: -------\n${logContents?.joinToString("\n")}\n-------", 0, resultCodes[it])
466+
logContents?.find { it.contains(LOG_PREFIX_ASSUMING_OTHER_DAEMONS_HAVE) }
467+
}
453468

454469
assertTrue("No daemon elected: \n${electionLogs.joinToString("\n")}",
455-
electionLogs.any { (_, electionLine) -> electionLine != null && (electionLine.contains("lower prio") || electionLine.contains("equal prio")) })
470+
electionLogs.any { it != null && (it.contains("lower prio") || it.contains("equal prio")) })
456471

457-
electionLogs.forEach { (logFile, _) -> logFile?.delete() }
458-
459-
(1..PARALLEL_THREADS_TO_START).forEach {
460-
assertEquals("Compilation on thread $it failed:\n${outStreams[it - 1]}", 0, resultCodes[it - 1])
461-
}
472+
logFiles.forEach { it?.delete() }
462473
}
463474

464475
fun testDaemonConnectionProblems() {

0 commit comments

Comments
 (0)