Hi,
I've been working with several tests that deal with Futures. I'd like to run the suite asynchronously but I can only seem to do this by introducing ParallelTestExecution and -P(number of tests). I've tried using both
AsyncFlatSpec and
ScalaFutures.whenReady but in all cases the tests run sequentially, so it's unclear to me why one would use either of those since you could just Await on the future with the same result. I can understand why ParallelTestExecution would be useful to execute a suite of synchronous tests concurrently but I'm already dealing with asynchronous tests/futures, so that doesn't make much sense. I can do the following but it's not pretty. Note, this is not using ParallelTestExecution, so single-threaded.
val queue = new mutable.Queue[Future[String]]
test1:
val future1 = ...
queue += future1
test2:
val future2 = ...
queue += future2
test3:
"await all" in {
for (future <- queue)
ScalaFutures.whenReady(future, patience) { s =>
s should ??
}
}
This works in that the none of the tests block and the suite takes only as long as the longest test, but it's clearly ugly and the assertions do not occur in the context of the right test.
So, I'd be very interested in finding out if there any way in ScalaTest to execute these asynchronous tests without blocking until the futures of all tests have been collected, without using ParallelTestExecution.
Thanks,
Andrew