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

Add support for exec/env/tags executor options #1428

Merged
merged 25 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e693715
Add support for non-default function execution
Apr 17, 2020
4913ad0
Add support for executor-specific env vars
Apr 17, 2020
71a7180
Add support for executor-specific tags
Apr 21, 2020
702f80d
Ignore funlen linter for PerVUIterations.Run
Apr 30, 2020
f7bc0fa
Move script function names to lib/consts package
May 4, 2020
a185924
Validate executor config earlier
May 4, 2020
f7e0214
Use helper function for VUActivationParams, simplify by passing BaseC…
May 4, 2020
1eafd11
Refactor exec fallback
May 6, 2020
d90078d
Check exports with lambda instead of passing object
May 7, 2020
ae5ef34
Fix custom exec tags not leaking between executors
May 11, 2020
60c3c09
Revert moving executor init before VU init
May 11, 2020
25a26ab
Get new VUActivationParams instance per VU in some executors
May 11, 2020
80bff4d
Add custom executor tags to WebSocket metrics
May 11, 2020
06aa32d
Add custom executor tags to checks and group metrics
May 11, 2020
d25c71a
Remove superfluous use of fmt.Sprintf
May 11, 2020
8c5d8df
Define httpbin.local host in NoCrossover test
May 11, 2020
28032b6
Cleanup NoCrossover test a bit
May 11, 2020
ba076f6
Revert "Get new VUActivationParams instance per VU in some executors"
May 12, 2020
4cf716c
Merge RunTags into state.Tags and reuse that everywhere
May 12, 2020
438b422
Move newManualVUHandle function to EC RunState
May 12, 2020
56c0a89
Minor simplification of VU activation in vuHandle
May 12, 2020
60b2ffe
Change defer order in VLV Run
May 12, 2020
a44509d
Fix a bunch of minor issues and repetitions in #1428
na-- May 18, 2020
e1a5c0a
Fix __ENV polution
na-- May 18, 2020
b2b8648
Tweak NoCrossover test to better cover VU reuse scenarios
May 18, 2020
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
5 changes: 3 additions & 2 deletions cmd/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ package cmd
import (
"os"

"github.com/loadimpact/k6/loader"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/loadimpact/k6/loader"
)

var archiveOut = "archive.tar"
Expand Down Expand Up @@ -77,7 +78,7 @@ An archive is a fully self-contained test run, and can be executed identically e
return err
}

if _, cerr := deriveAndValidateConfig(conf); cerr != nil {
if _, cerr := deriveAndValidateConfig(conf, r.IsExecutable); cerr != nil {
return ExitCode{error: cerr, Code: invalidConfigErrorCode}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ This will execute the test on the Load Impact cloud service. Use "k6 login cloud
return err
}

derivedConf, cerr := deriveAndValidateConfig(conf)
derivedConf, cerr := deriveAndValidateConfig(conf, r.IsExecutable)
if cerr != nil {
return ExitCode{error: cerr, Code: invalidConfigErrorCode}
}
Expand Down
21 changes: 18 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,24 @@ func applyDefault(conf Config) Config {
return conf
}

func deriveAndValidateConfig(conf Config) (result Config, err error) {
func deriveAndValidateConfig(conf Config, isExecutable func(string) bool) (result Config, err error) {
result = conf
result.Options, err = executor.DeriveExecutionFromShortcuts(conf.Options)
if err != nil {
return result, err
}
return result, validateConfig(result)
return result, validateConfig(result, isExecutable)
}

func validateConfig(conf Config) error {
func validateConfig(conf Config, isExecutable func(string) bool) error {
errList := conf.Validate()

for _, ec := range conf.Execution {
if err := validateExecutorConfig(ec, isExecutable); err != nil {
errList = append(errList, err)
}
}

if len(errList) == 0 {
return nil
}
Expand All @@ -284,3 +291,11 @@ func validateConfig(conf Config) error {

return errors.New(strings.Join(errMsgParts, "\n"))
}

func validateExecutorConfig(conf lib.ExecutorConfig, isExecutable func(string) bool) error {
execFn := conf.GetExec()
if !isExecutable(execFn) {
return fmt.Errorf("executor %s: function '%s' not found in exports", conf.GetName(), execFn)
}
return nil
}
52 changes: 51 additions & 1 deletion cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ package cmd
import (
"fmt"
"testing"
"time"

"github.com/kelseyhightower/envconfig"
"github.com/loadimpact/k6/lib/testutils"
"github.com/stretchr/testify/assert"
"gopkg.in/guregu/null.v3"

"github.com/loadimpact/k6/lib"
"github.com/loadimpact/k6/lib/executor"
"github.com/loadimpact/k6/lib/testutils"
"github.com/loadimpact/k6/lib/types"
)

type testCmdData struct {
Expand Down Expand Up @@ -134,3 +139,48 @@ func TestConfigApply(t *testing.T) {
assert.Equal(t, []string{"influxdb", "json"}, conf.Out)
})
}

func TestDeriveAndValidateConfig(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
conf Config
isExec bool
err string
}{
{"defaultOK", Config{}, true, ""},
{"defaultErr", Config{}, false,
"executor default: function 'default' not found in exports"},
{"nonDefaultOK", Config{Options: lib.Options{Execution: lib.ExecutorConfigMap{
"per_vu_iters": executor.PerVUIterationsConfig{BaseConfig: executor.BaseConfig{
Name: "per_vu_iters", Type: "per-vu-iterations", Exec: null.StringFrom("nonDefault")},
VUs: null.IntFrom(1),
Iterations: null.IntFrom(1),
MaxDuration: types.NullDurationFrom(time.Second),
}}}}, true, "",
},
{"nonDefaultErr", Config{Options: lib.Options{Execution: lib.ExecutorConfigMap{
"per_vu_iters": executor.PerVUIterationsConfig{BaseConfig: executor.BaseConfig{
Name: "per_vu_iters", Type: "per-vu-iterations", Exec: null.StringFrom("nonDefaultErr")},
VUs: null.IntFrom(1),
Iterations: null.IntFrom(1),
MaxDuration: types.NullDurationFrom(time.Second),
}}}}, false,
"executor per_vu_iters: function 'nonDefaultErr' not found in exports",
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
_, err := deriveAndValidateConfig(tc.conf,
func(_ string) bool { return tc.isExec })
if tc.err != "" {
assert.Contains(t, err.Error(), tc.err)
} else {
assert.NoError(t, err)
}
})
}
}
6 changes: 3 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ a commandline interface for interacting with it.`,
return err
}

conf, cerr := deriveAndValidateConfig(conf)
conf, cerr := deriveAndValidateConfig(conf, r.IsExecutable)
if cerr != nil {
return ExitCode{error: cerr, Code: invalidConfigErrorCode}
}
Expand Down Expand Up @@ -382,9 +382,9 @@ func getExitCodeFromEngine(err error) ExitCode {
switch e := errors.Cause(err).(type) {
case lib.TimeoutError:
switch e.Place() {
case "setup":
case consts.SetupFn:
return ExitCode{error: err, Code: setupTimeoutErrorCode, Hint: e.Hint()}
case "teardown":
case consts.TeardownFn:
return ExitCode{error: err, Code: teardownTimeoutErrorCode, Hint: e.Hint()}
default:
return ExitCode{error: err, Code: genericTimeoutErrorCode}
Expand Down
Loading