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

Class picker incorrectly populates Parsed Options #2192

Closed
Vino4 opened this issue Sep 11, 2022 · 9 comments
Closed

Class picker incorrectly populates Parsed Options #2192

Vino4 opened this issue Sep 11, 2022 · 9 comments
Labels

Comments

@Vino4
Copy link

Vino4 commented Sep 11, 2022

Describe the bug

When using the Web UI's class picker, Parsed Options are incorrectly populated

Expected behavior

Each name of a picked class is available as a single item in the environment.parsed_options.user_classes list
Example when selecting the class "PurchaseUser":
image

Actual behavior

When choosing classes through class picker, the name of the class is broken into characters. Each character is present as its own item in the environment.parsed_options.user_classes list.
Example when selecting the class "PurchaseUser":
image

Steps to reproduce

  • Start locust with the --class-picker option and without specifying a user class through the CLI
  • Select a class from the class picker menu and start the test
  • Access the environment.parsed_options.user_classes list in the test_start listener
@events.test_start.add_listener
def on_test_start(environment, **__):
    user_classes = environment.parsed_options.user_classes
    log.info(user_classes)

Environment

  • OS: MacOS Big Sur (11.4)
  • Python version: 3.7.9
  • Locust version: 2.12.0
  • Locust command line that you ran: locust --class-picker
  • Locust file contents (anonymized if necessary):
import logging
import time
from locust import HttpUser, task, between, events

log = logging.getLogger(__name__)

@events.test_start.add_listener
def on_test_start(environment, **_):
    user_classes = environment.parsed_options.user_classes
    log.info(user_classes)

class PurchaseUser(HttpUser):
    wait_time = between(1, 5)

    @task
    def hello_world(self):
        self.client.get("/hello")
        self.client.get("/world")

    @task(3)
    def view_items(self):
        for item_id in range(10):
            self.client.get(f"/item?id={item_id}", name="/item")
            time.sleep(1)

    def on_start(self):
        self.client.post("/login", json={"username":"foo", "password":"bar"})
@Vino4 Vino4 added the bug label Sep 11, 2022
@cyberw
Copy link
Collaborator

cyberw commented Sep 11, 2022

@mikenester Could you take a look?

@mikenester
Copy link
Contributor

Whoops! Yeah i'll take a look asap

@mikenester
Copy link
Contributor

I think this is happening when /swarm updates environment.parsed_options. I'll try to get a fix in today or tomorrow

@mikenester
Copy link
Contributor

@cyberw @Vino4 is the expected behavior on this issue correct?

If I have the following in a file called locustfiles/locustfile1.py

from locust import HttpUser, task, between, events


@events.test_start.add_listener
def on_test_start(environment, **__):
    user_classes = environment.parsed_options.user_classes
    print("\nevent listener:\n", user_classes)

class Base(HttpUser):
    wait_time = between(1, 2)

    @task
    def base(self):
        self.client.get("/")

It prints the following when Locust is ran with locust -f locustfiles --class-picker

event listener:
 ['B', 'a', 's', 'e']

Meanwhile, it prints the following when Locust is ran with locust -f locustfiles/locustfile1.py

event listener:
 []

Based on this, I would expect user_classes to be empty when a test is ran with the --class-picker flag.

@Vino4
Copy link
Author

Vino4 commented Sep 12, 2022

@cyberw @Vino4 is the expected behavior on this issue correct?

If I have the following in a file called locustfiles/locustfile1.py

from locust import HttpUser, task, between, events


@events.test_start.add_listener
def on_test_start(environment, **__):
    user_classes = environment.parsed_options.user_classes
    print("\nevent listener:\n", user_classes)

class Base(HttpUser):
    wait_time = between(1, 2)

    @task
    def base(self):
        self.client.get("/")

It prints the following when Locust is ran with locust -f locustfiles --class-picker

event listener:
 ['B', 'a', 's', 'e']

Meanwhile, it prints the following when Locust is ran with locust -f locustfiles/locustfile1.py

event listener:
 []

Based on this, I would expect user_classes to be empty when a test is ran with the --class-picker flag.

I'm very new to Locust so not quite sure, but from a users' perspective I propose that the expect behavior when running the following code snippet:

from locust import HttpUser, task, between, events


@events.init.add_listener
def on_init(environment, **__):
    user_classes = environment.parsed_options.user_classes
    print("\nInit event listener:\n", user_classes)

@events.test_start.add_listener
def on_test_start(environment, **__):
    user_classes = environment.parsed_options.user_classes
    print("\nTest start event listener:\n", user_classes)

class Base(HttpUser):
    wait_time = between(1, 2)

    @task
    def base(self):
        self.client.get("/")

with --class-picker and then starting the test is to produce the following output:

Init event listener:
 []

Test start event listener:
 ['Base']

The reasoning is: When I run locust -f locustfiles/locustfile1.py Base the output is:

Init event listener:
 ['Base']
[2022-09-11 17:34:13,697] MMBP.local/INFO/locust.main: Starting Locust 2.12.0

Test start event listener:
 ['Base']

This is operating under the assumption that the intended behavior when setting the class using class-picker is to simply specify the class when the test starts rather than when the test initializing :)

Support point: When specifying any custom arguments through the Web UI, they're injected into parsed_option when the test is started - a case could be made that --class-picker serves and function the same as a custom argument 😄

@mikenester
Copy link
Contributor

@cyberw Any thoughts on the above ^ ?

@cyberw
Copy link
Collaborator

cyberw commented Sep 13, 2022

@Vino4 's comment makes sense to me.

@mikenester
Copy link
Contributor

I have a PR open with the fix: #2201

@cyberw
Copy link
Collaborator

cyberw commented Oct 6, 2022

Should be fixed now

@cyberw cyberw closed this as completed Oct 6, 2022
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