mirror of https://github.com/sbt/sbt.git
parent
d61a9b24fb
commit
15597c3843
|
|
@ -1,27 +0,0 @@
|
|||
import sbt._
|
||||
import Keys._
|
||||
import Tests._
|
||||
import Defaults._
|
||||
|
||||
object ForkParallelTest extends Build {
|
||||
val check = taskKey[Unit]("Check that tests are executed in parallel")
|
||||
|
||||
lazy val root = Project("root", file("."), settings = defaultSettings ++ Seq(
|
||||
scalaVersion := "2.9.2",
|
||||
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test",
|
||||
fork in Test := true,
|
||||
check := {
|
||||
val nbProc = java.lang.Runtime.getRuntime().availableProcessors()
|
||||
if( nbProc < 4 ) {
|
||||
streams.value.log.warn("With fewer than 4 processors this test is meaningless")
|
||||
} else {
|
||||
// we've got at least 4 processors, we'll check the upper end but also 3 and 4 as the upper might not
|
||||
// be reached if the system is under heavy load.
|
||||
if( ! (file("max-concurrent-tests_3").exists() || file("max-concurrent-tests_4").exists() ||
|
||||
file("max-concurrent-tests_" + (nbProc -1)).exists() || file("max-concurrent-tests_" + nbProc).exists())) {
|
||||
sys.error("Forked tests were not executed in parallel!")
|
||||
}
|
||||
}
|
||||
}
|
||||
))
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
|
||||
import java.io.File
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import org.junit.Test
|
||||
import scala.annotation.tailrec
|
||||
|
||||
object ParallelTest {
|
||||
val nbConcurrentTests = new AtomicInteger(0)
|
||||
val maxConcurrentTests = new AtomicInteger(0)
|
||||
|
||||
private def updateMaxConcurrentTests(currentMax: Int, newMax: Int) : Boolean = {
|
||||
if( maxConcurrentTests.compareAndSet(currentMax, newMax) ) {
|
||||
val f = new File("max-concurrent-tests_" + newMax)
|
||||
f.createNewFile
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@tailrec
|
||||
def execute(f : => Unit): Unit = {
|
||||
val nb = nbConcurrentTests.incrementAndGet()
|
||||
val max = maxConcurrentTests.get()
|
||||
if( nb <= max || updateMaxConcurrentTests(max, nb)) {
|
||||
f
|
||||
nbConcurrentTests.getAndDecrement
|
||||
} else {
|
||||
nbConcurrentTests.getAndDecrement
|
||||
execute(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Test1 {
|
||||
@Test
|
||||
def slow(): Unit = ParallelTest.execute { Thread.sleep(1000) }
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
@Test
|
||||
def slow(): Unit = ParallelTest.execute { Thread.sleep(1000) }
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
@Test
|
||||
def slow(): Unit = ParallelTest.execute { Thread.sleep(1000) }
|
||||
}
|
||||
|
||||
class Test4 {
|
||||
@Test
|
||||
def slow(): Unit = ParallelTest.execute { Thread.sleep(1000) }
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
> test
|
||||
-> check
|
||||
|
||||
> clean
|
||||
> set testForkedParallel := true
|
||||
> test
|
||||
> check
|
||||
Loading…
Reference in New Issue