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

tag doesn't work fine #2849

Open
2 tasks done
evanchaoli opened this issue Aug 14, 2024 · 7 comments
Open
2 tasks done

tag doesn't work fine #2849

evanchaoli opened this issue Aug 14, 2024 · 7 comments
Assignees
Labels
bug hacktoberfest See https://hacktoberfest.digitalocean.com for more info

Comments

@evanchaoli
Copy link

Prerequisites

Description

With this simple locusfile:

from locust import HttpUser, task, tag


class RevisionApiUser(HttpUser):
    @tag('revision')
    @task
    def get_commit_list(self):
        print("revision")


class CBotApiUser(HttpUser):
    @tag('cbot')
    @task
    def get_commits(self):
        print("cbot")

Then run locust with a tag specified:

$ locust --tags cbot
[2024-08-14 15:05:43,870] C02GM2X6MD6R/ERROR/locust.user.task: No tasks defined on RevisionApiUser. Use the @task decorator or set the 'tasks' attribute of the User (or mark it as abstract = True if you only intend to subclass it)
Traceback (most recent call last):
  File "/Users/chaol/venv/3.9/lib/python3.9/site-packages/locust/user/task.py", line 335, in run
    self.schedule_task(self.get_next_task())
  File "/Users/chaol/venv/3.9/lib/python3.9/site-packages/locust/user/task.py", line 479, in get_next_task
    raise Exception(
Exception: No tasks defined on RevisionApiUser. Use the @task decorator or set the 'tasks' attribute of the User (or mark it as abstract = True if you only intend to subclass it)

From the UI, the test looks run properly, only CBotApiUser is executed. However, the terminal keeps scrolling the error message.

Command line

locust --tags cbot

Locustfile contents

from locust import HttpUser, task, tag


class RevisionApiUser(HttpUser):
    @tag('revision')
    @task
    def get_commit_list(self):
        print("revision")


class CBotApiUser(HttpUser):
    @tag('cbot')
    @task
    def get_commits(self):
        print("cbot")

Python version

3.9.19

Locust version

locust 2.31.2 from /Users/chaol/venv/3.9/lib/python3.9/site-packages/locust (Python 3.9.19, OpenSSL 3.3.0)

Operating system

MacOS

@evanchaoli evanchaoli added the bug label Aug 14, 2024
@cyberw
Copy link
Collaborator

cyberw commented Aug 14, 2024

This is kind of intentional. You are spawning a user with no tasks (after filtering tags) which is usually a mistake, so we should log an error message (although I guess it would be enough to do it once, PRs fixing that would be welcome.)

Instead, you can filter by User class, e.g. locust CBotApiUser, or use --config-users to temporarily give the user class weight = 0.

@cyberw cyberw added the hacktoberfest See https://hacktoberfest.digitalocean.com for more info label Oct 10, 2024
@vijay59122
Copy link

@cyberw , please assign it to me. I would like to work on this.

@skirtan1
Copy link

I think this is fixed already. I can see the warning message once

See:
Screenshot from 2024-10-18 23-42-21

@cyberw
Copy link
Collaborator

cyberw commented Oct 19, 2024

The problem (I think) I was referring to is that it gets logged once per user instance. When I think about it though, idk if it is worth fixing. Maybe not.

@vijay59122
Copy link

@skirtan1 , looks like you ran with only one user and that user picked CBotApiUser(alphabetically ordered). If you run with more than one user then you can see the issue.

@cyberw , it would be still good if it gets logged once per user instance instead of throwing exceptions right?

@cyberw
Copy link
Collaborator

cyberw commented Oct 19, 2024

Yes! As long as the implementation can be kept simple.

vijay59122 added a commit to vijay59122/locust that referenced this issue Oct 28, 2024
@vijay59122
Copy link

#2957

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug hacktoberfest See https://hacktoberfest.digitalocean.com for more info
Projects
None yet
Development

No branches or pull requests

4 participants