Merge "[Core] Make iterations numeration starting from `1'"

This commit is contained in:
Jenkins 2016-08-01 23:45:29 +00:00 committed by Gerrit Code Review
commit 0da699c1a3
7 changed files with 16 additions and 11 deletions

View File

@ -468,10 +468,12 @@ class Task(object):
"tstamp_start": tstamp_start,
"full_duration": scenario["data"]["full_duration"],
"load_duration": scenario["data"]["load_duration"]}
iterations = sorted(scenario["data"]["raw"],
key=lambda itr: itr["timestamp"])
if serializable:
scenario["iterations"] = scenario["data"]["raw"]
scenario["iterations"] = list(iterations)
else:
scenario["iterations"] = iter(scenario["data"]["raw"])
scenario["iterations"] = iter(iterations)
scenario["sla"] = scenario["data"]["sla"]
del scenario["data"]
del scenario["task_uuid"]

View File

@ -90,12 +90,15 @@ class UserContextMixin(object):
else:
# Second and last case - 'round_robin'.
tenants_amount = len(context_obj["tenants"])
tenant_id = sorted(context_obj["tenants"].keys())[
context_obj["iteration"] % tenants_amount]
# NOTE(amaretskiy): iteration is subtracted by `1' because it
# starts from `1' but we count from `0'
tenant_index = int((context_obj["iteration"] - 1) % tenants_amount)
tenant_id = sorted(context_obj["tenants"].keys())[tenant_index]
tenant = context_obj["tenants"][tenant_id]
users = context_obj["tenants"][tenant_id]["users"]
user = users[
int(context_obj["iteration"] / tenants_amount) % len(users)]
user_index = int(((context_obj["iteration"] - 1) / tenants_amount)
% len(users))
user = users[user_index]
scenario_ctx["user"], scenario_ctx["tenant"] = user, tenant

View File

@ -38,7 +38,7 @@ def _process_scenario(data, pos):
output_errors = []
additive_output_charts = []
complete_output = []
for idx, itr in enumerate(data["iterations"]):
for idx, itr in enumerate(data["iterations"], 1):
if itr["error"]:
typ, msg, trace = itr["error"]
errors.append({"iteration": idx,

View File

@ -47,7 +47,7 @@ def format_result_on_timeout(exc, timeout):
def _get_scenario_context(iteration, context_obj):
context_obj = copy.deepcopy(context_obj)
context_obj["iteration"] = iteration
context_obj["iteration"] = iteration + 1 # Numeration starts from `1'
return context.ContextManager(context_obj).map_for_scenario()

View File

@ -43,7 +43,7 @@ class SerialScenarioRunnerTestCase(test.TestCase):
expected_calls = []
for i in range(times):
ctxt = fakes.FakeContext().context
ctxt["iteration"] = i
ctxt["iteration"] = i + 1
ctxt["task"] = mock.ANY
expected_calls.append(
mock.call(fakes.FakeScenario, "do_it", ctxt, {})

View File

@ -120,7 +120,7 @@ class UserContextMixinTestCase(test.TestCase):
}
expected_ids = ["0_0", "1_0", "0_1", "1_1"] * 4
mapped_ids = []
for i in range(16):
for i in range(1, 17):
context["iteration"] = i
user = self.mixin.map_for_scenario(context)
mapped_ids.append(user["user"]["id"])

View File

@ -59,7 +59,7 @@ class ScenarioRunnerHelpersTestCase(test.TestCase):
result
)
mock_context_manager.assert_called_once_with({"iteration": 13})
mock_context_manager.assert_called_once_with({"iteration": 14})
mock_map_for_scenario.assert_called_once_with()
def test_run_scenario_once_internal_logic(self):