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

SequentialTaskSet: Allow weighted tasks and dict in .tasks #2742

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add: SequentialTasksSet uses itertools.cycle to loop over tasks
  • Loading branch information
bakhtos committed Jun 6, 2024
commit 03475fbc38ccd7a3e586943ed8af9a239428cb67
8 changes: 3 additions & 5 deletions locust/user/sequential_taskset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from locust.exception import LocustError

import logging
from itertools import cycle

from .task import TaskSet, TaskSetMeta

Expand Down Expand Up @@ -56,13 +56,11 @@ class SequentialTaskSet(TaskSet, metaclass=SequentialTaskSetMeta):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._task_index = 0
self._task_cycle = cycle(self.tasks)

def get_next_task(self):
if not self.tasks:
raise LocustError(
"No tasks defined. Use the @task decorator or set the 'tasks' attribute of the SequentialTaskSet"
)
task = self.tasks[self._task_index % len(self.tasks)]
self._task_index += 1
return task
return next(self._task_cycle)