Skip to content

Fix #5116: make it easy to sequentially run test #5120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.util.HashMap
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
import java.nio.file.{Files, NoSuchFileException, Path, Paths}
import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors}
import java.util.{Timer, TimerTask}

import scala.io.Source
import scala.util.control.NonFatal
Expand Down Expand Up @@ -285,11 +286,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
realStderr.println(msg + paddingRight)
}

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

Expand All @@ -299,16 +300,14 @@ trait ParallelTesting extends RunnerOrchestration { self =>
(" " * (39 - progress)) +
s"] completed ($tCompiled/$sourceCount, $failureCount failed, ${timestamp}s)\r"
)

Thread.sleep(100)
tCompiled = testSourcesCompleted
}

val timestamp = (System.currentTimeMillis - start) / 1000
// println, otherwise no newline and cursor at start of line
realStdout.println(
s"[=======================================] completed ($sourceCount/$sourceCount, $failureCount failed, ${timestamp}s)"
)
else {
val timestamp = (System.currentTimeMillis - start) / 1000
// println, otherwise no newline and cursor at start of line
realStdout.print(
s"[=======================================] completed ($sourceCount/$sourceCount, $failureCount failed, ${timestamp}s)\r"
)
}
}

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

if (isInteractive && !suppressAllOutput) pool.submit(createProgressMonitor)
val timer = new Timer()
val logProgress = isInteractive && !suppressAllOutput
if (logProgress) {
val task = new TimerTask {
def run() = updateProgressMonitor()
}
timer.schedule(task, 100, 200)
}

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

eventualResults.foreach(_.get)

if (logProgress) {
timer.cancel()
// update progress one last time
updateProgressMonitor()
}

if (didFail) {
reportFailed()
failedTestSources.toSet.foreach(addFailedTest)
Expand Down