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

Move core/local/ExecutionScheduler to execution/Scheduler #2812

Merged
merged 3 commits into from
Jan 24, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"go.k6.io/k6/api"
"go.k6.io/k6/cmd/state"
"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 @@ -72,7 +72,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 @@ -332,7 +332,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