Skip to content
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

Merged
merged 43 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
66e7942
Rename Locust to User
Apr 6, 2020
26573d8
Rename client to users where applicable
Apr 6, 2020
c6207d3
Correct the usage in tests
Apr 6, 2020
ad5f4b0
Merge remote-tracking branch 'locustmaster/master' into rename_locust…
Apr 8, 2020
0777fba
Rename clients options to users and suppress the existing ones
Apr 16, 2020
01a733f
More renaming from locust to user
Apr 16, 2020
b0ff683
Merge branch 'master' of https://github.com/locustio/locust into rena…
Apr 16, 2020
7db61c7
More renaming
Apr 16, 2020
ad584f5
Merge branch 'master' of https://github.com/locustio/locust into rena…
Apr 16, 2020
c783824
More renaming. This was causing the earlier build to fail.
Apr 17, 2020
5589257
rever to -c
Apr 17, 2020
25d253c
use User class in test data
Apr 17, 2020
3c03129
Rename runners
Apr 17, 2020
fdd4d5f
Merge branch 'master' of https://github.com/locustio/locust into rena…
anuj-ssharma Apr 18, 2020
39a42cc
Merge branch 'master' of https://github.com/locustio/locust into rena…
anuj-ssharma Apr 19, 2020
b990796
Use user instead of Locust
anuj-ssharma Apr 19, 2020
530db29
More renaming. Includes renaming in test and example files as well.
anuj-ssharma Apr 20, 2020
5076958
fixed typo
anuj-ssharma Apr 20, 2020
de53ef8
documentation updated
anuj-ssharma Apr 20, 2020
07ff348
Rename the locust_classes to user_classes. Updated relevant documenta…
anuj-ssharma Apr 21, 2020
365d2e5
More renaming. There is an implicit contextual change i.e. locusts ar…
anuj-ssharma Apr 21, 2020
a8239a3
Rename Runner.users to Runner.user_greenlets.
heyman Apr 21, 2020
5d23b6d
Fix broken tests
heyman Apr 21, 2020
6a2e914
Change LocustClass to UserClass in CLI help message
heyman Apr 21, 2020
f53d397
Fix docstring
heyman Apr 21, 2020
0dc6f05
Replace renamed `-c` flag with `-u` in the docs examples
heyman Apr 21, 2020
c078cad
Merge branch 'master' of https://github.com/locustio/locust into rena…
anuj-ssharma Apr 21, 2020
405dd86
fix broken test
anuj-ssharma Apr 22, 2020
e450dc2
More renaming after merging from master
anuj-ssharma Apr 22, 2020
8ba4629
fix broken test
anuj-ssharma Apr 22, 2020
3723be5
A fem more Locust -> User renames
heyman Apr 22, 2020
cc8d553
A fem more Locust -> User renames
heyman Apr 22, 2020
3667397
Rename locust attribute on TaskSet to user
heyman Apr 22, 2020
47c104b
Rename locust -> user in docstrings
heyman Apr 22, 2020
ad42d4e
Rename is_locust function to is_user_class
heyman Apr 22, 2020
17edbb6
More "locust" -> "user" renaming
heyman Apr 22, 2020
29c18cf
Rename "locust" to -> "user" in WebUI HTML template
heyman Apr 22, 2020
796d86e
Increase sleep time to make test less flaky
heyman Apr 22, 2020
8db7c2d
More "locust" -> "user" renaming
heyman Apr 23, 2020
08228a4
Update python references in documentation ("locust" -> "user" renaming)
heyman Apr 23, 2020
339eae3
Use new tasks API in example that had been missed
heyman Apr 23, 2020
4f4b83b
Rename local variable worker_num_clients to worker_num_users
heyman Apr 23, 2020
5aca141
Add entry about "Locust" -> "User" renaming, to Changelog
heyman Apr 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/custom_xmlrpc_client/xmlrpc_locustfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
from xmlrpc.client import ServerProxy, Fault

from locust import Locust, task, between
from locust import User, task, between


class XmlRpcClient(ServerProxy):
Expand Down Expand Up @@ -31,7 +31,7 @@ def wrapper(*args, **kwargs):
return wrapper


class XmlRpcLocust(Locust):
class XmlRpcLocust(User):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XmlRpcUser

