Skip to content

Commit

Permalink
Base main extension context on the context received in launch()
Browse files Browse the repository at this point in the history
This is the context passed from k6, and for synchronization purposes it
would be better if the extension depended on it, so that errors like the
`panic: send on close channel` from issue 49 wouldn't happen. This
technically probably doesn't fix that yet, since the context created
in k6 isn't synchronized with the Engine shutdown and closing of the
SampleContainer channel, but it seems like a good idea regardless.
  • Loading branch information
Ivan Mirić authored and inancgumus committed Nov 9, 2021
1 parent 878c905 commit 69626a2
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions chromium/browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/grafana/xk6-browser/common"
"github.com/pkg/errors"
k6common "go.k6.io/k6/js/common"
k6lib "go.k6.io/k6/lib"
)

// Ensure BrowserType implements the api.BrowserType interface.
Expand All @@ -44,15 +43,11 @@ type BrowserType struct {

func NewBrowserType(ctx context.Context) api.BrowserType {
rt := k6common.GetRuntime(ctx)
state := k6lib.GetState(ctx)
hooks := common.NewHooks()

// Create extension master context. If this context is cancelled we'll
// initiate an extension wide cancellation and shutdown.
extensionCtx := context.Background()
extensionCtx, extensionCancelFn := context.WithCancel(extensionCtx)
extensionCtx = k6common.WithRuntime(extensionCtx, rt)
extensionCtx = k6lib.WithState(extensionCtx, state)
extensionCtx, extensionCancelFn := context.WithCancel(ctx)
extensionCtx = common.WithHooks(extensionCtx, hooks)

b := BrowserType{
Expand Down

0 comments on commit 69626a2

Please sign in to comment.