sbt/tasks/src/test/scala/TaskRunnerFork.scala

38 lines
1.2 KiB
Scala
Raw Normal View History

2010-06-10 14:19:15 +02:00
import sbt._
2009-08-16 20:29:08 +02:00
import org.scalacheck._
import Prop._
import Task._
import TaskGen._
2010-06-10 14:19:15 +02:00
import math.abs
2009-08-16 20:29:08 +02:00
object TaskRunnerForkTest extends Properties("TaskRunner Fork")
{
property("fork m tasks and wait for all to complete") = forAll(MaxTasksGen, MaxWorkersGen) { (m: Int, workers: Int) =>
val values = (0 until m).toList
2010-06-10 14:19:15 +02:00
checkResult(tryRun(values.fork(f => () ).join.map(_.toList),false, workers), values)
true
}
property("Fork and reduce 2") = forAll(MaxTasksGen, MaxWorkersGen) { (m: Int, workers: Int) =>
(m > 1) ==> {
2011-05-29 05:49:17 +02:00
val task = (0 to m) fork {_ * 10} reduced{_ + _}
2010-06-10 14:19:15 +02:00
checkResult(tryRun(task, false, workers), 5*(m+1)*m)
}
}
property("Double join") = forAll(MaxJoinGen, MaxJoinGen, MaxWorkersGen) { (a: Int, b: Int, workers: Int) =>
runDoubleJoin(abs(a),abs(b),workers)
true
}
2009-08-16 20:29:08 +02:00
def runDoubleJoin(a: Int, b: Int, workers: Int)
{
2010-06-10 14:19:15 +02:00
def inner(i: Int) = List.range(0, b).map(j => pure(j.toString, j)).join
tryRun( List.range(0,a).map(inner).join, false, workers)
2009-08-16 20:29:08 +02:00
}
property("fork and reduce") = forAll(TaskListGen, MaxWorkersGen) { (m: List[Int], workers: Int) =>
(!m.isEmpty) ==> {
val expected = m.reduceLeft(_+_)
2011-05-29 05:49:17 +02:00
checkResult(tryRun( m.reduced(_ + _), false, workers), expected)
2009-08-16 20:29:08 +02:00
}
}
}