Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of using ScalaFutures from ScalaTest vs. Await.result

I recently had a discussions with colleagues over the use or whenReady or .futureValue from ScalaFutures in ScalaTest versus Await.result in tests. Besides the readability, consistency in configuration (timeouts) and result scoping when using whenReady, is there any other noticeable advantages of using ScalaFutures methods over Await.result ?

I noticed that ScalaFutures use a "polling" technique instead of blocking like Await, but can someone elaborate over the advantages ?

like image 755
jgagnon1 Avatar asked Dec 05 '14 15:12

jgagnon1


1 Answers

When you use Await.result you are blocking the calling thread. The effect of this would be most noticeable if you ran your tests in a single-threaded manner (e.g. with an SBT setting like parallelExecution in Test := false).

The polling done by ScalaFutures is done (afaik) via a scheduler; hence, it doesn't block any thread. As a result you could have a number of concurrently running tests that far exceed the Threads available on whatever ExecutionContext the tests are actually running on.

like image 58
Idan Waisman Avatar answered Nov 15 '22 20:11

Idan Waisman