summaryrefslogtreecommitdiff
path: root/test/files/jvm/future-spec
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2013-02-01 03:32:18 +0100
committerPhilipp Haller <hallerp@gmail.com>2013-02-01 03:32:18 +0100
commit5275baee6c563418f53abd2486764be08916c8c5 (patch)
tree06ceb2731b989e07674e67e69a5b71fac33142bb /test/files/jvm/future-spec
parent3f78bee128bd6a478bef6a66c5574f77a2d6dd74 (diff)
downloadscala-5275baee6c563418f53abd2486764be08916c8c5.tar.gz
scala-5275baee6c563418f53abd2486764be08916c8c5.tar.bz2
scala-5275baee6c563418f53abd2486764be08916c8c5.zip
SI-7029 - Make test more robust
Diffstat (limited to 'test/files/jvm/future-spec')
-rw-r--r--test/files/jvm/future-spec/FutureTests.scala36
1 files changed, 12 insertions, 24 deletions
diff --git a/test/files/jvm/future-spec/FutureTests.scala b/test/files/jvm/future-spec/FutureTests.scala
index ae2e72bf96..0efa83fbd9 100644
--- a/test/files/jvm/future-spec/FutureTests.scala
+++ b/test/files/jvm/future-spec/FutureTests.scala
@@ -70,33 +70,21 @@ object FutureTests extends MinimalScalaTest {
//FIXME should check
}
}
-
- "A future with global ExecutionContext" should {
- import ExecutionContext.Implicits._
- "output uncaught exceptions" in {
- import java.io.{ ByteArrayOutputStream, PrintStream }
-
- val baos = new ByteArrayOutputStream(1 << 16) { def isEmpty: Boolean = count == 0 }
- val tmpErr = new PrintStream(baos)
-
- def assertPrintedToErr(t: Throwable): Unit = {
- t.printStackTrace(tmpErr)
- tmpErr.flush()
- val expected = baos.toByteArray.toIndexedSeq
- baos.reset()
- val f = Future(throw t)
- val d = Deadline.now + 5.seconds
- while(d.hasTimeLeft && baos.isEmpty) Thread.sleep(10)
- baos.toByteArray.toIndexedSeq mustBe (expected)
- }
+ "The default ExecutionContext" should {
+ "report uncaught exceptions" in {
+ val p = Promise[Throwable]()
+ val logThrowable: Throwable => Unit = p.trySuccess(_)
+ val ec: ExecutionContext = ExecutionContext.fromExecutor(null, logThrowable)
- val oldErr = System.err
- System.setErr(tmpErr)
- try {
- assertPrintedToErr(new NotImplementedError("foo"))
- } finally System.setErr(oldErr)
+ val t = new NotImplementedError("foo")
+ val f = Future(throw t)(ec)
+ Await.result(p.future, 2.seconds) mustBe t
}
+ }
+
+ "A future with global ExecutionContext" should {
+ import ExecutionContext.Implicits._
"compose with for-comprehensions" in {
def async(x: Int) = future { (x * 2).toString }