Tasks
Tasks are functionality that is executed by locust
at run time as they are specified in the feature file.
The most essential task is Request, which all Load User is using to make requests to the endpoint that is being load tested.
All other tasks are helper tasks for things that needs to happen after or before a Request, stuff like extracting information from a previous response or fetching additional test data from a different endpoint ("Clients").
Custom
It is possible to implement custom tasks, the only requirement is that they inherit grizzly.tasks.GrizzlyTask
. To get them to be executed by grizzly
,
a step implementation is also needed.
Boilerplate example of a custom task:
from typing import Any, cast
from grizzly.context import GrizzlyContext
from grizzly.tasks import GrizzlyTask, grizzlytask
from grizzly.scenarios import GrizzlyScenario
from grizzly.types.behave import Context, then
class TestTask(GrizzlyTask):
def __call__(self) -> grizzlytask:
@grizzlytask
def task(parent: GrizzlyScenario) -> Any:
print(f'{self.__class__.__name__}::task called')
@task.on_start
def on_start() -> None:
print(f'{self.__class__.__name__}::on_start called')
@task.on_stop
def on_stop() -> None:
print(f'{self.__class__.__name__}::on_stop called')
return task
@then(u'run `TestTask`')
def step_run_testtask(context: Context) -> None:
grizzly = cast(GrizzlyContext, context.grizzly)
grizzly.scenario.tasks.add(TestTask())
There are examples of this in the Example.