-
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
Work towards 1.0. Refactoring of runners/events/web ui. Getting rid of global state. #1266
Merged
Changes from 6 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
78dba23
WIP: Refactor internal code to get rid of global LocustRunner instanc…
heyman 2dd2087
Remove LocustRunner.hatch_rate (the start and spawn methods takes hat…
heyman 021d928
Add Environment.host (move from options.host in order to not have to …
heyman 81e12b0
Add Environment.reset_stats (move from options.reset_stats in order t…
heyman aae6bb1
stats_printer only needs access to RequestStats instance, and not the…
heyman 32216d8
Merge branch 'master' into v1.0
heyman f7e4317
Log actual exception in retry exception handler
heyman 4cdb808
Set strict_map_key=False when unserializing master/slave messages, si…
heyman 48d94fc
Always round response times, stored in response_times dict, to integer.
heyman 40a159f
Merge branch 'master' into v1.0
heyman ee30daa
Move LocustRunner.step_load into Environment.step_load
heyman 3923cef
Fix broken CSV stats writer
heyman 4ae8b2b
Speed up test
heyman 46ad14c
Remove EventHook.__iadd__ and EventHook.__isub__ methods in favour of…
heyman ac79808
Make add_listener return handler, because it’ll make it possible to u…
heyman 705fcae
Merge branch 'master' into v1.0
heyman 1a7c3a4
Remove unused import
heyman 21d4833
Fix bug where EventHook.fire(reverse=True) would permanently reverse …
heyman 5a7704c
Add locust.event.init event hook that can be used by end-users to run…
heyman 91019fa
Fix re-structured text syntax
heyman 9c559f7
Fix example in docstring
heyman c12f615
Update extending-locust and API documentation page for the new API
heyman c4fcd0e
Remove deprecated info about installing libev on macOS
heyman fbc04ce
Fix example code that used old API for specifying wait time in millis…
heyman 33a068b
Rewrote the “Common libraries” section in the documentation, and rena…
heyman 489987f
Add documentation page about running Locust as a lib (so far it only …
heyman 5f6937c
Update documentation on custom clients to new event API.
heyman 23f2388
Update example to use new event API
heyman 9e1a816
Remove LocustRunner.request_stats property
heyman 8444d09
Remove HttpSession’s dependency on the Environment instance, and inst…
heyman 507d546
More refactoring. Move stats and locust_clases from Environment onto …
heyman 3f8d700
Add LocustRunner and WebUI instances as argument to the init event
heyman 9fdeb12
Reinstate code for saving and restoring event listeners, since we sti…
heyman 84153b0
Improve code for creating temporary locustfiles that can be used in t…
heyman d1f7c4e
Refactor code for parsing command line arguments.
heyman fd1ce43
Remove global locust.events.events Event instance, in favour of using…
heyman 8a1f4b5
Update example (event arguments was changed)
heyman f6715f5
Rename locust.events module to locust.event
heyman cfba346
Add missing change from previous commit
heyman d5ec17e
Replace --heartbeat-liveness and --heartbeat-interval command line op…
heyman 1cc9450
Add more config variables to Environment class (get rid of LocustRunn…
heyman b380197
Make sure init event is fired before the runner is started.
heyman b945a80
Do set process exit code to non-zero when CPU warning has been emitte…
heyman 0758a8f
Remove master_host/master_port/master_bind_host/master_bind_port from…
heyman 216f771
When stopping a test, log a warning message if the CPU went above 90%…
heyman 3f9e0ad
Escape failure messages
heyman 4115010
Merge branch 'master' into v1.0
heyman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from .events import Events | ||
from .stats import RequestStats | ||
|
||
|
||
class Environment: | ||
locust_classes = None | ||
"""The locust user classes that is to be run""" | ||
|
||
events = None | ||
"""Event hooks used by Locust internally, as well as """ | ||
|
||
stats = None | ||
"""Instance of RequestStats which holds the request statistics for this Locust test""" | ||
|
||
options = None | ||
"""Other environment options""" | ||
|
||
runner = None | ||
"""Reference to the runner instance""" | ||
|
||
web_ui = None | ||
"""Reference to the WebUI instance""" | ||
|
||
host = None | ||
"""Base URL of the target system""" | ||
|
||
reset_stats = False | ||
"""Determines if stats should be reset once all simulated users have been spawned""" | ||
|
||
def __init__(self, locust_classes=None, options=None, host=None, reset_stats=False): | ||
self.events = Events() | ||
self.stats = RequestStats() | ||
self.locust_classes = locust_classes | ||
self.host = host | ||
self.reset_stats = reset_stats | ||
self.options = options | ||
|
||
# set up event listeners for recording requests | ||
def on_request_success(request_type, name, response_time, response_length, **kwargs): | ||
self.stats.log_request(request_type, name, response_time, response_length) | ||
|
||
def on_request_failure(request_type, name, response_time, response_length, exception, **kwargs): | ||
self.stats.log_request(request_type, name, response_time, response_length) | ||
self.stats.log_error(request_type, name, exception) | ||
|
||
self.events.request_success.add_listener(on_request_success) | ||
self.events.request_failure.add_listener(on_request_failure) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think it could be called just ”environment” instead of locust_environment?
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 prefixed it with
locust_
just to make sure that we won't clash with any (current or future) attribute in requests.Session.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.
yea, this is gone now anyways :)