diff --git a/cmd/inspect.go b/cmd/inspect.go index 76d411fde16..712aaa878ae 100644 --- a/cmd/inspect.go +++ b/cmd/inspect.go @@ -30,7 +30,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "go.k6.io/k6/core/local" "go.k6.io/k6/js" "go.k6.io/k6/lib" "go.k6.io/k6/lib/metrics" @@ -57,7 +56,6 @@ func getInspectCmd(logger *logrus.Logger, globalFlags *commandFlags) *cobra.Comm return err } registry := metrics.NewRegistry() - builtinMetrics := metrics.RegisterBuiltinMetrics(registry) var b *js.Bundle typ := globalFlags.runType @@ -85,7 +83,7 @@ func getInspectCmd(logger *logrus.Logger, globalFlags *commandFlags) *cobra.Comm inspectOutput := interface{}(b.Options) if addExecReqs { - inspectOutput, err = addExecRequirements(b, builtinMetrics, registry, logger, globalFlags) + inspectOutput, err = addExecRequirements(b, logger, globalFlags) if err != nil { return err } @@ -112,37 +110,24 @@ func getInspectCmd(logger *logrus.Logger, globalFlags *commandFlags) *cobra.Comm return inspectCmd } -func addExecRequirements(b *js.Bundle, - builtinMetrics *metrics.BuiltinMetrics, registry *metrics.Registry, - logger *logrus.Logger, globalFlags *commandFlags) (interface{}, error) { - // TODO: after #1048 issue, consider rewriting this without a Runner: - // just creating ExecutionPlan directly from validated options - - runner, err := js.NewFromBundle(logger, b, builtinMetrics, registry) - if err != nil { - return nil, err - } - +func addExecRequirements(b *js.Bundle, logger *logrus.Logger, globalFlags *commandFlags) (interface{}, error) { conf, err := getConsolidatedConfig( - afero.NewOsFs(), Config{}, runner.GetOptions(), buildEnvMap(os.Environ()), globalFlags) + afero.NewOsFs(), Config{}, b.Options, buildEnvMap(os.Environ()), globalFlags) if err != nil { return nil, err } - conf, err = deriveAndValidateConfig(conf, runner.IsExecutable, logger) + conf, err = deriveAndValidateConfig(conf, b.IsExecutable, logger) if err != nil { return nil, err } - if err = runner.SetOptions(conf.Options); err != nil { - return nil, err - } - execScheduler, err := local.NewExecutionScheduler(runner, logger) + et, err := lib.NewExecutionTuple(conf.ExecutionSegment, conf.ExecutionSegmentSequence) if err != nil { return nil, err } - executionPlan := execScheduler.GetExecutionPlan() + executionPlan := conf.Scenarios.GetFullExecutionRequirements(et) duration, _ := lib.GetEndOffset(executionPlan) return struct { diff --git a/js/bundle.go b/js/bundle.go index d80ec7a2b27..b13adc26639 100644 --- a/js/bundle.go +++ b/js/bundle.go @@ -296,6 +296,13 @@ func (b *Bundle) Instantiate( return bi, instErr } +// IsExecutable returns whether the given name is an exported and +// executable function in the script. +func (b *Bundle) IsExecutable(name string) bool { + _, exists := b.exports[name] + return exists +} + // Instantiates the bundle into an existing runtime. Not public because it also messes with a bunch // of other things, will potentially thrash data and makes a mess in it if the operation fails. func (b *Bundle) instantiate(logger logrus.FieldLogger, rt *goja.Runtime, init *InitContext, vuID uint64) error { diff --git a/js/runner.go b/js/runner.go index 80aad46cd5f..a0a4caefa2e 100644 --- a/js/runner.go +++ b/js/runner.go @@ -347,9 +347,10 @@ func (r *Runner) GetOptions() lib.Options { // IsExecutable returns whether the given name is an exported and // executable function in the script. +// +// TODO: completely remove this? func (r *Runner) IsExecutable(name string) bool { - _, exists := r.Bundle.exports[name] - return exists + return r.Bundle.IsExecutable(name) } // HandleSummary calls the specified summary callback, if supplied.