mirror of https://github.com/sbt/sbt.git
38 lines
1.1 KiB
Scala
38 lines
1.1 KiB
Scala
import xsbt._
|
|
|
|
import org.scalacheck._
|
|
import Prop._
|
|
import Task._
|
|
import Math.abs
|
|
|
|
object TaskRunnerForkTest extends Properties("TaskRunner Fork")
|
|
{
|
|
specify("fork m tasks and wait for all to complete", (m: Int, workers: Int) =>
|
|
(workers > 0 && m >= 0) ==> {
|
|
val values = (0 until m).toList
|
|
checkResult(TaskRunner(values.fork(f => () ).join.map(_.toList),workers), values)
|
|
true
|
|
}
|
|
)
|
|
specify("Fork and reduce 2", (m: Int, workers: Int) =>
|
|
(workers > 0 && m > 1) ==> {
|
|
val task = (0 to m) fork {_ * 10} reduce{_ + _}
|
|
checkResult(TaskRunner(task, workers), 5*(m+1)*m)
|
|
}
|
|
)
|
|
specify("Double join", (a: Int, b: Int, workers: Int) =>
|
|
(workers > 0) ==> { runDoubleJoin(abs(a),abs(b),workers); true }
|
|
)
|
|
def runDoubleJoin(a: Int, b: Int, workers: Int)
|
|
{
|
|
def inner(i: Int) = List.range(0, b).map(j => Task(j) named(j.toString)).join.named("Join " + i)
|
|
TaskRunner( List.range(0,a).map(inner).join.named("Outermost join"), workers)
|
|
}
|
|
specify("fork and reduce", (m: List[Int], workers: Int) => {
|
|
(workers > 0 && !m.isEmpty) ==> {
|
|
val expected = m.reduceLeft(_+_)
|
|
checkResult(TaskRunner( m.reduce(_ + _), workers), expected)
|
|
}
|
|
}
|
|
)
|
|
} |