Skip to content

Commit

Permalink
Move core/local.ExecutionScheduler to execution.Scheduler
Browse files Browse the repository at this point in the history
We also remove the lib.ExecutionScheduler interface because it only ever had a single implementation and it's unlikely we'll ever need more than that. Distributed execution will be implemented another way and we should not mock the execution scheduler, we should mock the parts it moves (e.g. the Runner and Executors, if needs be).
  • Loading branch information
na-- committed Dec 7, 2022
1 parent 62eb4f9 commit ef18b38
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 444 deletions.
4 changes: 2 additions & 2 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"go.k6.io/k6/api/common"
"go.k6.io/k6/core"
"go.k6.io/k6/core/local"
"go.k6.io/k6/execution"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/testutils"
"go.k6.io/k6/lib/testutils/minirunner"
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestWithEngine(t *testing.T) {
Runner: &minirunner.MiniRunner{},
}

execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)
engine, err := core.NewEngine(testState, execScheduler, nil)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions api/v1/group_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"

"go.k6.io/k6/core"
"go.k6.io/k6/core/local"
"go.k6.io/k6/execution"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/testutils"
"go.k6.io/k6/lib/testutils/minirunner"
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestGetGroups(t *testing.T) {
assert.NoError(t, err)

testState := getTestRunState(t, lib.Options{}, &minirunner.MiniRunner{Group: g0})
execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)
engine, err := core.NewEngine(testState, execScheduler, nil)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions api/v1/metric_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"gopkg.in/guregu/null.v3"

"go.k6.io/k6/core"
"go.k6.io/k6/core/local"
"go.k6.io/k6/execution"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/testutils/minirunner"
"go.k6.io/k6/metrics"
Expand All @@ -23,7 +23,7 @@ func TestGetMetrics(t *testing.T) {
testState := getTestRunState(t, lib.Options{}, &minirunner.MiniRunner{})
testMetric, err := testState.Registry.NewMetric("my_metric", metrics.Trend, metrics.Time)
require.NoError(t, err)
execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)
engine, err := core.NewEngine(testState, execScheduler, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestGetMetric(t *testing.T) {
testState := getTestRunState(t, lib.Options{}, &minirunner.MiniRunner{})
testMetric, err := testState.Registry.NewMetric("my_metric", metrics.Trend, metrics.Time)
require.NoError(t, err)
execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)
engine, err := core.NewEngine(testState, execScheduler, nil)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions api/v1/setup_teardown_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"gopkg.in/guregu/null.v3"

"go.k6.io/k6/core"
"go.k6.io/k6/core/local"
"go.k6.io/k6/execution"
"go.k6.io/k6/js"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/types"
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestSetupData(t *testing.T) {
TeardownTimeout: types.NullDurationFrom(5 * time.Second),
}, runner)

execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)
engine, err := core.NewEngine(testState, execScheduler, nil)
require.NoError(t, err)
Expand Down
6 changes: 2 additions & 4 deletions api/v1/status_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"

"go.k6.io/k6/api/common"
"go.k6.io/k6/lib"
"go.k6.io/k6/execution"
"go.k6.io/k6/lib/executor"
)

Expand All @@ -24,9 +24,7 @@ func handleGetStatus(rw http.ResponseWriter, r *http.Request) {
_, _ = rw.Write(data)
}

