Files
team/server/channels/api4/websocket_norace_test.go
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

65 lines
2.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
//go:build !race
package api4
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/hanzoteam/server/server/public/model"
)
// TestWebSocket is intentionally made to skip -race mode
// because the websocket client is known to be racy and needs a big overhaul
// to fix everything.
func TestWebSocket(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t).InitBasic(t)
WebSocketClient, err := th.CreateWebSocketClient()
require.NoError(t, err)
defer WebSocketClient.Close()
time.Sleep(300 * time.Millisecond)
// Test closing and reconnecting
WebSocketClient.Close()
appErr := WebSocketClient.Connect()
require.Nil(t, appErr)
WebSocketClient.Listen()
resp := <-WebSocketClient.ResponseChannel
require.Equal(t, resp.Status, model.StatusOk, "should have responded OK to authentication challenge")
WebSocketClient.SendMessage("ping", nil)
resp = <-WebSocketClient.ResponseChannel
require.Equal(t, resp.Data["text"].(string), "pong", "wrong response")
WebSocketClient.SendMessage("", nil)
resp = <-WebSocketClient.ResponseChannel
require.Equal(t, resp.Error.Id, "api.web_socket_router.no_action.app_error", "should have been no action response")
WebSocketClient.SendMessage("junk", nil)
resp = <-WebSocketClient.ResponseChannel
require.Equal(t, resp.Error.Id, "api.web_socket_router.bad_action.app_error", "should have been bad action response")
WebSocketClient.UserTyping("", "")
resp = <-WebSocketClient.ResponseChannel
require.Equal(t, resp.Error.Id, "api.websocket_handler.invalid_param.app_error", "should have been invalid param response")
require.Equal(t, resp.Error.DetailedError, "", "detailed error not cleared")
WebSocketClient.UserTyping(th.BasicChannel.Id, "")
resp = <-WebSocketClient.ResponseChannel
require.Nil(t, resp.Error)
WebSocketClient.UserTyping(th.BasicPrivateChannel2.Id, "")
resp = <-WebSocketClient.ResponseChannel
require.Equal(t, resp.Error.Id, "api.websocket_handler.invalid_param.app_error", "should have been invalid param response")
require.Equal(t, resp.Error.DetailedError, "", "detailed error not cleared")
}