I have the following unit test:
test("All - gather message") {
def fs: List[Future[Int]] = List(Future{
blocking {Thread.sleep(4000)}
println("Finished sleeping in future 1!")
1
}, Future {
blocking {Thread.sleep(3000)}
println("Finished sleeping in future 2!")
2
}, Future {
blocking {Thread.sleep(2000)}
println("Finished sleeping in future 3!")
3
})
val f: Future[List[Int]] = Future.all(fs)
f onComplete { case x => {
println("x is: " + x.get)
assert(x.get == List(1, 2, 3))
}
}
Await.ready(f, 5 seconds)
}
This is part of a test suite.
The problem is that when my code doesn't produce the correct result, the test is still passed and the error message appears in the output of the next unit test in the test suite.
I think this is because once f
completes, the test function returns, and only after this the code from the onComplete
block gets executed.
I would like the test function to return only after the code from onComplete
is executed.
How can I do this?