* MM-25516: Changed to byte slice instead of string for cluster messages https://mattermost.atlassian.net/browse/MM-25116 Testing: Manually tested. Load-tested with Cluster Controller. I looked into changing the serialization method to use msgpack, but the ClusterMessage struct was mainly used for only 3 fields which didn't lead to much of a CPU time improvement, whereas actually led to more allocations using msgpack. Hence, I chose to remain with JSON. ``` name old time/op new time/op delta ClusterMarshal-8 3.51µs ± 1% 3.10µs ± 2% -11.59% (p=0.000 n=9+10) name old alloc/op new alloc/op delta ClusterMarshal-8 776B ± 0% 1000B ± 0% +28.87% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ClusterMarshal-8 12.0 ± 0% 13.0 ± 0% +8.33% (p=0.000 n=10+10) ``` ```release-note Changed the field type of Data in model.ClusterMessage to []byte from string. ``` * Trigger CI ```release-note NONE ```
94 строки
3.2 KiB
Go
94 строки
3.2 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package slashcommands
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/testlib"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/app"
|
|
"github.com/mattermost/mattermost-server/v6/services/remotecluster"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/model"
|
|
)
|
|
|
|
func TestShareProviderDoCommand(t *testing.T) {
|
|
t.Run("share command sends a websocket channel converted event", func(t *testing.T) {
|
|
th := setup(t).initBasic()
|
|
defer th.tearDown()
|
|
|
|
th.addPermissionToRole(model.PermissionManageSharedChannels.Id, th.BasicUser.Roles)
|
|
|
|
mockSyncService := app.NewMockSharedChannelService(nil)
|
|
th.Server.SetSharedChannelSyncService(mockSyncService)
|
|
mockRemoteCluster, err := remotecluster.NewRemoteClusterService(th.Server)
|
|
require.NoError(t, err)
|
|
|
|
th.Server.SetRemoteClusterService(mockRemoteCluster)
|
|
testCluster := &testlib.FakeClusterInterface{}
|
|
th.Server.Cluster = testCluster
|
|
|
|
commandProvider := ShareProvider{}
|
|
channel := th.CreateChannel(th.BasicTeam, WithShared(false))
|
|
|
|
args := &model.CommandArgs{
|
|
T: func(s string, args ...interface{}) string { return s },
|
|
ChannelId: channel.Id,
|
|
UserId: th.BasicUser.Id,
|
|
TeamId: th.BasicTeam.Id,
|
|
Command: "/share-channel share",
|
|
}
|
|
|
|
response := commandProvider.DoCommand(th.App, th.Context, args, "")
|
|
require.Equal(t, "##### "+args.T("api.command_share.channel_shared"), response.Text)
|
|
|
|
channelConvertedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
|
event := model.WebSocketEventFromJson(bytes.NewReader(msg.Data))
|
|
return event != nil && event.EventType() == model.WebsocketEventChannelConverted
|
|
})
|
|
assert.Len(t, channelConvertedMessages, 1)
|
|
})
|
|
|
|
t.Run("unshare command sends a websocket channel converted event", func(t *testing.T) {
|
|
th := setup(t).initBasic()
|
|
defer th.tearDown()
|
|
|
|
th.addPermissionToRole(model.PermissionManageSharedChannels.Id, th.BasicUser.Roles)
|
|
|
|
mockSyncService := app.NewMockSharedChannelService(nil)
|
|
th.Server.SetSharedChannelSyncService(mockSyncService)
|
|
mockRemoteCluster, err := remotecluster.NewRemoteClusterService(th.Server)
|
|
require.NoError(t, err)
|
|
|
|
th.Server.SetRemoteClusterService(mockRemoteCluster)
|
|
testCluster := &testlib.FakeClusterInterface{}
|
|
th.Server.Cluster = testCluster
|
|
|
|
commandProvider := ShareProvider{}
|
|
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
|
args := &model.CommandArgs{
|
|
T: func(s string, args ...interface{}) string { return s },
|
|
ChannelId: channel.Id,
|
|
UserId: th.BasicUser.Id,
|
|
TeamId: th.BasicTeam.Id,
|
|
Command: "/share-channel unshare",
|
|
}
|
|
|
|
response := commandProvider.DoCommand(th.App, th.Context, args, "")
|
|
require.Equal(t, "##### "+args.T("api.command_share.shared_channel_unavailable"), response.Text)
|
|
|
|
channelConvertedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
|
event := model.WebSocketEventFromJson(bytes.NewReader(msg.Data))
|
|
return event != nil && event.EventType() == model.WebsocketEventChannelConverted
|
|
})
|
|
require.Len(t, channelConvertedMessages, 1)
|
|
})
|
|
}
|