Skip to content

Commit

Permalink
TestServer and Endpoint API: Reproduce bug reported in Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
guizmaii committed Jul 31, 2024
1 parent fdfde8e commit 5066420
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion zio-http-testkit/src/test/scala/zio/http/TestServerSpec.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package zio.http

import zio._
import zio.http.endpoint.Endpoint
import zio.test._

import zio.http.netty.NettyConfig
import zio.http.netty.server.NettyDriver

object TestServerSpec extends ZIOHttpSpec {
def status(response: Response): Status = response.status

object Api {
val hello: Route[Any, Nothing] =
Endpoint(RoutePattern.GET / "hello").out[String]
.implementAs("Hi")
}

def spec = suite("TestServerSpec")(
test("with state") {
for {
Expand Down Expand Up @@ -106,6 +112,19 @@ object TestServerSpec extends ZIOHttpSpec {
TestServer.layer,
Scope.default,
),
test("with Endpoints API - 'GET /hello' returns 'Hi'") {
for {
client <- ZIO.service[Client]
port <- ZIO.serviceWithZIO[Server](_.port)
baseRequest = Request.get(url = URL.root.port(port))
_ <- TestServer.addRoute(Api.hello)
helloResponse <- client(Request.get(baseRequest.url / "hello"))
helloBody <- helloResponse.body.asString
} yield assertTrue(helloBody == "Hi")
}.provideSome[Client with Driver](
TestServer.layer,
Scope.default,
),
).provide(
ZLayer.succeed(Server.Config.default.onAnyOpenPort),
Client.default,
Expand Down

2 comments on commit 5066420

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 : Performance Benchmarks (SimpleEffectBenchmarkServer)

concurrency: 256
requests/sec: 337343

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 : Performance Benchmarks (PlainTextBenchmarkServer)

concurrency: 256
requests/sec: 336977

Please sign in to comment.