mirror of
https://github.com/coder/coder.git
synced 2026-06-03 04:58:23 +00:00
fix(coderd/httpapi): CloseRead on test conns to ensure pings pong (#25184)
The `websocketPair` test helper was not calling `CloseRead` on either side of the connection. Without `CloseRead`, the websocket library does not process control frames (ping/pong), so the heartbeat tests were passing only because no pings had yet failed, not because pings were actually succeeding. Add `CloseRead` on both the client and server connections so that pong frames are delivered in response to pings. Split out from #25012. > 🤖 Generated with [Coder Agents](https://coder.com)
This commit is contained in:
@@ -38,12 +38,14 @@ func websocketPair(ctx context.Context, t *testing.T) *websocket.Conn {
|
||||
//nolint:bodyclose
|
||||
clientConn, _, err := websocket.Dial(ctx, srv.URL, nil)
|
||||
require.NoError(t, err)
|
||||
_ = clientConn.CloseRead(ctx) // Needed to handle pings/pongs.
|
||||
t.Cleanup(func() {
|
||||
_ = clientConn.Close(websocket.StatusNormalClosure, "test cleanup")
|
||||
})
|
||||
|
||||
select {
|
||||
case sc := <-serverConnCh:
|
||||
_ = sc.CloseRead(ctx) // Needed to handle pings/pongs.
|
||||
return sc
|
||||
case <-ctx.Done():
|
||||
t.Fatal("timed out waiting for server websocket accept")
|
||||
|
||||
Reference in New Issue
Block a user