mirror of https://github.com/sbt/sbt.git
Allow sbt scripted tests to run in parallel
I'm not sure if this is a huge benefit or not, but it's nice to have the option to run the scripted tests in parallel. The default behavior should be the same as before.
This commit is contained in:
parent
9023b58f83
commit
7b8ed4d13f
|
|
@ -115,6 +115,7 @@ object Scripted {
|
|||
bootProperties: File,
|
||||
launchOpts: Array[String],
|
||||
prescripted: java.util.List[File],
|
||||
instances: Int
|
||||
): Unit
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +124,6 @@ object Scripted {
|
|||
Thread.currentThread.setContextClassLoader(loader)
|
||||
val bridge =
|
||||
bridgeClass.getDeclaredConstructor().newInstance().asInstanceOf[SbtScriptedRunner]
|
||||
|
||||
try {
|
||||
// Using java.util.List to encode File => Unit.
|
||||
val callback = new java.util.AbstractList[File] {
|
||||
|
|
@ -131,6 +131,13 @@ object Scripted {
|
|||
def get(x: Int): sbt.File = ???
|
||||
def size(): Int = 0
|
||||
}
|
||||
val instances: Int = (System.getProperty("sbt.scripted.parallel.instances") match {
|
||||
case null => 1
|
||||
case i => scala.util.Try(i.toInt).getOrElse(1)
|
||||
}) match {
|
||||
case i if i > 0 => i
|
||||
case _ => 1
|
||||
}
|
||||
import scala.language.reflectiveCalls
|
||||
bridge.runInParallel(
|
||||
sourcePath,
|
||||
|
|
@ -139,6 +146,7 @@ object Scripted {
|
|||
launcher,
|
||||
launchOpts.toArray,
|
||||
callback,
|
||||
instances
|
||||
)
|
||||
} catch { case ite: InvocationTargetException => throw ite.getCause }
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -125,7 +125,10 @@ final class ScriptedTests(
|
|||
if (labelsAndDirs.isEmpty) List()
|
||||
else {
|
||||
val totalSize = labelsAndDirs.size
|
||||
val batchSize = totalSize / sbtInstances
|
||||
val batchSize = totalSize / sbtInstances match {
|
||||
case 0 => 1
|
||||
case s => s
|
||||
}
|
||||
|
||||
val (launcherBasedTests, runFromSourceBasedTests) = labelsAndDirs.partition {
|
||||
case (testName, _) =>
|
||||
|
|
|
|||
Loading…
Reference in New Issue