Skip to content
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

MM-17468: Accept a number of days instead of two date arguments in /incident test bulk-data #549

Merged
merged 6 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ To quickly test Mattermost Incident Collaboration, use the following test comman

* An example command looks like: `/incident test create-incident 6utgh6qg7p8ndeef9edc583cpc 2020-11-23 PR-Testing`

- `/incident test bulk-data [ongoing] [ended] [start date] [end date] [seed]` - Provide a number of ongoing and ended incidents, a start and end date, and an optional random seed. The command creates the given number of ongoing and ended incidents, with creation dates randomly between the start and end dates. The seed may be used to reproduce the same outcome on multiple invocations. Incident names are generated randomly.
- `/incident test bulk-data [ongoing] [ended] [days] [seed]` - Provide a number of ongoing and ended incidents, a number of days, and an optional random seed. The command creates the given number of ongoing and ended incidents, with creation dates randomly between n days ago and the day when the command was issued. The seed may be used to reproduce the same outcome on multiple invocations. Incident names are generated randomly.

* An example command looks like: `/incident test bulk-data 10 3 2020-01-31 2020-11-22 2`
* An example command looks like: `/incident test bulk-data 10 3 342 2`

## Contributing

Expand Down
32 changes: 14 additions & 18 deletions server/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ func getAutocompleteData(addTestCommands bool) *model.AutocompleteData {
testCreate.AddTextArgument("Name of the incident", "Incident name", "")
test.AddCommand(testCreate)

testData := model.NewAutocompleteData("bulk-data", "[ongoing] [ended] [begin] [end] [seed]", "Generate random test data in bulk")
testData := model.NewAutocompleteData("bulk-data", "[ongoing] [ended] [days] [seed]", "Generate random test data in bulk")
testData.AddTextArgument("An integer indicating how many ongoing incidents will be generated.", "Number of ongoing incidents", "")
testData.AddTextArgument("An integer indicating how many ended incidents will be generated.", "Number of ended incidents", "")
testData.AddTextArgument("Date in format 2020-01-31", "First possible creation date", "")
testData.AddTextArgument("Date in format 2020-01-31", "Last possible creation date", "")
testData.AddTextArgument("An integer n. The incidents generated will have a start date between n days ago and today.", "Range of days for the incident start date", "")
testData.AddTextArgument("An integer in case you need random, but reproducible, results", "Random seed (optional)", "")
test.AddCommand(testData)

Expand Down Expand Up @@ -1117,8 +1116,8 @@ func (r *Runner) actionTestCreate(params []string) {
}

func (r *Runner) actionTestData(params []string) {
if len(params) < 4 {
r.postCommandResponse("`/incident test bulk-data` expects at least 4 arguments: [ongoing] [ended] [begin] [end]. Optionally, a fifth argument can be added: [seed].")
if len(params) < 3 {
r.postCommandResponse("`/incident test bulk-data` expects at least 3 arguments: [ongoing] [ended] [days]. Optionally, a fourth argument can be added: [seed].")
return
}

Expand All @@ -1134,23 +1133,25 @@ func (r *Runner) actionTestData(params []string) {
return
}

begin, err := time.ParseInLocation("2006-01-02", params[2], time.Now().Location())
days, err := strconv.Atoi((params[2]))
if err != nil {
r.postCommandResponse(fmt.Sprintf("The provided value for the first possible date, '%s', is not a valid date. It needs to be in the format 2020-01-31.", params[2]))
r.postCommandResponse(fmt.Sprintf("The provided value for days, '%s', is not an integer.", params[2]))
return
}

end, err := time.ParseInLocation("2006-01-02", params[3], time.Now().Location())
if err != nil {
r.postCommandResponse(fmt.Sprintf("The provided value for the last possible date, '%s', is not a valid date. It needs to be in the format 2020-01-31.", params[3]))
if days < 1 {
r.postCommandResponse(fmt.Sprintf("The provided value for days, '%d', is not greater than 0.", days))
return
}

begin := time.Now().AddDate(0, 0, -days)
end := time.Now()

seed := time.Now().Unix()
if len(params) > 4 {
parsedSeed, err := strconv.ParseInt(params[4], 10, 0)
if len(params) > 3 {
parsedSeed, err := strconv.ParseInt(params[3], 10, 0)
if err != nil {
r.postCommandResponse(fmt.Sprintf("The provided value for the random seed, '%s', is not an integer.", params[4]))
r.postCommandResponse(fmt.Sprintf("The provided value for the random seed, '%s', is not an integer.", params[3]))
return
}

Expand Down Expand Up @@ -1265,11 +1266,6 @@ func (r *Runner) generateTestData(numActiveIncidents, numEndedIncidents int, beg
return
}

if !end.After(begin) {
r.postCommandResponse("`end` must be a later date than `begin`")
return
}

timestamps := make([]int64, 0, numIncidents)
for i := 0; i < numIncidents; i++ {
timestamp := rand.Int63n(endMillis-beginMillis) + beginMillis
Expand Down