Skip to content

Commit

Permalink
attempt fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NavidJalali committed Oct 26, 2024
1 parent 88dc99d commit 8d0b3f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.apache.pekko
import pekko.actor.ActorSystem
import pekko.grpc.internal.{ GrpcProtocolNative, GrpcRequestHelpers, Identity }
import pekko.grpc.scaladsl.headers.`Status`
import pekko.http.scaladsl.model.{ AttributeKeys, HttpEntity, HttpRequest, HttpResponse }
import pekko.http.scaladsl.model.{ HttpEntity, HttpRequest, HttpResponse }
import pekko.http.scaladsl.model.HttpEntity.{ Chunked, LastChunk, Strict }
import pekko.grpc.GrpcProtocol
import pekko.stream.scaladsl.{ Sink, Source }
Expand Down Expand Up @@ -58,7 +58,7 @@ class GrpcExceptionDefaultHandleSpec
case Seq(LastChunk("", List(`Status`("3")))) => // ok
}
case _: Strict =>
response.attribute(AttributeKeys.trailer).get.headers.contains("grpc-status" -> "3")
response.headers.find(_.is("grpc-status")).map(_.value()) shouldBe Some("3")
case other =>
fail(s"Unexpected [$other]")
}
Expand Down Expand Up @@ -131,14 +131,18 @@ class GrpcExceptionDefaultHandleSpec

val reply = GreeterServiceHandler(ExampleImpl).apply(request).futureValue

val lastChunk = reply.entity.asInstanceOf[Chunked].chunks.runWith(Sink.last).futureValue.asInstanceOf[LastChunk]
reply.entity shouldBe a[Strict]
val strict = reply.entity.asInstanceOf[Strict]
strict.contentType.mediaType.toString shouldBe "application/grpc+proto"
strict.dataBytes.runFold(ByteString.empty)(_ ++ _).futureValue.seq.isEmpty shouldBe true

// Invalid argument is '3' https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
val statusHeader = lastChunk.trailer.find { _.name == "grpc-status" }
val statusHeader = reply.headers.find(_.is("grpc-status"))
statusHeader.map(_.value()) should be(Some("3"))
val statusMessageHeader = lastChunk.trailer.find { _.name == "grpc-message" }
val statusMessageHeader = reply.headers.find(_.is("grpc-message"))
statusMessageHeader.map(_.value()) should be(Some("No name found"))

val metadata = MetadataBuilder.fromHeaders(lastChunk.trailer)
val metadata = MetadataBuilder.fromHeaders(reply.headers)
metadata.getText("test-text") should be(Some("test-text-data"))
metadata.getBinary("test-binary-bin") should be(Some(ByteString("test-binary-data")))
}
Expand Down
2 changes: 1 addition & 1 deletion project/PekkoHttpDependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ import com.github.pjfanning.pekkobuild.PekkoDependency
object PekkoHttpDependency extends PekkoDependency {
override val checkProject: String = "pekko-http-testkit"
override val module: Option[String] = Some("http")
override val currentVersion: String = "1.1.0"
override val currentVersion: String = "1.1.0+13-750e8f96-SNAPSHOT"
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ private final class PekkoNettyGrpcClientGraphStage[I, O](
override def onMessage(message: O): Unit =
callback.invoke(message)
override def onClose(status: Status, trailers: Metadata): Unit = {
if (!matVal.isCompleted) onHeaders(trailers)
trailerPromise.success(trailers)
callback.invoke(Closed(status, trailers))
}
Expand Down

0 comments on commit 8d0b3f8

Please sign in to comment.