diff --git a/akka-http-core/src/main/scala/akka/http/util/package.scala b/akka-http-core/src/main/scala/akka/http/util/package.scala index 9e427bbcf1..f2d1c06af6 100644 --- a/akka-http-core/src/main/scala/akka/http/util/package.scala +++ b/akka-http-core/src/main/scala/akka/http/util/package.scala @@ -10,7 +10,9 @@ import java.nio.charset.Charset import com.typesafe.config.Config import akka.stream.{ FlowMaterializer, FlattenStrategy, Transformer } import akka.stream.scaladsl.{ Flow, Source } -import scala.concurrent.Future +import scala.concurrent.duration.Duration +import scala.concurrent.{ Await, Future } +import scala.util.{ Failure, Success } import scala.util.matching.Regex import akka.event.LoggingAdapter import akka.util.ByteString @@ -77,6 +79,17 @@ package object util { underlying.fold(Vector.empty[T])(_ :+ _) } + private[http] implicit class AddFutureAwaitResult[T](future: Future[T]) { + /** "Safe" Await.result that doesn't throw away half of the stacktrace */ + def awaitResult(atMost: Duration): T = { + Await.ready(future, atMost) + future.value.get match { + case Success(t) ⇒ t + case Failure(ex) ⇒ throw new RuntimeException("Trying to await result of failed Future, see the cause for the original problem.", ex) + } + } + } + private[http] def errorLogger(log: LoggingAdapter, msg: String): Transformer[ByteString, ByteString] = new Transformer[ByteString, ByteString] { def onNext(element: ByteString) = element :: Nil diff --git a/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTestResultComponent.scala b/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTestResultComponent.scala index 26a0d520de..373c864821 100644 --- a/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTestResultComponent.scala +++ b/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTestResultComponent.scala @@ -7,7 +7,8 @@ package akka.http.testkit import java.util.concurrent.CountDownLatch import scala.collection.immutable import scala.concurrent.duration._ -import scala.concurrent.{ Await, ExecutionContext } +import scala.concurrent.ExecutionContext +import akka.http.util._ import akka.stream.FlowMaterializer import akka.stream.scaladsl._ import akka.http.model.HttpEntity.ChunkStreamPart @@ -95,6 +96,6 @@ trait RouteTestResultComponent { failTest("Request was neither completed nor rejected within " + timeout) private def awaitAllElements[T](data: Source[T]): immutable.Seq[T] = - Await.result(data.grouped(Int.MaxValue).runWith(Sink.head), timeout) + data.collectAll.awaitResult(timeout) } } \ No newline at end of file