예제 #1
0
파일: engine.py 프로젝트: frobware/rally
    def consume_results(self, key, task, is_done, runner):
        """Consume scenario runner results from queue and send them to db.

        Has to be run from different thread simultaneously with the runner.run
        method.

        :param key: Scenario identifier
        :param task: Running task
        :param is_done: Event which is set from the runner thread after the
                        runner finishes it's work.
        :param runner: ScenarioRunner object that was used to run a task
        """
        results = []
        sla_checker = base_sla.SLAChecker(key["kw"])
        while True:
            if runner.result_queue:
                result = runner.result_queue.popleft()
                results.append(result)
                success = sla_checker.add_iteration(result)
                if self.abort_on_sla_failure and not success:
                    runner.abort()
            elif is_done.isSet():
                break
            else:
                time.sleep(0.1)

        task.append_results(
            key, {
                "raw": results,
                "load_duration": self.duration,
                "full_duration": self.full_duration,
                "sla": sla_checker.results()
            })
예제 #2
0
 def test_set_aborted(self):
     sla_checker = base.SLAChecker({"sla": {}})
     self.assertEqual([], sla_checker.results())
     sla_checker.set_aborted()
     self.assertEqual([{
         "criterion": "aborted_on_sla",
         "success": False,
         "detail": "Task was aborted due to SLA failure(s)."
     }], sla_checker.results())
예제 #3
0
 def test_set_unexpected_failure(self):
     exc = "error;("
     sla_checker = base.SLAChecker({"sla": {}})
     self.assertEqual([], sla_checker.results())
     sla_checker.set_unexpected_failure(exc)
     self.assertEqual([{
         "criterion": "something_went_wrong",
         "success": False,
         "detail": "Unexpected error: %s" % exc
     }], sla_checker.results())
예제 #4
0
    def test_add_iteration_and_results(self):
        sla_checker = base.SLAChecker({"sla": {"test_criterion": 42}})

        iteration = {"key": {"name": "fake", "pos": 0}, "data": 42}
        self.assertTrue(sla_checker.add_iteration(iteration["data"]))
        expected_result = [{
            "criterion": "test_criterion",
            "detail": "detail",
            "success": True
        }]
        self.assertEqual(expected_result, sla_checker.results())

        iteration["data"] = 43
        self.assertFalse(sla_checker.add_iteration(iteration["data"]))
        expected_result = [{
            "criterion": "test_criterion",
            "detail": "detail",
            "success": False
        }]
        self.assertEqual(expected_result, sla_checker.results())