@@ -14,6 +14,7 @@ import zio.schema.{DeriveSchema, Schema}
1414
1515import zio .http ._
1616import zio .http .codec .HttpCodec
17+ import zio .http .netty .NettyConfig
1718
1819object ServerSentEventEndpointSpec extends ZIOHttpSpec {
1920
@@ -40,13 +41,14 @@ object ServerSentEventEndpointSpec extends ZIOHttpSpec {
4041 : Invocation [Unit , Unit , ZNothing , ZStream [Any , Nothing , ServerSentEvent [String ]], AuthType .None ] =
4142 sseEndpoint(())
4243
43- def client (port : Int ): ZIO [Scope , Throwable , Chunk [ServerSentEvent [String ]]] =
44- ( for {
44+ def client (port : Int ): ZIO [Client , Throwable , Chunk [ServerSentEvent [String ]]] = ZIO .scoped {
45+ for {
4546 client <- ZIO .service[Client ]
4647 executor = EndpointExecutor (client, locator(port))
4748 stream <- executor(invocation)
4849 events <- stream.take(5 ).runCollect
49- } yield events).provideSome[Scope ](ZClient .default)
50+ } yield events
51+ }
5052 }
5153
5254 object JsonPayload {
@@ -77,13 +79,14 @@ object ServerSentEventEndpointSpec extends ZIOHttpSpec {
7779 : Invocation [Unit , Unit , ZNothing , ZStream [Any , Nothing , ServerSentEvent [Payload ]], AuthType .None ] =
7880 sseEndpoint(())
7981
80- def client (port : Int ): ZIO [Scope , Throwable , Chunk [ServerSentEvent [Payload ]]] =
81- ( for {
82+ def client (port : Int ): ZIO [Client , Throwable , Chunk [ServerSentEvent [Payload ]]] = ZIO .scoped {
83+ for {
8284 client <- ZIO .service[Client ]
8385 executor = EndpointExecutor (client, locator(port))
8486 stream <- executor(invocation)
8587 events <- stream.take(5 ).runCollect
86- } yield events).provideSome[Scope ](ZClient .default)
88+ } yield events
89+ }
8790 }
8891
8992 override def spec : Spec [TestEnvironment with Scope , Any ] =
@@ -95,14 +98,22 @@ object ServerSentEventEndpointSpec extends ZIOHttpSpec {
9598 port <- ZIO .serviceWithZIO[Server ](_.port)
9699 events <- client(port)
97100 } yield assertTrue(events.size == 5 && events.forall(event => Try (ISO_LOCAL_TIME .parse(event.data)).isSuccess))
98- }.provideSome[ Scope ]( Server .defaultWithPort( 0 )) ,
101+ },
99102 test(" Send and receive ServerSentEvent with json payload" ) {
100103 import JsonPayload ._
101104 for {
102105 _ <- server.fork
103106 port <- ZIO .serviceWithZIO[Server ](_.port)
104107 events <- client(port)
105108 } yield assertTrue(events.size == 5 && events.forall(event => Try (event.data.timeStamp).isSuccess))
106- }.provideSome[Scope ](Server .defaultWithPort(0 )),
107- ) @@ TestAspect .withLiveClock
109+ },
110+ )
111+ .provideSomeLayer[Client & Server .Config & NettyConfig ](Server .customized)
112+ .provideShared(
113+ Client .live,
114+ ZLayer .succeed(Server .Config .default.port(0 )),
115+ ZLayer .succeed(NettyConfig .defaultWithFastShutdown),
116+ ZLayer .succeed(ZClient .Config .default),
117+ DnsResolver .default,
118+ ) @@ TestAspect .withLiveClock
108119}
0 commit comments