-
Notifications
You must be signed in to change notification settings - Fork 5
Implement deterministic WebSocket close semantics in Http4s client backend #772
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9f9b576
Initial plan
Copilot 5d6a099
Fix http4s websocket disconnect close semantics
Copilot 73c12f1
Formatting
hugo-vrijswijk 6b72c20
Update binary compatibility version
hugo-vrijswijk c552a77
Run CI on jdk 25
hugo-vrijswijk c359950
Add guaranteeCase and cleanup refactor close functions creation
hugo-vrijswijk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| include ".scalafix-common.conf" | ||
|
|
||
| OrganizeImports.removeUnused = false # scala 3 | ||
| OrganizeImports.targetDialect = Scala3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
http4s/src/test/scala/clue/http4s/Http4sWebSocketBackendSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright (c) 2016-2025 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
| // For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
|
||
| package clue.http4s | ||
|
|
||
| import cats.Foldable | ||
| import cats.effect.* | ||
| import cats.syntax.all.* | ||
| import clue.ConnectionId | ||
| import clue.websocket.* | ||
| import munit.CatsEffectSuite | ||
| import org.http4s.Uri | ||
| import org.http4s.client.websocket.* | ||
| import org.http4s.syntax.literals.* | ||
|
|
||
| class Http4sWebSocketBackendSuite extends CatsEffectSuite: | ||
|
|
||
| test("close releases high-level connection and only notifies onClose once") { | ||
| for { | ||
| releases <- Ref.of[IO, Int](0) | ||
| closes <- Ref.of[IO, Int](0) | ||
| deferred <- Deferred[IO, WSFrame.Close] | ||
| wsConn = new WSConnectionHighLevel[IO]: | ||
| override def send(wsf: WSDataFrame): IO[Unit] = IO.unit | ||
| override def sendMany[G[_]: Foldable, A <: WSDataFrame](wsfs: G[A]): IO[Unit] = | ||
| IO.unit | ||
| override def receive: IO[Option[WSDataFrame]] = IO.never | ||
| override def subprotocol: Option[String] = none | ||
| override def closeFrame: Deferred[IO, WSFrame.Close] = deferred | ||
| wsClient = new WSClient[IO]: | ||
| override def connect(request: WSRequest): Resource[IO, WSConnection[IO]] = | ||
| Resource.eval(IO.raiseError(new RuntimeException("unused"))) | ||
| override def connectHighLevel( | ||
| request: WSRequest | ||
| ): Resource[IO, WSConnectionHighLevel[IO]] = | ||
| Resource.make(IO.pure(wsConn))(_ => releases.update(_ + 1)) | ||
| handler = new WebSocketHandler[IO]: | ||
| override def onMessage(connectionId: ConnectionId, msg: String): IO[Unit] = | ||
| IO.unit | ||
| override def onClose(connectionId: ConnectionId, event: CloseEvent): IO[Unit] = | ||
| closes.update(_ + 1) | ||
| connection <- Http4sWebSocketBackend[IO](wsClient).connect( | ||
| uri"ws://127.0.0.1/ws", | ||
| handler, | ||
| ConnectionId.Zero | ||
| ) | ||
| _ <- connection.close() | ||
| _ <- connection.close() | ||
| _ <- IO.cede | ||
| releaseN <- releases.get | ||
| closeN <- closes.get | ||
|
hugo-vrijswijk marked this conversation as resolved.
|
||
| } yield { | ||
| assertEquals(releaseN, 1) | ||
| assertEquals(closeN, 1) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.