Skip to content

Commit

Permalink
Allow simultaneous use of duration and iterations exec shortcuts
Browse files Browse the repository at this point in the history
This would just produce a shared-iterations scheduler with the specified number of iterations and a maxDuration equal to the passed duration, similar to how it works in the current k6 execution. This should fix #1058.
  • Loading branch information
na-- committed Jun 28, 2019
1 parent 83193f8 commit 3ed0fb8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
30 changes: 14 additions & 16 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,13 @@ func getVariableLoopingVUsExecution(stages []lib.Stage, startVUs null.Int) sched
return scheduler.ConfigMap{lib.DefaultSchedulerName: ds}
}

func getSharedIterationsExecution(iterations null.Int, vus null.Int) scheduler.ConfigMap {
func getSharedIterationsExecution(iterations null.Int, duration types.NullDuration, vus null.Int) scheduler.ConfigMap {
ds := scheduler.NewSharedIterationsConfig(lib.DefaultSchedulerName)
ds.VUs = vus
ds.Iterations = iterations
if duration.Valid {
ds.MaxDuration = duration
}
return scheduler.ConfigMap{lib.DefaultSchedulerName: ds}
}

Expand All @@ -234,12 +237,19 @@ func checkExecutionMismatch(observedExecution, derivedExecution scheduler.Config
func deriveExecutionConfig(conf Config) (Config, error) {
result := conf
switch {
case conf.Duration.Valid:
if conf.Iterations.Valid {
case conf.Iterations.Valid:
if len(conf.Stages) > 0 { // stages isn't nil (not set) and isn't explicitly set to empty
//TODO: make this an executionConflictConfigError in the next version
log.Warnf("Specifying both duration and iterations is deprecated and won't be supported in the future k6 versions")
log.Warnf("Specifying both iterations and stages is deprecated and won't be supported in the future k6 versions")
}

result.Execution = getSharedIterationsExecution(conf.Iterations, conf.Duration, conf.VUs)
if err := checkExecutionMismatch(conf.Execution, result.Execution, "iterations"); err != nil {
return conf, err
}
// TODO: maybe add a new flag that will be used as a shortcut to per-VU iterations?

case conf.Duration.Valid:
if len(conf.Stages) > 0 { // stages isn't nil (not set) and isn't explicitly set to empty
//TODO: make this an executionConflictConfigError in the next version
log.Warnf("Specifying both duration and stages is deprecated and won't be supported in the future k6 versions")
Expand All @@ -258,23 +268,11 @@ func deriveExecutionConfig(conf Config) (Config, error) {
}

case len(conf.Stages) > 0: // stages isn't nil (not set) and isn't explicitly set to empty
if conf.Iterations.Valid {
//TODO: make this an executionConflictConfigError in the next version
log.Warnf("Specifying both iterations and stages is deprecated and won't be supported in the future k6 versions")
}

result.Execution = getVariableLoopingVUsExecution(conf.Stages, conf.VUs)
if err := checkExecutionMismatch(conf.Execution, result.Execution, "stages"); err != nil {
return conf, err
}

case conf.Iterations.Valid:
result.Execution = getSharedIterationsExecution(conf.Iterations, conf.VUs)
if err := checkExecutionMismatch(conf.Execution, result.Execution, "iterations"); err != nil {
return conf, err
}
// TODO: maybe add a new flag that will be used as a shortcut to per-VU iterations?

default:
if conf.Execution != nil { // If someone set this, regardless if its empty
//TODO: remove this warning in the next version
Expand Down
18 changes: 12 additions & 6 deletions cmd/config_consolidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,27 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {
opts{cli: []string{"-s", "1m6s:5", "--vus", "10"}}, exp{},
verifyVarLoopingVUs(null.NewInt(10, true), buildStages(66, 5)),
},
{opts{cli: []string{"-u", "1", "-i", "6", "-d", "10s"}}, exp{}, func(t *testing.T, c Config) {
verifySharedIters(I(1), I(6))(t, c)
sharedIterConfig := c.Execution[lib.DefaultSchedulerName].(scheduler.SharedIteationsConfig)
assert.Equal(t, time.Duration(sharedIterConfig.MaxDuration.Duration), 10*time.Second)
}},
// This should get a validation error since VUs are more than the shared iterations
{opts{cli: []string{"--vus", "10", "-i", "6"}}, exp{validationErrors: true}, verifySharedIters(I(10), I(6))},
{opts{cli: []string{"-s", "10s:5", "-s", "10s:"}}, exp{validationErrors: true}, nil},
{opts{fs: defaultConfig(`{"stages": [{"duration": "20s"}], "vus": 10}`)}, exp{validationErrors: true}, nil},
// These should emit a warning
//TODO: in next version, those should be an error
{opts{cli: []string{"-u", "1", "-i", "6", "-d", "10s"}}, exp{logWarning: true}, nil},
{opts{cli: []string{"-u", "2", "-d", "10s", "-s", "10s:20"}}, exp{logWarning: true}, nil},
{opts{cli: []string{"-u", "3", "-i", "5", "-s", "10s:20"}}, exp{logWarning: true}, nil},
{opts{cli: []string{"-u", "3", "-d", "0"}}, exp{logWarning: true}, nil},
{
opts{runner: &lib.Options{
VUs: null.IntFrom(5),
Duration: types.NullDurationFrom(44 * time.Second),
Iterations: null.IntFrom(10),
VUs: null.IntFrom(5),
Duration: types.NullDurationFrom(44 * time.Second),
Stages: []lib.Stage{
{Duration: types.NullDurationFrom(3 * time.Second), Target: I(20)},
},
}}, exp{logWarning: true}, nil,
},
{opts{fs: defaultConfig(`{"execution": {}}`)}, exp{logWarning: true}, verifyOneIterPerOneVU},
Expand Down Expand Up @@ -317,7 +323,7 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {
{
opts{
runner: &lib.Options{VUs: null.IntFrom(5), Duration: types.NullDurationFrom(50 * time.Second)},
cli: []string{"--iterations", "5"},
cli: []string{"--stage", "5s:5"},
},
//TODO: this shouldn't be a warning in the next version, but the result will be different
exp{logWarning: true}, verifyConstLoopingVUs(I(5), 50*time.Second),
Expand All @@ -337,7 +343,7 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {
env: []string{"K6_VUS=15", "K6_ITERATIONS=15"},
},
exp{logWarning: true}, //TODO: this won't be a warning in the next version, but the result will be different
verifyVarLoopingVUs(null.NewInt(15, true), buildStages(20, 10)),
verifySharedIters(I(15), I(15)),
},
{
opts{
Expand Down

0 comments on commit 3ed0fb8

Please sign in to comment.