diff --git a/lib/executor/helpers.go b/lib/executor/helpers.go index 80699407dab..701d8a3e10a 100644 --- a/lib/executor/helpers.go +++ b/lib/executor/helpers.go @@ -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() @@ -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 diff --git a/lib/executor/ramping_vus.go b/lib/executor/ramping_vus.go index 9acdc4e1773..5887c7accd1 100644 --- a/lib/executor/ramping_vus.go +++ b/lib/executor/ramping_vus.go @@ -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( @@ -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) } } @@ -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 +}