Skip to content

Commit

Permalink
Handle Vert.X flaky Web Socket tests (#3727)
Browse files Browse the repository at this point in the history
  • Loading branch information
kciesielski authored Apr 26, 2024
1 parent 9e819cd commit 97cf1d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ abstract class ServerWebSocketTests[F[_], S <: Streams[S], OPTIONS, ROUTE](
val streams: S,
autoPing: Boolean,
failingPipe: Boolean,
handlePong: Boolean
handlePong: Boolean,
// Disabled for eaxmple for vert.x, which sometimes drops connection without returning Close
expectCloseResponse: Boolean = true
)(implicit
m: MonadError[F]
) extends EitherValues {
Expand All @@ -52,12 +54,21 @@ abstract class ServerWebSocketTests[F[_], S <: Streams[S], OPTIONS, ROUTE](
m1 <- ws.receiveText()
m2 <- ws.receiveText()
_ <- ws.close()
m3 <- ws.eitherClose(ws.receiveText())
m3 <- if (expectCloseResponse) ws.eitherClose(ws.receiveText()).map(Some(_)) else IO.pure(None)
} yield List(m1, m2, m3)
})
.get(baseUri.scheme("ws"))
.send(backend)
.map(_.body shouldBe Right(List("echo: test1", "echo: test2", Left(WebSocketFrame.Close(1000, "normal closure")))))
.map { r =>
r.body.map(_.take(2)) shouldBe Right(List("echo: test1", "echo: test2"))
assert(
r.body
.map(_.last)
.value
.asInstanceOf[Option[Either[WebSocketFrame, String]]]
.forall(_ == Left(WebSocketFrame.Close(1000, "normal closure")))
)
}
},
testServer(
endpoint.in("elsewhere").out(stringBody),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class CatsVertxServerTest extends TestSuite {
createServerTest,
Fs2Streams.apply[IO],
autoPing = false,
failingPipe = true,
handlePong = true
failingPipe = false,
handlePong = true,
expectCloseResponse = false
) {
override def functionToPipe[A, B](f: A => B): streams.Pipe[A, B] = in => in.map(f)
override def emptyPipe[A, B]: streams.Pipe[A, B] = _ => Stream.empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class VertxServerTest extends TestSuite {
VertxStreams,
autoPing = false,
failingPipe = false,
handlePong = false
handlePong = false,
expectCloseResponse = false
) {
override def functionToPipe[A, B](f: A => B): VertxStreams.Pipe[A, B] = in => new ReadStreamMapping(in, f)
override def emptyPipe[A, B]: VertxStreams.Pipe[A, B] = _ => new EmptyReadStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class ZioVertxServerTest extends TestSuite with OptionValues {
createServerTest,
ZioStreams,
autoPing = true,
failingPipe = true,
handlePong = false
failingPipe = false,
handlePong = false,
expectCloseResponse = false
) {
override def functionToPipe[A, B](f: A => B): streams.Pipe[A, B] = in => in.map(f)
override def emptyPipe[A, B]: streams.Pipe[A, B] = _ => ZStream.empty
Expand Down

0 comments on commit 97cf1d5

Please sign in to comment.