-
Notifications
You must be signed in to change notification settings - Fork 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
Adds support for setup, teardown, and on_stop methods #658
Conversation
if a TaskSet has an `on_stop` method, it will be run before the proccess exits. It will also look for a property on the class named `always_run_on_stop`, which if True will run regardless if the `on_start` method finished.
Hi! I've looked through the changes and here are my initial thoughts: The If we want to provide some hook that is executed for each Locust user when a test is stopped, I think it should be a method under the Locust class, and I also think it should be executed within the Locust greenlet (by catching So that's actually two different issues. And then we also have a third issue of having some kind of teardown hook that is called a single time when the test has stopped, which I believe is what the OP of #59 was seeking. |
This should also take care of the greenlets
That makes way more sense than what I was thinking/doing. I re-worked the Locust run method to catch that exception, then run Here is my idea for the setup and teardown. The Locust class and the TaskSet class can have a |
I just thought I'd feed back that I've been using this branch for a few weeks for the |
@j616 Thanks for letting me know! Let me add some documentation, then I'll remove the [WIP] |
They were used in a previous commit, but are not used any more
Removed always_run_on_stop variable as it is no longer used
on_stop
method
I'm also actively using the functionality provided by this branch, the on_stop functions exactly how I'd expect it to. I have a websocket associated with each locust running own their on greenlet so I needed some way to close the websockets when the controlling locust was stopped. This branch provides that ability, would be nice to see it merged into the official branch. |
this LGTM. @heyman @cgbystrom @mbeacom any of you have thoughts on this? It'd be nice to get this into the 0.9.0 release. |
@aldenpeterson-wf Unless there are any objections, lgtm. We'll wait a little and if no one speaks up, maybe merge it this week? |
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.
nit: in the documentation, can you change the wording so it refers to on_start/on_stop as "methods" rather than "functions"?
Codecov Report
@@ Coverage Diff @@
## master #658 +/- ##
=========================================
Coverage ? 65.13%
=========================================
Files ? 14
Lines ? 1417
Branches ? 222
=========================================
Hits ? 923
Misses ? 443
Partials ? 51
Continue to review full report at Codecov.
|
@cgoldberg Changed, while I'm at it should I change the language in the rest of the docs? |
sure.. might as well be consistent
…On Monday, March 19, 2018, Joshua Milas ***@***.***> wrote:
@cgoldberg <https://github.com/cgoldberg> Changed, while I'm at it should
I change the language in the rest of the docs?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#658 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABD7-bGxUjdu6sPqVEMK8UpOmy2fm7fuks5tgGgGgaJpZM4PeUgd>
.
|
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.
lgtm
@DeepHorizons thanks for the contribution! |
@heyman you want to cut another release? This is pretty great functionality and combined with the time based run worthy of releasing imo. |
+1 for release. We also need to add a nice description of this to |
Waiting anxiously |
@cgoldberg How's things ? Do you think that it will take long before releasing this ? |
@migueleliasweb |
Hey! I realize that this comment is way late, but as far as I can tell from the code, the setup/teardown will run multiple times when running Locust distributed. I think we either need to make sure this is not the case (perhaps by only running the setup & teardown in the master node), or at least update the documentation which currently states that the setup/teardown is run only once. Though I think it's much preferable if Locust works the same wether it's being run distributed or not. |
Hello! Is there any way for a Locust script to know if it is running as a Master or a Slave? Knowing that would help when writing the setup() function to ensure a database setup command only runs one time. |
As far as I can tell Locust teardown is not working in 0.9.0. |
Sorry, I was wrong, it actually works, great work guys!!! :) |
If a TaskSet has an
on_stop
method, it will be run before the process exits. It will also look for a property on the class namedalways_run_on_stop
, which if True will run regardless if theon_start
method finished.Looking to solve #59
Any comments on this functionality?