@@ -401,7 +401,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
401
401
402
402
fun testParallelDaemonStart () {
403
403
404
- val PARALLEL_THREADS_TO_START = 10
404
+ val PARALLEL_THREADS_TO_START = 16
405
405
406
406
val doneLatch = CountDownLatch (PARALLEL_THREADS_TO_START )
407
407
@@ -417,14 +417,17 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
417
417
runFilesPath = File (tmpdir, getTestName(true )).absolutePath,
418
418
verbose = true )
419
419
val logFile = createTempFile(" kotlin-daemon-test" , " .log" )
420
+ logFiles[threadNo] = logFile
420
421
val daemonJVMOptions =
421
422
configureDaemonJVMOptions(DaemonJVMOptions (maxMemory = " 2048m" ),
422
423
" D$COMPILE_DAEMON_LOG_PATH_PROPERTY =\" ${logFile.loggerCompatiblePath} \" " ,
423
424
inheritMemoryLimits = false , inheritAdditionalProperties = false )
424
425
val daemonWithSession = KotlinCompilerClient .connectAndLease(compilerId, flagFile, daemonJVMOptions, daemonOptions,
425
426
DaemonReportingTargets (out = System .err), autostart = true ,
426
427
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
+ }
428
431
val jar = tmpdir.absolutePath + File .separator + " hello.$threadNo .jar"
429
432
val res = KotlinCompilerClient .compile(
430
433
daemonWithSession!! .first,
@@ -433,7 +436,6 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
433
436
arrayOf(File (getHelloAppBaseDir(), " hello.kt" ).absolutePath, " -d" , jar),
434
437
outStreams[threadNo])
435
438
resultCodes[threadNo] = res
436
- logFiles[threadNo] = logFile
437
439
}
438
440
}
439
441
}
@@ -442,23 +444,32 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
442
444
}
443
445
}
444
446
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
+ }
446
458
447
- val succeeded = doneLatch.await(PARALLEL_WAIT_TIMEOUT_S , TimeUnit .SECONDS )
448
459
assertTrue(" parallel daemons start failed to complete in $PARALLEL_WAIT_TIMEOUT_S s, ${doneLatch.count} unfinished threads" , succeeded)
449
460
450
461
Thread .sleep(100 ) // Wait for processes to finish and close log files
451
462
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
+ }
453
468
454
469
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" )) })
456
471
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() }
462
473
}
463
474
464
475
fun testDaemonConnectionProblems () {
0 commit comments