Skip to content

Commit

Permalink
clean up future handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcovarr committed Dec 4, 2015
1 parent 6783d72 commit 54e531c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/test/scala/cromwell/engine/db/slick/SlickDataAccessSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,16 @@ class SlickDataAccessSpec extends FlatSpec with Matchers with ScalaFutures {
}

def assertCallCachingFailure(id: WorkflowId, callName: Option[String], messages: String*): Future[Unit] = {
// The `from` Future is expected to fail, so if the `map` block runs the test should fail. `recover` the
// failed Future and assert all the expected messages are present in the exception text and the correct number
// of expected failures are seen.
CallCachingParameters.from(id, None, AllowFalse, dataAccess) map {
s => throw new RuntimeException(s"Unexpected success: $s") } recover {
// The `from` Future is expected to fail, so if the forcomp actually runs the test should fail.
val parameters = for {
s <- CallCachingParameters.from(id, None, AllowFalse, dataAccess)
} yield throw new RuntimeException(s"Unexpected success: $s")

// `recover` the failed Future looking for an expected `IllegalArgumentException`. Assert all the expected
// messages are present in the exception text and the correct number of expected failures are seen.
// If the `parameters` Future is failed but the exception isn't an `IllegalArgumentException` then this recover
// won't match and the Future will remain failed and fail the test.
parameters recover {
case e: IllegalArgumentException =>
messages foreach { m => if (!e.getMessage.contains(m)) throw new RuntimeException(s"Missing message: $m. Exception text: ${e.getMessage}") }
if (e.getMessage.count(_ == '\n') != messages.size - 1) throw new RuntimeException(s"Unexpected messages seen: ${e.getMessage}")
Expand Down

0 comments on commit 54e531c

Please sign in to comment.