Skip to content

Commit 0fd4e6a

Browse files
liufengyunallanrenucci
authored andcommitted
Fix #5116: make it easy to sequentially run test (#5120)
Fix #5116: make it easy to sequentially run test With this change, it suffices to use `1` to make all tests sequential: val pool = threadLimit match { case Some(i) => JExecutors.newWorkStealingPool(1) case None => JExecutors.newWorkStealingPool(1) } Previously, `1` didn't work because the progress bar monopolizes one thread in the thread pool.
1 parent 52a5bdb commit 0fd4e6a

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import java.util.HashMap
88
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
99
import java.nio.file.{Files, NoSuchFileException, Path, Paths}
1010
import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors}
11+
import java.util.{Timer, TimerTask}
1112

1213
import scala.io.Source
1314
import scala.util.control.NonFatal
@@ -285,11 +286,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
285286
realStderr.println(msg + paddingRight)
286287
}
287288

288-
/** A single `Runnable` that prints a progress bar for the curent `Test` */
289-
private def createProgressMonitor: Runnable = () => {
289+
/** Print a progress bar for the curent `Test` */
290+
private def updateProgressMonitor(): Unit = {
290291
val start = System.currentTimeMillis
291292
var tCompiled = testSourcesCompleted
292-
while (tCompiled < sourceCount) {
293+
if (tCompiled < sourceCount) {
293294
val timestamp = (System.currentTimeMillis - start) / 1000
294295
val progress = (tCompiled.toDouble / sourceCount * 40).toInt
295296

@@ -299,16 +300,14 @@ trait ParallelTesting extends RunnerOrchestration { self =>
299300
(" " * (39 - progress)) +
300301
s"] completed ($tCompiled/$sourceCount, $failureCount failed, ${timestamp}s)\r"
301302
)
302-
303-
Thread.sleep(100)
304-
tCompiled = testSourcesCompleted
305303
}
306-
307-
val timestamp = (System.currentTimeMillis - start) / 1000
308-
// println, otherwise no newline and cursor at start of line
309-
realStdout.println(
310-
s"[=======================================] completed ($sourceCount/$sourceCount, $failureCount failed, ${timestamp}s)"
311-
)
304+
else {
305+
val timestamp = (System.currentTimeMillis - start) / 1000
306+
// println, otherwise no newline and cursor at start of line
307+
realStdout.print(
308+
s"[=======================================] completed ($sourceCount/$sourceCount, $failureCount failed, ${timestamp}s)\r"
309+
)
310+
}
312311
}
313312

314313
/** Wrapper function to make sure that the compiler itself did not crash -
@@ -465,7 +464,14 @@ trait ParallelTesting extends RunnerOrchestration { self =>
465464
case None => JExecutors.newWorkStealingPool()
466465
}
467466

468-
if (isInteractive && !suppressAllOutput) pool.submit(createProgressMonitor)
467+
val timer = new Timer()
468+
val logProgress = isInteractive && !suppressAllOutput
469+
if (logProgress) {
470+
val task = new TimerTask {
471+
def run() = updateProgressMonitor()
472+
}
473+
timer.schedule(task, 100, 200)
474+
}
469475

470476
val eventualResults = filteredSources.map { target =>
471477
pool.submit(encapsulatedCompilation(target))
@@ -481,6 +487,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
481487

482488
eventualResults.foreach(_.get)
483489

490+
if (logProgress) {
491+
timer.cancel()
492+
// update progress one last time
493+
updateProgressMonitor()
494+
}
495+
484496
if (didFail) {
485497
reportFailed()
486498
failedTestSources.toSet.foreach(addFailedTest)

0 commit comments

Comments
 (0)