-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix navigation when errorText is not empty #4862
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
Conversation
if errorText != "" { | ||
err = fmt.Errorf("navigation failed: %v", errorText) | ||
} |
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.
In k6 browser, when a navigation fails due to something like a DNS lookup, at the moment it continues on with the navigation and seems to assume that it succeeded. This is a problem down the line since future calls to APIs in the test script will eventually fail.
Running all the browser tests, i realised it seems that the old behaviour is valid? For example TestBlockHostname now fails on page.goto
, but the test expects the page.goto
call to succeed. What do you think the behaviour should be?
CC @inancgumus
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 you help me understand your concerns? How can I run and compare the "new" and "old" behavior? Do you mean the code in this PR by the "new" behavior? Thanks!
08e8f07
to
4e02ef8
Compare
@@ -629,7 +629,7 @@ func (fs *FrameSession) navigateFrame(frame *Frame, url, referrer string) (strin | |||
err = fmt.Errorf("%q: %w", errorText, err) | |||
} | |||
} | |||
return documentID.String(), err | |||
return documentID.String(), errorText, err |
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.
return documentID.String(), errorText, err | |
return documentID.String(), err |
Why do we need to return this error? Can't we throw an error here if we identify that the errorText
is not empty?
In addition, a DNS error is generally an error on any system, why isn't the case here? Are we sure to not silencing the error somewhere else?
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.
Right, i agree that this is a smell. Happy to have any suggestions on how to improve this.
Context
The issue in this case where err
is nil
and errorText
is not empty is that once we return an error after calling navigateFrame, it will return an error back to the caller, but the event loop will contain older events which could be consumed by the next event handler of the same type.
k6 browser uses event loops in the background. We register an event handler here to listen out for incoming EventFrameNavigation
CDP events from chromium once a page navigation occurs -- it turns out that this event is fired even when a DNS issue occurs, which makes sense since if you type in https://blah.madeupurl.com into chromium you will see This site can’t be reached
page, so a navigation does indeed occur.
If we don't consume the event then the next time we create the same event handler it might consume the older event, which is what was happening in TestBlockHostnames
when i ran the test when returning err
early.
After an event is consumed the event handler is destroyed regardless of whether it successfully handled the event or not.
To avoid this, the handling of errorText
needs to be done differently to err
when calling navigateFrame
(code link). The error case is handled straight away since we assume that we will never get a EventFrameNavigation
event. For the case where errorText
is not empty, we need to wait for the EventFrameNavigation
, and then we can return an error (code link).
Changing the event loop itself will be super complex -- we have tried to make fixes and refactors in the past and it's super difficult which can cause other issues further down the line! I want to avoid that.
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.
Have you seen #4918? It seems to be related 🤔
@ankur22 the latest added tests seems to fail |
db7b358
to
b9f1d7f
Compare
🤷 it's one of those cases where it works on my machine and not in CI. I've tried working with GOMAXPROCS and i can't get the test to fail locally. I am seeing an unusaly high number of CI failures this week, could it be a change in githubs actions? @inancgumus any pointers on how I could try to cox the new |
@ankur22 Did you try to run with
I don't think so, we should see it across all the modules. Instead, they seem localized on the browser. Honestly, based on all the |
yeah i used that too.
The browser module is a little more sensitive to github action changes since the tests require significantly more resource than the other modules to run a single test with a browser.
That's nothing new (unfortunately), neither are the context canceled issues which end the test early. |
b9f1d7f
to
ac8669b
Compare
@ankur22 Do you mean the current (this PR's) failures? The Github actions should not affect the outcome of these runs unless you see a Vault communication error.
It's probably a Windows issue because the preceding errors (before your tests) are often like this:
I can get the same test error when I give it a file other than |
* Base release notes for v1.1.0 * Add release notes for dependabot PRs * Add #4809 and #4831 into the v1.1.0 release note * Add #4845 to the v1.1.0 release notes * Add example for locator.count * Remove await on expect in count example * Add section for nth, first and count in v1.1.0... ... release notes. * Update examples to work with latest test library This also updates the nth, first and last example. * Add some PRs from the beginning of the cycle into release notes * Add external PRs, among others, to release notes * Clean up stuff from release notes template * Add remaining PRs into release notes * Add #4862 to the v1.1.0 release note * Apply suggestions from code review Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> * Add #4864 to v1.1.0 release notes * Remove #4862 from v1.1.0 * Apply suggestions from code review Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com> * web/crypto updates * Update release notes/v1.1.0.md Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> * docs: document v1.1.0 forward roadmap * Refine experimental modules notes --------- Co-authored-by: ankur22 <ankur.agarwal@grafana.com> Co-authored-by: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com> Co-authored-by: oleiade <theo@crevon.me> Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com>
This breaks the test into three separate tests so that we can properly focus on each different area of skipping loading of a file/blob.
Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com>
ac8669b
to
86e3a6d
Compare
Closing this PR in favour of #4918 |
What?
We now check whether
errorText
is not empty during a navigation, to fail the test early.Why?
When
errorText
is not empty anderr
isnil
, it means that the navigation failed; for example when a DNS lookup fails.Checklist
make check
) and all pass.Checklist: Documentation (only for k6 maintainers and if relevant)
Please do not merge this PR until the following items are filled out.
Related PR(s)/Issue(s)
#4861