From b0da697d6fed2c2f7ffcf456c4f0db0b36e9d2e8 Mon Sep 17 00:00:00 2001 From: codebien <2103732+codebien@users.noreply.github.com> Date: Wed, 28 Feb 2024 14:34:36 +0100 Subject: [PATCH] Moved the validation function to the ramping vus --- lib/executor/helpers.go | 27 --------------------------- lib/executor/ramping_vus.go | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 29 deletions(-) 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 +}