-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Channel bookmarks to loadtest #828
base: master
Are you sure you want to change the base?
Changes from 5 commits
1770f69
93ce19d
e18fd55
319aaf0
6d2cb32
3f2c74f
b78d2d9
8255edb
5c455d8
6509a99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,7 +220,7 @@ func collect(config deployment.Config, deploymentId string, outputName string) e | |
if err := json.Unmarshal(input, &cfg); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal MM configuration: %w", err) | ||
} | ||
cfg.Sanitize() | ||
cfg.Sanitize([]*model.Manifest{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can just be |
||
sanitizedCfg, err := json.MarshalIndent(cfg, "", " ") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to sanitize MM configuration: %w", err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
package simulcontroller | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
|
||
"github.com/mattermost/mattermost-load-test-ng/loadtest/control" | ||
"github.com/mattermost/mattermost-load-test-ng/loadtest/user" | ||
"github.com/mattermost/mattermost/server/public/model" | ||
) | ||
|
||
var ( | ||
bookmarkNames = []string{"this is a file", "this is a link", "this is another file", "this is another link"} | ||
bookmarkType = []model.ChannelBookmarkType{model.ChannelBookmarkLink, model.ChannelBookmarkFile} | ||
) | ||
|
||
func (c *SimulController) addBookmark(u user.User) control.UserActionResponse { | ||
channel, err := u.Store().CurrentChannel() | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
emoji := "" | ||
// 10% of the times bookmarks will have an emoji assigned. | ||
agnivade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if rand.Float64() < 0.1 { | ||
emoji = control.RandomEmoji() | ||
} | ||
|
||
bookmark := &model.ChannelBookmark{ | ||
ChannelId: channel.Id, | ||
DisplayName: control.PickRandomString(bookmarkNames), | ||
Emoji: emoji, | ||
Type: bookmarkType[rand.Intn(len(bookmarkType))], | ||
} | ||
|
||
if bookmark.Type == model.ChannelBookmarkFile { | ||
control.AttachFileToBookmark(u, bookmark) | ||
} else { | ||
bookmark.LinkUrl = control.RandomLink() | ||
} | ||
|
||
err = u.AddChannelBookmark(channel.Id, bookmark) | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
return control.UserActionResponse{Info: fmt.Sprintf("bookmark created in channel id %v", channel.Id)} | ||
} | ||
|
||
func (c *SimulController) AddChannelBookmark(u user.User) control.UserActionResponse { | ||
if ok, resp := control.ChannelBookmarkEnabled(u); resp.Err != nil { | ||
return resp | ||
} else if !ok { | ||
return control.UserActionResponse{Info: "channel bookmarks not enabled"} | ||
} | ||
|
||
return c.addBookmark(u) | ||
} | ||
|
||
func (c *SimulController) UpdateOrAddBookmark(u user.User) control.UserActionResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the server API, there is no updateOrAdd API. Just individual update and add. Could we do the same here? Or do we need to keep the add logic if there are no bookmarks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can just make sure that if the channel has no bookmarks, nothing happens There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, let's do that. |
||
if ok, resp := control.ChannelBookmarkEnabled(u); resp.Err != nil { | ||
return resp | ||
} else if !ok { | ||
return control.UserActionResponse{Info: "channel bookmarks not enabled"} | ||
} | ||
|
||
channel, err := u.Store().CurrentChannel() | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
currentBookmarks := u.Store().ChannelBookmarks(channel.Id) | ||
if len(currentBookmarks) > 0 { | ||
// here we update | ||
bookmark := currentBookmarks[rand.Intn(len(currentBookmarks))] | ||
if bookmark != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this check necessary? |
||
bookmarkWithFileInfo := bookmark.Clone() | ||
bookmarkWithFileInfo.DisplayName = control.PickRandomString(bookmarkNames) | ||
|
||
// 10% of the times bookmarks will have an emoji assigned. | ||
if bookmarkWithFileInfo.Emoji == "" && rand.Float64() < 0.1 { | ||
bookmarkWithFileInfo.Emoji = control.RandomEmoji() | ||
} | ||
|
||
if bookmarkWithFileInfo.Type == model.ChannelBookmarkFile { | ||
control.AttachFileToBookmark(u, bookmarkWithFileInfo.ChannelBookmark) | ||
} else { | ||
bookmarkWithFileInfo.LinkUrl = control.RandomLink() | ||
} | ||
|
||
err = u.UpdateChannelBookmark(bookmarkWithFileInfo) | ||
|
||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
return control.UserActionResponse{Info: fmt.Sprintf("bookmark %v updated in channel id %v", bookmarkWithFileInfo.Id, channel.Id)} | ||
} | ||
} | ||
|
||
return c.addBookmark(u) | ||
} | ||
|
||
func (c *SimulController) DeleteBookmark(u user.User) control.UserActionResponse { | ||
if ok, resp := control.ChannelBookmarkEnabled(u); resp.Err != nil { | ||
return resp | ||
} else if !ok { | ||
return control.UserActionResponse{Info: "channel bookmarks not enabled"} | ||
} | ||
|
||
channel, err := u.Store().CurrentChannel() | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
currentBookmarks := u.Store().ChannelBookmarks(channel.Id) | ||
if len(currentBookmarks) > 0 { | ||
bookmark := currentBookmarks[rand.Intn(len(currentBookmarks))] | ||
if bookmark != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above |
||
err = u.DeleteChannelBookmark(bookmark.ChannelId, bookmark.Id) | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
return control.UserActionResponse{Info: fmt.Sprintf("bookmark id %v deleted in channel id %v", bookmark.Id, channel.Id)} | ||
} | ||
} | ||
|
||
return control.UserActionResponse{Info: "no channel bookmarks deleted"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a better string would be "no channel bookmarks found"? |
||
} | ||
|
||
func (c *SimulController) UpdateBookmarksSortOrder(u user.User) control.UserActionResponse { | ||
if ok, resp := control.ChannelBookmarkEnabled(u); resp.Err != nil { | ||
return resp | ||
} else if !ok { | ||
return control.UserActionResponse{Info: "channel bookmarks not enabled"} | ||
} | ||
|
||
channel, err := u.Store().CurrentChannel() | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
currentBookmarks := u.Store().ChannelBookmarks(channel.Id) | ||
if len(currentBookmarks) > 1 { | ||
bookmark := currentBookmarks[rand.Intn(len(currentBookmarks))] | ||
newIndex := rand.Int63n(int64(len(currentBookmarks))) | ||
if bookmark != nil { | ||
err = u.UpdateChannelBookmarkSortOrder(channel.Id, bookmark.Id, newIndex) | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
return control.UserActionResponse{Info: fmt.Sprintf("bookmark id %v in channel id %v sorted at index %d", bookmark.Id, channel.Id, newIndex)} | ||
} | ||
} | ||
|
||
return control.UserActionResponse{Info: "not enough channel bookmarks to sort"} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh my dear ..
https://hub.mattermost.com/private-core/pl/hih74enmn7bwunmy6eamgct67r
Let's fix it everywhere else as well :)
I also mentioned this additionally in the dev meeting, but probably I could have done a better job.