diff options
Diffstat (limited to 'Tools/TestResultServer')
-rwxr-xr-x | Tools/TestResultServer/model/jsonresults.py | 21 | ||||
-rwxr-xr-x | Tools/TestResultServer/model/jsonresults_unittest.py | 30 |
2 files changed, 41 insertions, 10 deletions
diff --git a/Tools/TestResultServer/model/jsonresults.py b/Tools/TestResultServer/model/jsonresults.py index f5a0fde..d61a860 100755 --- a/Tools/TestResultServer/model/jsonresults.py +++ b/Tools/TestResultServer/model/jsonresults.py @@ -114,6 +114,7 @@ class JsonResults(object): Args: aggregated_json: aggregated json object. incremental_json: incremental json object. + num_runs: number of total runs to include. Returns: True if merge succeeds or @@ -140,6 +141,7 @@ class JsonResults(object): Args: aggregated_json: aggregated json object. incremental_json: incremental json object. + num_runs: number of total runs to include. Returns: True if merge succeeds or @@ -188,6 +190,7 @@ class JsonResults(object): aggregated_json: aggregated json object. incremental_json: incremental json object. incremental_index: index of the incremental json results to merge. + num_runs: number of total runs to include. """ for key in incremental_json.keys(): @@ -211,6 +214,7 @@ class JsonResults(object): Args: aggregated_json: aggregated json object. incremental_json: incremental json object. + num_runs: number of total runs to include. """ all_tests = (set(aggregated_json.iterkeys()) | @@ -230,7 +234,7 @@ class JsonResults(object): results, aggregated_test[JSON_RESULTS_RESULTS], num_runs) cls._insert_item_run_length_encoded( times, aggregated_test[JSON_RESULTS_TIMES], num_runs) - cls._normalize_results_json(test_name, aggregated_json) + cls._normalize_results_json(test_name, aggregated_json, num_runs) else: aggregated_json[test_name] = incremental_json[test_name] @@ -242,6 +246,7 @@ class JsonResults(object): Args: incremental_item: incremental run-length encoded results. aggregated_item: aggregated run-length encoded results. + num_runs: number of total runs to include. """ for item in incremental_item: @@ -252,23 +257,24 @@ class JsonResults(object): aggregated_item.insert(0, item) @classmethod - def _normalize_results_json(cls, test_name, aggregated_json): + def _normalize_results_json(cls, test_name, aggregated_json, num_runs): """ Prune tests where all runs pass or tests that no longer exist and - truncate all results to JSON_RESULTS_MAX_BUILDS. + truncate all results to num_runs. Args: test_name: Name of the test. aggregated_json: The JSON object with all the test results for this builder. + num_runs: number of total runs to include. """ aggregated_test = aggregated_json[test_name] aggregated_test[JSON_RESULTS_RESULTS] = \ cls._remove_items_over_max_number_of_builds( - aggregated_test[JSON_RESULTS_RESULTS]) + aggregated_test[JSON_RESULTS_RESULTS], num_runs) aggregated_test[JSON_RESULTS_TIMES] = \ cls._remove_items_over_max_number_of_builds( - aggregated_test[JSON_RESULTS_TIMES]) + aggregated_test[JSON_RESULTS_TIMES], num_runs) is_all_pass = cls._is_results_all_of_type( aggregated_test[JSON_RESULTS_RESULTS], JSON_RESULTS_PASS) @@ -285,20 +291,21 @@ class JsonResults(object): del aggregated_json[test_name] @classmethod - def _remove_items_over_max_number_of_builds(cls, encoded_list): + def _remove_items_over_max_number_of_builds(cls, encoded_list, num_runs): """Removes items from the run-length encoded list after the final item that exceeds the max number of builds to track. Args: encoded_results: run-length encoded results. An array of arrays, e.g. [[3,'A'],[1,'Q']] encodes AAAQ. + num_runs: number of total runs to include. """ num_builds = 0 index = 0 for result in encoded_list: num_builds = num_builds + result[0] index = index + 1 - if num_builds > JSON_RESULTS_MAX_BUILDS: + if num_builds >= num_runs: return encoded_list[:index] return encoded_list diff --git a/Tools/TestResultServer/model/jsonresults_unittest.py b/Tools/TestResultServer/model/jsonresults_unittest.py index c70b90c..eb8c864 100755 --- a/Tools/TestResultServer/model/jsonresults_unittest.py +++ b/Tools/TestResultServer/model/jsonresults_unittest.py @@ -118,11 +118,11 @@ class JsonResultsTest(unittest.TestCase): return JSON_RESULTS_PREFIX + json + JSON_RESULTS_SUFFIX - def _test_merge(self, aggregated_data, incremental_data, expected_data): + def _test_merge(self, aggregated_data, incremental_data, expected_data, max_builds=jsonresults.JSON_RESULTS_MAX_BUILDS): aggregated_results = self._make_test_json(aggregated_data) incremental_results = self._make_test_json(incremental_data) merged_results = JsonResults.merge(self._builder, - aggregated_results, incremental_results, jsonresults.JSON_RESULTS_MAX_BUILDS, + aggregated_results, incremental_results, max_builds, sort_keys=True) if expected_data: @@ -299,7 +299,7 @@ class JsonResultsTest(unittest.TestCase): # Expected results (["3", "2", "1"], [["001.html", "[201,\"P\"]", "[1,1],[200,0]"], ["002.html", "[1,\"P\"],[10,\"F\"]", "[11,0]"]])) - # Remove items from test results and times that exceeds the max number + # Remove items from test results and times that exceed the max number # of builds to track. max_builds = str(jsonresults.JSON_RESULTS_MAX_BUILDS) self._test_merge( @@ -310,6 +310,30 @@ class JsonResultsTest(unittest.TestCase): # Expected results (["3", "2", "1"], [["001.html", "[1,\"T\"],[" + max_builds + ",\"F\"]", "[1,1],[" + max_builds + ",0]"]])) + # Remove items from test results and times that exceed the max number + # of builds to track, using smaller threshold. + max_builds = str(jsonresults.JSON_RESULTS_MAX_BUILDS_SMALL) + self._test_merge( + # Aggregated results + (["2", "1"], [["001.html", "[" + max_builds + ",\"F\"],[1,\"I\"]", "[" + max_builds + ",0],[1,1]"]]), + # Incremental results + (["3"], [["001.html", "[1,\"T\"]", "[1,1]"]]), + # Expected results + (["3", "2", "1"], [["001.html", "[1,\"T\"],[" + max_builds + ",\"F\"]", "[1,1],[" + max_builds + ",0]"]]), + int(max_builds)) + + # Test that merging in a new result of the same type as the last result + # causes old results to fall off. + max_builds = str(jsonresults.JSON_RESULTS_MAX_BUILDS_SMALL) + self._test_merge( + # Aggregated results + (["2", "1"], [["001.html", "[" + max_builds + ",\"F\"],[1,\"N\"]", "[" + max_builds + ",0],[1,1]"]]), + # Incremental results + (["3"], [["001.html", "[1,\"F\"]", "[1,0]"]]), + # Expected results + (["3", "2", "1"], [["001.html", "[" + max_builds + ",\"F\"]", "[" + max_builds + ",0]"]]), + int(max_builds)) + # Get test name list only. Don't include non-test-list data and # of test result details. self._test_get_test_list( |