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

chore: Move the validation func from helpers to ramping vus #3616

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
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 result
}

// 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 @@
"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 @@
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 @@
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
}
Loading