Reputation: 137
I need to implement the next logic:
1) Execute on_start method (eg login)
2) Execute the next task (task_2) 5 times
3) After that execute the next task (task_3) 10 times
Return to on_start etc...
So finally I need login:1, task_2: 5, task_3: 10. (5 and 10 times per 1 login)
I try to implement it with the next code:
class MyTaskSet(TaskSequence):
def on_start(self):
login()
@seq_task(1)
def task_2(self):
print('Need to be executed 5 times after 1 login')
@seq_task(2)
def task_3(self):
print('Need to be executed 10 times after 1 login')
class LocustUser(HttpLocust):
host = http://localhost
task_set = MyTaskSet
Could someone of performance guru help me with this logic?
Upvotes: 6
Views: 5326
Reputation: 149
If I understand your use-case correctly you could create a task out of your login logic. If the login is in a on_start()
i think it only gets run once. As of version 1.4.3 of Locust this can be accomplished as such:
class MyTaskSet(SequentialTaskSet):
@task(1)
def task_login(self):
login()
@task(5)
def task_2(self):
print('Need to be executed 5 times after 1 login')
@task(10)
def task_3(self):
print('Need to be executed 10 times after 1 login')
This should run the tasks in order with the assigned weights.
Upvotes: 2
Reputation: 11416
I think the easiest way is just to use ordinary for-loops in a single task. No on_start, no seq_task or anything.
I think the documentation needs to be adjusted, because a lot of people get the (incorrect) impression that you can only do a single request in a task.
Upvotes: 1