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

Allow stages to be properly disabled by fixing the CLI parsing #786

Merged
merged 3 commits into from Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/config_test.go
Expand Up @@ -83,6 +83,8 @@ func TestConfigCmd(t *testing.T) {
}
}

//TODO: write end-to-end configuration tests - how the config file, in-script options, environment variables and CLI flags are parsed and interact... and how the end result is then propagated back into the script

func TestConfigEnv(t *testing.T) {
testdata := map[struct{ Name, Key string }]map[string]func(Config){
{"Linger", "K6_LINGER"}: {
Expand Down
18 changes: 11 additions & 7 deletions cmd/options.go
Expand Up @@ -96,18 +96,22 @@ func getOptions(flags *pflag.FlagSet) (lib.Options, error) {
MetricSamplesBufferSize: null.NewInt(1000, false),
}

stageStrings, err := flags.GetStringSlice("stage")
if err != nil {
return opts, err
}
if len(stageStrings) > 0 {
opts.Stages = make([]lib.Stage, len(stageStrings))
// Using Lookup() because GetStringSlice() doesn't differentiate between --stage="" and no value
if flags.Lookup("stage").Changed {
stageStrings, err := flags.GetStringSlice("stage")
if err != nil {
return opts, err
}
opts.Stages = []lib.Stage{}
for i, s := range stageStrings {
var stage lib.Stage
if err := stage.UnmarshalText([]byte(s)); err != nil {
return opts, errors.Wrapf(err, "stage %d", i)
}
opts.Stages[i] = stage
if !stage.Duration.Valid {
return opts, fmt.Errorf("stage %d doesn't have a specified duration", i)
}
opts.Stages = append(opts.Stages, stage)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Expand Up @@ -143,7 +143,7 @@ a commandline interface for interacting with it.`,
}

// If -d/--duration, -i/--iterations and -s/--stage are all unset, run to one iteration.
if !conf.Duration.Valid && !conf.Iterations.Valid && conf.Stages == nil {
if !conf.Duration.Valid && !conf.Iterations.Valid && len(conf.Stages) == 0 {
conf.Iterations = null.IntFrom(1)
}

Expand Down
2 changes: 1 addition & 1 deletion core/local/local.go
Expand Up @@ -279,7 +279,7 @@ func (e *Executor) Run(parent context.Context, engineOut chan<- stats.SampleCont
}

stages := e.stages
if stages != nil {
if len(stages) > 0 {
vus, keepRunning := ProcessStages(startVUs, stages, at)
if !keepRunning {
e.Logger.WithField("at", at).Debug("Local: Ran out of stages")
Expand Down
3 changes: 2 additions & 1 deletion release notes/upcoming.md
Expand Up @@ -103,4 +103,5 @@ Thanks to @AndriiChuzhynov for implementing this! (#766)
* Config: Stages were appended instead of overwritten from upper config "tiers", and were doubled when supplied via the CLI flag (#759)
* HAR converter: Fixed a panic due to a missing array length check (#760)
* HTTP: `http.batch()` calls could panic because of a data race when the `batchPerHost` global option was used (#770)
* Docker: Fixed the grafana image in the docker-compose setup. Thanks @entone and @mariolopjr! (#783)
* Docker: Fixed the grafana image in the docker-compose setup. Thanks @entone and @mariolopjr! (#783)
* Config: Stages configured via the script `options` or environment variables couldn't be disabled via the CLI flags (#786)