diff --git a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ClientServerSpec.scala b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ClientServerSpec.scala index 6ee016d36..aa7c2a5a5 100644 --- a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ClientServerSpec.scala +++ b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ClientServerSpec.scala @@ -39,6 +39,7 @@ import pekko.http.scaladsl.model.{ Uri } import pekko.http.scaladsl.model.headers.HttpEncodings +import pekko.http.scaladsl.server.{ Directives, Route } import pekko.http.scaladsl.settings.ClientConnectionSettings import pekko.http.scaladsl.settings.ServerSettings import pekko.http.scaladsl.unmarshalling.Unmarshal @@ -303,6 +304,44 @@ class Http2ClientServerSpec extends PekkoSpecWithMaterializer( expectClientResponse().status should be(StatusCodes.OK) } + "complete a concurrent request when another route fails" in new TestSetup { + override def handler: HttpRequest => Future[HttpResponse] = { + import Directives._ + val applicationHandler = super.handler + Route.toFunction(extractRequest(request => complete(applicationHandler(request)))) + } + + def sendAndObserve(path: String): ServerRequest = { + sendClientRequest(HttpRequest(uri = path).addAttribute(requestIdAttr, RequestId(path))) + val observed = expectServerRequest() + observed.request.uri.path.toString shouldBe path + observed + } + + try { + val failing = sendAndObserve("/failing") + val healthy = sendAndObserve("/healthy") + + // Both requests reached the application before either response was released. + EventFilter[TE](occurrences = 1).intercept { + failing.promise.failure(TE("application failure")) + val response = expectClientResponse() + response.attribute(requestIdAttr) shouldBe Some(RequestId("/failing")) + response.status shouldBe StatusCodes.InternalServerError + response.discardEntityBytes().future.futureValue + } + + healthy.sendResponse(HttpResponse(entity = "healthy response")) + val response = expectClientResponse() + response.attribute(requestIdAttr) shouldBe Some(RequestId("/healthy")) + response.status shouldBe StatusCodes.OK + Unmarshal(response.entity).to[String].futureValue shouldBe "healthy response" + } finally { + try clientRequestsOut.sendComplete() + finally binding.terminate(1.second).futureValue(timeout(3.seconds)) + } + } + "return internal server error when handler throws synchronously" in new TestSetup { override def handler: HttpRequest => Future[HttpResponse] = _ => throw TE("boom-sync")