[Plugins] Class-based scenario DummyFailure

This adds the first class-based scenario.

Change-Id: Ia1a0ea6988b21f792070ac15e425dc52441ff4c2
Implements: class-based-scenarios
This commit is contained in:
Alexander Maretskiy 2016-05-30 16:47:47 +03:00
parent 393b32ce66
commit 4d22d8944b
5 changed files with 119 additions and 0 deletions

View File

@ -672,6 +672,26 @@
action_3: 4.0
action_4: 5.0
dummy.failure:
-
args:
sleep: 0.2
from_iteration: 5
to_iteration: 15
each: 2
runner:
type: "constant"
times: 20
concurrency: 5
context:
users:
tenants: 1
users_per_tenant: 1
sla:
failure_rate:
min: 25
max: 25
FakePlugin.testplugin:
-
runner:

View File

@ -28,6 +28,28 @@ class DummyScenarioException(exceptions.RallyException):
msg_fmt = _("Dummy scenario expected exception: '%(message)s'")
@scenario.configure(name="dummy.failure")
class DummyFailure(scenario.Scenario):
"""Dummy benchmarks for testing Rally benchmark engine at scale."""
def run(self, sleep=0.1, from_iteration=0, to_iteration=0, each=1):
"""Raise errors in some iterations.
:param sleep: float iteration sleep time in seconds
:param from_iteration: int iteration number which starts range
of failed iterations
:param to_iteration: int iteration number which ends range of
failed iterations
:param each: int cyclic number of iteration which actually raises
an error in selected range. For example, each=3 will
raise error in each 3rd iteration.
"""
utils.interruptable_sleep(sleep)
if from_iteration <= self.context["iteration"] <= to_iteration:
if each and not self.context["iteration"] % each:
raise DummyScenarioException(_("Expected failure"))
class Dummy(scenario.Scenario):
"""Dummy benchmarks for testing Rally benchmark engine at scale."""

View File

@ -0,0 +1,23 @@
{
"dummy.failure": [
{
"args": {
"sleep": 0.2,
"from_iteration": 5,
"to_iteration": 10,
"each": 2
},
"runner": {
"type": "constant",
"times": 20,
"concurrency": 5
},
"context": {
"users": {
"tenants": 1,
"users_per_tenant": 1
}
}
}
]
}

View File

@ -0,0 +1,16 @@
---
dummy.failure:
-
args:
sleep: 0.2
from_iteration: 5
to_iteration: 10
each: 2
runner:
type: "constant"
times: 20
concurrency: 5
context:
users:
tenants: 1
users_per_tenant: 1

View File

@ -21,6 +21,44 @@ from tests.unit import test
DUMMY = "rally.plugins.common.scenarios.dummy.dummy."
@ddt.ddt
class DummyFailureTestCase(test.TestCase):
@ddt.data({"iteration": 0, "kwargs": {}},
{"iteration": 0, "kwargs": {"each": 1}},
{"iteration": 5, "kwargs": {"from_iteration": 4},
"raises": False},
{"iteration": 5,
"kwargs": {"from_iteration": 5, "to_iteration": 5}},
{"iteration": 5,
"kwargs": {"from_iteration": 4, "to_iteration": 5}},
{"iteration": 5,
"kwargs": {"from_iteration": 5, "to_iteration": 6}},
{"iteration": 5,
"kwargs": {"from_iteration": 4, "to_iteration": 6}},
{"iteration": 5, "kwargs": {"from_iteration": 4,
"to_iteration": 6, "sleep": 5}},
{"iteration": 5, "raises": False,
"kwargs": {"from_iteration": 4, "to_iteration": 6,
"sleep": 5, "each": 2}},
{"iteration": 6, "kwargs": {"from_iteration": 4,
"to_iteration": 6,
"sleep": 5, "each": 2}})
@ddt.unpack
@mock.patch(DUMMY + "utils.interruptable_sleep")
def test_run(self, mock_interruptable_sleep, iteration, kwargs,
raises=True):
scenario = dummy.DummyFailure(
test.get_test_context(iteration=iteration))
if raises:
self.assertRaises(dummy.DummyScenarioException, scenario.run,
**kwargs)
else:
scenario.run(**kwargs)
mock_interruptable_sleep.assert_called_once_with(
kwargs.get("sleep", 0.1))
@ddt.ddt
class DummyTestCase(test.TestCase):