-
Notifications
You must be signed in to change notification settings - Fork 39
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
Refactor force browser close on panic #755
Conversation
8a11c31
to
6407ceb
Compare
1e3c2c0
to
3afac7d
Compare
c688fd2
to
d8f1ed9
Compare
browserprocess/register_test.go
Outdated
@@ -1,57 +0,0 @@ | |||
package browserprocess |
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.
This became a bit meaningless after removing unregister
. Testing this is a little tricky 🤔 Does need tests though.
d8f1ed9
to
efc5107
Compare
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.
Nice idea 👍 I'll take a look at this in detail later. Here's one suggestion after skimming the 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.
Thanks for working on this @ankur22 ! Added a couple of comments.
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 am providing a suggestion with which I was experimenting in order to avoid the usage of string concatenation for iterationID
-pid
relationship. Feel free to discard it or discuss just some options of it. We take advantage of the fact that when not using test_browser
, we'll have one "default iteration ID" which is a void string. Or we could even fix that in the GetIterationID
method.
Let me know if I misunderstood something.
30ce3df
to
ad33a2d
Compare
This rename better defines what the package does. Resolves: #755 (comment)
a1f72e4
to
edb07ac
Compare
Helps distinguish what is being created now that the package is called osext instead of browserprocess. Resolves: #755 (comment)
This will avoid any confusion when debugging the register -- an empty RunID in the register might confuse devs, whereas default shouldn't and can be tracked to where it was set. Resolves: #755 (comment)
f5a50ea
to
f86b6eb
Compare
This rename better defines what the package does. Resolves: #755 (comment)
This renaming better reflects what this type is and how we can use it. It should avoid any confusion as to it being part of the external JS API. Resolves: #755 (comment)
Helps distinguish what is being created now that the package is called osext instead of browserprocess. Resolves: #755 (comment)
f86b6eb
to
f309af9
Compare
This will avoid any confusion when debugging the register -- an empty RunID in the register might confuse devs, whereas default shouldn't and can be tracked to where it was set. Resolves: #755 (comment)
Before we can refactor to work with a registering system for the pid that can help us to shutdown all the browser processes. We need to abstract away the BrowserProcess into its own package to avoid cyclic dependencies.
Since BrowserProcessor is in a package called browserprocess we can rename the new method to just New.
This process register will store all the currently running browser pids that xk6-browser has started in the current test iteration. It's main use is to be able to quickly and easily shutdown these processes if a panic occurs. This negates the need to store the pid in the context. This also solves an issue where if more than one browser was started, only the last one could be forced to shutdown.
The BrowserProcess will register the pid in the register as it seems most capable of doing so and it is the closest to the os process.
Remove the need to write and read to the context. Now we can use the method ForceProcessShutdown to force shutdown the browser instances.
Although the register works for a normal test run with multiple browser where a panic will warrant the closure of all the browser instance, this is not the same for unit tests. Unit tests share the same register, which is a problem since if one test run panics, then all currently open browser instances will close. To fix this, register is now aware of interval ids which is a way for unit tests to isolate panics within their own test. Normal running of xk6-browser doesn't require an interval id.
Co-authored-by: ka3de <daniel.jimenez@grafana.com>
This rename better defines what the package does. Resolves: #755 (comment)
This renaming better reflects what this type is and how we can use it. It should avoid any confusion as to it being part of the external JS API. Resolves: #755 (comment)
Helps distinguish what is being created now that the package is called osext instead of browserprocess. Resolves: #755 (comment)
We already have an iterationID, so to avoid confusion, it's being renamed to runID.
This will avoid any confusion when debugging the register -- an empty RunID in the register might confuse devs, whereas default shouldn't and can be tracked to where it was set. Resolves: #755 (comment)
This will prevent integration tests from running the os.Kill command on the browser instances that are open. Instead they will be gracefully shutdown, as was the assumption when these tests were written.
This was only needed to prevent one integration tests from affecting other integration tests if it panicked. Now that we're not allowing os.Kill in integration tests this runID isn't needed.
f309af9
to
b901685
Compare
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.
Yes, i've been thinking about this too. I'm not a fan of doing it this way, but as far as I can tell there's no nice way to inject a register instance to both the osext.Process (which is registering the browser pids) and k6ext.Panic without affecting the current API and a lot of code.
Please see #779.
We're currently storing the browser pid in the context. This is an issue because:
This change adds a
register
which is internally updated byBrowserProcess
. When there is a need to panic (withk6ext.Panic
) we can use theregister
'sForceProcessShutdown
, which will loop over all the registeredpid
s and force kill the processes.