"New test" with different number of users
See original GitHub issueIt seems likes a bug to me, but please correct me if I’m wrong. It seems that after clicking on “new test” and giving lower amount of users to be created, Locust still uses some of the users created on first run.
Describe the bug
Example: When i start locust and create (total) 5 users with 5 users per sec, I get correct amount of users/requests. That is correct. Then i click Stop (in the UI). After clicking on “New test” and specifying lower amount of users(total 1 and 1 per sec), Locust still starts 4 users in total and execute tasks - but in console i can see that 1 user was spawned
Code:
import logging
import time
import uuid
from locust import task, HttpUser, SequentialTaskSet, constant_pacing, task, events
from locust.exception import StopUser
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("locust")
class UserTasks(SequentialTaskSet):
wait_time = constant_pacing(1)
@task
def test_api_one(self):
logger.info(f"Task1: {self.parent.user_id}")
time.sleep(1)
@task
def test_api_two(self):
logger.info(f"Task2: {self.parent.user_id}")
time.sleep(1)
@task
def test_api_three(self):
self.interrupt(False)
class WebsiteUser(HttpUser):
host = "http://local"
wait_time = constant_pacing(5)
tasks = [UserTasks]
def on_start(self):
self.user_id = str(uuid.uuid4())
logger.info(f"START USER: {self.user_id}")
def on_stop(self):
logger.info(f"STOP USER: {self.user_id}")
Expected behaviour
I would expect that if i run new test with lower number of users - from 5 to 1 users, Locust will just create 1 user and run (spawn) only that one.
You can see it on the screenshot:
Environment
- OS: docker with python 3.9
- Python version: 3.9
- Locust 2.9.0
- locust -f temp.py
Issue Analytics
- State:
- Created a year ago
- Comments:8 (1 by maintainers)
Top GitHub Comments
Damn, I dropped the ball here. Will pick it up some time next week if nobody else has the time. Maybe @mboutet ?
Getting the exact same behavior. Additionally, all the users from the previous test are spawned instantaneously and don’t respect the chosen “Spawn rate”.