"""
This is the abstract Locust class which should be subclassed. It provides an XML-RPC client
that can be used to make XML-RPC requests that will be tracked in Locust's statistics.
Expand Down
2 changes: 1 addition & 1 deletion locust/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .core import HttpLocust, Locust, TaskSet, task
from .core import HttpLocust, User, TaskSet, task
from .event import Events
from .sequential_taskset import SequentialTaskSet
from .wait_time import between, constant, constant_pacing
Expand Down
17 changes: 11 additions & 6 deletions locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def setup_parser_arguments(parser):
)
# Number of Locust users
parser.add_argument(
'-c', '--clients',
'-u', '--users',
type=int,
dest='num_clients',
dest='num_users',
default=1,
help="Number of concurrent Locust users. Only used together with --headless"
)
Expand All @@ -140,7 +140,7 @@ def setup_parser_arguments(parser):
'-r', '--hatch-rate',
type=float,
default=1,
help="The rate per second in which clients are spawned. Only used together with --headless"
help="The rate per second in which users are spawned. Only used together with --headless"
)
# Time limit of the test run
parser.add_argument(
Expand Down Expand Up @@ -306,12 +306,17 @@ def setup_parser_arguments(parser):
action='store_true',
help="Enable Step Load mode to monitor how performance metrics varies when user load increases. Requires --step-clients and --step-time to be specified."
)
# Number of clients to incease by Step
# Number of users to increase by Step
step_load_group.add_argument(
'--step-clients',
'--step-users',
type=int,
default=1,
help="Client count to increase by step in Step Load mode. Only used together with --step-load"
help="User count to increase by step in Step Load mode. Only used together with --step-load"
)
step_load_group.add_argument(
'--step-clients',
action='store_true',
help=configargparse.SUPPRESS
)
# Time limit of each step
step_load_group.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
Expand Down
62 changes: 31 additions & 31 deletions locust/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand All @@ -511,7 +511,7 @@ def start(self, gevent_group):
def run_locust(user):
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()
Expand All @@ -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
"""
Expand All @@ -538,12 +538,12 @@ def stop(self, gevent_group, force=False):
return False


class HttpLocust(Locust):
class HttpLocust(User):
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Down
12 changes: 6 additions & 6 deletions locust/env.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .event import Events
from .exception import RunnerAlreadyExistsError
from .stats import RequestStats
from .runners import LocalLocustRunner, MasterLocustRunner, WorkerLocustRunner
from .runners import LocalRunner, MasterRunner, WorkerRunner
from .web import WebUI


Expand Down Expand Up @@ -76,20 +76,20 @@ def _create_runner(self, runner_class, *args, **kwargs):

def create_local_runner(self):
"""
Create a :class:`LocalLocustRunner <locust.runners.LocalLocustRunner>` instance for this Environment
Create a :class:`LocalRunner <locust.runners.LocalRunner>` instance for this Environment
"""
return self._create_runner(LocalLocustRunner)
return self._create_runner(LocalRunner)

def create_master_runner(self, master_bind_host="*", master_bind_port=5557):
"""
Create a :class:`MasterLocustRunner <locust.runners.MasterLocustRunner>` instance for this Environment
Create a :class:`MasterRunner <locust.runners.MasterRunner>` instance for this Environment

:param master_bind_host: Interface/host that the master should use for incoming worker connections.
Defaults to "*" which means all interfaces.
:param master_bind_port: Port that the master should listen for incoming worker connections on
"""
return self._create_runner(
MasterLocustRunner,
MasterRunner,
master_bind_host=master_bind_host,
master_bind_port=master_bind_port,
)
Expand All @@ -105,7 +105,7 @@ def create_worker_runner(self, master_host, master_port):
# and CPU cycles, since the response_times_cache is not needed for Worker nodes
self.stats = RequestStats(use_response_times_cache=False)
return self._create_runner(
WorkerLocustRunner,
WorkerRunner,
master_host=master_host,
master_port=master_port,
)
Expand Down
4 changes: 2 additions & 2 deletions locust/inspectlocust.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect

from .core import Locust, TaskSet
from .core import User, TaskSet


def print_task_ratio(locusts, total=False, level=0, parent_ratio=1.0):
Expand Down Expand Up @@ -36,7 +36,7 @@ def get_task_ratio_dict(tasks, total=False, parent_ratio=1.0):
for locust, ratio in ratio_percent.items():
d = {"ratio":ratio}
if inspect.isclass(locust):
if issubclass(locust, (Locust, TaskSet)):
if issubclass(locust, (User, TaskSet)):
T = locust.tasks
if total:
d["tasks"] = get_task_ratio_dict(T, total, ratio)
Expand Down
10 changes: 5 additions & 5 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import locust

from .argument_parser import parse_locustfile_option, parse_options
from .core import HttpLocust, Locust
from .core import HttpLocust, User
from .env import Environment
from .inspectlocust import get_task_ratio_dict, print_task_ratio
from .log import setup_logging, greenlet_exception_logger
Expand All @@ -21,7 +21,7 @@
from .util.timespan import parse_timespan
from .exception import AuthCredentialsError

_internals = [Locust, HttpLocust]
_internals = [User, HttpLocust]
version = locust.__version__


Expand All @@ -31,7 +31,7 @@ def is_locust(item):
"""
return bool(
inspect.isclass(item)
and issubclass(item, Locust)
and issubclass(item, User)
and item.abstract == False
)

Expand Down Expand Up @@ -249,9 +249,9 @@ def timelimit_stop():
if not options.worker:
# start the test
if options.step_time:
runner.start_stepload(options.num_clients, options.hatch_rate, options.step_clients, options.step_time)
runner.start_stepload(options.num_users, options.hatch_rate, options.step_users, options.step_time)
else:
runner.start(options.num_clients, options.hatch_rate)
runner.start(options.num_users, options.hatch_rate)

if options.run_time:
spawn_run_time_limit_greenlet()
Expand Down
Loading