Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify multiple websocket upgrades test #948

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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