Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down