From 25bc720a9ab86b6c31b37f39fed27603cd833022 Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Tue, 29 Aug 2023 06:34:24 -0700 Subject: [PATCH] Fix Scoping Of Test Resources (#2407) * investigate ci flakiness * provide per test scope * provide per test scope * format * provide per test scope * provide per test scope * provide per test scope * provide per test scope * provide per test scope * update example * cleanup * rename * cleanup * enable web socket spec * revert * cleanup * cleanup * endpoint spec * revert * fix * client https spec * client streaming spec * endpoint spec cleanup * cleanup * cleanup * fix * client streaming spec * ssl spec --- .../zio/http/endpoint/cli/CliRequest.scala | 2 +- .../zio/http/endpoint/cli/HttpCliApp.scala | 6 +++--- .../scala/zio/http/endpoint/cli/Retriever.scala | 2 +- .../scala/zio/http/endpoint/cli/CliSpec.scala | 2 +- .../scala/example/WebSocketSimpleClient.scala | 6 ++---- .../test/scala/zio/http/TestServerSpec.scala | 7 ++++--- .../src/main/scala/zio/http/DnsResolver.scala | 2 +- zio-http/src/main/scala/zio/http/Driver.scala | 2 +- zio-http/src/main/scala/zio/http/Server.scala | 2 +- zio-http/src/main/scala/zio/http/ZClient.scala | 2 +- .../scala/zio/http/netty/server/package.scala | 4 ++-- zio-http/src/test/scala/zio/http/BodySpec.scala | 2 +- .../test/scala/zio/http/ClientHttpsSpec.scala | 6 ++---- .../test/scala/zio/http/ClientProxySpec.scala | 5 ++--- .../src/test/scala/zio/http/ClientSpec.scala | 6 +++--- .../scala/zio/http/ClientStreamingSpec.scala | 6 +++--- .../test/scala/zio/http/ContentTypeSpec.scala | 6 ++---- .../src/test/scala/zio/http/HandlerSpec.scala | 2 +- .../src/test/scala/zio/http/KeepAliveSpec.scala | 8 +++----- .../zio/http/RequestStreamingServerSpec.scala | 17 +++++++++-------- zio-http/src/test/scala/zio/http/SSLSpec.scala | 3 +-- .../src/test/scala/zio/http/ServerSpec.scala | 16 ++++++++-------- .../scala/zio/http/StaticFileServerSpec.scala | 7 +++---- .../test/scala/zio/http/StaticServerSpec.scala | 16 ++++++++-------- .../src/test/scala/zio/http/WebSocketSpec.scala | 10 ++++------ .../http/endpoint/EndpointRoundtripSpec.scala | 6 +++--- .../scala/zio/http/internal/DynamicServer.scala | 2 +- .../test/scala/zio/http/internal/package.scala | 2 +- .../scala/zio/http/netty/NettyChannelSpec.scala | 2 +- .../netty/client/NettyConnectionPoolSpec.scala | 16 +++++++++------- 30 files changed, 83 insertions(+), 92 deletions(-) diff --git a/zio-http-cli/src/main/scala/zio/http/endpoint/cli/CliRequest.scala b/zio-http-cli/src/main/scala/zio/http/endpoint/cli/CliRequest.scala index e81de175ca..d2c44bc8a8 100644 --- a/zio-http-cli/src/main/scala/zio/http/endpoint/cli/CliRequest.scala +++ b/zio-http-cli/src/main/scala/zio/http/endpoint/cli/CliRequest.scala @@ -54,7 +54,7 @@ private[cli] final case class CliRequest( } for { - forms <- ZIO.foreach(body)(_.retrieve()).provideSome(clientLayer) + forms <- ZIO.foreach(body)(_.retrieve()).provide(clientLayer) finalBody <- Body.fromMultipartFormUUID(Form(forms)) } yield Request(method = method, url = url.host(host).port(port), body = finalBody, headers = headers) } diff --git a/zio-http-cli/src/main/scala/zio/http/endpoint/cli/HttpCliApp.scala b/zio-http-cli/src/main/scala/zio/http/endpoint/cli/HttpCliApp.scala index 321e02064b..f164eea6af 100644 --- a/zio-http-cli/src/main/scala/zio/http/endpoint/cli/HttpCliApp.scala +++ b/zio-http-cli/src/main/scala/zio/http/endpoint/cli/HttpCliApp.scala @@ -66,9 +66,9 @@ object HttpCliApp { for { request <- req.toRequest(host, port, client) response <- client match { - case CliZIOClient(client) => client.request(request).provideSome(Scope.default) - case CliZLayerClient(client) => Client.request(request).provideSome(Scope.default, client) - case DefaultClient() => Client.request(request).provideSome(Scope.default, Client.default) + case CliZIOClient(client) => client.request(request).provide(Scope.default) + case CliZLayerClient(client) => Client.request(request).provide(Scope.default, client) + case DefaultClient() => Client.request(request).provide(Scope.default, Client.default) } _ <- Console.printLine(s"Got response") diff --git a/zio-http-cli/src/main/scala/zio/http/endpoint/cli/Retriever.scala b/zio-http-cli/src/main/scala/zio/http/endpoint/cli/Retriever.scala index 1c5003ebc2..f50ed09649 100644 --- a/zio-http-cli/src/main/scala/zio/http/endpoint/cli/Retriever.scala +++ b/zio-http-cli/src/main/scala/zio/http/endpoint/cli/Retriever.scala @@ -35,7 +35,7 @@ private[cli] object Retriever { lazy val request = Request.get(http.URL(http.Path.decode(url))) override def retrieve(): ZIO[Client, Throwable, FormField] = for { client <- ZIO.service[Client] - response <- client.request(request).provideSome(Scope.default) + response <- client.request(request).provide(Scope.default) chunk <- response.body.asChunk } yield FormField.binaryField(name, chunk, media) } diff --git a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CliSpec.scala b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CliSpec.scala index ffa778af41..670ac56604 100644 --- a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CliSpec.scala +++ b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CliSpec.scala @@ -132,7 +132,7 @@ object CliSpec extends ZIOSpecDefault { } } }, - ) @@ timeout(60.second), + ), suite("Correct behaviour of CliApp")( test("Simple endpoint") { for { diff --git a/zio-http-example/src/main/scala/example/WebSocketSimpleClient.scala b/zio-http-example/src/main/scala/example/WebSocketSimpleClient.scala index ef7f4903ff..7246f7c036 100644 --- a/zio-http-example/src/main/scala/example/WebSocketSimpleClient.scala +++ b/zio-http-example/src/main/scala/example/WebSocketSimpleClient.scala @@ -36,9 +36,7 @@ object WebSocketSimpleClient extends ZIOAppDefault { val app: ZIO[Client with Scope, Throwable, Response] = socketApp.connect(url) *> ZIO.never - val run: ZIO[ZIOAppArgs with Scope, Throwable, Any] = - ZIO.scoped { - app.provideSome[Scope](Client.default) - } + val run: ZIO[Any, Throwable, Any] = + app.provide(Client.default, Scope.default) } diff --git a/zio-http-testkit/src/test/scala/zio/http/TestServerSpec.scala b/zio-http-testkit/src/test/scala/zio/http/TestServerSpec.scala index 37c37a6b01..2676a2bb85 100644 --- a/zio-http-testkit/src/test/scala/zio/http/TestServerSpec.scala +++ b/zio-http-testkit/src/test/scala/zio/http/TestServerSpec.scala @@ -34,8 +34,9 @@ object TestServerSpec extends ZIOHttpSpec { ) } yield assertTrue(status(response1) == Status.Ok) && assertTrue(status(response2) == Status.InternalServerError) - }.provideSome[Client with Driver with Scope]( + }.provideSome[Client with Driver]( TestServer.layer, + Scope.default, ), suite("Exact Request=>Response version")( test("matches") { @@ -85,14 +86,14 @@ object TestServerSpec extends ZIOHttpSpec { } yield assertTrue(status(finalResponse) == Status.NotFound) }, ) - .provideSome[Client with Driver with Scope]( + .provideSome[Client with Driver]( TestServer.layer, + Scope.default, ), ).provide( ZLayer.succeed(Server.Config.default.onAnyOpenPort), Client.default, NettyDriver.live, - Scope.default, ) private def requestToCorrectPort = diff --git a/zio-http/src/main/scala/zio/http/DnsResolver.scala b/zio-http/src/main/scala/zio/http/DnsResolver.scala index 7122d0726f..ce89fed555 100644 --- a/zio-http/src/main/scala/zio/http/DnsResolver.scala +++ b/zio-http/src/main/scala/zio/http/DnsResolver.scala @@ -291,7 +291,7 @@ object DnsResolver { } } - lazy val live: ZLayer[DnsResolver.Config, Nothing, DnsResolver] = { + val live: ZLayer[DnsResolver.Config, Nothing, DnsResolver] = { implicit val trace: Trace = Trace.empty ZLayer.scoped { diff --git a/zio-http/src/main/scala/zio/http/Driver.scala b/zio-http/src/main/scala/zio/http/Driver.scala index e88542fb5a..80a6f39392 100644 --- a/zio-http/src/main/scala/zio/http/Driver.scala +++ b/zio-http/src/main/scala/zio/http/Driver.scala @@ -34,6 +34,6 @@ trait Driver { object Driver { final case class StartResult(port: Int, inFlightRequests: LongAdder) - def default: ZLayer[Server.Config, Throwable, Driver] = + val default: ZLayer[Server.Config, Throwable, Driver] = NettyDriver.live } diff --git a/zio-http/src/main/scala/zio/http/Server.scala b/zio-http/src/main/scala/zio/http/Server.scala index 95a34a0d52..ad526438c2 100644 --- a/zio-http/src/main/scala/zio/http/Server.scala +++ b/zio-http/src/main/scala/zio/http/Server.scala @@ -381,7 +381,7 @@ object Server { ZLayer.succeed(Config.default) >>> live } - lazy val live: ZLayer[Config, Throwable, Server] = { + val live: ZLayer[Config, Throwable, Server] = { implicit val trace: Trace = Trace.empty NettyDriver.live >+> base } diff --git a/zio-http/src/main/scala/zio/http/ZClient.scala b/zio-http/src/main/scala/zio/http/ZClient.scala index e1bc3a484b..adcc681d74 100644 --- a/zio-http/src/main/scala/zio/http/ZClient.scala +++ b/zio-http/src/main/scala/zio/http/ZClient.scala @@ -283,7 +283,7 @@ object ZClient { driver, ) - lazy val live: ZLayer[ZClient.Config with NettyConfig with DnsResolver, Throwable, Client] = { + val live: ZLayer[ZClient.Config with NettyConfig with DnsResolver, Throwable, Client] = { implicit val trace: Trace = Trace.empty (NettyClientDriver.live ++ ZLayer.service[DnsResolver]) >>> customized }.fresh diff --git a/zio-http/src/main/scala/zio/http/netty/server/package.scala b/zio-http/src/main/scala/zio/http/netty/server/package.scala index f288a4a990..1c42f5d56f 100644 --- a/zio-http/src/main/scala/zio/http/netty/server/package.scala +++ b/zio-http/src/main/scala/zio/http/netty/server/package.scala @@ -26,9 +26,9 @@ package object server { private[server] type AppRef = AtomicReference[(HttpApp[Any], ZEnvironment[Any])] private[server] type EnvRef = AtomicReference[ZEnvironment[Any]] - def live: ZLayer[Server.Config, Throwable, Driver] = + val live: ZLayer[Server.Config, Throwable, Driver] = NettyDriver.live - def manual: ZLayer[EventLoopGroup & ChannelFactory[ServerChannel] & Server.Config & NettyConfig, Nothing, Driver] = + val manual: ZLayer[EventLoopGroup & ChannelFactory[ServerChannel] & Server.Config & NettyConfig, Nothing, Driver] = NettyDriver.manual } diff --git a/zio-http/src/test/scala/zio/http/BodySpec.scala b/zio-http/src/test/scala/zio/http/BodySpec.scala index ed734e85ea..828473eb04 100644 --- a/zio-http/src/test/scala/zio/http/BodySpec.scala +++ b/zio-http/src/test/scala/zio/http/BodySpec.scala @@ -56,5 +56,5 @@ object BodySpec extends ZIOHttpSpec { ), ), ), - ) @@ timeout(10 seconds) + ) } diff --git a/zio-http/src/test/scala/zio/http/ClientHttpsSpec.scala b/zio-http/src/test/scala/zio/http/ClientHttpsSpec.scala index c1f000794a..ad93ec2dbd 100644 --- a/zio-http/src/test/scala/zio/http/ClientHttpsSpec.scala +++ b/zio-http/src/test/scala/zio/http/ClientHttpsSpec.scala @@ -61,7 +61,7 @@ object ClientHttpsSpec extends ZIOHttpSpec { ) .map(_.status) assertZIO(actual)(equalTo(Status.BadRequest)) - }, + } @@ ignore, test("should throw DecoderException for handshake failure") { val actual = Client .request( @@ -77,7 +77,5 @@ object ClientHttpsSpec extends ZIOHttpSpec { DnsResolver.default, ZLayer.succeed(NettyConfig.default), Scope.default, - ) @@ timeout( - 30 seconds, - ) @@ ignore + ) } diff --git a/zio-http/src/test/scala/zio/http/ClientProxySpec.scala b/zio-http/src/test/scala/zio/http/ClientProxySpec.scala index 36ca6510a9..2c2e00b1af 100644 --- a/zio-http/src/test/scala/zio/http/ClientProxySpec.scala +++ b/zio-http/src/test/scala/zio/http/ClientProxySpec.scala @@ -23,7 +23,7 @@ import zio.test.TestAspect.{sequential, timeout, withLiveClock} import zio.test._ import zio.{Scope, ZIO, ZLayer, durationInt} -import zio.http.internal.{DynamicServer, HttpRunnableSpec, severTestLayer} +import zio.http.internal.{DynamicServer, HttpRunnableSpec, serverTestLayer} import zio.http.netty.NettyConfig import zio.http.netty.client.NettyClientDriver @@ -109,6 +109,5 @@ object ClientProxySpec extends HttpRunnableSpec { override def spec: Spec[TestEnvironment with Scope, Any] = suite("ClientProxy") { serve.as(List(clientProxySpec)) - }.provideShared(DynamicServer.live, severTestLayer) @@ - timeout(5 seconds) @@ sequential @@ withLiveClock + }.provideShared(DynamicServer.live, serverTestLayer) @@ sequential @@ withLiveClock } diff --git a/zio-http/src/test/scala/zio/http/ClientSpec.scala b/zio-http/src/test/scala/zio/http/ClientSpec.scala index 08b88755fa..8078829bfc 100644 --- a/zio-http/src/test/scala/zio/http/ClientSpec.scala +++ b/zio-http/src/test/scala/zio/http/ClientSpec.scala @@ -25,7 +25,7 @@ import zio.test._ import zio.stream.ZStream -import zio.http.internal.{DynamicServer, HttpRunnableSpec, severTestLayer} +import zio.http.internal.{DynamicServer, HttpRunnableSpec, serverTestLayer} object ClientSpec extends HttpRunnableSpec { @@ -91,7 +91,7 @@ object ClientSpec extends HttpRunnableSpec { override def spec = { suite("Client") { serve.as(List(clientSpec)) - }.provideSomeShared[Scope](DynamicServer.live, severTestLayer, Client.default) @@ - timeout(5 seconds) @@ sequential @@ withLiveClock + }.provideSome[DynamicServer & Server & Client](Scope.default) + .provideShared(DynamicServer.live, serverTestLayer, Client.default) @@ sequential @@ withLiveClock } } diff --git a/zio-http/src/test/scala/zio/http/ClientStreamingSpec.scala b/zio-http/src/test/scala/zio/http/ClientStreamingSpec.scala index 037b47b835..a8b3b78004 100644 --- a/zio-http/src/test/scala/zio/http/ClientStreamingSpec.scala +++ b/zio-http/src/test/scala/zio/http/ClientStreamingSpec.scala @@ -166,7 +166,7 @@ object ClientStreamingSpec extends HttpRunnableSpec { ) } } yield result - } @@ timeout(5.minutes) @@ samples(50) @@ TestAspect.ifEnvNotSet("CI"), // NOTE: random hangs on CI + } @@ samples(50) @@ TestAspect.ifEnvNotSet("CI"), test("decoding random pre-encoded form") { for { port <- server(streamingServer) @@ -199,7 +199,7 @@ object ClientStreamingSpec extends HttpRunnableSpec { ) } } yield result - } @@ timeout(5.minutes) @@ samples(50) @@ TestAspect.ifEnvNotSet("CI"), // NOTE: random hangs on CI + } @@ samples(50) @@ TestAspect.ifEnvNotSet("CI"), test("decoding large form with random chunk and buffer sizes") { val N = 1024 * 1024 for { @@ -234,7 +234,7 @@ object ClientStreamingSpec extends HttpRunnableSpec { )).tapErrorCause(cause => ZIO.debug(cause.prettyPrint)) } } yield result - } @@ samples(20) @@ timeout(5.minutes) @@ TestAspect.ifEnvNotSet("CI"), // NOTE: random hangs on CI + } @@ samples(20) @@ TestAspect.ifEnvNotSet("CI"), test("failed stream") { for { port <- server(streamingServer) diff --git a/zio-http/src/test/scala/zio/http/ContentTypeSpec.scala b/zio-http/src/test/scala/zio/http/ContentTypeSpec.scala index 26799e8340..ead7cfbefc 100644 --- a/zio-http/src/test/scala/zio/http/ContentTypeSpec.scala +++ b/zio-http/src/test/scala/zio/http/ContentTypeSpec.scala @@ -21,7 +21,7 @@ import zio.test.Assertion.{equalTo, isNone, isSome} import zio.test.TestAspect.{timeout, withLiveClock} import zio.test._ -import zio.http.internal.{DynamicServer, HttpRunnableSpec, severTestLayer} +import zio.http.internal.{DynamicServer, HttpRunnableSpec, serverTestLayer} object ContentTypeSpec extends HttpRunnableSpec { @@ -74,8 +74,6 @@ object ContentTypeSpec extends HttpRunnableSpec { override def spec = { suite("Content-type") { serve.as(List(contentSpec)) - }.provideShared(DynamicServer.live, severTestLayer, Client.default, Scope.default) @@ timeout( - 5 seconds, - ) @@ withLiveClock + }.provideShared(DynamicServer.live, serverTestLayer, Client.default, Scope.default) @@ withLiveClock } } diff --git a/zio-http/src/test/scala/zio/http/HandlerSpec.scala b/zio-http/src/test/scala/zio/http/HandlerSpec.scala index ba9b156297..6a45ae0cf9 100644 --- a/zio-http/src/test/scala/zio/http/HandlerSpec.scala +++ b/zio-http/src/test/scala/zio/http/HandlerSpec.scala @@ -422,5 +422,5 @@ object HandlerSpec extends ZIOHttpSpec with ExitAssertion { } yield assertTrue(status == Status.Ok) }, ), - ) @@ timeout(10 seconds) + ) } diff --git a/zio-http/src/test/scala/zio/http/KeepAliveSpec.scala b/zio-http/src/test/scala/zio/http/KeepAliveSpec.scala index 2d879b7856..0147b4e27f 100644 --- a/zio-http/src/test/scala/zio/http/KeepAliveSpec.scala +++ b/zio-http/src/test/scala/zio/http/KeepAliveSpec.scala @@ -21,7 +21,7 @@ import zio.test.TestAspect.{sequential, timeout, withLiveClock} import zio.test.{Spec, assert} import zio.{Scope, ZIO, durationInt} -import zio.http.internal.{DynamicServer, HttpRunnableSpec, severTestLayer} +import zio.http.internal.{DynamicServer, HttpRunnableSpec, serverTestLayer} object KeepAliveSpec extends HttpRunnableSpec { @@ -63,12 +63,10 @@ object KeepAliveSpec extends HttpRunnableSpec { ), ) - override def spec: Spec[Scope, Throwable] = { + override def spec: Spec[Any, Throwable] = { suite("KeepAliveSpec") { keepAliveSpec - }.provideSome[Scope](DynamicServer.live, severTestLayer, Client.default) @@ timeout( - 30.seconds, - ) @@ withLiveClock @@ sequential + }.provide(DynamicServer.live, serverTestLayer, Client.default, Scope.default) @@ withLiveClock @@ sequential } } diff --git a/zio-http/src/test/scala/zio/http/RequestStreamingServerSpec.scala b/zio-http/src/test/scala/zio/http/RequestStreamingServerSpec.scala index becfc3d427..41b45532c4 100644 --- a/zio-http/src/test/scala/zio/http/RequestStreamingServerSpec.scala +++ b/zio-http/src/test/scala/zio/http/RequestStreamingServerSpec.scala @@ -102,18 +102,19 @@ object RequestStreamingServerSpec extends HttpRunnableSpec { } } }: _*), - ) @@ timeout(10 seconds) + ) override def spec = suite("RequestStreamingServerSpec") { suite("app with request streaming") { - ZIO.scoped(appWithReqStreaming.as(List(requestBodySpec, streamingServerSpec))) + appWithReqStreaming.as(List(requestBodySpec, streamingServerSpec)) } - }.provideSomeShared[Scope]( - DynamicServer.live, - ZLayer.succeed(configAppWithRequestStreaming), - Server.live, - Client.default, - ) @@ timeout(30 seconds) @@ diagnose(15.seconds) @@ sequential @@ shrinks(0) @@ withLiveClock + }.provideSome[DynamicServer & Server.Config & Server & Client](Scope.default) + .provideShared( + DynamicServer.live, + ZLayer.succeed(configAppWithRequestStreaming), + Server.live, + Client.default, + ) @@ diagnose(15.seconds) @@ sequential @@ shrinks(0) @@ withLiveClock } diff --git a/zio-http/src/test/scala/zio/http/SSLSpec.scala b/zio-http/src/test/scala/zio/http/SSLSpec.scala index cf755e7948..2fb101ac1a 100644 --- a/zio-http/src/test/scala/zio/http/SSLSpec.scala +++ b/zio-http/src/test/scala/zio/http/SSLSpec.scala @@ -130,7 +130,6 @@ object SSLSpec extends ZIOHttpSpec { ), ).provideShared( Server.default, - ) @@ - timeout(5 second) @@ ignore + ) @@ ignore } diff --git a/zio-http/src/test/scala/zio/http/ServerSpec.scala b/zio-http/src/test/scala/zio/http/ServerSpec.scala index 51505c937b..d418e69f86 100644 --- a/zio-http/src/test/scala/zio/http/ServerSpec.scala +++ b/zio-http/src/test/scala/zio/http/ServerSpec.scala @@ -19,10 +19,10 @@ package zio.http import java.nio.charset.StandardCharsets import java.nio.file.Paths +import zio._ import zio.test.Assertion._ import zio.test.TestAspect._ import zio.test._ -import zio.{Chunk, Scope, ZIO, ZLayer, durationInt} import zio.stream.{ZPipeline, ZStream} @@ -457,12 +457,12 @@ object ServerSpec extends HttpRunnableSpec { suite("ServerSpec") { val spec = dynamicAppSpec + responseSpec + requestSpec + requestBodySpec + serverErrorSpec suite("app without request streaming") { ZIO.scoped(app.as(List(spec))) } - }.provideSomeShared[TestEnvironment]( - DynamicServer.live, - ZLayer.succeed(configApp), - Server.live, - Client.default, - Scope.default, - ) @@ timeout(30 seconds) @@ sequential @@ withLiveClock + }.provideSome[DynamicServer & Server.Config & Server & Client](Scope.default) + .provideShared( + DynamicServer.live, + ZLayer.succeed(configApp), + Server.live, + Client.default, + ) @@ sequential @@ withLiveClock } diff --git a/zio-http/src/test/scala/zio/http/StaticFileServerSpec.scala b/zio-http/src/test/scala/zio/http/StaticFileServerSpec.scala index 1a0ccd08da..7499ab3c3f 100644 --- a/zio-http/src/test/scala/zio/http/StaticFileServerSpec.scala +++ b/zio-http/src/test/scala/zio/http/StaticFileServerSpec.scala @@ -23,7 +23,7 @@ import zio.test.Assertion._ import zio.test.TestAspect.{timeout, unix, withLiveClock} import zio.test.assertZIO -import zio.http.internal.{DynamicServer, HttpRunnableSpec, severTestLayer} +import zio.http.internal.{DynamicServer, HttpRunnableSpec, serverTestLayer} object StaticFileServerSpec extends HttpRunnableSpec { @@ -41,9 +41,8 @@ object StaticFileServerSpec extends HttpRunnableSpec { .deploy override def spec = suite("StaticFileServerSpec") { - ZIO.scoped(serve.as(List(staticSpec))) - }.provideShared(DynamicServer.live, severTestLayer, Client.default, Scope.default) @@ - timeout(5 seconds) @@ withLiveClock + serve.as(List(staticSpec)) + }.provideShared(DynamicServer.live, serverTestLayer, Client.default, Scope.default) @@ withLiveClock private def staticSpec = suite("Static RandomAccessFile Server")( suite("fromResource")( diff --git a/zio-http/src/test/scala/zio/http/StaticServerSpec.scala b/zio-http/src/test/scala/zio/http/StaticServerSpec.scala index 709354f625..0f72ec729f 100644 --- a/zio-http/src/test/scala/zio/http/StaticServerSpec.scala +++ b/zio-http/src/test/scala/zio/http/StaticServerSpec.scala @@ -16,14 +16,14 @@ package zio.http +import zio._ import zio.test.Assertion.equalTo import zio.test.TestAspect.{timeout, withLiveClock} import zio.test.{Gen, TestEnvironment, assertTrue, assertZIO, checkAll} -import zio.{Exit, Scope, ZIO, durationInt} import zio.http.Header.AccessControlAllowMethods import zio.http.Middleware.{CorsConfig, cors} -import zio.http.internal.{DynamicServer, HttpGen, HttpRunnableSpec, severTestLayer, testClientLayer} +import zio.http.internal.{DynamicServer, HttpGen, HttpRunnableSpec, serverTestLayer, testClientLayer} object StaticServerSpec extends HttpRunnableSpec { @@ -101,12 +101,12 @@ object StaticServerSpec extends HttpRunnableSpec { .as( List(staticAppSpec, nonZIOSpec, throwableAppSpec, multiHeadersSpec), ) - }.provideSomeShared[TestEnvironment]( - DynamicServer.live, - severTestLayer, - testClientLayer, - Scope.default, - ) @@ timeout(30 seconds) @@ withLiveClock + }.provideSome[DynamicServer & Server.Config & Server & Client](Scope.default) + .provideShared( + DynamicServer.live, + serverTestLayer, + testClientLayer, + ) @@ withLiveClock def staticAppSpec = suite("StaticAppSpec")( diff --git a/zio-http/src/test/scala/zio/http/WebSocketSpec.scala b/zio-http/src/test/scala/zio/http/WebSocketSpec.scala index 095e33e48f..b68d266c87 100644 --- a/zio-http/src/test/scala/zio/http/WebSocketSpec.scala +++ b/zio-http/src/test/scala/zio/http/WebSocketSpec.scala @@ -23,7 +23,7 @@ import zio.test.{TestClock, assertCompletes, assertTrue, assertZIO, testClock} import zio.http.ChannelEvent.UserEvent.HandshakeComplete import zio.http.ChannelEvent.{Read, Unregistered, UserEvent, UserEventTriggered} -import zio.http.internal.{DynamicServer, HttpRunnableSpec, severTestLayer} +import zio.http.internal.{DynamicServer, HttpRunnableSpec, serverTestLayer} object WebSocketSpec extends HttpRunnableSpec { @@ -209,12 +209,10 @@ object WebSocketSpec extends HttpRunnableSpec { ) override def spec = suite("Server") { - ZIO.scoped { - serve.as(List(websocketSpec)) - } + serve.as(List(websocketSpec)) } - .provideShared(DynamicServer.live, severTestLayer, Client.default, Scope.default) @@ - timeout(30 seconds) @@ diagnose(30.seconds) @@ withLiveClock @@ sequential + .provideShared(DynamicServer.live, serverTestLayer, Client.default, Scope.default) @@ + diagnose(30.seconds) @@ withLiveClock @@ sequential final class MessageCollector[A](ref: Ref[List[A]], promise: Promise[Nothing, Unit]) { def add(a: A, isDone: Boolean = false): UIO[Unit] = ref.update(_ :+ a) <* promise.succeed(()).when(isDone) diff --git a/zio-http/src/test/scala/zio/http/endpoint/EndpointRoundtripSpec.scala b/zio-http/src/test/scala/zio/http/endpoint/EndpointRoundtripSpec.scala index a1722768bc..5f83ffa1a4 100644 --- a/zio-http/src/test/scala/zio/http/endpoint/EndpointRoundtripSpec.scala +++ b/zio-http/src/test/scala/zio/http/endpoint/EndpointRoundtripSpec.scala @@ -291,7 +291,7 @@ object EndpointRoundtripSpec extends ZIOHttpSpec { ("name", 10, Post(1, "title", "body", 111)), "name: name, value: 10, post: Post(1,title,body,111)", ) - } @@ timeout(10.seconds) @@ ifEnvNotSet("CI"), // NOTE: random hangs on CI + } @@ ifEnvNotSet("CI"), test("endpoint error returned") { val api = Endpoint(POST / "test") .outError[String](Status.Custom(999)) @@ -460,7 +460,7 @@ object EndpointRoundtripSpec extends ZIOHttpSpec { s"name: xyz, value: 100, count: ${1024 * 1024}", ) } - } @@ timeout(10.seconds) @@ ifEnvNotSet("CI"), // NOTE: random hangs on CI + } @@ ifEnvNotSet("CI"), ).provide( Server.live, ZLayer.succeed(Server.Config.default.onAnyOpenPort.enableRequestStreaming), @@ -470,7 +470,7 @@ object EndpointRoundtripSpec extends ZIOHttpSpec { ZLayer.succeed(ZClient.Config.default), DnsResolver.default, Scope.default, - ) @@ withLiveClock @@ sequential @@ timeout(300.seconds) + ) @@ withLiveClock @@ sequential private def extraLogging: PartialFunction[Response, String] = { case r => r.headers.get(Header.ContentType).map(_.renderedValue).mkString("ContentType: ", "", "") diff --git a/zio-http/src/test/scala/zio/http/internal/DynamicServer.scala b/zio-http/src/test/scala/zio/http/internal/DynamicServer.scala index 211750fe3a..ca062f5cac 100644 --- a/zio-http/src/test/scala/zio/http/internal/DynamicServer.scala +++ b/zio-http/src/test/scala/zio/http/internal/DynamicServer.scala @@ -70,7 +70,7 @@ object DynamicServer { def httpURL: ZIO[DynamicServer, Nothing, String] = baseURL(Scheme.HTTP) - def live: ZLayer[Any, Nothing, DynamicServer] = + val live: ZLayer[Any, Nothing, DynamicServer] = ZLayer { for { ref <- Ref.make(Map.empty[Id, HttpApp[Any]]) diff --git a/zio-http/src/test/scala/zio/http/internal/package.scala b/zio-http/src/test/scala/zio/http/internal/package.scala index d3b4f32610..0861f35e5b 100644 --- a/zio-http/src/test/scala/zio/http/internal/package.scala +++ b/zio-http/src/test/scala/zio/http/internal/package.scala @@ -30,7 +30,7 @@ package object internal { val testNettyServerConfig: ZLayer[Any, Nothing, NettyConfig] = ZLayer.succeed(NettyConfig.default.leakDetection(LeakDetectionLevel.PARANOID)) - val severTestLayer: ZLayer[Any, Throwable, Server.Config with Server] = + val serverTestLayer: ZLayer[Any, Throwable, Server.Config with Server] = ZLayer.make[Server.Config with Server]( testServerConfig, testNettyServerConfig, diff --git a/zio-http/src/test/scala/zio/http/netty/NettyChannelSpec.scala b/zio-http/src/test/scala/zio/http/netty/NettyChannelSpec.scala index 45ab20f9f9..fd38d67b7e 100644 --- a/zio-http/src/test/scala/zio/http/netty/NettyChannelSpec.scala +++ b/zio-http/src/test/scala/zio/http/netty/NettyChannelSpec.scala @@ -73,7 +73,7 @@ object NettyChannelSpec extends ZIOHttpSpec { } yield assertTrue(out == 3) }, ), - ) @@ timeout(5 second) + ) final class EmbeddedTestChannel[A] { val jChannel: EmbeddedChannel = new EmbeddedChannel() diff --git a/zio-http/src/test/scala/zio/http/netty/client/NettyConnectionPoolSpec.scala b/zio-http/src/test/scala/zio/http/netty/client/NettyConnectionPoolSpec.scala index d8b04a29e2..340ce4e539 100644 --- a/zio-http/src/test/scala/zio/http/netty/client/NettyConnectionPoolSpec.scala +++ b/zio-http/src/test/scala/zio/http/netty/client/NettyConnectionPoolSpec.scala @@ -25,7 +25,7 @@ import zio.stream.ZStream import zio.http._ import zio.http.codec.PathCodec.trailing -import zio.http.internal.{DynamicServer, HttpRunnableSpec, severTestLayer} +import zio.http.internal.{DynamicServer, HttpRunnableSpec, serverTestLayer} import zio.http.netty.NettyConfig object NettyConnectionPoolSpec extends HttpRunnableSpec { @@ -168,7 +168,7 @@ object NettyConnectionPoolSpec extends HttpRunnableSpec { }, ) - def connectionPoolSpec: Spec[Scope, Throwable] = + def connectionPoolSpec: Spec[Any, Throwable] = suite("ConnectionPool")( suite("fixed")( connectionPoolTests( @@ -185,15 +185,16 @@ object NettyConnectionPoolSpec extends HttpRunnableSpec { "with keep-alive" -> keepAliveHeader, ), ), - ).provideSome[Scope]( + ).provide( ZLayer(appKeepAliveEnabled.unit), DynamicServer.live, - severTestLayer, + serverTestLayer, Client.customized, ZLayer.succeed(ZClient.Config.default.fixedConnectionPool(2)), NettyClientDriver.live, DnsResolver.default, ZLayer.succeed(NettyConfig.default), + Scope.default, ), suite("dynamic")( connectionPoolTests( @@ -210,20 +211,21 @@ object NettyConnectionPoolSpec extends HttpRunnableSpec { "with keep-alive" -> keepAliveHeader, ), ), - ).provideSome[Scope]( + ).provide( ZLayer(appKeepAliveEnabled.unit), DynamicServer.live, - severTestLayer, + serverTestLayer, Client.customized, ZLayer.succeed(ZClient.Config.default.dynamicConnectionPool(4, 16, 100.millis)), NettyClientDriver.live, DnsResolver.default, ZLayer.succeed(NettyConfig.default), + Scope.default, ), ) override def spec: Spec[Scope, Throwable] = { - connectionPoolSpec @@ timeout(30.seconds) @@ sequential @@ withLiveClock + connectionPoolSpec @@ sequential @@ withLiveClock } }