diff --git a/rally/cmd/commands/task.py b/rally/cmd/commands/task.py index 1aa0f32ea2..891d80d326 100644 --- a/rally/cmd/commands/task.py +++ b/rally/cmd/commands/task.py @@ -214,11 +214,11 @@ class TaskCommands(object): print("Benchmarking... This can take a while...\n") print("To track task status use:\n") print("\trally task status\n\tor\n\trally task detailed\n") + if do_use: + self.use(task["uuid"]) api.Task.start(deployment, input_task, task=task, abort_on_sla_failure=abort_on_sla_failure) self.detailed(task_id=task["uuid"]) - if do_use: - self.use(task["uuid"]) except exceptions.InvalidConfigException: return(1) @@ -420,7 +420,6 @@ class TaskCommands(object): :param task_id: Task uuid """ - results = [{"key": x["key"], "result": x["data"]["raw"], "sla": x["data"]["sla"], "load_duration": x["data"]["load_duration"], @@ -430,7 +429,8 @@ class TaskCommands(object): if results: print(json.dumps(results, sort_keys=True, indent=4)) else: - print(_("The task %s can not be found") % task_id) + print(_("The task %s is still running, results will become " + "available when it is finished.") % task_id) return(1) @cliutils.args("--deployment", type=str, dest="deployment", diff --git a/tests/unit/cmd/commands/test_task.py b/tests/unit/cmd/commands/test_task.py index 42d910cd42..02bbbdaf97 100644 --- a/tests/unit/cmd/commands/test_task.py +++ b/tests/unit/cmd/commands/test_task.py @@ -303,16 +303,19 @@ class TaskCommandsTestCase(test.TestCase): mock_json.call_args[1]) mock_get.assert_called_once_with(task_id) + @mock.patch("rally.cmd.commands.task.sys.stdout") @mock.patch("rally.cmd.commands.task.objects.Task.get") - def test_invalid_results(self, mock_get): + def test_results_no_data(self, mock_get, mock_stdout): task_id = "foo_task_id" - data = [] - mock_results = mock.Mock(return_value=data) + mock_results = mock.Mock(return_value=[]) mock_get.return_value = mock.Mock(get_results=mock_results) result = self.task.results(task_id) mock_get.assert_called_once_with(task_id) self.assertEqual(1, result) + expected_out = ("The task %s is still running, results will become" + " available when it is finished." % task_id) + mock_stdout.write.assert_has_calls([mock.call(expected_out)]) @mock.patch("rally.cmd.commands.task.jsonschema.validate", return_value=None)