Skip to content

Commit

Permalink
Validate timeUnit in ramping-arrival-rate
Browse files Browse the repository at this point in the history
Previous to this negative time units will error but 0 timeunit will
panic.

This was fixed in constant-arrival-rate long ago, but nobody checked
ramping-arrival-rate.
  • Loading branch information
mstoykov committed Mar 21, 2024
1 parent fc60f4d commit 0af62a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/executor/executors_test.go
Expand Up @@ -340,6 +340,7 @@ var configMapTestCases = []configMapTestCase{
},
{`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "preAllocatedVUs": 20, "maxVUs": 30}}`, exp{}},
{`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "preAllocatedVUs": 20, "maxVUs": 30, "timeUnit": "-1s"}}`, exp{validationError: true}},
{`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "preAllocatedVUs": 20, "maxVUs": 30, "timeUnit": "0s"}}`, exp{validationError: true}},
{
`{"carrival": {"executor": "constant-arrival-rate", "rate": 10, "duration": "10m", "preAllocatedVUs": 20}}`,
exp{custom: func(t *testing.T, cm lib.ScenarioConfigs) {
Expand Down Expand Up @@ -403,6 +404,7 @@ var configMapTestCases = []configMapTestCase{
{`{"varrival": {"executor": "ramping-arrival-rate", "preAllocatedVUs": 20, "maxVUs": 50}}`, exp{validationError: true}},
{`{"varrival": {"executor": "ramping-arrival-rate", "preAllocatedVUs": 20, "maxVUs": 50, "stages": []}}`, exp{validationError: true}},
{`{"varrival": {"executor": "ramping-arrival-rate", "preAllocatedVUs": 20, "maxVUs": 50, "stages": [{"duration": "5m", "target": 10}], "timeUnit": "-1s"}}`, exp{validationError: true}},
{`{"varrival": {"executor": "ramping-arrival-rate", "preAllocatedVUs": 20, "maxVUs": 50, "stages": [{"duration": "5m", "target": 10}], "timeUnit": "0s"}}`, exp{validationError: true}},
{`{"varrival": {"executor": "ramping-arrival-rate", "preAllocatedVUs": 30, "maxVUs": 20, "stages": [{"duration": "5m", "target": 10}]}}`, exp{validationError: true}},
// TODO: more tests of mixed executors and execution plans

Expand Down
2 changes: 1 addition & 1 deletion lib/executor/ramping_arrival_rate.go
Expand Up @@ -91,7 +91,7 @@ func (varc *RampingArrivalRateConfig) Validate() []error {
errors = append(errors, fmt.Errorf("the startRate value can't be negative"))
}

if varc.TimeUnit.TimeDuration() < 0 {
if varc.TimeUnit.TimeDuration() <= 0 {
errors = append(errors, fmt.Errorf("the timeUnit must be more than 0"))
}

Expand Down

0 comments on commit 0af62a2

Please sign in to comment.