Skip to content

Commit

Permalink
Moved the validation function to the ramping vus
Browse files Browse the repository at this point in the history
  • Loading branch information
codebien committed Feb 28, 2024
1 parent b217bbf commit b0da697
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
27 changes: 0 additions & 27 deletions lib/executor/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ import (
"go.k6.io/k6/ui/pb"
)

const (
// maxConcurrentVUs is an arbitrary limit for sanity checks.
// It prevents running an exaggeratedly large number of concurrent VUs which may lead to an out-of-memory.
maxConcurrentVUs int = 100_000_000
)

func sumStagesDuration(stages []Stage) (result time.Duration) {
for _, s := range stages {
result += s.Duration.TimeDuration()
Expand All @@ -39,27 +33,6 @@ func getStagesUnscaledMaxTarget(unscaledStartValue int64, stages []Stage) int64
return max
}

// validateTargetShifts validates the VU Target shifts.
// It will append an error for any VU target that is larger than the maximum value allowed.
// Each Stage needs a Target value. The stages array can be empty. The Targes could be negative.
func validateTargetShifts(startVUs int64, stages []Stage) []error {
var errors []error

if startVUs > int64(maxConcurrentVUs) {
errors = append(errors, fmt.Errorf(
"the startVUs exceed max limit of %d", maxConcurrentVUs))
}

for i := 0; i < len(stages); i++ {
if stages[i].Target.Int64 > int64(maxConcurrentVUs) {
errors = append(errors, fmt.Errorf(
"target for stage %d exceeds max limit of %d", i+1, maxConcurrentVUs))
}
}

return errors
}

// A helper function to avoid code duplication
func validateStages(stages []Stage) []error {
var errors []error
Expand Down
34 changes: 32 additions & 2 deletions lib/executor/ramping_vus.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import (
"go.k6.io/k6/ui/pb"
)

const rampingVUsType = "ramping-vus"
const (
rampingVUsType = "ramping-vus"

// maxConcurrentVUs is an arbitrary limit for sanity checks.
// It prevents running an exaggeratedly large number of concurrent VUs which may lead to an out-of-memory.
maxConcurrentVUs int = 100_000_000
)

func init() {
lib.RegisterExecutorConfigType(
Expand Down Expand Up @@ -612,7 +618,7 @@ func (rs *rampingVUsRunState) runLoopsIfPossible(ctx context.Context, cancel fun
rs.vuHandles[i] = newStoppedVUHandle(
ctx, getVU, returnVU, rs.executor.nextIterationCounters,
&rs.executor.config.BaseConfig, rs.executor.logger.WithField("vuNum", i))
go rs.vuHandles[i].runLoopsIfPossible(rs.runIteration) //nolint:contextcheck
go rs.vuHandles[i].runLoopsIfPossible(rs.runIteration)

Check failure on line 621 in lib/executor/ramping_vus.go

View workflow job for this annotation

GitHub Actions / lint

Function `runLoopsIfPossible` should pass the context parameter (contextcheck)
}
}

Expand Down Expand Up @@ -710,3 +716,27 @@ func waiter(ctx context.Context, start time.Time) func(offset time.Duration) boo
return false
}
}

// validateTargetShifts validates the VU Target shifts.
// It will append an error for any VU target that is larger than the maximum value allowed.
// Each Stage needs a Target value. The stages array can be empty. The Targes could be negative.
//
// TODO: after https://github.com/grafana/k6/issues/1499 this validation
// function could be useless.
func validateTargetShifts(startVUs int64, stages []Stage) []error {
var errors []error

if startVUs > int64(maxConcurrentVUs) {
errors = append(errors, fmt.Errorf(
"the startVUs exceed max limit of %d", maxConcurrentVUs))
}

for i := 0; i < len(stages); i++ {
if stages[i].Target.Int64 > int64(maxConcurrentVUs) {
errors = append(errors, fmt.Errorf(
"target for stage %d exceeds max limit of %d", i+1, maxConcurrentVUs))
}
}

return errors
}

0 comments on commit b0da697

Please sign in to comment.