[Plugins] New scenario Dummy.dummy_random_action
Generate atomic actions with random durations. This scenario is suitable for demonstration of upcoming trends report (will be introduced in further patches) Change-Id: I46207c2d7db848f923820fcc499c46d3c8ecb855
This commit is contained in:
parent
11b70e7d5c
commit
01408ff786
rally-jobs
rally/plugins/common/scenarios/dummy
samples/tasks/scenarios/dummy
tests/unit/plugins/common/scenarios/dummy
@ -618,6 +618,13 @@
|
||||
times: 50
|
||||
concurrency: 10
|
||||
|
||||
Dummy.dummy_random_action:
|
||||
-
|
||||
runner:
|
||||
type: "constant"
|
||||
times: 10
|
||||
concurrency: 5
|
||||
|
||||
FakePlugin.testplugin:
|
||||
-
|
||||
runner:
|
||||
|
@ -183,3 +183,16 @@ class Dummy(scenario.Scenario):
|
||||
"""
|
||||
self._random_fail_emitter(exception_probability)
|
||||
self._random_fail_emitter(exception_probability)
|
||||
|
||||
@scenario.configure()
|
||||
def dummy_random_action(self, actions_num=5, sleep_min=0, sleep_max=2):
|
||||
"""Sleep random time in dummy actions.
|
||||
|
||||
:param actions_num: int number of actions to generate
|
||||
:param sleep_min: minimal time to sleep, numeric seconds
|
||||
:param sleep_max: maximum time to sleep, numeric seconds
|
||||
"""
|
||||
for idx in range(actions_num):
|
||||
duration = random.uniform(sleep_min, sleep_max)
|
||||
with atomic.ActionTimer(self, "action_%d" % idx):
|
||||
utils.interruptable_sleep(duration)
|
||||
|
22
samples/tasks/scenarios/dummy/dummy_random_action.json
Normal file
22
samples/tasks/scenarios/dummy/dummy_random_action.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"Dummy.dummy_random_action": [
|
||||
{
|
||||
"args": {
|
||||
"atomics_num": 5,
|
||||
"sleep_min": 0,
|
||||
"sleep_max": 2
|
||||
},
|
||||
"runner": {
|
||||
"type": "constant",
|
||||
"times": 5,
|
||||
"concurrency": 5
|
||||
},
|
||||
"context": {
|
||||
"users": {
|
||||
"tenants": 1,
|
||||
"users_per_tenant": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
15
samples/tasks/scenarios/dummy/dummy_random_action.yaml
Normal file
15
samples/tasks/scenarios/dummy/dummy_random_action.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
Dummy.dummy_random_action:
|
||||
-
|
||||
args:
|
||||
atomics_num: 5
|
||||
sleep_min: 0
|
||||
sleep_max: 2
|
||||
runner:
|
||||
type: "constant"
|
||||
times: 5
|
||||
concurrency: 5
|
||||
context:
|
||||
users:
|
||||
tenants: 1
|
||||
users_per_tenant: 1
|
@ -11,16 +11,20 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
|
||||
from rally.plugins.common.scenarios.dummy import dummy
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
DUMMY = "rally.plugins.common.scenarios.dummy.dummy."
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class DummyTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.plugins.common.scenarios.dummy.dummy.utils."
|
||||
"interruptable_sleep")
|
||||
@mock.patch(DUMMY + "utils.interruptable_sleep")
|
||||
def test_dummy(self, mock_interruptable_sleep):
|
||||
scenario = dummy.Dummy(test.get_test_context())
|
||||
scenario.sleep_between = mock.MagicMock()
|
||||
@ -28,8 +32,7 @@ class DummyTestCase(test.TestCase):
|
||||
scenario.dummy(sleep=10)
|
||||
mock_interruptable_sleep.assert_called_once_with(10)
|
||||
|
||||
@mock.patch("rally.plugins.common.scenarios.dummy.dummy.utils."
|
||||
"interruptable_sleep")
|
||||
@mock.patch(DUMMY + "utils.interruptable_sleep")
|
||||
def test_dummy_exception(self, mock_interruptable_sleep):
|
||||
scenario = dummy.Dummy(test.get_test_context())
|
||||
|
||||
@ -51,7 +54,7 @@ class DummyTestCase(test.TestCase):
|
||||
scenario.dummy_exception_probability,
|
||||
exception_probability=1)
|
||||
|
||||
@mock.patch("rally.plugins.common.scenarios.dummy.dummy.random")
|
||||
@mock.patch(DUMMY + "random")
|
||||
def test_dummy_output(self, mock_random):
|
||||
mock_random.randint.side_effect = lambda min_, max_: max_
|
||||
desc = "This is a description text for %s"
|
||||
@ -132,3 +135,29 @@ class DummyTestCase(test.TestCase):
|
||||
self.assertRaises(KeyError,
|
||||
scenario.dummy_random_fail_in_atomic,
|
||||
exception_probability=1)
|
||||
|
||||
@ddt.data({},
|
||||
{"actions_num": 5, "sleep_min": 0, "sleep_max": 2},
|
||||
{"actions_num": 7, "sleep_min": 1.23, "sleep_max": 4.56},
|
||||
{"actions_num": 1, "sleep_max": 4.56},
|
||||
{"sleep_min": 1})
|
||||
@ddt.unpack
|
||||
@mock.patch(DUMMY + "random")
|
||||
@mock.patch(DUMMY + "utils.interruptable_sleep")
|
||||
def test_dummy_random_action(self, mock_interruptable_sleep, mock_random,
|
||||
**kwargs):
|
||||
mock_random.uniform.side_effect = range(100)
|
||||
|
||||
scenario = dummy.Dummy(test.get_test_context())
|
||||
scenario.dummy_random_action(**kwargs)
|
||||
actions_num = kwargs.get("actions_num", 5)
|
||||
calls = [mock.call(i) for i in range(actions_num)]
|
||||
self.assertEqual(calls, mock_interruptable_sleep.mock_calls)
|
||||
|
||||
calls = [mock.call(kwargs.get("sleep_min", 0),
|
||||
kwargs.get("sleep_max", 2))
|
||||
for i in range(actions_num)]
|
||||
self.assertEqual(calls, mock_random.uniform.mock_calls)
|
||||
for i in range(actions_num):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"action_%d" % i)
|
||||
|
Loading…
x
Reference in New Issue
Block a user