From 69626a2984614be45c28fe8b895bcd3fb7cffaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Thu, 4 Nov 2021 14:56:31 +0100 Subject: [PATCH] Base main extension context on the context received in launch() 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. --- chromium/browser_type.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/chromium/browser_type.go b/chromium/browser_type.go index b95a18d3d..8f7e5a61c 100644 --- a/chromium/browser_type.go +++ b/chromium/browser_type.go @@ -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. @@ -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{