Skip to content

Commit 83134af

Browse files
xerialclaude
andauthored
fix: Await each WebSocket client send in tests to fix flaky fragmented-message test (#651)
## Why The `Scala 3` CI job failed on PR #650 with a flaky `WebSocketTest` failure: ``` - fragmented text messages are aggregated: Expected <len:12> but got <null> (WebSocketTest.scala:219) (12.01s) ``` The JDK `java.net.http.WebSocket` client rejects a new send while a previous send is still pending. The test called `sendText("first-", false)` and `sendText("second", true)` back-to-back without awaiting the returned futures, so under scheduling pressure the final fragment is dropped, the server-side aggregator never sees a complete message, and `nextText` times out returning `null`. ## What Await each `sendText` future (`.get(10, TimeUnit.SECONDS)`) before the next send in the fragmented-message and echo tests. Verified locally: all 12 `WebSocketTest` tests pass, `scalafmtCheckAll` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent e589a75 commit 83134af

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

uni-netty/src/test/scala/wvlet/uni/http/netty/WebSocketTest.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ class WebSocketTest extends UniTest:
137137
val listener = CollectingListener()
138138
val ws = connect(server.localPort, "/ws/echo", listener)
139139
try
140-
ws.sendText("hello", true)
140+
ws.sendText("hello", true).get(10, TimeUnit.SECONDS)
141141
listener.nextText shouldBe "echo:hello"
142-
ws.sendText("world", true)
142+
ws.sendText("world", true).get(10, TimeUnit.SECONDS)
143143
listener.nextText shouldBe "echo:world"
144144
finally
145145
ws.sendClose(WebSocket.NORMAL_CLOSURE, "bye")
@@ -213,9 +213,11 @@ class WebSocketTest extends UniTest:
213213
val listener = CollectingListener()
214214
val ws = connect(server.localPort, "/ws/frag", listener)
215215
try
216-
// Send across two fragments; the server should see one coalesced message.
217-
ws.sendText("first-", false)
218-
ws.sendText("second", true)
216+
// Send across two fragments; the server should see one coalesced message. Each send must
217+
// complete before the next: the JDK client rejects a send while one is pending, which
218+
// would silently drop the final fragment and leave the aggregator waiting forever.
219+
ws.sendText("first-", false).get(10, TimeUnit.SECONDS)
220+
ws.sendText("second", true).get(10, TimeUnit.SECONDS)
219221
listener.nextText shouldBe s"len:${"first-second".length}"
220222
finally
221223
ws.sendClose(WebSocket.NORMAL_CLOSURE, "bye")

0 commit comments

Comments
 (0)