I am using specs2 as my test framework. I want to test a piece of code which is heavily depended on futures.
For example this is the piece of code:
def register(x: Int){
val f1 = dao1.save(x)
.map{
f2 = dao2.save(x)
f2.onFailure{
case t => action.revert()
}
f2
}
f1.onFailure{
case t => action.revert()
}
f1
}
I want to test the scenario in which dao2.save(x) fails. In this case I expect action.revert() to be executed twice.
The problem is the when I actually test it, while mocking dao2, the assertion occur before the onFailure content get executed. So on my laptop all tests pass, but on the build server(where stuff is a little slower) it fails.
Any good way to handle this case?
Thanks!
Aucun commentaire:
Enregistrer un commentaire