diff options
Diffstat (limited to 'buildscripts/tests/util/test_teststats.py')
| -rw-r--r-- | buildscripts/tests/util/test_teststats.py | 110 |
1 files changed, 109 insertions, 1 deletions
diff --git a/buildscripts/tests/util/test_teststats.py b/buildscripts/tests/util/test_teststats.py index ebba930d032..9e72d87a737 100644 --- a/buildscripts/tests/util/test_teststats.py +++ b/buildscripts/tests/util/test_teststats.py @@ -2,8 +2,12 @@ import datetime import unittest +from json import JSONDecodeError +from unittest.mock import patch from mock import Mock +from mock.mock import MagicMock +from requests import Session import buildscripts.util.teststats as under_test @@ -21,6 +25,60 @@ class NormalizeTestNameTest(unittest.TestCase): under_test.normalize_test_name("\\home\\user\\test.js")) +class TestHistoricTestInfo(unittest.TestCase): + def test_total_test_runtime_not_passing_test_no_hooks(self): + test_info = under_test.HistoricTestInfo( + test_name='jstests/test.js', + num_pass=0, + avg_duration=0.0, + hooks=[], + ) + + self.assertEqual(0.0, test_info.total_test_runtime()) + + def test_total_test_runtime_not_passing_test_with_hooks(self): + test_info = under_test.HistoricTestInfo( + test_name='jstests/test.js', + num_pass=0, + avg_duration=0.0, + hooks=[ + under_test.HistoricHookInfo( + hook_id='test:hook', + num_pass=10, + avg_duration=5.0, + ), + ], + ) + + self.assertEqual(0.0, test_info.total_test_runtime()) + + def test_total_test_runtime_passing_test_no_hooks(self): + test_info = under_test.HistoricTestInfo( + test_name='jstests/test.js', + num_pass=10, + avg_duration=23.0, + hooks=[], + ) + + self.assertEqual(23.0, test_info.total_test_runtime()) + + def test_total_test_runtime_passing_test_with_hooks(self): + test_info = under_test.HistoricTestInfo( + test_name='jstests/test.js', + num_pass=10, + avg_duration=23.0, + hooks=[ + under_test.HistoricHookInfo( + hook_id='test:hook', + num_pass=10, + avg_duration=5.0, + ), + ], + ) + + self.assertEqual(28.0, test_info.total_test_runtime()) + + class TestHistoricTaskData(unittest.TestCase): def test_no_hooks(self): evg_results = [ @@ -80,7 +138,7 @@ class TestHistoricTaskData(unittest.TestCase): @staticmethod def _make_evg_result(test_file="dir/test1.js", num_pass=0, duration=0): return Mock( - test_file=test_file, + test_name=test_file, task_name="task1", variant="variant1", distro="distro1", @@ -89,3 +147,53 @@ class TestHistoricTaskData(unittest.TestCase): num_fail=0, avg_duration_pass=duration, ) + + @patch.object(Session, 'get') + def test_get_stats_from_s3_returns_data(self, mock_get): + mock_response = MagicMock() + mock_response.json.return_value = [ + { + "test_name": "jstests/noPassthroughWithMongod/geo_near_random1.js", + "num_pass": 74, + "num_fail": 0, + "avg_duration_pass": 23.16216216216216, + "max_duration_pass": 27.123, + }, + { + "test_name": "shell_advance_cluster_time:ValidateCollections", + "num_pass": 74, + "num_fail": 0, + "avg_duration_pass": 1.662162162162162, + "max_duration_pass": 100.0987, + }, + ] + mock_get.return_value = mock_response + + result = under_test.HistoricTaskData.get_stats_from_s3("project", "task", "variant") + + self.assertEqual(result, [ + under_test.HistoricalTestInformation( + test_name="jstests/noPassthroughWithMongod/geo_near_random1.js", + num_pass=74, + num_fail=0, + avg_duration_pass=23.16216216216216, + max_duration_pass=27.123, + ), + under_test.HistoricalTestInformation( + test_name="shell_advance_cluster_time:ValidateCollections", + num_pass=74, + num_fail=0, + avg_duration_pass=1.662162162162162, + max_duration_pass=100.0987, + ), + ]) + + @patch.object(Session, 'get') + def test_get_stats_from_s3_json_decode_error(self, mock_get): + mock_response = MagicMock() + mock_response.json.side_effect = JSONDecodeError("msg", "doc", 0) + mock_get.return_value = mock_response + + result = under_test.HistoricTaskData.get_stats_from_s3("project", "task", "variant") + + self.assertEqual(result, []) |
