35846a9b7c
In a lot of placeses we are using word "benchmark" which can mean workload, subtask, or test case which is very confusing. This patch partially address wrong usage of "benchamrk" word Change-Id: Id3b2b7ae841a5243684c12cc51c96f005dbe7544
3.2 KiB
3.2 KiB
Scenario runner as a plugin
Let's create a runner plugin that runs a given scenario a random number of times (chosen at random from a given range).
Creation
Inherit a class for your plugin from the base ScenarioRunner class and implement its API (the _run_scenario() method):
import random
from rally.task import runner
from rally import consts
@runner.configure(name="random_times")
class RandomTimesScenarioRunner(runner.ScenarioRunner):
"""Sample scenario runner plugin.
Run scenario random number of times (between min_times and max_times)
"""
= {
CONFIG_SCHEMA "type": "object",
"$schema": consts.JSON_SCHEMA,
"properties": {
"type": {
"type": "string"
},"min_times": {
"type": "integer",
"minimum": 1
},"max_times": {
"type": "integer",
"minimum": 1
}
},"additionalProperties": True
}
def _run_scenario(self, cls, method_name, context, args):
# runners settings are stored in self.config
= self.config.get('min_times', 1)
min_times = self.config.get('max_times', 1)
max_times
for i in range(random.randrange(min_times, max_times)):
= (i, cls, method_name,
run_args
runner._get_scenario_context(context), args)= runner._run_scenario_once(run_args)
result # use self.send_result for result of each iteration
self._send_result(result)
Usage
You can refer to your scenario runner in the input task files in the same way as any other runners. Don't forget to put your runner-specific parameters in the configuration as well ("min_times" and "max_times" in our example):
{
"Dummy.dummy": [
{
"runner": {
"type": "random_times",
"min_times": 10,
"max_times": 20,
},
"context": {
"users": {
"tenants": 1,
"users_per_tenant": 1
}
}
}
]
}
Different plugin samples are available here.