From 1b4e7d2d3a598f9a4ab78d6ac1731bf839d3f4eb Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Thu, 30 Apr 2020 21:46:09 +0200 Subject: [PATCH 1/9] Add locust.user package --- locust/user/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 locust/user/__init__.py diff --git a/locust/user/__init__.py b/locust/user/__init__.py new file mode 100644 index 0000000000..e69de29bb2 From 7971876cd1a17491baf65f00d709cab396d72f6f Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Thu, 30 Apr 2020 21:47:20 +0200 Subject: [PATCH 2/9] Move locust/core.py to locust/user/task.py --- locust/{core.py => user/task.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename locust/{core.py => user/task.py} (100%) diff --git a/locust/core.py b/locust/user/task.py similarity index 100% rename from locust/core.py rename to locust/user/task.py From c64b08c330774fb2c1ddcdc385baea2c9f750fae Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 1 May 2020 01:10:02 +0200 Subject: [PATCH 3/9] Split previous core.py into two modules user/task.py and user/users.py --- locust/__init__.py | 3 +- locust/contrib/fasthttp.py | 2 +- locust/inspectlocust.py | 2 +- locust/main.py | 3 +- locust/sequential_taskset.py | 2 +- locust/test/test_fasthttp.py | 2 +- locust/test/test_main.py | 2 +- locust/test/test_runners.py | 2 +- locust/test/test_taskratio.py | 2 +- locust/test/test_web.py | 2 +- locust/user/__init__.py | 2 + locust/user/task.py | 224 +--------------------------------- locust/user/users.py | 218 +++++++++++++++++++++++++++++++++ locust/util/deprecation.py | 2 +- 14 files changed, 237 insertions(+), 231 deletions(-) create mode 100644 locust/user/users.py diff --git a/locust/__init__.py b/locust/__init__.py index 41ce22aa7b..b158c28d79 100644 --- a/locust/__init__.py +++ b/locust/__init__.py @@ -1,4 +1,5 @@ -from .core import HttpUser, User, TaskSet, task +from .user.task import task, TaskSet +from .user.users import HttpUser, User from .event import Events from .sequential_taskset import SequentialTaskSet from .wait_time import between, constant, constant_pacing diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py index 4f99a7d279..f6346a63dd 100644 --- a/locust/contrib/fasthttp.py +++ b/locust/contrib/fasthttp.py @@ -16,7 +16,7 @@ from geventhttpclient.useragent import UserAgent, CompatRequest, CompatResponse, ConnectionError from geventhttpclient.response import HTTPConnectionClosed -from locust.core import User +from locust.user import User from locust.exception import LocustError, CatchResponseError, ResponseError from locust.env import Environment diff --git a/locust/inspectlocust.py b/locust/inspectlocust.py index 7e8b4b8a5a..b3f9c57b19 100644 --- a/locust/inspectlocust.py +++ b/locust/inspectlocust.py @@ -1,6 +1,6 @@ import inspect -from .core import User, TaskSet +from .user import User, TaskSet def print_task_ratio(user_classes, total=False, level=0, parent_ratio=1.0): diff --git a/locust/main.py b/locust/main.py index 5e500cc7e9..cdde7bf8ad 100644 --- a/locust/main.py +++ b/locust/main.py @@ -13,7 +13,7 @@ from . import log from .argument_parser import parse_locustfile_option, parse_options -from .core import HttpUser, User +from .user import User from .env import Environment from .inspectlocust import get_task_ratio_dict, print_task_ratio from .log import setup_logging, greenlet_exception_logger @@ -22,7 +22,6 @@ from .util.timespan import parse_timespan from .exception import AuthCredentialsError -_internals = [User, HttpUser] version = locust.__version__ diff --git a/locust/sequential_taskset.py b/locust/sequential_taskset.py index 6bdca60ee7..da46ae1048 100644 --- a/locust/sequential_taskset.py +++ b/locust/sequential_taskset.py @@ -1,4 +1,4 @@ -from .core import TaskSet, TaskSetMeta +from locust.user.task import TaskSet, TaskSetMeta from .exception import LocustError diff --git a/locust/test/test_fasthttp.py b/locust/test/test_fasthttp.py index e187da8f66..b6ef617eed 100644 --- a/locust/test/test_fasthttp.py +++ b/locust/test/test_fasthttp.py @@ -1,7 +1,7 @@ import socket import gevent -from locust.core import task, TaskSet +from locust.user import task, TaskSet from locust.contrib.fasthttp import FastHttpSession, FastHttpUser from locust.exception import CatchResponseError, InterruptTaskSet, ResponseError from locust.main import is_user_class diff --git a/locust/test/test_main.py b/locust/test/test_main.py index 34ef2bbe17..932ea96844 100644 --- a/locust/test/test_main.py +++ b/locust/test/test_main.py @@ -12,7 +12,7 @@ from locust import main from locust.argument_parser import parse_options from locust.main import create_environment -from locust.core import HttpUser, User, TaskSet +from locust.user import HttpUser, User, TaskSet from .mock_locustfile import mock_locustfile from .testcases import LocustTestCase from .util import temporary_file, get_free_tcp_port diff --git a/locust/test/test_runners.py b/locust/test/test_runners.py index a055439d24..f2bbfdbd89 100644 --- a/locust/test/test_runners.py +++ b/locust/test/test_runners.py @@ -8,7 +8,7 @@ import locust from locust import runners, between, constant from locust.main import create_environment -from locust.core import User, TaskSet, task +from locust.user import User, TaskSet, task from locust.env import Environment from locust.exception import RPCError, StopUser from locust.rpc import Message diff --git a/locust/test/test_taskratio.py b/locust/test/test_taskratio.py index 4a917eb506..ba2eac866c 100644 --- a/locust/test/test_taskratio.py +++ b/locust/test/test_taskratio.py @@ -1,6 +1,6 @@ import unittest -from locust.core import User, TaskSet, task +from locust.user import User, TaskSet, task from locust.inspectlocust import get_task_ratio_dict diff --git a/locust/test/test_web.py b/locust/test/test_web.py index 47e4cd3a8d..4dbb2cb452 100644 --- a/locust/test/test_web.py +++ b/locust/test/test_web.py @@ -14,7 +14,7 @@ from locust import constant from locust.argument_parser import get_parser, parse_options -from locust.core import User, task +from locust.user import User, task from locust.env import Environment from locust.runners import Runner from locust.web import WebUI diff --git a/locust/user/__init__.py b/locust/user/__init__.py index e69de29bb2..f89a01be37 100644 --- a/locust/user/__init__.py +++ b/locust/user/__init__.py @@ -0,0 +1,2 @@ +from .task import task, TaskSet +from .users import HttpUser, User \ No newline at end of file diff --git a/locust/user/task.py b/locust/user/task.py index b71ccce747..40a12af0b3 100644 --- a/locust/user/task.py +++ b/locust/user/task.py @@ -7,20 +7,18 @@ import gevent from gevent import GreenletExit, monkey +from locust.exception import InterruptTaskSet, LocustError, RescheduleTask,\ + RescheduleTaskImmediately, StopUser, MissingWaitTimeError + + # The monkey patching must run before requests is imported, or else # we'll get an infinite recursion when doing SSL/HTTPS requests. # See: https://github.com/requests/requests/issues/3752#issuecomment-294608002 monkey.patch_all() -from .clients import HttpSession -from .exception import (InterruptTaskSet, LocustError, RescheduleTask, - RescheduleTaskImmediately, StopUser, MissingWaitTimeError) -from .util import deprecation - logger = logging.getLogger(__name__) - LOCUST_STATE_RUNNING, LOCUST_STATE_WAITING, LOCUST_STATE_STOPPING = ["running", "waiting", "stopping"] @@ -58,15 +56,6 @@ def my_task() return decorator_func -class NoClientWarningRaiser(object): - """ - The purpose of this class is to emit a sensible error message for old test scripts that - inherit from User, and expects there to be an HTTP client under the client attribute. - """ - def __getattr__(self, _): - raise LocustError("No client instantiated. Did you intend to inherit from HttpUser?") - - def get_tasks_from_base_classes(bases, class_dict): """ Function used by both TaskSetMeta and UserMeta for collecting all declared tasks @@ -182,10 +171,8 @@ def __init__(self, parent): if isinstance(parent, TaskSet): self.user = parent.user - elif isinstance(parent, User): - self.user = parent else: - raise LocustError("TaskSet should be called with User instance or TaskSet instance as first argument") + self.user = parent self.parent = parent @@ -370,204 +357,3 @@ def execute_task(self, task, *args, **kwargs): # task is a function task(self.user, *args, **kwargs) - -class UserMeta(type): - """ - Meta class for the main User class. It's used to allow User classes to specify task execution - ratio using an {task:int} dict, or a [(task0,int), ..., (taskN,int)] list. - """ - def __new__(mcs, classname, bases, class_dict): - # gather any tasks that is declared on the class (or it's bases) - tasks = get_tasks_from_base_classes(bases, class_dict) - class_dict["tasks"] = tasks - - if not class_dict.get("abstract"): - # Not a base class - class_dict["abstract"] = False - - # check if class uses deprecated task_set attribute - deprecation.check_for_deprecated_task_set_attribute(class_dict) - - return type.__new__(mcs, classname, bases, class_dict) - - -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 ` on methods, or by setting - the :py:attr:`tasks attribute `. - - This class should usually be subclassed by a class that defines some kind of client. For - example when load testing an HTTP system, you probably want to use the - :py:class:`HttpUser ` class. - """ - - host = None - """Base hostname to swarm. i.e: http://127.0.0.1:1234""" - - min_wait = None - """Deprecated: Use wait_time instead. Minimum waiting time between the execution of locust tasks""" - - max_wait = None - """Deprecated: Use wait_time instead. Maximum waiting time between the execution of locust tasks""" - - wait_time = None - """ - Method that returns the time (in seconds) between the execution of locust tasks. - Can be overridden for individual TaskSets. - - Example:: - - from locust import User, between - class MyUser(User): - wait_time = between(3, 25) - """ - - wait_function = None - """ - .. warning:: - - DEPRECATED: Use wait_time instead. Note that the new wait_time method should return seconds and not milliseconds. - - Method that returns the time between the execution of locust tasks in milliseconds - """ - - tasks = [] - """ - Collection of python callables and/or TaskSet classes that the Locust user(s) will run. - - If tasks is a list, the task to be performed will be picked randomly. - - If tasks is a *(callable,int)* list of two-tuples, or a {callable:int} dict, - the task to be performed will be picked randomly, but each task will be weighted - according to its corresponding int value. So in the following case, *ThreadPage* will - be fifteen times more likely to be picked than *write_post*:: - - class ForumPage(TaskSet): - tasks = {ThreadPage:15, write_post:1} - """ - - weight = 10 - """Probability of user class being chosen. The higher the weight, the greater the chance of it being chosen.""" - - abstract = True - """If abstract is True, the class is meant to be subclassed, and locust will not spawn users of this class during a test.""" - - client = NoClientWarningRaiser() - _state = None - _greenlet = None - _taskset_instance = None - - def __init__(self, environment): - super(User, self).__init__() - self.environment = environment - - def on_start(self): - """ - Called when a User starts running. - """ - pass - - def on_stop(self): - """ - Called when a User stops running (is killed) - """ - pass - - def run(self): - self._state = LOCUST_STATE_RUNNING - self._taskset_instance = DefaultTaskSet(self) - try: - # run the task_set on_start method, if it has one - self.on_start() - - self._taskset_instance.run() - except (GreenletExit, StopUser) as e: - # run the on_stop method, if it has one - self.on_stop() - - def wait(self): - """ - Make the running user sleep for a duration defined by the User.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 User instance. - - :param gevent_group: Group instance where the greenlet will be spawned. - :type gevent_group: gevent.pool.Group - :returns: The spawned greenlet. - """ - def run_user(user): - """ - Main function for User greenlet. It's important that this function takes the user - instance as an argument, since we use greenlet_instance.args[0] to retrieve a reference to the - User instance. - """ - user.run() - self._greenlet = gevent_group.spawn(run_user, self) - return self._greenlet - - def stop(self, gevent_group, force=False): - """ - Stop the hyhyj1u1 user greenlet that exists in the gevent_group. - This method is not meant to be called from within the User'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 User 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 - """ - if force or self._state == LOCUST_STATE_WAITING: - gevent_group.killone(self._greenlet) - return True - elif self._state == LOCUST_STATE_RUNNING: - self._state = LOCUST_STATE_STOPPING - return False - - -class HttpUser(User): - """ - 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 ` on methods, or by setting - the :py:attr:`tasks attribute `. - - This class creates a *client* attribute on instantiation which is an HTTP client with support - for keeping a user session between requests. - """ - - abstract = True - """If abstract is True, the class is meant to be subclassed, and users will not choose this locust during a test""" - - client = None - """ - Instance of HttpSession that is created upon instantiation of Locust. - The client supports cookies, and therefore keeps the session between HTTP requests. - """ - - def __init__(self, *args, **kwargs): - super(HttpUser, self).__init__(*args, **kwargs) - if self.host is None: - raise LocustError("You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option.") - - session = HttpSession( - base_url=self.host, - request_success=self.environment.events.request_success, - request_failure=self.environment.events.request_failure, - ) - session.trust_env = False - self.client = session diff --git a/locust/user/users.py b/locust/user/users.py new file mode 100644 index 0000000000..a8cc3a8d21 --- /dev/null +++ b/locust/user/users.py @@ -0,0 +1,218 @@ +from gevent import GreenletExit + +from locust.clients import HttpSession +from locust.exception import LocustError, StopUser +from locust.util import deprecation +from .task import DefaultTaskSet, get_tasks_from_base_classes, \ + LOCUST_STATE_RUNNING, LOCUST_STATE_WAITING, LOCUST_STATE_STOPPING + + +class NoClientWarningRaiser(object): + """ + The purpose of this class is to emit a sensible error message for old test scripts that + inherit from User, and expects there to be an HTTP client under the client attribute. + """ + def __getattr__(self, _): + raise LocustError("No client instantiated. Did you intend to inherit from HttpUser?") + + +class UserMeta(type): + """ + Meta class for the main User class. It's used to allow User classes to specify task execution + ratio using an {task:int} dict, or a [(task0,int), ..., (taskN,int)] list. + """ + def __new__(mcs, classname, bases, class_dict): + # gather any tasks that is declared on the class (or it's bases) + tasks = get_tasks_from_base_classes(bases, class_dict) + class_dict["tasks"] = tasks + + if not class_dict.get("abstract"): + # Not a base class + class_dict["abstract"] = False + + # check if class uses deprecated task_set attribute + deprecation.check_for_deprecated_task_set_attribute(class_dict) + + return type.__new__(mcs, classname, bases, class_dict) + + +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 ` on methods, or by setting + the :py:attr:`tasks attribute `. + + This class should usually be subclassed by a class that defines some kind of client. For + example when load testing an HTTP system, you probably want to use the + :py:class:`HttpUser ` class. + """ + + host = None + """Base hostname to swarm. i.e: http://127.0.0.1:1234""" + + min_wait = None + """Deprecated: Use wait_time instead. Minimum waiting time between the execution of locust tasks""" + + max_wait = None + """Deprecated: Use wait_time instead. Maximum waiting time between the execution of locust tasks""" + + wait_time = None + """ + Method that returns the time (in seconds) between the execution of locust tasks. + Can be overridden for individual TaskSets. + + Example:: + + from locust import User, between + class MyUser(User): + wait_time = between(3, 25) + """ + + wait_function = None + """ + .. warning:: + + DEPRECATED: Use wait_time instead. Note that the new wait_time method should return seconds and not milliseconds. + + Method that returns the time between the execution of locust tasks in milliseconds + """ + + tasks = [] + """ + Collection of python callables and/or TaskSet classes that the Locust user(s) will run. + + If tasks is a list, the task to be performed will be picked randomly. + + If tasks is a *(callable,int)* list of two-tuples, or a {callable:int} dict, + the task to be performed will be picked randomly, but each task will be weighted + according to its corresponding int value. So in the following case, *ThreadPage* will + be fifteen times more likely to be picked than *write_post*:: + + class ForumPage(TaskSet): + tasks = {ThreadPage:15, write_post:1} + """ + + weight = 10 + """Probability of user class being chosen. The higher the weight, the greater the chance of it being chosen.""" + + abstract = True + """If abstract is True, the class is meant to be subclassed, and locust will not spawn users of this class during a test.""" + + client = NoClientWarningRaiser() + _state = None + _greenlet = None + _taskset_instance = None + + def __init__(self, environment): + super(User, self).__init__() + self.environment = environment + + def on_start(self): + """ + Called when a User starts running. + """ + pass + + def on_stop(self): + """ + Called when a User stops running (is killed) + """ + pass + + def run(self): + self._state = LOCUST_STATE_RUNNING + self._taskset_instance = DefaultTaskSet(self) + try: + # run the task_set on_start method, if it has one + self.on_start() + + self._taskset_instance.run() + except (GreenletExit, StopUser) as e: + # run the on_stop method, if it has one + self.on_stop() + + def wait(self): + """ + Make the running user sleep for a duration defined by the User.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 User instance. + + :param gevent_group: Group instance where the greenlet will be spawned. + :type gevent_group: gevent.pool.Group + :returns: The spawned greenlet. + """ + def run_user(user): + """ + Main function for User greenlet. It's important that this function takes the user + instance as an argument, since we use greenlet_instance.args[0] to retrieve a reference to the + User instance. + """ + user.run() + self._greenlet = gevent_group.spawn(run_user, self) + return self._greenlet + + def stop(self, gevent_group, force=False): + """ + Stop the hyhyj1u1 user greenlet that exists in the gevent_group. + This method is not meant to be called from within the User'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 User 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 + """ + if force or self._state == LOCUST_STATE_WAITING: + gevent_group.killone(self._greenlet) + return True + elif self._state == LOCUST_STATE_RUNNING: + self._state = LOCUST_STATE_STOPPING + return False + + +class HttpUser(User): + """ + 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 ` on methods, or by setting + the :py:attr:`tasks attribute `. + + This class creates a *client* attribute on instantiation which is an HTTP client with support + for keeping a user session between requests. + """ + + abstract = True + """If abstract is True, the class is meant to be subclassed, and users will not choose this locust during a test""" + + client = None + """ + Instance of HttpSession that is created upon instantiation of Locust. + The client supports cookies, and therefore keeps the session between HTTP requests. + """ + + def __init__(self, *args, **kwargs): + super(HttpUser, self).__init__(*args, **kwargs) + if self.host is None: + raise LocustError("You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option.") + + session = HttpSession( + base_url=self.host, + request_success=self.environment.events.request_success, + request_failure=self.environment.events.request_failure, + ) + session.trust_env = False + self.client = session diff --git a/locust/util/deprecation.py b/locust/util/deprecation.py index 5ba63dc68b..e09b5046e8 100644 --- a/locust/util/deprecation.py +++ b/locust/util/deprecation.py @@ -6,7 +6,7 @@ def check_for_deprecated_task_set_attribute(class_dict): - from locust.core import TaskSet + from locust.user.task import TaskSet if "task_set" in class_dict: task_set = class_dict["task_set"] if issubclass(task_set, TaskSet) and not hasattr(task_set, "locust_task_weight"): From a16a3df44da7beda4de37b395d6f6085f466f5e2 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 1 May 2020 01:10:41 +0200 Subject: [PATCH 4/9] Move sequential_taskset.py into user module --- locust/{ => user}/sequential_taskset.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename locust/{ => user}/sequential_taskset.py (100%) diff --git a/locust/sequential_taskset.py b/locust/user/sequential_taskset.py similarity index 100% rename from locust/sequential_taskset.py rename to locust/user/sequential_taskset.py From 01904f39108220cec5cc93ad762b4c5a78a2d215 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 1 May 2020 01:13:05 +0200 Subject: [PATCH 5/9] Move sequential_taskset.py into user module --- locust/__init__.py | 2 +- locust/test/test_sequential_taskset.py | 2 +- locust/user/sequential_taskset.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/locust/__init__.py b/locust/__init__.py index b158c28d79..286137e694 100644 --- a/locust/__init__.py +++ b/locust/__init__.py @@ -1,7 +1,7 @@ +from .user.sequential_taskset import SequentialTaskSet from .user.task import task, TaskSet from .user.users import HttpUser, User from .event import Events -from .sequential_taskset import SequentialTaskSet from .wait_time import between, constant, constant_pacing events = Events() diff --git a/locust/test/test_sequential_taskset.py b/locust/test/test_sequential_taskset.py index 2d9dd0a916..47cf0251ca 100644 --- a/locust/test/test_sequential_taskset.py +++ b/locust/test/test_sequential_taskset.py @@ -1,5 +1,5 @@ from locust import User, task, constant -from locust.sequential_taskset import SequentialTaskSet +from locust.user.sequential_taskset import SequentialTaskSet from locust.exception import RescheduleTask from .testcases import LocustTestCase diff --git a/locust/user/sequential_taskset.py b/locust/user/sequential_taskset.py index da46ae1048..1675095544 100644 --- a/locust/user/sequential_taskset.py +++ b/locust/user/sequential_taskset.py @@ -1,5 +1,5 @@ -from locust.user.task import TaskSet, TaskSetMeta -from .exception import LocustError +from locust.exception import LocustError +from .task import TaskSet, TaskSetMeta class SequentialTaskSetMeta(TaskSetMeta): From 055e288d630ef4652f6f2511299414ee3d43d08d Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 1 May 2020 01:14:55 +0200 Subject: [PATCH 6/9] Move wait_time.py into user module --- locust/{ => user}/wait_time.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename locust/{ => user}/wait_time.py (100%) diff --git a/locust/wait_time.py b/locust/user/wait_time.py similarity index 100% rename from locust/wait_time.py rename to locust/user/wait_time.py From 7316d1cb953812ae0286d59d1abc014b2f90794b Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 1 May 2020 01:17:02 +0200 Subject: [PATCH 7/9] Move wait_time.py into user module --- locust/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locust/__init__.py b/locust/__init__.py index 286137e694..c5367f8e02 100644 --- a/locust/__init__.py +++ b/locust/__init__.py @@ -1,8 +1,8 @@ from .user.sequential_taskset import SequentialTaskSet from .user.task import task, TaskSet from .user.users import HttpUser, User +from .user.wait_time import between, constant, constant_pacing from .event import Events -from .wait_time import between, constant, constant_pacing events = Events() From cddbff14776e3bbc36f0349d0f0a08863b342d72 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 1 May 2020 01:18:50 +0200 Subject: [PATCH 8/9] Move and rename locust.inspectlocust to locust.user.inspectuser --- locust/{inspectlocust.py => user/inspectuser.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename locust/{inspectlocust.py => user/inspectuser.py} (100%) diff --git a/locust/inspectlocust.py b/locust/user/inspectuser.py similarity index 100% rename from locust/inspectlocust.py rename to locust/user/inspectuser.py From b9112993750e4b4a3304cacc27c0c9d237f4b607 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 1 May 2020 01:22:10 +0200 Subject: [PATCH 9/9] Move and rename locust.inspectlocust to locust.user.inspectuser --- locust/main.py | 4 ++-- locust/test/test_stats.py | 4 ++-- locust/test/test_taskratio.py | 2 +- locust/user/inspectuser.py | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/locust/main.py b/locust/main.py index cdde7bf8ad..f66fa6cbb4 100644 --- a/locust/main.py +++ b/locust/main.py @@ -13,12 +13,12 @@ from . import log from .argument_parser import parse_locustfile_option, parse_options -from .user import User from .env import Environment -from .inspectlocust import get_task_ratio_dict, print_task_ratio from .log import setup_logging, greenlet_exception_logger from .stats import (print_error_report, print_percentile_stats, print_stats, stats_printer, stats_writer, write_csv_files) +from .user import User +from .user.inspectuser import get_task_ratio_dict, print_task_ratio from .util.timespan import parse_timespan from .exception import AuthCredentialsError diff --git a/locust/test/test_stats.py b/locust/test/test_stats.py index dc0b6a1181..f5eaee59e8 100644 --- a/locust/test/test_stats.py +++ b/locust/test/test_stats.py @@ -9,10 +9,10 @@ import locust from locust import HttpUser, TaskSet, task, User, constant from locust.env import Environment -from locust.inspectlocust import get_task_ratio_dict from locust.rpc.protocol import Message from locust.stats import CachedResponseTimes, RequestStats, StatsEntry, diff_response_time_dicts, stats_writer from locust.test.testcases import LocustTestCase +from locust.user.inspectuser import get_task_ratio_dict from .testcases import WebserverTestCase from .test_runners import mocked_rpc @@ -621,7 +621,7 @@ def task1(self): def task2(self): pass -class TestInspectLocust(unittest.TestCase): +class TestInspectUser(unittest.TestCase): def test_get_task_ratio_dict_relative(self): ratio = get_task_ratio_dict([MyTaskSet]) self.assertEqual(1.0, ratio["MyTaskSet"]["ratio"]) diff --git a/locust/test/test_taskratio.py b/locust/test/test_taskratio.py index ba2eac866c..f0a622d2bd 100644 --- a/locust/test/test_taskratio.py +++ b/locust/test/test_taskratio.py @@ -1,7 +1,7 @@ import unittest from locust.user import User, TaskSet, task -from locust.inspectlocust import get_task_ratio_dict +from locust.user.inspectuser import get_task_ratio_dict class TestTaskRatio(unittest.TestCase): diff --git a/locust/user/inspectuser.py b/locust/user/inspectuser.py index b3f9c57b19..f04781e1ce 100644 --- a/locust/user/inspectuser.py +++ b/locust/user/inspectuser.py @@ -1,6 +1,7 @@ import inspect -from .user import User, TaskSet +from .task import TaskSet +from .users import User def print_task_ratio(user_classes, total=False, level=0, parent_ratio=1.0):