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

"New test" with different number of users #2135

Closed
bsypniewski opened this issue Jul 20, 2022 · 8 comments · Fixed by #2152
Closed

"New test" with different number of users #2135

bsypniewski opened this issue Jul 20, 2022 · 8 comments · Fixed by #2152
Labels

Comments

@bsypniewski
Copy link

bsypniewski commented Jul 20, 2022

It 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

Screenshot 2022-07-20 at 16 21 47

@cyberw
Copy link
Collaborator

cyberw commented Jul 20, 2022

Wow, that looks crazy. Can you update to latest and see if it makes a difference?

@bsypniewski
Copy link
Author

Hi.
I got the same results on latest (v.2.10.1)

@cyberw
Copy link
Collaborator

cyberw commented Jul 21, 2022

Any difference if you remove test_api_three?

@bsypniewski
Copy link
Author

this was added because of the logic we try to test but even when i remove it unfortunately still starts 4 users instead of 1 :/

screenshot:
Screenshot 2022-07-21 at 13 18 13

@cyberw
Copy link
Collaborator

cyberw commented Jul 21, 2022

Very strange. I’ll take a look.

@prestonhale
Copy link

Getting the exact same behavior. Additionally, all the users from the previous test are spawned instantaneously and don't respect the chosen "Spawn rate".

@cyberw
Copy link
Collaborator

cyberw commented Aug 5, 2022

Damn, I dropped the ball here. Will pick it up some time next week if nobody else has the time. Maybe @mboutet ?

@mboutet
Copy link
Contributor

mboutet commented Aug 7, 2022

I implemented a failing test case in dfa3074 and a fix in #2152.

danigoland added a commit to danigoland/locust that referenced this issue Aug 9, 2022
* More robust handling of ZMQ/RPC errors (locustio#2120)

* More robust RPC error handling on msg from worker

* Use dedicated exceptions, fewer nested try blocks

* Fix test_zmqrpc.py

* Undo function split since added new exceptions

* Fix more tests

* Fix some tests

* Fix typo

* Fix scoping of variables

* Add tests for RPC/ZMQ changes

* flake and black fixes

* Remove debug print line

Co-authored-by: Ryan Warner <[email protected]>

* Remove timeout parameter from FastHttpUser unit tests

* Update changelog for 2.10

* Increase CONNECT_RETRY_COUNT to avoid workers giving up too soon if master is not up yet

* Escape user supplied data in html report (locustio#2126) (locustio#2127)

* Escape user supplied data in html report (locustio#2126)

authored-by: Tom Herrmann <[email protected]>

* Replace the MD5 usage by SHA256

MD5 is old, insecure, and can create problems for people using this package when they are trying to pass some compliance requirements (for example, FIPS).

* Fix escaping for exceptions in normal web ui (related to locustio#2126)

* implement table-sorting in report.html

* fix: Fix typo at user/wait_time.py

* improve report sorting

* enabled sorting of error messages as well as stacktraces

* Minor edits to the documentation

* Small documentation correction

* Minor edits to the documentation

* Log an error for every failed attempt to connect to master

The connection timeout and number of attempts are hardcoded, so a failure will take very long
These log lines will allow to troubleshoot issues with the connection to master

* Minor edits to the documentation

* Minor edits to the documentation

* Minor edits to the documentation

* Stop calling attributes 'properties' in some places.

* Give a better error message when someone accidentally sets User.task instead of User.tasks

* Fix detection of accidental TaskSet.task attribute

* fix spelling in comment

* style: add a report favicon

* Removed cache_timeout kwarg from request_stats_full_history_csv for flask 2.2.0

* temporary change to see logs for py38

* restored resource warning masking

* enabled tracemalloc temporarily

* removed tracemalloc

* Ensure no caching of stats history csv (replaces cache_timeout=None which was removed in locustio#2148)

* Update changelog for 2.10.2 (automatic changelog generation is broken, so CHANGELOG.md is incomplete)

* test: Implement failing test for issue locustio#2135

* fix: Set users_dispatcher to None when test is stopped

* chore: Remove misleading docstring in test

* chore: Do not use intermediate variable for one-use

* perf(test): Decrease test runtime

Co-authored-by: solowalker27 <[email protected]>
Co-authored-by: Ryan Warner <[email protected]>
Co-authored-by: Lars Holmberg <[email protected]>
Co-authored-by: Tom Herrmann <[email protected]>
Co-authored-by: Renan Gomes Barreto <[email protected]>
Co-authored-by: Tom Herrmann <[email protected]>
Co-authored-by: Lukas Lanzner <[email protected]>
Co-authored-by: Dmytro Litvinov <[email protected]>
Co-authored-by: Xavier Sosnovsky <[email protected]>
Co-authored-by: Andy Byrne <[email protected]>
Co-authored-by: gdm85 <[email protected]>
Co-authored-by: Xavier Sosnovsky <[email protected]>
Co-authored-by: Lars Holmberg <[email protected]>
Co-authored-by: Lijiawei <[email protected]>
Co-authored-by: Michael Nester <[email protected]>
Co-authored-by: Maxence Boutet <[email protected]>
Co-authored-by: Maxence Boutet <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants