diff --git a/go.mod b/go.mod index a7e50ce..fa0035c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.21 toolchain go1.21.13 require ( - github.com/grafana/sobek v0.0.0-20240808084414-f7ac208544fe github.com/stretchr/testify v1.9.0 go.k6.io/k6 v0.53.0 ) @@ -20,6 +19,7 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect github.com/google/pprof v0.0.0-20230728192033-2ba5b33183c6 // indirect + github.com/grafana/sobek v0.0.0-20240808084414-f7ac208544fe // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect diff --git a/taskqueue/queuer_test.go b/taskqueue/queuer_test.go index 51aed94..5f89fc5 100644 --- a/taskqueue/queuer_test.go +++ b/taskqueue/queuer_test.go @@ -5,10 +5,7 @@ import ( "testing" "time" - "github.com/grafana/sobek" "github.com/stretchr/testify/require" - "go.k6.io/k6/js/common" - "go.k6.io/k6/js/eventloop" "go.k6.io/k6/js/modulestest" "github.com/mstoykov/k6-taskqueue-lib/taskqueue" @@ -17,17 +14,10 @@ import ( func TestTaskQueue(t *testing.T) { // really basic test t.Parallel() - rt := sobek.New() - vu := &modulestest.VU{ - RuntimeField: rt, - InitEnvField: &common.InitEnvironment{}, - CtxField: context.Background(), - StateField: nil, - } - loop := eventloop.New(vu) - fq := taskqueue.New(loop.RegisterCallback) + tr := modulestest.NewRuntime(t) + fq := taskqueue.New(tr.EventLoop.RegisterCallback) var i int - require.NoError(t, rt.Set("a", func() { + require.NoError(t, tr.VU.Runtime().Set("a", func() { fq.Queue(func() error { fq.Queue(func() error { fq.Queue(func() error { @@ -43,8 +33,8 @@ func TestTaskQueue(t *testing.T) { }) })) - err := loop.Start(func() error { - _, err := vu.Runtime().RunString(`a()`) + err := tr.EventLoop.Start(func() error { + _, err := tr.VU.Runtime().RunString(`a()`) return err }) require.NoError(t, err) @@ -54,16 +44,14 @@ func TestTaskQueue(t *testing.T) { func TestTwoTaskQueues(t *testing.T) { // try to find any kind of races through running multiple queues and having them race with each other t.Parallel() - rt := sobek.New() - ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*100) + tr := modulestest.NewRuntime(t) + ctx, cancel := context.WithTimeout(tr.VU.Context(), time.Millisecond*100) t.Cleanup(cancel) - vu := &modulestest.VU{ - RuntimeField: rt, - CtxField: ctx, - } - loop := eventloop.New(vu) - fq := taskqueue.New(loop.RegisterCallback) - fq2 := taskqueue.New(loop.RegisterCallback) + tr.VU.CtxField = ctx + + rt := tr.VU.Runtime() + fq := taskqueue.New(tr.EventLoop.RegisterCallback) + fq2 := taskqueue.New(tr.EventLoop.RegisterCallback) var i int incrimentI := func() { i++ } var j int @@ -112,12 +100,12 @@ func TestTwoTaskQueues(t *testing.T) { fq2.Close() }() - err := loop.Start(func() error { - _, err := vu.Runtime().RunString(`a()`) + err := tr.EventLoop.Start(func() error { + _, err := tr.VU.Runtime().RunString(`a()`) return err }) require.NoError(t, err) - loop.WaitOnRegistered() + tr.EventLoop.WaitOnRegistered() require.Equal(t, i, k+j) require.Greater(t, k, 100) require.Greater(t, j, 100)