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):
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 = Truevariable then do:Steps to reproduce
The above runs for ~10s when run with:
locust --headlessBut might never run if started manually (10s later) via:
locustEnvironment