summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorRoland <rk@rkuhn.info>2012-09-10 15:52:07 +0200
committerRoland <rk@rkuhn.info>2012-09-10 15:52:07 +0200
commit3767a6a83efc74d34e9025f798eeb2a043e6df8d (patch)
tree85d5b78144bf8a9ab4ddd41c74c69ef2d7bb0db5 /test/files/jvm
parentb7e08723d142c8227181eed283e7c982f449425a (diff)
downloadscala-3767a6a83efc74d34e9025f798eeb2a043e6df8d.tar.gz
scala-3767a6a83efc74d34e9025f798eeb2a043e6df8d.tar.bz2
scala-3767a6a83efc74d34e9025f798eeb2a043e6df8d.zip
fix usage of Duration in Promise impl
- correctly treat MinusInf and Undefined - don't toMillis in the timeout message (could be MinusInf) - also notice that Inf did not actually wait unbounded - and further notice that tryAwait swallows InterruptedException instead of bailing out early => changed to do so and added throws annotation - also removed some unused imports of Duration
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/scala-concurrent-tck.scala34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala
index ffb5608fd2..a60f3c8a63 100644
--- a/test/files/jvm/scala-concurrent-tck.scala
+++ b/test/files/jvm/scala-concurrent-tck.scala
@@ -11,6 +11,7 @@ import scala.concurrent.{
import scala.concurrent.{ future, promise, blocking }
import scala.util.{ Try, Success, Failure }
import scala.concurrent.util.Duration
+import scala.reflect.{ classTag, ClassTag }
trait TestBase {
@@ -19,6 +20,14 @@ trait TestBase {
body(() => sv put true)
sv.take(2000)
}
+
+ def intercept[T <: Exception : ClassTag](code: => Unit): Unit =
+ try {
+ code
+ assert(false, "did not throw " + classTag[T])
+ } catch {
+ case ex: Exception if classTag[T].runtimeClass isInstance ex =>
+ }
// def assert(cond: => Boolean) {
// try {
@@ -663,6 +672,29 @@ trait FutureProjections extends TestBase {
case nsee: NoSuchElementException => done()
}
}
+
+ def testAwaitPositiveDuration(): Unit = once { done =>
+ val p = Promise[Int]()
+ val f = p.future
+ future {
+ intercept[IllegalArgumentException] { Await.ready(f, Duration.Undefined) }
+ p.success(0)
+ Await.ready(f, Duration.Zero)
+ Await.ready(f, Duration(500, "ms"))
+ Await.ready(f, Duration.Inf)
+ done()
+ } onFailure { case x => throw x }
+ }
+
+ def testAwaitNegativeDuration(): Unit = once { done =>
+ val f = Promise().future
+ future {
+ intercept[TimeoutException] { Await.ready(f, Duration.Zero) }
+ intercept[TimeoutException] { Await.ready(f, Duration.MinusInf) }
+ intercept[TimeoutException] { Await.ready(f, Duration(-500, "ms")) }
+ done()
+ } onFailure { case x => throw x }
+ }
testFailedFailureOnComplete()
testFailedFailureOnSuccess()
@@ -670,6 +702,8 @@ trait FutureProjections extends TestBase {
testFailedSuccessOnFailure()
testFailedFailureAwait()
testFailedSuccessAwait()
+ testAwaitPositiveDuration()
+ testAwaitNegativeDuration()
}