Skip to content

Commit

Permalink
refactor: simplify multiple websocket upgrades test (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
girdharshubham authored Feb 2, 2022
1 parent 540c420 commit 10b760f
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions zio-http/src/test/scala/zhttp/service/WebSocketServerSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zhttp.service

import zhttp.http._
import zhttp.http.Status
import zhttp.internal.{DynamicServer, HttpRunnableSpec}
import zhttp.service.server._
import zhttp.socket.{Socket, WebSocketFrame}
Expand All @@ -23,21 +23,12 @@ object WebSocketServerSpec extends HttpRunnableSpec {
def websocketSpec = suite("WebSocket Server") {
suite("connections") {
testM("Multiple websocket upgrades") {

val app = Socket.succeed(WebSocketFrame.text("BAR")).toHttp.deployWS
val codes = ZIO.foreach(1 to 1024) { _ =>
for {
code <- app(Socket.empty.toSocketApp)
.map(_.status)
.catchAll {
case None => ZIO.fail(new Error("No status code"))
case Some(error) => ZIO.fail(error)
}
} yield code == Status.SWITCHING_PROTOCOLS
}
val codes = ZIO
.foreach(1 to 1024)(_ => app(Socket.empty.toSocketApp).map(_.status))
.map(r => r.count(_ == Status.SWITCHING_PROTOCOLS))

val allTrue = codes.map(_.count(identity))
assertM(allTrue)(equalTo(1024))
assertM(codes)(equalTo(1024))
}
}
}
Expand Down

0 comments on commit 10b760f

Please sign in to comment.