Skip to content
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
12 changes: 11 additions & 1 deletion dot/rpc/subscription/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func setupWSConn(t *testing.T) (*WSConn, *websocket.Conn, func()) {
CheckOrigin: func(r *http.Request) bool { return true },
}

// Use a channel to notify when the WebSocket connection is ready
connReady := make(chan struct{})

h := func(w http.ResponseWriter, r *http.Request) {
c, err := up.Upgrade(w, r, nil)
if err != nil {
Expand All @@ -30,17 +33,24 @@ func setupWSConn(t *testing.T) (*WSConn, *websocket.Conn, func()) {
}

wskt.Wsconn = c

// Notify that the WebSocket connection is ready
close(connReady)
}

server := httptest.NewServer(http.HandlerFunc(h))
defer server.Close()

wsURL := "ws" + strings.TrimPrefix(server.URL, "http")
ws, r, err := websocket.DefaultDialer.Dial(wsURL, nil)
defer r.Body.Close()
r.Body.Close()

require.NoError(t, err)

// Wait for the WebSocket connection to be ready before proceeding
<-connReady
require.NotNil(t, wskt.Wsconn)

cancel := func() {
server.Close()
ws.Close()
Expand Down