func getFirstExternallyControlledExecutor(
execScheduler lib.ExecutionScheduler,
) (*executor.ExternallyControlled, error) {
func getFirstExternallyControlledExecutor(execScheduler *execution.Scheduler) (*executor.ExternallyControlled, error) {
executors := execScheduler.GetExecutors()
for _, s := range executors {
if mex, ok := s.(*executor.ExternallyControlled); ok {
Expand Down
6 changes: 3 additions & 3 deletions api/v1/status_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"gopkg.in/guregu/null.v3"

"go.k6.io/k6/core"
"go.k6.io/k6/core/local"
"go.k6.io/k6/execution"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/testutils/minirunner"
)
Expand All @@ -23,7 +23,7 @@ func TestGetStatus(t *testing.T) {
t.Parallel()

testState := getTestRunState(t, lib.Options{}, &minirunner.MiniRunner{})
execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)
engine, err := core.NewEngine(testState, execScheduler, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestPatchStatus(t *testing.T) {
require.NoError(t, err)

testState := getTestRunState(t, lib.Options{Scenarios: scenarios}, &minirunner.MiniRunner{})
execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)
engine, err := core.NewEngine(testState, execScheduler, nil)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/integration_tests/eventloop/eventloop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"go.k6.io/k6/cmd/integration_tests/testmodules/events"
"go.k6.io/k6/core/local"
"go.k6.io/k6/execution"
"go.k6.io/k6/js"
"go.k6.io/k6/js/modules"
"go.k6.io/k6/lib"
Expand Down Expand Up @@ -57,7 +57,7 @@ func eventLoopTest(t *testing.T, script []byte, testHandle func(context.Context,
RunTags: piState.Registry.RootTagSet().WithTagsFromMap(newOpts.RunTags),
}

execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)

samples := make(chan metrics.SampleContainer, newOpts.MetricSamplesBufferSize.Int64)
Expand Down
6 changes: 3 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (

"go.k6.io/k6/api"
"go.k6.io/k6/core"
"go.k6.io/k6/core/local"
"go.k6.io/k6/errext"
"go.k6.io/k6/errext/exitcodes"
"go.k6.io/k6/execution"
"go.k6.io/k6/js/common"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/consts"
Expand Down Expand Up @@ -71,7 +71,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
logger := testRunState.Logger
// Create a local execution scheduler wrapping the runner.
logger.Debug("Initializing the execution scheduler...")
execScheduler, err := local.NewExecutionScheduler(testRunState)
execScheduler, err := execution.NewScheduler(testRunState)
if err != nil {
return err
}
Expand Down Expand Up @@ -329,7 +329,7 @@ a commandline interface for interacting with it.`,
return runCmd
}

func reportUsage(execScheduler *local.ExecutionScheduler) error {
func reportUsage(execScheduler *execution.Scheduler) error {
execState := execScheduler.GetState()
executorConfigs := execScheduler.GetExecutorConfigs()

Expand Down
5 changes: 3 additions & 2 deletions core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"go.k6.io/k6/errext"
"go.k6.io/k6/errext/exitcodes"
"go.k6.io/k6/execution"
"go.k6.io/k6/lib"
"go.k6.io/k6/metrics"
"go.k6.io/k6/metrics/engine"
Expand All @@ -33,7 +34,7 @@ type Engine struct {

// TODO: completely remove the engine and use all of these separately, in a
// much more composable and testable manner
ExecutionScheduler lib.ExecutionScheduler
ExecutionScheduler *execution.Scheduler
MetricsEngine *engine.MetricsEngine
OutputManager *output.Manager

Expand All @@ -53,7 +54,7 @@ type Engine struct {
}

// NewEngine instantiates a new Engine, without doing any heavy initialization.
func NewEngine(testState *lib.TestRunState, ex lib.ExecutionScheduler, outputs []output.Output) (*Engine, error) {
func NewEngine(testState *lib.TestRunState, ex *execution.Scheduler, outputs []output.Output) (*Engine, error) {
if ex == nil {
return nil, errors.New("missing ExecutionScheduler instance")
}
Expand Down
8 changes: 4 additions & 4 deletions core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v3"

"go.k6.io/k6/core/local"
"go.k6.io/k6/errext"
"go.k6.io/k6/execution"
"go.k6.io/k6/js"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/executor"
Expand Down Expand Up @@ -82,7 +82,7 @@ func newTestEngineWithTestPreInitState( //nolint:golint

testRunState := getTestRunState(t, piState, newOpts, runner)

execScheduler, err := local.NewExecutionScheduler(testRunState)
execScheduler, err := execution.NewScheduler(testRunState)
require.NoError(t, err)

engine, err := NewEngine(testRunState, execScheduler, outputs)
Expand Down Expand Up @@ -927,7 +927,7 @@ func TestVuInitException(t *testing.T) {

testState := getTestRunState(t, piState, opts, runner)

execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)
engine, err := NewEngine(testState, execScheduler, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -1315,7 +1315,7 @@ func TestActiveVUsCount(t *testing.T) {
require.NoError(t, err)

testState := getTestRunState(t, piState, opts, runner)
execScheduler, err := local.NewExecutionScheduler(testState)
execScheduler, err := execution.NewScheduler(testState)
require.NoError(t, err)
engine, err := NewEngine(testState, execScheduler, []output.Output{mockOutput})
require.NoError(t, err)
Expand Down
Loading

0 comments on commit ef18b38

Please sign in to comment.