-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Upgrade xk6-browser to v1.0.2 #3235
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3235 +/- ##
==========================================
- Coverage 73.22% 73.05% -0.18%
==========================================
Files 259 256 -3
Lines 19899 19882 -17
==========================================
- Hits 14572 14524 -48
- Misses 4403 4426 +23
- Partials 924 932 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
|
6184d29
to
8a204fc
Compare
@@ -1827,80 +1827,6 @@ func BenchmarkReadResponseBody(b *testing.B) { | |||
cmd.ExecuteWithGlobalState(ts.GlobalState) | |||
} | |||
|
|||
func TestBrowserPermissions(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we actually have a test with the scenarios options instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for having an e2e coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to create a test but now I think i've found an issue with the events channel from the new event loop that the browser module subscribes to.
After creating a simple test
Simple test
func TestBrowserPermissions(t *testing.T) {
t.Parallel()
tests := []struct {
name string
expectedExitCode exitcodes.ExitCode
expectedError string
}{
{
name: "browser option not set",
expectedExitCode: 0,
expectedError: "GoError: browser not found in registry. make sure to set browser type option in scenario definition in order to use the browser module",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
script := `
import { browser } from 'k6/experimental/browser';
export default function() {
browser.isConnected();
};
`
ts := getSingleFileTestState(t, script, []string{}, tt.expectedExitCode)
cmd.ExecuteWithGlobalState(ts.GlobalState)
loglines := ts.LoggerHook.Drain()
if tt.expectedError == "" {
require.Len(t, loglines, 0)
return
}
assert.Contains(t, loglines[0].Message, tt.expectedError)
})
}
}
The output of the test is:
found unexpected goroutines:
[Goroutine 69 in state chan receive, with github.com/grafana/xk6-browser/browser.(*browserRegistry).handleIterEvents on top of the stack:
goroutine 69 [chan receive]:
github.com/grafana/xk6-browser/browser.(*browserRegistry).handleIterEvents(0x14001fb6b00, 0x0?, 0x14000b7f6e0)
/Users/ankuragarwal/go/src/github.com/grafana/k6/vendor/github.com/grafana/xk6-browser/browser/registry.go:239 +0xa4
created by github.com/grafana/xk6-browser/browser.newBrowserRegistry
/Users/ankuragarwal/go/src/github.com/grafana/k6/vendor/github.com/grafana/xk6-browser/browser/registry.go:226 +0x2f8
Goroutine 60 in state chan receive, with github.com/grafana/xk6-browser/browser.(*browserRegistry).handleIterEvents on top of the stack:
goroutine 60 [chan receive]:
github.com/grafana/xk6-browser/browser.(*browserRegistry).handleIterEvents(0x14001fd90c0, 0x105b12700?, 0x14000d0de30)
/Users/ankuragarwal/go/src/github.com/grafana/k6/vendor/github.com/grafana/xk6-browser/browser/registry.go:239 +0xa4
created by github.com/grafana/xk6-browser/browser.newBrowserRegistry
/Users/ankuragarwal/go/src/github.com/grafana/k6/vendor/github.com/grafana/xk6-browser/browser/registry.go:226 +0x2f8
]
So it would seem that the channel the browser module gets after subscribing isn't being closed when the test exits, am i correct in thinking that? I'd prefer to suppress this error for now and work on the fix in the next cycle.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't being closed when the test exits, am i correct in thinking that?
Yes, it seems you're right. Do you have a guess why this is happening? I see the code for unsubscribing is implemented on the core and invoked from the browser.
I'd prefer to suppress this error for now and work on the fix in the next cycle.
How do you intend to suppress it? Do you want to remove the e2e test? I would prefer if at least we understand the root of the problem and we open an issue so we can classify it as non-critical with confidence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created a new issue. I believe the issue actually lies within the browser module scope and so we will work on it asap.
When the test run completes, does the k6 processes exit, or can it ever be reused? The reason I'm asking is because these uncleared goroutines will leak if the k6 process is reused. If it isn't then this is non-critical issue, but we will not be able to add the e2e test in this release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a fix for the leaky goroutines in grafana/xk6-browser#990. As soon as that has been merged into main, i'll upgrade this PR to work with the latest commit from main, and finally add the e2e tests for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this branch to work with v1.0.1 of xk6-browser which contains the fix for the goroutine leaks. I've also added an e2e test.
It's worth noting that the e2e test will start a chrome process in the background.
Also, i'm looking at this data race now 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still prefer to have a test that the options enable the browser and without them it won't work.
@@ -1827,80 +1827,6 @@ func BenchmarkReadResponseBody(b *testing.B) { | |||
cmd.ExecuteWithGlobalState(ts.GlobalState) | |||
} | |||
|
|||
func TestBrowserPermissions(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for having an e2e coverage
8e31247
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ka3de, could you also drop K6_BROWSER_ENABLED from the Dockerfile?
Done in 85af866. |
Currently (as of grafana/xk6-browser@v1.0.0) the browser extension requires the definition of the browser type parameter inside the options element for every scenario that wants to use the browser module. Therefore the K6_BROWSER_ENABLED flag has become redundant, as both parameters have to be set, being the scenario one more restrictive. Because we no longer have to parse the environment variable, the module wrapper implementation can be removed completely and use the xk6-browser root module constructor directly instead.
This includes some fixes for the goroutine leaks that we were seeing when we tried to create the e2e tests for the browser module in k6.
This test ensures that an error occurs and the test ends when the browser module is imported but the options are missing, otherwise when setup correctly the browser test runs.
85af866
to
5eee08d
Compare
This contains a fix for the race condition where the ctx was being read before the vu was setup.
a32cc6f
to
0837ee5
Compare
What?
This PR upgrades the xk6-browser extension version to v1.0.2. Being this one the latest release for the extension.
Additionally, it also removes the requirement for the
K6_BROWSER_ENABLED
environment variable in order to execute tests that use the experimental browser module.Why?
Upgrade
Keep xk6-browser extension version up to date in k6.
Removal of
K6_BROWSER_ENABLED
flagCurrently (as of xk6-browser v1.0.2) the browser extension requires the definition of the browser type parameter inside the options element for every scenario that wants to use the browser module. Therefore the usage of
K6_BROWSER_ENABLED
flag as an explicit approval to use the browser module has become redundant, as both parameters have to be set, being the scenario one more restrictive.Checklist
make ci-like-lint
) and all checks pass.make tests
) and all tests pass.Related PR(s)/Issue(s)
Closes #3197