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

Run time relative to start when using LoadTestShape #1581

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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 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 LocalRunner, MasterRunner, WorkerRunner
from .runners import LocalRunner, MasterRunner, Runner, WorkerRunner
from .web import WebUI
from .user.task import filter_tasks_by_tags
from .shape import LoadTestShape
Expand Down Expand Up @@ -29,7 +29,7 @@ class Environment:
stats = None
"""Reference to RequestStats instance"""

runner = None
runner: Runner = None
"""Reference to the :class:`Runner <locust.runners.Runner>` instance"""

web_ui = None
Expand Down
5 changes: 2 additions & 3 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,9 @@ def main():
environment = create_environment(user_classes, options, events=locust.events, shape_class=shape_class)

if shape_class and (options.num_users or options.spawn_rate or options.step_load):
logger.error(
"The specified locustfile contains a shape class but a conflicting argument was specified: users, spawn-rate or step-load"
logger.warning(
Copy link
Contributor

Choose a reason for hiding this comment

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

Like it 👍

"The specified locustfile contains a shape class but a conflicting argument was specified: users, spawn-rate or step-load. Ignoring arguments"
)
sys.exit(1)

if options.show_task_ratio:
print("\n Task ratio per User class")
Expand Down
3 changes: 2 additions & 1 deletion locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import traceback
import warnings
from uuid import uuid4
from time import time
from time import time, monotonic

import gevent
import greenlet
Expand Down Expand Up @@ -352,6 +352,7 @@ def start_shape(self):
self.update_state(STATE_INIT)
self.shape_greenlet = self.greenlet.spawn(self.shape_worker)
self.shape_greenlet.link_exception(greenlet_exception_handler)
self.environment.shape_class.start_time = monotonic()
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you not just call self.environment.shape_class.reset_time() here and that would be enough?


def shape_worker(self):
logger.info("Shape worker starting")
Expand Down
3 changes: 2 additions & 1 deletion locust/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class LoadTestShape(object):
during a load test.
"""

start_time = time.monotonic()
def __init__(self):
self.start_time = time.monotonic()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is ever called? Because the class is never instantiated, it's just declared eg, so __init__ is never run.

Copy link
Collaborator

@cyberw cyberw Sep 30, 2020

Choose a reason for hiding this comment

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

Isn't it instantiated here:

shape_class = shape_classes[0]()
(making the shape_class variable name a bit of a misnomer...)

(but maybe that is a mistake)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, you are right. I wrote that, I should know!


def reset_time(self):
"""
Expand Down