-
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
Rename locust to user #1314
Rename locust to user #1314
Changes from 13 commits
66e7942
26573d8
c6207d3
ad5f4b0
0777fba
01a733f
b0ff683
7db61c7
ad584f5
c783824
5589257
25d253c
3c03129
fdd4d5f
39a42cc
b990796
530db29
5076958
de53ef8
07ff348
365d2e5
a8239a3
5d23b6d
6a2e914
f53d397
0dc6f05
c078cad
405dd86
e450dc2
8ba4629
3723be5
cc8d553
3667397
47c104b
ad42d4e
17edbb6
29c18cf
796d86e
8db7c2d
08228a4
339eae3
4f4b83b
5aca141
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
from geventhttpclient.useragent import UserAgent, CompatRequest, CompatResponse, ConnectionError | ||
from geventhttpclient.response import HTTPConnectionClosed | ||
|
||
from locust.core import Locust | ||
from locust.core import User | ||
from locust.exception import LocustError, CatchResponseError, ResponseError | ||
from locust.env import Environment | ||
|
||
|
@@ -47,7 +47,7 @@ def _construct_basic_auth_str(username, password): | |
return 'Basic ' + b64encode(b':'.join((username, password))).strip().decode("ascii") | ||
|
||
|
||
class FastHttpLocust(Locust): | ||
class FastHttpLocust(User): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FastHttpUser |
||
""" | ||
FastHttpLocust uses a different HTTP client (geventhttpclient) compared to HttpLocust (python-requests). | ||
It's significantly faster, but not as capable. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,13 +114,13 @@ class TaskSet(object, metaclass=TaskSetMeta): | |
Class defining a set of tasks that a Locust user will execute. | ||
|
||
When a TaskSet starts running, it will pick a task from the *tasks* attribute, | ||
execute it, and then sleep for the number of seconds returned by its *wait_time* | ||
execute it, and then sleep for the number of seconds returned by its *wait_time* | ||
function. If no wait_time method has been declared on the TaskSet, it'll call the | ||
wait_time function on the Locust by default. It will then schedule another task | ||
for execution and so on. | ||
|
||
TaskSets can be nested, which means that a TaskSet's *tasks* attribute can contain | ||
another TaskSet. If the nested TaskSet is scheduled to be executed, it will be | ||
another TaskSet. If the nested TaskSet is scheduled to be executed, it will be | ||
instantiated and called from the currently executing TaskSet. Execution in the | ||
currently running TaskSet will then be handed over to the nested TaskSet which will | ||
continue to run until it throws an InterruptTaskSet exception, which is done when | ||
|
@@ -176,13 +176,13 @@ class ForumPage(TaskSet): | |
instantiated. Useful for nested TaskSet classes. | ||
""" | ||
|
||
def __init__(self, parent): | ||
def __init__(self, parent): | ||
self._task_queue = [] | ||
self._time_start = time() | ||
|
||
if isinstance(parent, TaskSet): | ||
self.locust = parent.locust | ||
elif isinstance(parent, Locust): | ||
elif isinstance(parent, User): | ||
self.locust = parent | ||
else: | ||
raise LocustError("TaskSet should be called with Locust instance or TaskSet instance as first argument") | ||
|
@@ -205,7 +205,7 @@ def on_start(self): | |
|
||
def on_stop(self): | ||
""" | ||
Called when a Locust user stops executing this TaskSet. E.g. when TaskSet.interrupt() is called | ||
Called when a Locust user stops executing this TaskSet. E.g. when TaskSet.interrupt() is called | ||
or when the user is killed | ||
""" | ||
pass | ||
|
@@ -311,12 +311,12 @@ class Tasks(TaskSet): | |
|
||
def wait(self): | ||
""" | ||
Make the running locust user sleep for a duration defined by the Locust.wait_time | ||
function (or TaskSet.wait_time function if it's been defined). | ||
The user can also be killed gracefully while it's sleeping, so calling this | ||
method within a task makes it possible for a user to be killed mid-task, even if you've | ||
set a stop_timeout. If this behavour is not desired you should make the user wait using | ||
Make the running locust user sleep for a duration defined by the Locust.wait_time | ||
function (or TaskSet.wait_time function if it's been defined). | ||
|
||
The user can also be killed gracefully while it's sleeping, so calling this | ||
method within a task makes it possible for a user to be killed mid-task, even if you've | ||
set a stop_timeout. If this behavour is not desired you should make the user wait using | ||
gevent.sleep() instead. | ||
""" | ||
self._check_stop_condition() | ||
|
@@ -371,7 +371,7 @@ def execute_task(self, task, *args, **kwargs): | |
task(self.locust, *args, **kwargs) | ||
|
||
|
||
class LocustMeta(type): | ||
class UserMeta(type): | ||
""" | ||
Meta class for the main Locust class. It's used to allow Locust classes to specify task execution | ||
ratio using an {task:int} dict, or a [(task0,int), ..., (taskN,int)] list. | ||
|
@@ -391,12 +391,12 @@ def __new__(mcs, classname, bases, class_dict): | |
return type.__new__(mcs, classname, bases, class_dict) | ||
|
||
|
||
class Locust(object, metaclass=LocustMeta): | ||
heyman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class User(object, metaclass=UserMeta): | ||
""" | ||
Represents a "user" which is to be hatched and attack the system that is to be load tested. | ||
|
||
The behaviour of this user is defined by its tasks. Tasks can be declared either directly on the | ||
class by using the :py:func:`@task decorator <locust.core.task>` on methods, or by setting | ||
The behaviour of this user is defined by its tasks. Tasks can be declared either directly on the | ||
class by using the :py:func:`@task decorator <locust.core.task>` on methods, or by setting | ||
the :py:attr:`tasks attribute <locust.core.Locust.tasks>`. | ||
|
||
This class should usually be subclassed by a class that defines some kind of client. For | ||
|
@@ -459,9 +459,9 @@ class ForumPage(TaskSet): | |
_state = None | ||
_greenlet = None | ||
_taskset_instance = None | ||
|
||
def __init__(self, environment): | ||
super(Locust, self).__init__() | ||
super(User, self).__init__() | ||
self.environment = environment | ||
|
||
def on_start(self): | ||
|
@@ -490,16 +490,16 @@ def run(self): | |
|
||
def wait(self): | ||
""" | ||
Make the running locust user sleep for a duration defined by the Locust.wait_time | ||
function. | ||
The user can also be killed gracefully while it's sleeping, so calling this | ||
method within a task makes it possible for a user to be killed mid-task even if you've | ||
set a stop_timeout. If this behavour is not desired, you should make the user wait using | ||
Make the running locust user sleep for a duration defined by the Locust.wait_time | ||
function. | ||
|
||
The user can also be killed gracefully while it's sleeping, so calling this | ||
method within a task makes it possible for a user to be killed mid-task even if you've | ||
set a stop_timeout. If this behavour is not desired, you should make the user wait using | ||
gevent.sleep() instead. | ||
""" | ||
self._taskset_instance.wait() | ||
|
||
def start(self, gevent_group): | ||
""" | ||
Start a greenlet that runs this locust instance. | ||
|
@@ -511,7 +511,7 @@ def start(self, gevent_group): | |
def run_locust(user): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. run_user |
||
""" | ||
Main function for Locust user greenlet. It's important that this function takes the locust | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. user instance |
||
instance as an argument, since we use greenlet_instance.args[0] to retrieve a reference to the | ||
instance as an argument, since we use greenlet_instance.args[0] to retrieve a reference to the | ||
locust instance. | ||
""" | ||
user.run() | ||
|
@@ -521,12 +521,12 @@ def run_locust(user): | |
def stop(self, gevent_group, force=False): | ||
""" | ||
Stop the locust user greenlet that exists in the gevent_group. | ||
This method is not meant to be called from within the Locust's greenlet. | ||
This method is not meant to be called from within the Locust's greenlet. | ||
|
||
:param gevent_group: Group instance where the greenlet will be spawned. | ||
:type gevent_group: gevent.pool.Group | ||
:param force: If False (the default) the stopping is done gracefully by setting the state to LOCUST_STATE_STOPPING | ||
which will make the Locust instance stop once any currently running task is complete and on_stop | ||
:param force: If False (the default) the stopping is done gracefully by setting the state to LOCUST_STATE_STOPPING | ||
which will make the Locust instance stop once any currently running task is complete and on_stop | ||
methods are called. If force is True the greenlet will be killed immediately. | ||
:returns: True if the greenlet was killed immediately, otherwise False | ||
""" | ||
|
@@ -538,12 +538,12 @@ def stop(self, gevent_group, force=False): | |
return False | ||
|
||
|
||
class HttpLocust(Locust): | ||
class HttpLocust(User): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HttpUser |
||
""" | ||
Represents an HTTP "user" which is to be hatched and attack the system that is to be load tested. | ||
|
||
The behaviour of this user is defined by its tasks. Tasks can be declared either directly on the | ||
class by using the :py:func:`@task decorator <locust.core.task>` on methods, or by setting | ||
The behaviour of this user is defined by its tasks. Tasks can be declared either directly on the | ||
class by using the :py:func:`@task decorator <locust.core.task>` on methods, or by setting | ||
the :py:attr:`tasks attribute <locust.core.Locust.tasks>`. | ||
|
||
This class creates a *client* attribute on instantiation which is an HTTP client with support | ||
|
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.
XmlRpcUser