2017-10-04 19:01:06 +02:00
|
|
|
/*
|
|
|
|
|
* sbt
|
2018-09-14 09:40:39 +02:00
|
|
|
* Copyright 2011 - 2018, Lightbend, Inc.
|
2017-10-04 19:01:06 +02:00
|
|
|
* Copyright 2008 - 2010, Mark Harrah
|
2018-09-14 09:40:39 +02:00
|
|
|
* Licensed under Apache License 2.0 (see LICENSE)
|
2017-10-04 19:01:06 +02:00
|
|
|
*/
|
|
|
|
|
|
2010-06-10 14:19:15 +02:00
|
|
|
package sbt
|
2009-08-16 20:29:08 +02:00
|
|
|
|
|
|
|
|
import org.scalacheck._
|
|
|
|
|
import Prop._
|
2009-11-12 00:41:39 +01:00
|
|
|
import TaskGen._
|
2009-08-16 20:29:08 +02:00
|
|
|
|
2014-05-07 17:52:23 +02:00
|
|
|
object TaskRunnerCircularTest extends Properties("TaskRunner Circular") {
|
2017-04-21 09:14:31 +02:00
|
|
|
property("Catches circular references") = forAll(MaxTasksGen, MaxWorkersGen) {
|
|
|
|
|
checkCircularReferences _
|
|
|
|
|
}
|
|
|
|
|
property("Allows references to completed tasks") = forAllNoShrink(MaxTasksGen, MaxWorkersGen) {
|
|
|
|
|
allowedReference _
|
|
|
|
|
}
|
|
|
|
|
final def allowedReference(intermediate: Int, workers: Int) = {
|
|
|
|
|
val top = task(intermediate).named("top")
|
|
|
|
|
def iterate(tk: Task[Int]): Task[Int] =
|
|
|
|
|
tk flatMap { t =>
|
|
|
|
|
if (t <= 0)
|
|
|
|
|
top
|
|
|
|
|
else
|
|
|
|
|
iterate(task(t - 1).named((t - 1).toString))
|
|
|
|
|
}
|
2019-04-20 09:23:54 +02:00
|
|
|
try {
|
|
|
|
|
checkResult(tryRun(iterate(top), true, workers), intermediate)
|
|
|
|
|
} catch {
|
2017-04-21 09:14:31 +02:00
|
|
|
case i: Incomplete if cyclic(i) => ("Unexpected cyclic exception: " + i) |: false
|
2014-05-07 17:52:23 +02:00
|
|
|
}
|
2017-04-21 09:14:31 +02:00
|
|
|
}
|
|
|
|
|
final def checkCircularReferences(intermediate: Int, workers: Int) = {
|
|
|
|
|
lazy val top = iterate(task(intermediate).named("bottom"), intermediate)
|
|
|
|
|
def iterate(tk: Task[Int], i: Int): Task[Int] =
|
|
|
|
|
tk flatMap { t =>
|
|
|
|
|
if (t <= 0)
|
|
|
|
|
top
|
|
|
|
|
else
|
|
|
|
|
iterate(task(t - 1).named((t - 1).toString), i - 1)
|
|
|
|
|
}
|
2019-04-20 09:23:54 +02:00
|
|
|
try {
|
|
|
|
|
tryRun(top, true, workers); false
|
|
|
|
|
} catch { case i: Incomplete => cyclic(i) }
|
2017-04-21 09:14:31 +02:00
|
|
|
}
|
2017-12-04 17:33:20 +01:00
|
|
|
|
2017-04-21 09:14:31 +02:00
|
|
|
def cyclic(i: Incomplete) =
|
|
|
|
|
Incomplete
|
|
|
|
|
.allExceptions(i)
|
2017-12-04 17:33:20 +01:00
|
|
|
.exists(_.isInstanceOf[Execute[({ type A[_] <: AnyRef })#A @unchecked]#CyclicException[_]])
|
2016-06-18 01:12:59 +02:00
|
|
|
}
|