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

LoadTestShape.get_run_time is not relative to start of test #1557

Closed
Bubba74 opened this issue Sep 10, 2020 · 2 comments
Closed

LoadTestShape.get_run_time is not relative to start of test #1557

Bubba74 opened this issue Sep 10, 2020 · 2 comments
Labels
bug hacktoberfest See https://hacktoberfest.digitalocean.com for more info

Comments

@Bubba74
Copy link

Bubba74 commented Sep 10, 2020

Admittedly, I'd say this particular bug is open to interpretation and I can see benefit to the current behavior.
However, I believe the current behavior is the opposite of what most implementations would require.

Describe the bug

The get_run_time() method in LoadTestShape returns the time delta relative to the start of Locust, not the start of the test.
This is exacerbated when there is a significant delay between Locust startup and test start (for example through the WebUI)

Expected behavior

LoadTestShape.get_run_time() should return roughly 0 seconds the first time LoadTestShape.tick() is called.
If the test resets (say, through the WebUI), the LoadTestShape timer should reset too.

Actual behavior

When Locust calls LoadTestShape.tick() for the first time, a call to self.get_run_time() will return a time delay that incorporates Locust startup and all time spent in the WebUI.

Restarting the example below is basically impossible as the timer has already exceeded 10 seconds if the LoadTest finished normally.

Workaround

A subclass of LoadTestShape could keep a self.first_loop = True variable then do:

if self.first_loop:
    self.reset_time()
    self.first_loop = False

Steps to reproduce

# locustfile.py
from locust import User, task, LoadTestShape, constant

class MyUser(User):
    wait_time = constant(10)

    @task
    def noop(self):
        pass

class Shape(LoadTestShape):
    def tick(self):
        time = self.get_run_time()
        if time > 10:
            return None
        print("Time:", time)
        return (1, 1)

The above runs for ~10s when run with: locust --headless
But might never run if started manually (10s later) via: locust

Environment

  • OS:
  • Python version: PyPy 7.3.1 with Python 3.6.9 (but this problem is evident in the master branch source)
  • Locust version: 1.2.3
  • Locust command line that you ran:
  • Locust file contents (anonymized if necessary):
@Bubba74 Bubba74 added the bug label Sep 10, 2020
@max-rocket-internet
Copy link
Contributor

You're right @Bubba74. I like your solution, please open a PR 🙂

@cyberw cyberw added the hacktoberfest See https://hacktoberfest.digitalocean.com for more info label Sep 28, 2020
@cyberw
Copy link
Collaborator

cyberw commented Oct 1, 2020

fixed

@cyberw cyberw closed this as completed Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug hacktoberfest See https://hacktoberfest.digitalocean.com for more info
Projects
None yet
Development

No branches or pull requests

3 participants