locust icon indicating copy to clipboard operation
locust copied to clipboard

tag doesn't work fine

Open evanchaoli opened this issue 1 year ago • 6 comments

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 avatar Aug 14 '24 07:08 evanchaoli

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 avatar Aug 14 '24 08:08 cyberw

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

vijay59122 avatar Oct 18 '24 13:10 vijay59122

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

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

skirtan1 avatar Oct 19 '24 06:10 skirtan1

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.

cyberw avatar Oct 19 '24 07:10 cyberw

@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?

vijay59122 avatar Oct 19 '24 08:10 vijay59122

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

cyberw avatar Oct 19 '24 11:10 cyberw

https://github.com/locustio/locust/pull/2957

vijay59122 avatar Oct 28 '24 04:10 vijay59122

@vijay59122 That PR does more than I expected. I dont want to change any behaviour apart from the log spam.

cyberw avatar Oct 31 '24 09:10 cyberw

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Dec 31 '24 02:12 github-actions[bot]

This issue was closed because it has been stalled for 10 days with no activity. This does not necessarily mean that the issue is bad, but it most likely means that nobody is willing to take the time to fix it. If you have found Locust useful, then consider contributing a fix yourself!

github-actions[bot] avatar Jan 10 '25 02:01 github-actions[bot]