0

Is there some method (ideally for a User class) or event or other way in Locust to execute some setup code before each task?


What I have looked into:

  • there are some useful events, unfortunately none like on_task_start
  • there are some useful methods like test_start, but unfortunately none like task_start
  • I could use the wait_time() method on a User class, but that is an ugly work around, and the method is not called before the first task of each User instance.
DaveFar
  • 7,078
  • 4
  • 50
  • 90

1 Answers1

1

You can add custom events to locust see: https://docs.locust.io/en/stable/api.html#EventHook%20class

update:

class DbTaskSet(TaskSet):
    def __init__(self, parent):
        super().__init__(parent)

    def execute_next_task(self):
        myevent.fire()
        super().execute_next_task()
  • Thanks @Muhammeed Tanir (+1), that gives me the class to implement a custom event. However, I still do not know where to locate the code (in this case the `event.fire()` to trigger the event before each task execution. – DaveFar Jul 29 '20 at 14:42
  • a quick workaround would be fire the event in tasks that you wrote, but i think it would be better to overwrite execute_task method which is under task.py . Updated the answer – Muhammed Tanır Aug 04 '20 at 11:57