Beispiel #1
0
    def test__prepare_data(self, mock_compress):

        mock_compress.side_effect = lambda i, **kv: i
        rows_num = 100
        load_duration = 1234.5
        full_duration = 6789.1
        sla = [{"foo": "bar"}]
        data = []
        for i in range(rows_num):
            atomic_actions = {
                "a1": i + 0.1,
                "a2": i + 0.8,
            }
            row = {
                "duration": i * 3.1,
                "idle_duration": i * 0.2,
                "error": [],
                "atomic_actions": atomic_actions,
                "scenario_output": {"errors": ["err"],
                                    "data": {"out_key": "out_value"}}
            }
            data.append(row)

        data[42]["error"] = ["foo", "bar", "spam"]
        data[52]["error"] = ["spam", "bar", "foo"]

        values_atomic_a1 = [i + 0.1 for i in range(rows_num)]
        values_atomic_a2 = [i + 0.8 for i in range(rows_num)]
        values_duration = [i * 3.1 for i in range(rows_num)]
        values_duration[42] = 0
        values_duration[52] = 0
        values_idle = [i * 0.2 for i in range(rows_num)]
        values_idle[42] = 0
        values_idle[52] = 0

        prepared_data = plot._prepare_data({"result": data,
                                            "load_duration": load_duration,
                                            "full_duration": full_duration,
                                            "sla": sla,
                                            "key": "foo_key"})
        self.assertEqual(2, len(prepared_data["errors"]))

        calls = [mock.call(values_atomic_a1),
                 mock.call(values_atomic_a2),
                 mock.call(values_duration),
                 mock.call(values_idle)]
        mock_compress.assert_has_calls(calls)

        expected_output = [{"key": "out_key",
                            "values": ["out_value"] * rows_num}]
        expected_output_errors = [(i, [e])
                                  for i, e in enumerate(["err"] * rows_num)]
        self.assertEqual({
            "total_durations": {"duration": values_duration,
                                "idle_duration": values_idle},
            "atomic_durations": {"a1": values_atomic_a1,
                                 "a2": values_atomic_a2},
            "errors": [{"iteration": 42,
                        "message": "bar",
                        "traceback": "spam",
                        "type": "foo"},
                       {"iteration": 52,
                        "message": "bar",
                        "traceback": "foo",
                        "type": "spam"}],
            "output": expected_output,
            "output_errors": expected_output_errors,
            "load_duration": load_duration,
            "full_duration": full_duration,
            "sla": sla,
        }, prepared_data)
Beispiel #2
0
    def test__prepare_data(self, mock_compress):

        mock_compress.side_effect = lambda i, **kv: i
        rows_num = 100
        load_duration = 1234.5
        full_duration = 6789.1
        sla = [{"foo": "bar"}]
        data = []
        for i in range(rows_num):
            atomic_actions = {
                "a1": i + 0.1,
                "a2": i + 0.8,
            }
            row = {
                "duration": i * 3.1,
                "idle_duration": i * 0.2,
                "error": [],
                "atomic_actions": atomic_actions,
                "scenario_output": {
                    "errors": ["err"],
                    "data": {
                        "out_key": "out_value"
                    }
                }
            }
            data.append(row)

        data[42]["error"] = ["foo", "bar", "spam"]
        data[52]["error"] = ["spam", "bar", "foo"]

        values_atomic_a1 = [i + 0.1 for i in range(rows_num)]
        values_atomic_a2 = [i + 0.8 for i in range(rows_num)]
        values_duration = [i * 3.1 for i in range(rows_num)]
        values_duration[42] = 0
        values_duration[52] = 0
        values_idle = [i * 0.2 for i in range(rows_num)]
        values_idle[42] = 0
        values_idle[52] = 0

        prepared_data = plot._prepare_data({
            "result": data,
            "load_duration": load_duration,
            "full_duration": full_duration,
            "sla": sla,
            "key": "foo_key"
        })
        self.assertEqual(2, len(prepared_data["errors"]))

        calls = [
            mock.call(values_atomic_a1),
            mock.call(values_atomic_a2),
            mock.call(values_duration),
            mock.call(values_idle)
        ]
        mock_compress.assert_has_calls(calls)

        expected_output = [{
            "key": "out_key",
            "values": ["out_value"] * rows_num
        }]
        expected_output_errors = [(i, [e])
                                  for i, e in enumerate(["err"] * rows_num)]
        self.assertEqual(
            {
                "total_durations": {
                    "duration": values_duration,
                    "idle_duration": values_idle
                },
                "atomic_durations": {
                    "a1": values_atomic_a1,
                    "a2": values_atomic_a2
                },
                "errors": [{
                    "iteration": 42,
                    "message": "bar",
                    "traceback": "spam",
                    "type": "foo"
                }, {
                    "iteration": 52,
                    "message": "bar",
                    "traceback": "foo",
                    "type": "spam"
                }],
                "output":
                expected_output,
                "output_errors":
                expected_output_errors,
                "load_duration":
                load_duration,
                "full_duration":
                full_duration,
                "sla":
                sla,
            }, prepared_data)
