Skip to content

Conversation

@liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Sep 18, 2018

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 doesn't work because the progress bar monopolizes one thread
in the thread pool.

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` doesn't work because the progress bar monopolizes one thread
in the thread pool.
/** A single `Runnable` that prints a progress bar for the curent `Test` */
private def createProgressMonitor: Runnable = () => {
/** A `TimerTask` that prints a progress bar for the curent `Test` */
private def updateProgressMonitor: Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side effectful, so def updateProgressMonitor()

}

// wait for the timer task to execute once
Thread.sleep(300)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just call updateProgressMonitor() and not wait

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it should probably go after eventualResults.foreach(_.get)

eventualResults.foreach(_.get)

// update progress one last time
updateProgressMonitor()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would cancel the timer first to make sure there is no concurrent call to updateProgressMonitor.

Also it should only be called if isInteractive && !suppressAllOutput is true. I suggest something like:

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

...

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

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

@allanrenucci allanrenucci merged commit 0fd4e6a into scala:master Sep 19, 2018
@allanrenucci allanrenucci deleted the fix-5116 branch September 19, 2018 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants