question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RPS doesn't fall to 0 after test has finished if raise StopUser() in on_stop() method

See original GitHub issue

Describe the bug

Screenshot 2021-09-29 at 11 35 08

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

  1. Create a class that inherits from SequentialTaskSet
  2. Do something on_start() method
  3. 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:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
cyberwcommented, Sep 29, 2021

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.

0reactions
Groshacommented, Sep 30, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found