Beispiel #3
0
    def test__process_main_time(self):
        result = {
            "result": [
                {
                    "error": [],
                    "duration": 1,
                    "idle_duration": 2,
                    "atomic_actions": {},
                    "scenario_output": {"errors": [], "data": {}}
                },
                {
                    "error": ["some", "error", "occurred"],
                    "duration": 1,
                    "idle_duration": 1,
                    "atomic_actions": {},
                    "scenario_output": {"errors": [], "data": {}}
                },
                {
                    "error": [],
                    "duration": 2,
                    "idle_duration": 3,
                    "atomic_actions": {},
                    "scenario_output": {"errors": [], "data": {}}
                }
            ],
            "sla": "foo_sla",
            "load_duration": 1234.5,
            "full_duration": 6789.1
        }

        output = plot._process_main_duration(result,
                                             plot._prepare_data(result))

        self.assertEqual({
            "pie": [
                {"key": "success", "value": 2},
                {"key": "errors", "value": 1}
            ],
            "iter": [
                {
                    "key": "duration",
                    "values": [(1, 1.0), (2, 0), (3, 2.0)]
                },
                {
                    "key": "idle_duration",
                    "values": [(1, 2.0), (2, 0), (3, 3.0)]
                }
            ],
            "histogram": [
                {
                    "key": "task",
                    "method": "Square Root Choice",
                    "values": [{"x": 1.0, "y": 1.0}, {"x": 1.0, "y": 0.0}]
                },
                {
                    "key": "task",
                    "method": "Sturges Formula",
                    "values": [{"x": 1.0, "y": 1.0}, {"x": 1.0, "y": 0.0}]
                },
                {
                    "key": "task",
                    "method": "Rice Rule",
                    "values": [{"x": 1.0, "y": 1.0}, {"x": 1.0, "y": 0.0},
                               {"x": 1.0, "y": 0.0}]
                },
                {
                    "key": "task",
                    "method": "One Half",
                    "values": [{"x": 2.0, "y": 2.0}]
                }
            ]
        }, output)
Beispiel #4
0
    def test__process_main_time(self):
        result = {
            "result": [{
                "error": [],
                "duration": 1,
                "idle_duration": 2,
                "atomic_actions": {},
                "scenario_output": {
                    "errors": [],
                    "data": {}
                }
            }, {
                "error": ["some", "error", "occurred"],
                "duration": 1,
                "idle_duration": 1,
                "atomic_actions": {},
                "scenario_output": {
                    "errors": [],
                    "data": {}
                }
            }, {
                "error": [],
                "duration": 2,
                "idle_duration": 3,
                "atomic_actions": {},
                "scenario_output": {
                    "errors": [],
                    "data": {}
                }
            }],
            "sla":
            "foo_sla",
            "load_duration":
            1234.5,
            "full_duration":
            6789.1
        }

        output = plot._process_main_duration(result,
                                             plot._prepare_data(result))

        self.assertEqual(
            {
                "pie": [{
                    "key": "success",
                    "value": 2
                }, {
                    "key": "errors",
                    "value": 1
                }],
                "iter": [{
                    "key": "duration",
                    "values": [(1, 1.0), (2, 0), (3, 2.0)]
                }, {
                    "key": "idle_duration",
                    "values": [(1, 2.0), (2, 0), (3, 3.0)]
                }],
                "histogram": [
                    {
                        "key": "task",
                        "method": "Square Root Choice",
                        "values": [{
                            "x": 1.0,
                            "y": 1.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }]
                    }, {
                        "key": "task",
                        "method": "Sturges Formula",
                        "values": [{
                            "x": 1.0,
                            "y": 1.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }]
                    }, {
                        "key":
                        "task",
                        "method":
                        "Rice Rule",
                        "values": [{
                            "x": 1.0,
                            "y": 1.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }, {
                            "x": 1.0,
                            "y": 0.0
                        }]
                    }, {
                        "key": "task",
                        "method": "One Half",
                        "values": [{
                            "x": 2.0,
                            "y": 2.0
                        }]
                    }
                ]
            }, output)