[MM-62437] Fix flakyness in channel bookmark tests (#29893)

* Fix flakyness in channel bookmark tests

* Use existing util to initialize client

* Update server/channels/api4/apitestlib.go

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>

* Remove redundant close

---------

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Claudio Costa
2025-01-23 08:16:21 -06:00
коммит произвёл GitHub
родитель 106cd66d69
Коммит 835b276ff0
2 изменённых файлов: 25 добавлений и 25 удалений

Просмотреть файл

@@ -555,6 +555,25 @@ func (th *TestHelper) CreateLocalClient(socketPath string) *model.Client4 {
} }
} }
func (th *TestHelper) CreateConnectedWebSocketClient(t *testing.T) *model.WebSocketClient {
t.Helper()
wsClient, err := th.CreateWebSocketClient()
require.NoError(t, err)
require.NotNil(t, wsClient, "webSocketClient should not be nil")
wsClient.Listen()
t.Cleanup(wsClient.Close)
// Ensure WS is connected. First event should be hello message.
select {
case ev := <-wsClient.EventChannel:
require.Equal(t, model.WebsocketEventHello, ev.EventType())
case <-time.After(5 * time.Second):
require.FailNow(t, "hello event was not received within the timeout period")
}
return wsClient
}
func (th *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, error) { func (th *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, error) {
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port), th.Client.AuthToken) return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port), th.Client.AuthToken)
} }

Просмотреть файл

@@ -221,13 +221,7 @@ func TestCreateChannelBookmark(t *testing.T) {
}) })
t.Run("a websockets event should be fired as part of creating a bookmark", func(t *testing.T) { t.Run("a websockets event should be fired as part of creating a bookmark", func(t *testing.T) {
t.Skip("MM-62437") webSocketClient := th.CreateConnectedWebSocketClient(t)
webSocketClient, err := th.CreateWebSocketClient()
require.NoError(t, err)
require.NotNil(t, webSocketClient, "webSocketClient should not be nil")
webSocketClient.Listen()
defer webSocketClient.Close()
bookmark1 := &model.ChannelBookmark{ bookmark1 := &model.ChannelBookmark{
ChannelId: th.BasicChannel.Id, ChannelId: th.BasicChannel.Id,
@@ -242,7 +236,7 @@ func TestCreateChannelBookmark(t *testing.T) {
th.Context.Session().UserId = th.BasicUser.Id th.Context.Session().UserId = th.BasicUser.Id
defer func() { th.Context.Session().UserId = originalSessionUserId }() defer func() { th.Context.Session().UserId = originalSessionUserId }()
_, appErr := th.App.CreateChannelBookmark(th.Context, bookmark1, "") bookmark, appErr := th.App.CreateChannelBookmark(th.Context, bookmark1, "")
require.Nil(t, appErr) require.Nil(t, appErr)
var b model.ChannelBookmarkWithFileInfo var b model.ChannelBookmarkWithFileInfo
@@ -266,6 +260,7 @@ func TestCreateChannelBookmark(t *testing.T) {
require.True(t, eventReceived, "Expected WebSocket event was not received within the timeout period") require.True(t, eventReceived, "Expected WebSocket event was not received within the timeout period")
require.NotNil(t, b) require.NotNil(t, b)
require.NotEmpty(t, b.Id) require.NotEmpty(t, b.Id)
require.Equal(t, bookmark, &b)
}) })
} }
@@ -600,12 +595,7 @@ func TestEditChannelBookmark(t *testing.T) {
}) })
t.Run("a websockets event should be fired as part of editing a bookmark", func(t *testing.T) { t.Run("a websockets event should be fired as part of editing a bookmark", func(t *testing.T) {
t.Skip("https://mattermost.atlassian.net/browse/MM-61779") webSocketClient := th.CreateConnectedWebSocketClient(t)
webSocketClient, err := th.CreateWebSocketClient()
require.NoError(t, err)
require.NotNil(t, webSocketClient, "webSocketClient should not be nil")
webSocketClient.Listen()
defer webSocketClient.Close()
bookmark1 := &model.ChannelBookmark{ bookmark1 := &model.ChannelBookmark{
ChannelId: th.BasicChannel.Id, ChannelId: th.BasicChannel.Id,
@@ -975,14 +965,9 @@ func TestUpdateChannelBookmarkSortOrder(t *testing.T) {
}) })
t.Run("a websockets event should be fired as part of editing a bookmark's sort order", func(t *testing.T) { t.Run("a websockets event should be fired as part of editing a bookmark's sort order", func(t *testing.T) {
t.Skip("MM-61301")
now := model.GetMillis() now := model.GetMillis()
webSocketClient, err := th.CreateWebSocketClient()
require.NoError(t, err)
require.NotNil(t, webSocketClient, "webSocketClient should not be nil")
webSocketClient.Listen()
defer webSocketClient.Close() webSocketClient := th.CreateConnectedWebSocketClient(t)
bookmark := &model.ChannelBookmark{ bookmark := &model.ChannelBookmark{
ChannelId: th.BasicChannel.Id, ChannelId: th.BasicChannel.Id,
@@ -1332,11 +1317,7 @@ func TestDeleteChannelBookmark(t *testing.T) {
}) })
t.Run("a websockets event should be fired as part of deleting a bookmark", func(t *testing.T) { t.Run("a websockets event should be fired as part of deleting a bookmark", func(t *testing.T) {
webSocketClient, err := th.CreateWebSocketClient() webSocketClient := th.CreateConnectedWebSocketClient(t)
require.NoError(t, err)
require.NotNil(t, webSocketClient, "webSocketClient should not be nil")
webSocketClient.Listen()
defer webSocketClient.Close()
bookmark := &model.ChannelBookmark{ bookmark := &model.ChannelBookmark{
ChannelId: th.BasicChannel.Id, ChannelId: th.BasicChannel.Id,