Skip to content

Commit

Permalink
Speedup test suite execution (#2624)
Browse files Browse the repository at this point in the history
Use `NettyConfig.defaultWithFastShutdown` in test suites
  • Loading branch information
kyri-petrou authored Jan 15, 2024
1 parent bc595f3 commit ffac725
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import zio.test.Assertion._
import zio.test._

import zio.http.ChannelEvent.{Read, Unregistered, UserEvent, UserEventTriggered}
import zio.http.netty.NettyConfig
import zio.http.netty.server.NettyDriver
import zio.http.{Headers, Status, Version, ZIOHttpSpec}

Expand Down Expand Up @@ -104,7 +105,8 @@ object SocketContractSpec extends ZIOHttpSpec {
} yield assert(response.status)(equalTo(Status.SwitchingProtocols))
}.provideSome[Client](
TestServer.layer,
NettyDriver.live,
NettyDriver.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
ZLayer.succeed(Server.Config.default.onAnyOpenPort),
Scope.default,
).provide(Client.default),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zio.http
import zio._
import zio.test._

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

object TestServerSpec extends ZIOHttpSpec {
Expand Down Expand Up @@ -114,7 +115,8 @@ object TestServerSpec extends ZIOHttpSpec {
).provide(
ZLayer.succeed(Server.Config.default.onAnyOpenPort),
Client.default,
NettyDriver.live,
NettyDriver.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
)

private def requestToCorrectPort =
Expand Down
6 changes: 3 additions & 3 deletions zio-http/src/test/scala/zio/http/ClientProxySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object ClientProxySpec extends HttpRunnableSpec {
ZLayer.succeed(ZClient.Config.default.proxy(Proxy(proxyUrl))),
NettyClientDriver.live,
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Scope.default,
)
} yield out
Expand Down Expand Up @@ -87,7 +87,7 @@ object ClientProxySpec extends HttpRunnableSpec {
ZLayer.succeed(ZClient.Config.default.proxy(proxy)),
NettyClientDriver.live,
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Scope.default,
)
} yield out
Expand Down Expand Up @@ -121,7 +121,7 @@ object ClientProxySpec extends HttpRunnableSpec {
ZLayer.succeed(ZClient.Config.default.proxy(proxy)),
NettyClientDriver.live,
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Scope.default,
)
} yield out
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/test/scala/zio/http/ClientStreamingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ object ClientStreamingSpec extends HttpRunnableSpec {
),
).provide(
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
ZLayer.succeed(Client.Config.default.connectionTimeout(100.seconds).idleTimeout(100.seconds)),
Client.live,
Scope.default,
Expand All @@ -322,7 +322,7 @@ object ClientStreamingSpec extends HttpRunnableSpec {
.intoPromise(portPromise)
.zipRight(ZIO.never)
.provide(
ZLayer.succeed(NettyConfig.default.leakDetection(LeakDetectionLevel.PARANOID)),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown.leakDetection(LeakDetectionLevel.PARANOID)),
ZLayer.succeed(
Server.Config.default.onAnyOpenPort
.requestStreaming(
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/test/scala/zio/http/DynamicAppTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ object DynamicAppTest extends ZIOHttpSpec {
NettyClientDriver.live,
Client.customized,
ZLayer.succeed(Server.Config.default.onAnyOpenPort),
Server.live,
Server.customized,
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Scope.default,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import zio.test.TestAspect.withLiveClock
import zio.test._
import zio.{Scope, ZLayer}

import zio.http.netty.NettyConfig

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

Expand Down Expand Up @@ -48,7 +50,8 @@ object NettyMaxHeaderLengthSpec extends ZIOHttpSpec {
} yield assertTrue(extractStatus(res) == Status.InternalServerError, data == "")
}.provide(
Client.default,
Server.live,
Server.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
ZLayer.succeed(serverConfig),
Scope.default,
) @@ withLiveClock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import zio.test.TestAspect.withLiveClock
import zio.test._
import zio.{Scope, ZLayer}

import zio.http.netty.NettyConfig

object NettyMaxInitialLineLength extends ZIOHttpSpec {
val minimalInitialLineLength: Int = "GET / HTTP/1.1".getBytes.length

Expand Down Expand Up @@ -52,7 +54,8 @@ object NettyMaxInitialLineLength extends ZIOHttpSpec {
} yield assertTrue(extractStatus(res) == Status.InternalServerError, data == "")
}.provide(
Client.default,
Server.live,
Server.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
ZLayer.succeed(serverConfig),
Scope.default,
) @@ withLiveClock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package zio.http

import zio._
import zio.test.Assertion.equalTo
import zio.test.TestAspect.{diagnose, sequential, shrinks, timeout, withLiveClock}
import zio.test.{assertCompletes, assertTrue, assertZIO}
import zio.test.TestAspect.{diagnose, sequential, shrinks, withLiveClock}
import zio.test.{assertTrue, assertZIO}

import zio.http.ServerSpec.requestBodySpec
import zio.http.internal.{DynamicServer, HttpRunnableSpec}
import zio.http.netty.NettyConfig

object RequestStreamingServerSpec extends HttpRunnableSpec {
def extractStatus(res: Response): Status = res.status
Expand Down Expand Up @@ -113,7 +114,8 @@ object RequestStreamingServerSpec extends HttpRunnableSpec {
.provideShared(
DynamicServer.live,
ZLayer.succeed(configAppWithRequestStreaming),
Server.live,
Server.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Client.default,
) @@ diagnose(15.seconds) @@ sequential @@ shrinks(0) @@ withLiveClock

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import zio.{Chunk, Scope, ZIO, ZInputStream, ZLayer}

import zio.stream.ZStream

import zio.http.netty.NettyConfig

object ResponseCompressionSpec extends ZIOHttpSpec {

private val text: HttpApp[Any] =
Expand Down Expand Up @@ -93,7 +95,8 @@ object ResponseCompressionSpec extends ZIOHttpSpec {
},
).provide(
ZLayer.succeed(serverConfig),
Server.live,
Server.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Client.default,
Scope.default,
) @@ withLiveClock
Expand Down
11 changes: 6 additions & 5 deletions zio-http/src/test/scala/zio/http/SSLSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object SSLSpec extends ZIOHttpSpec {
ZLayer.succeed(ZClient.Config.default.ssl(clientSSL1)),
NettyClientDriver.live,
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Scope.default,
),
// Unfortunately if the channel closes before we create the request, we can't extract the DecoderException
Expand All @@ -81,7 +81,7 @@ object SSLSpec extends ZIOHttpSpec {
ZLayer.succeed(ZClient.Config.default.ssl(clientSSL2)),
NettyClientDriver.live,
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Scope.default,
),
test("succeed when client has default SSL") {
Expand All @@ -94,7 +94,7 @@ object SSLSpec extends ZIOHttpSpec {
ZLayer.succeed(ZClient.Config.default.ssl(ClientSSLConfig.Default)),
NettyClientDriver.live,
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Scope.default,
),
test("Https Redirect when client makes http request") {
Expand All @@ -107,13 +107,14 @@ object SSLSpec extends ZIOHttpSpec {
ZLayer.succeed(ZClient.Config.default.ssl(clientSSL1)),
NettyClientDriver.live,
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Scope.default,
),
),
),
).provideShared(
Server.live,
Server.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
ZLayer.succeed(config),
)

Expand Down
4 changes: 3 additions & 1 deletion zio-http/src/test/scala/zio/http/ServerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import zio.test._
import zio.stream.{ZPipeline, ZStream}

import zio.http.internal.{DynamicServer, HttpGen, HttpRunnableSpec}
import zio.http.netty.NettyConfig
import zio.http.template.{body, div, id}

object ServerSpec extends HttpRunnableSpec {
Expand Down Expand Up @@ -495,7 +496,8 @@ object ServerSpec extends HttpRunnableSpec {
.provideShared(
DynamicServer.live,
ZLayer.succeed(configApp),
Server.live,
Server.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Client.default,
) @@ sequential @@ withLiveClock

Expand Down
15 changes: 13 additions & 2 deletions zio-http/src/test/scala/zio/http/ServerStartSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import zio.test._
import zio.{Scope, ZIO, ZLayer}

import zio.http.internal.{DynamicServer, HttpRunnableSpec}
import zio.http.netty.NettyConfig

object ServerStartSpec extends HttpRunnableSpec {

Expand All @@ -31,14 +32,24 @@ object ServerStartSpec extends HttpRunnableSpec {
val config = Server.Config.default.port(port)
serve(HttpApp.empty).flatMap { port =>
assertZIO(ZIO.attempt(port))(equalTo(port))
}.provide(ZLayer.succeed(config), DynamicServer.live, Server.live)
}.provide(
ZLayer.succeed(config),
DynamicServer.live,
Server.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
)
},
test("available port") {
val port = 0
val config = Server.Config.default.port(port)
serve(HttpApp.empty).flatMap { bindPort =>
assertZIO(ZIO.attempt(bindPort))(not(equalTo(port)))
}.provide(ZLayer.succeed(config), DynamicServer.live, Server.live)
}.provide(
ZLayer.succeed(config),
DynamicServer.live,
Server.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
)
},
)

Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/WebSocketConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object WebSocketConfigSpec extends HttpRunnableSpec {
.forwardCloseFrames(true),
),
) ++
ZLayer.succeed(NettyConfig.default) ++
ZLayer.succeed(NettyConfig.defaultWithFastShutdown) ++
DnsResolver.default >>>
Client.live

Expand Down
4 changes: 3 additions & 1 deletion zio-http/src/test/scala/zio/http/ZClientAspectSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import zio.test._
import zio.{Chunk, Scope, ZIO, ZLayer}

import zio.http.URL.Location
import zio.http.netty.NettyConfig

object ZClientAspectSpec extends ZIOHttpSpec {
def extractStatus(response: Response): Status = response.status
Expand Down Expand Up @@ -100,7 +101,8 @@ object ZClientAspectSpec extends ZIOHttpSpec {
),
).provide(
ZLayer.succeed(Server.Config.default.onAnyOpenPort),
Server.live,
Server.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
Client.default,
Scope.default,
) @@ withLiveClock
Expand Down
17 changes: 9 additions & 8 deletions zio-http/src/test/scala/zio/http/endpoint/RoundtripSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@

package zio.http.endpoint

import java.time.Instant

import zio._
import zio.test.Assertion._
import zio.test.TestAspect._
import zio.test._

import zio.stream.{Take, ZStream}
import zio.stream.ZStream

import zio.schema.{DeriveSchema, Schema}

import zio.http.Header.Authorization
import zio.http.Method._
import zio.http._
import zio.http.codec.HttpCodec.{authorization, query}
import zio.http.codec.HttpCodec.authorization
import zio.http.codec.{Doc, HeaderCodec, HttpCodec, QueryCodec}
import zio.http.endpoint.EndpointSpec.ImageMetadata
import zio.http.netty.NettyConfig
import zio.http.netty.server.NettyDriver

object RoundtripSpec extends ZIOHttpSpec {
val testLayer: ZLayer[Any, Throwable, Server & Client & Scope] =
ZLayer.make[Server & Client & Scope](
Server.live,
Server.customized,
ZLayer.succeed(Server.Config.default.onAnyOpenPort.enableRequestStreaming),
Client.customized.map(env => ZEnvironment(env.get @@ ZClientAspect.debug)),
ClientDriver.shared,
NettyDriver.live,
NettyDriver.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
ZLayer.succeed(ZClient.Config.default),
DnsResolver.default,
Scope.default,
Expand Down Expand Up @@ -530,11 +530,12 @@ object RoundtripSpec extends ZIOHttpSpec {
}
},
).provide(
Server.live,
Server.customized,
ZLayer.succeed(Server.Config.default.onAnyOpenPort.enableRequestStreaming),
Client.customized.map(env => ZEnvironment(env.get @@ clientDebugAspect)),
ClientDriver.shared,
NettyDriver.live,
NettyDriver.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
ZLayer.succeed(ZClient.Config.default),
DnsResolver.default,
Scope.default,
Expand Down
6 changes: 5 additions & 1 deletion zio-http/src/test/scala/zio/http/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ package object internal {
ZLayer.succeed(Server.Config.default.onAnyOpenPort)

val testNettyServerConfig: ZLayer[Any, Nothing, NettyConfig] =
ZLayer.succeed(NettyConfig.default.leakDetection(LeakDetectionLevel.PARANOID))
ZLayer.succeed(
NettyConfig.defaultWithFastShutdown
.copy(shutdownQuietPeriodDuration = zio.Duration.fromSeconds(0))
.leakDetection(LeakDetectionLevel.PARANOID),
)

val serverTestLayer: ZLayer[Any, Throwable, Server.Config with Server] =
ZLayer.make[Server.Config with Server](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object NettyStreamBodySpec extends HttpRunnableSpec {
.intoPromise(portPromise)
.zipRight(ZIO.never)
.provide(
ZLayer.succeed(NettyConfig.default.leakDetection(LeakDetectionLevel.PARANOID)),
ZLayer.succeed(NettyConfig.defaultWithFastShutdown.leakDetection(LeakDetectionLevel.PARANOID)),
ZLayer.succeed(Server.Config.default.onAnyOpenPort),
Server.customized,
)
Expand All @@ -46,7 +46,7 @@ object NettyStreamBodySpec extends HttpRunnableSpec {
val singleConnectionClient: ZLayer[Any, Throwable, Client] = {
implicit val trace: Trace = Trace.empty
(ZLayer.succeed(Config.default.copy(connectionPool = ConnectionPoolConfig.Fixed(1))) ++ ZLayer.succeed(
NettyConfig.default,
NettyConfig.defaultWithFastShutdown,
) ++
DnsResolver.default) >>> Client.live
}
Expand Down

0 comments on commit ffac725

Please sign in to comment.