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

Have the ability to run one task once to test it #1950

Closed
jerri opened this issue Dec 2, 2021 · 4 comments
Closed

Have the ability to run one task once to test it #1950

jerri opened this issue Dec 2, 2021 · 4 comments
Labels
feature request stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it

Comments

@jerri
Copy link

jerri commented Dec 2, 2021

Is your feature request related to a problem? Please describe.

I am coming from funkload, where you basically create a script that can be also executed once to test your code. This is especially necessary when you are creating a complex user journey including e.g. login, selection of some pages, addition to basket and full checkout. As far as I see right now, I would have to start locust for any change I am doing and then executing it with one user? Maybe I didn't get it right. I would prefer to have the ability to just execute a specific task once, so I can also check any logs on the target system.

Describe the solution you'd like

I assume the easist would be to have a parameter --run-once or similar, which would run every task only once. And optimally an additional parameter --run-task that takes the name of a task to run.

Describe alternatives you've considered

As mentioned, I guess the only alternative at the moment is to run with 1 user and stop the script after some seconds.

Additional context

This request is basically about debugging posibilities for locust script, especially when they become more complex.

@cyberw
Copy link
Collaborator

cyberw commented Dec 7, 2021

There are a couple of options, either run a single User in the debugger (using locust-plugins): https://github.com/SvenskaSpel/locust-plugins/blob/master/examples/debug_ex.py

Or (again using locust-plugins) use -i to limit the number of task iterations to 1: https://github.com/SvenskaSpel/locust-plugins/blob/master/examples/cmd_line_examples.sh#L12

@github-actions
Copy link

github-actions bot commented Feb 6, 2022

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

@github-actions github-actions bot added the stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it label Feb 6, 2022
@cyberw
Copy link
Collaborator

cyberw commented Feb 6, 2022

Fixed in #1985, released in 2.7.0

@cyberw cyberw closed this as completed Feb 6, 2022
@dylan-shipwell
Copy link

dylan-shipwell commented Jun 17, 2024

motion to reopen,
#1985 appears to offers quirky way to filter a locust run to a single locust.HttpUser case; but does not appear to limit the running of each task within that HttpUser case to a single execution, nor accept either None or a list of all HttpUser classes to run one of each task.

therefore I don't see how 1985 soles the need to test locust tasks.

i'm looking for more of an

# ...
import inspect

import locust
import locust.util.load_locustfile

# collect all classes like locust does
all_user_classes_this_file = [ i[1] for i in inspect.getmembers(sys.modules[__name__]) if inspect.isclass(i[1]) and locust.util.load_locustfile.is_user_class(i)]

# define a new run function that only schedules each task one time total
class MyOnceHttpUser(locust.HttpUser):
    def run(self): # bad & broken run implementation, do not use, lost of missing error handling
        self.on_start()
        for i in self.user.tasks:
            self.schedule_task(i)
        while self._task_queue:
            self.execute_next_task()
        self.on_stop()

# run each http task one time
for user_class in all_user_classes_this_file:
    MyOnceHttpUser.run(user_class)

while poking around, I noticed there is a SequentialHttpTask class, i didin't look at its run method but maybe it would help provide this requested battery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it
Projects
None yet
Development

No branches or pull requests

3 participants