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

Unable to load multiple custom shape classes in web UI from --class-picker #2412

Closed
2 tasks done
shamithas99 opened this issue Oct 3, 2023 · 11 comments
Closed
2 tasks done
Labels

Comments

@shamithas99
Copy link

shamithas99 commented Oct 3, 2023

Prerequisites

Description

Why does locust load only the 1st LoadTestShape class in web UI, when there is more than 1 LoadTestShape class defined in locustfile?
In the docs we can see multiple shape classes appearing in the UI but unable to implement it.

image

Command line

locust -f locustfile.py --class-picker

Locustfile contents

from locust import HttpUser, TaskSet, task
from locust import LoadTestShape

class Tasks1(TaskSet):
    @task
    def service(self):
        print("Launching URL")

class FirstUser(HttpUser):
    tasks = [Tasks1]

class SecondUser(HttpUser):
    tasks = [Tasks1]

class ThirdUser(HttpUser):
    tasks = [Tasks1]

class FourthUser(HttpUser):
    tasks = [Tasks1]

class FifthUser(HttpUser):
    tasks = [Tasks1]

class ramp_up_1min_40users_hold_20min(LoadTestShape):
    stages = [
        {"duration": 60, "users": 40, "spawn_rate": 0.67},
        {"duration": 1200, "users": 40, "spawn_rate": 1},
    ]

    def tick(self):
        run_time = self.get_run_time()
        for stage in self.stages:
            if run_time < stage["duration"]:
                try:
                    tick_data = (
                        stage["users"], stage["spawn_rate"], stage["user_classes"])
                except:
                    tick_data = (stage["users"], stage["spawn_rate"])
                return tick_data
        return None

class ramp_up_20min_40users_hold_5min_ramp_down_5min_1user(LoadTestShape):
    stages = [
        {"duration": 1200, "users": 40, "spawn_rate": 0.034},
        {"duration": 300, "users": 40, "spawn_rate": 1},
        {"duration": 300, "users": 1, "spawn_rate": 0.0325}
    ]

    def tick(self):
        run_time = self.get_run_time()
        for stage in self.stages:
            if run_time < stage["duration"]:
                try:
                    tick_data = (
                        stage["users"], stage["spawn_rate"], stage["user_classes"])
                except:
                    tick_data = (stage["users"], stage["spawn_rate"])
                return tick_data
        return None

Python version

3.9

Locust version

2.16.1

Operating system

Windows

@shamithas99 shamithas99 added the bug label Oct 3, 2023
@cyberw
Copy link
Collaborator

cyberw commented Oct 3, 2023

2.15.1 is not latest version

@shamithas99
Copy link
Author

2.15.1 is not latest version

It doesn't work in 2.16.1 either

@cyberw
Copy link
Collaborator

cyberw commented Oct 3, 2023

I can reproduce the error: The problem is that the class picker was only ever implemented for reading the shape classes from different files (e.g. using locust -f mylocustfile.py -f shape1.py -f shape2.py), if they are all in the same file it will not work: https://github.com/locustio/locust/blob/master/locust/main.py#L90

The class picker was implemented by @mikenester . I dont know if he has time to take a look.

@mikenester
Copy link
Contributor

It's been a minute since I've touched this, but I can definitely take a look. @shamithas99 Thanks for the details & screenshots on your report 🙏

@shamithas99
Copy link
Author

I can reproduce the error: The problem is that the class picker was only ever implemented for reading the shape classes from different files (e.g. using locust -f mylocustfile.py -f shape1.py -f shape2.py), if they are all in the same file it will not work: https://github.com/locustio/locust/blob/master/locust/main.py#L90

The class picker was implemented by @mikenester . I dont know if he has time to take a look.

I have tried to implement class picker with shape files in different files but we don't see all the shape files coming in the UI dropdown, if there is more than 1 shapefile.

@cyberw
Copy link
Collaborator

cyberw commented Oct 27, 2023

@mikenester Did you have time to investigate this?

@mikenester
Copy link
Contributor

@cyberw Sorry, I've been quite busy and lost sight of this. I was trying to take a look today, but while setting up the project, I'm getting the following error when running pip3 install -e locust/

ERROR: File "setup.py" or "setup.cfg" not found. Directory cannot be installed in editable mode: /Users/michaelnester/git/locust
(A "pyproject.toml" file was found, but editable mode currently requires a setuptools-based build.)

I'm guessing I need to force it to use pyproject.toml, but am not sure how. Any suggestions?

@cyberw
Copy link
Collaborator

cyberw commented Oct 30, 2023

Try updating setuptools and pip to latest versions.

@mikenester
Copy link
Contributor

mikenester commented Oct 31, 2023

That worked. Thanks 🙏

I suspect this is the offending block of code. I'll try to have a fix soon.

@mikenester
Copy link
Contributor

I think I have a fix. I need to add tests and check for edge cases, then I'll open up a pull request.
fix_1
fix_2
fix_3

@mikenester
Copy link
Contributor

@cyberw I've opened a PR: #2441. I also included a fix for a legacy UI styling issue, which was quite minor.

@cyberw cyberw closed this as completed Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants