Skip to content

Commit

Permalink
Add new /test dms command (#19565)
Browse files Browse the repository at this point in the history
* Add new /test dms command

* Remove useless team get
  • Loading branch information
jwilander committed Feb 18, 2022
1 parent f45b03d commit a71d67e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/slashcommands/auto_channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,23 @@ func (cfg *AutoChannelCreator) CreateTestChannels(c *request.Context, num utils.

return channels, nil
}

func (cfg *AutoChannelCreator) CreateTestDMs(c *request.Context, num utils.Range) ([]*model.Channel, error) {
numDMs := utils.RandIntFromRange(num)
dms := make([]*model.Channel, numDMs)

users, err := cfg.a.GetUsers(&model.UserGetOptions{Page: 0, PerPage: numDMs})
if err != nil {
return nil, err
}

for i, user := range users {
var err *model.AppError
dms[i], err = cfg.a.GetOrCreateDirectChannel(c, cfg.userID, user.Id)
if err != nil {
return nil, err
}
}

return dms, nil
}
26 changes: 26 additions & 0 deletions app/slashcommands/command_loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ var usage = `Mattermost testing commands to help configure the system
Example:
/test channels fuzz 5 10
DMs - Add a specified number of DMs for current user. Requires enough users to be loaded.
/test dms <Min DMs> <Max DMs>
Example:
/test dms 5 10
ThreadedPost - create a large threaded post
/test threaded_post
Expand Down Expand Up @@ -145,6 +151,10 @@ func (lt *LoadTestProvider) doCommand(a *app.App, c *request.Context, args *mode
return lt.ChannelsCommand(a, c, args, message)
}

if strings.HasPrefix(message, "dms") {
return lt.DMsCommand(a, c, args, message)
}

if strings.HasPrefix(message, "posts") {
return lt.PostsCommand(a, c, args, message)
}
Expand Down Expand Up @@ -333,6 +343,22 @@ func (*LoadTestProvider) ChannelsCommand(a *app.App, c *request.Context, args *m
return &model.CommandResponse{Text: "Added channels", ResponseType: model.CommandResponseTypeEphemeral}, nil
}

func (*LoadTestProvider) DMsCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "dms"))

channelsr, ok := parseRange(cmd, "")
if !ok {
channelsr = utils.Range{Begin: 2, End: 5}
}

channelCreator := NewAutoChannelCreator(a, nil, args.UserId)
if _, err := channelCreator.CreateTestDMs(c, channelsr); err != nil {
return &model.CommandResponse{Text: "Failed to create test DMs: " + err.Error(), ResponseType: model.CommandResponseTypeEphemeral}, err
}

return &model.CommandResponse{Text: "Added DMs", ResponseType: model.CommandResponseTypeEphemeral}, nil
}

func (*LoadTestProvider) ThreadedPostCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
var usernames []string
options := &model.UserGetOptions{InTeamId: args.TeamId, Page: 0, PerPage: 1000}
Expand Down

0 comments on commit a71d67e

Please sign in to comment.