RPS doesn't fall to 0 after test has finished if raise StopUser() in on_stop() method
See original GitHub issueDescribe the bug
Expected behavior
When 0 users work must be 0 RPS because nobody sends requests
Actual behavior
When 0 users work shows the same saved result with RPS. And it will present till I click the stop button
Steps to reproduce
- Create a class that inherits from SequentialTaskSet
- Do something on_start() method
- Raise StopUser() in on_stop() method
Environment
- OS: Ubuntu 20.04.2 LTS / MacOs BigSur v:11.6
- Python version:3.8.5
- Locust version: 2.2.2/2.2.3
- Locust command line that you ran: locust -f file.py / locust --config=local.yml
- Locust file contents (anonymized if necessary):
logger = logging.getLogger(__name__)
users = []
def init_env_configurations():
if os.getenv('ENV_TYPE') == EnvType.DEV:
logger.debug(f"ENV is {EnvType.DEV}")
users.extend(read_files(Resources.DEV_USERS))
elif os.getenv('ENV_TYPE') == EnvType.QA:
logger.debug(f"ENV is {EnvType.QA}")
users.extend(read_files(Resources.QA_USERS))
elif os.getenv('ENV_TYPE') == EnvType.PROD:
logger.debug(f"ENV is {EnvType.PROD}")
users.extend(read_files(Resources.PROD_USERS))
@events.test_start.add_listener
def init_locust_configuration(**kwargs):
init_env_configurations()
class StartSomethingWithUser(SequentialTaskSet):
wait_time = between(1, 2)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user_access_token = None
def on_start(self):
logging.info(f"Len: {len(users)}")
if len(users) > 0:
user_params = users.pop().rstrip("\n").split(",")
logging.info(f"User params:: {user_params}")
phone = user_params[1]
body = {test_body}
with self.client.post(api_call, json=body, catch_response=True, name="Authorise user") as authorise_user:
if authorise_user.status_code != 200:
log_error(authorise_user)
raise StopUser()
else:
log_data(authorise_user)
self.user_access_token = authorise_user.json()["session"]["accessToken"]
self.client.headers.update({"Authorization": f"Bearer {self.user_access_token}", "Accept-Language": "EN"})
else:
logging.info("There are no users")
raise StopUser()
@task()
def start_something(self):
with self.client.post(aoi_call, catch_response=True, name="start_something") as start_something:
if start_something.status_code != 201:
log_error(start_something)
raise StopUser()
else:
log_data(start_something)
@task()
def on_stop(self):
raise StopUser()
class UserLoader(HttpUser):
wait_time = between(1, 2)
tasks = {StartSomethingWithUser: 1}
host = os.getenv("URL")
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Stop Locust When Specified Number Of User Tasks Complete
My experience with this test is that page requests continue to be made after the last user task completes until I either manually...
Read more >finish() from onStop() doesn't set ActivityScenario's state to ...
The test should pass, since the activity is being destroyed. Actual Results. The test doesn't pass, the state remains CREATED . AndroidX Test...
Read more >Writing a locustfile — Locust 2.14.0 documentation
A locust file is just a normal Python module, it can import code from other files or packages. class QuickstartUser(HttpUser):. Here we define...
Read more >How we manipulated Locust to test system performance under ...
Our observations that: The load test must reflect real user behaviors and interactions; Load testing alone doesn't validate system behavior against target ...
Read more >Apache JMeter - History of Previous Changes
Implemented by Artem Fedorov (artem.fedorov at blazemeter.com) and contributed by BlazeMeter. Bug 62842 - HTTP(S) Test Script Recorder: Brotli compression is ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m sorry but I’m obviously not getting thru to you - you just keep replying with big examples that are anything but minimal? Using a public api in your example is good, but that wasnt the point.
Maybe someone else can help, but I wont spend more time on this issue right now.
You try to explain that stopping users by raising StopUser() it in on_stop() method is incorrect but there is no suggestion on how to do it. I would be glad any hint on how to run suit just once for one user.