-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Handle task weights efficiently in TaskSet
s
#2820
Conversation
Error is raised when the 'tasks' attribute is parsed if it is not a list or a dict And during the run() function
add: abstract _setup_tasks() method which processes tasks after filtering tags and is executed at run()
This PR 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. |
This PR was closed because it has been stalled for 10 days with no activity. |
This PR 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. |
This PR was closed because it has been stalled for 10 days with no activity. |
Fixes #2651
After realising that my initial idea of storing a dictionary of task weights in
TaskSet
would not work due to incompatibility withSequentialTaskSet
and the rest of the code (many things in the codebase assumetasks
is a list, refactoring which will be too much work), I started from scratch compared to #2741 and here are the changes:TaskSet
andSequentialTaskSet
now use the same metaclass, which uses the sameget_tasks_from_base_classes
methodSequentialTaskSet
is moved to thetask.py
, since keeping it in a separate file is no longer sensibleget_tasks_from_base_classes
method will process all tasks in order they are declared and put them in a list (only one of each), adding alocust_task_weight
attribute with the corresponding weight if it is missing (which now all tasks are thus guaranteed to have)TaskSet
andSequentialTaskSet
will process this list of tasks as they need, adding necessary data structures (in new_setup_tasks()
method, see belowTaskSet
will calculate the cumulative weights necessary forrandom.choices
SequentialTaskSet
will expand thetasks
list into a list where tasks are duplicated according to the weight and make a cycle out of it@task
decorator can now receive also afloat
as a weightTo facilitate these changes, also inheritance of classes is changed:
AbstractTaskSet
class, which keeps most of the functionality that was previously in theTaskSet
(init, run, wait_time etc);TaskSet
,SequentialTaskSet
andDefaultTaskSet
all inherit this class_setup_tasks()
andget_next_task()
which concrete classes need to implement_setup_tasks()
is necessary since the originaltasks
attribute can be filtered using tags after class instantiation, so the actual preparation of additional data structures needs to happen later; this method is called byrun()
(also, some tests needed to call it explicitly since they check some things without callingrun()
, but this should not be a problemget_next_task()
is the method that provides the next task torun()
. Arguably, this is where the specialized logic of a newTaskSet
class would be implementedtasks
is empty is now the responsibility ofrun()
during its start. It is, after all, only necessary to do once and not on every call toget_next_task()
. If there are no tasks,LocustError
is raised. It is also raised byget_tasks_from_base_classes
iftasks
is not a dict or a list. Tests are also modified to check for this specific error rather thanException
.Test are modified to account for these changes.
I think this refactoring makes it easier to introduce new specialized Task Sets, since there is now a unified data model/interface that they should accommodate.