| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from testing_utils import testing | 5 from testing_utils import testing |
| 6 | 6 |
| 7 from common.git_repository import GitRepository | 7 from common.git_repository import GitRepository |
| 8 from common.waterfall import failure_type | 8 from common.waterfall import failure_type |
| 9 from model import analysis_status | 9 from model import analysis_status |
| 10 from model import result_status | 10 from model import result_status |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 'Test1': { | 924 'Test1': { |
| 925 'revision': 'rev1' | 925 'revision': 'rev1' |
| 926 } | 926 } |
| 927 } | 927 } |
| 928 } | 928 } |
| 929 } | 929 } |
| 930 | 930 |
| 931 self.assertEqual(culprit_map, expected_culprit_map) | 931 self.assertEqual(culprit_map, expected_culprit_map) |
| 932 self.assertEqual(failed_revisions, ['rev1']) | 932 self.assertEqual(failed_revisions, ['rev1']) |
| 933 | 933 |
| 934 def testReturnNoneIfNoTryJob(self): |
| 935 master_name = 'm' |
| 936 builder_name = 'b' |
| 937 build_number = 8 |
| 938 |
| 939 try_job = WfTryJob.Create(master_name, builder_name, build_number).put() |
| 940 pipeline = IdentifyTryJobCulpritPipeline() |
| 941 culprit = pipeline.run(master_name, builder_name, build_number, ['rev1'], |
| 942 failure_type.TEST, None, None) |
| 943 self.assertIsNone(culprit) |
| 944 |
| 945 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
| 946 self.assertEqual(try_job.test_results, []) |
| 947 self.assertEqual(try_job.status, analysis_status.COMPLETED) |
| 948 |
| 949 |
| 934 def testNotifyCulprits(self): | 950 def testNotifyCulprits(self): |
| 935 instances = [] | 951 instances = [] |
| 936 class Mocked_SendNotificationForCulpritPipeline(object): | 952 class Mocked_SendNotificationForCulpritPipeline(object): |
| 937 def __init__(self, *args): | 953 def __init__(self, *args): |
| 938 self.args = args | 954 self.args = args |
| 939 self.started = False | 955 self.started = False |
| 940 instances.append(self) | 956 instances.append(self) |
| 941 | 957 |
| 942 def start(self): | 958 def start(self): |
| 943 self.started = True | 959 self.started = True |
| 944 | 960 |
| 945 self.mock( | 961 self.mock( |
| 946 identify_try_job_culprit_pipeline, 'SendNotificationForCulpritPipeline', | 962 identify_try_job_culprit_pipeline, 'SendNotificationForCulpritPipeline', |
| 947 Mocked_SendNotificationForCulpritPipeline) | 963 Mocked_SendNotificationForCulpritPipeline) |
| 948 | 964 |
| 949 culprits = { | 965 culprits = { |
| 950 'r1': { | 966 'r1': { |
| 951 'repo_name': 'chromium', | 967 'repo_name': 'chromium', |
| 952 'revision': 'r1', | 968 'revision': 'r1', |
| 953 } | 969 } |
| 954 } | 970 } |
| 971 heuristic_cls = [('chromium', 'r1')] |
| 955 | 972 |
| 956 identify_try_job_culprit_pipeline._NotifyCulprits('m', 'b', 1, culprits) | 973 identify_try_job_culprit_pipeline._NotifyCulprits( |
| 974 'm', 'b', 1, culprits, heuristic_cls, None) |
| 957 self.assertEqual(1, len(instances)) | 975 self.assertEqual(1, len(instances)) |
| 958 self.assertTrue(instances[0].started) | 976 self.assertTrue(instances[0].started) |
| 959 | 977 |
| 960 def testReturnNoneIfNoTryJob(self): | 978 def testGetSuspectedCLFoundByHeuristicForCompile(self): |
| 961 master_name = 'm' | 979 master_name = 'm' |
| 962 builder_name = 'b' | 980 builder_name = 'b' |
| 963 build_number = 8 | 981 build_number = 9 |
| 982 analysis = WfAnalysis.Create(master_name, builder_name, build_number) |
| 983 analysis.result = { |
| 984 'failures': [ |
| 985 { |
| 986 'step_name': 'other_step', |
| 987 'suspected_cls': [ |
| 988 { |
| 989 'repo_name': 'chromium', |
| 990 'revision': 'rev1' |
| 991 } |
| 992 ] |
| 993 }, |
| 994 { |
| 995 'step_name': 'compile', |
| 996 'suspected_cls': [ |
| 997 { |
| 998 'repo_name': 'chromium', |
| 999 'revision': 'rev1' |
| 1000 } |
| 1001 ] |
| 1002 } |
| 1003 ] |
| 1004 } |
| 1005 analysis.put() |
| 964 | 1006 |
| 965 try_job = WfTryJob.Create(master_name, builder_name, build_number).put() | 1007 cl = (identify_try_job_culprit_pipeline.\ |
| 966 pipeline = IdentifyTryJobCulpritPipeline() | 1008 _GetSuspectedCLFoundByHeuristicForCompile(analysis)) |
| 967 culprit = pipeline.run(master_name, builder_name, build_number, ['rev1'], | |
| 968 failure_type.TEST, None, None) | |
| 969 self.assertIsNone(culprit) | |
| 970 | 1009 |
| 971 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 1010 expected_cl = { |
| 972 self.assertEqual(try_job.test_results, []) | 1011 'repo_name': 'chromium', |
| 973 self.assertEqual(try_job.status, analysis_status.COMPLETED) | 1012 'revision': 'rev1' |
| 1013 } |
| 1014 |
| 1015 self.assertEqual(cl, expected_cl) |
| 1016 |
| 1017 def testGetSuspectedCLFoundByHeuristicForCompileReturnNoneIfNoAnalysis(self): |
| 1018 self.assertIsNone(identify_try_job_culprit_pipeline.\ |
| 1019 _GetSuspectedCLFoundByHeuristicForCompile(None)) |
| 1020 |
| 1021 def testGetSuspectedCLFoundByHeuristicForCompileReturnNone(self): |
| 1022 master_name = 'm' |
| 1023 builder_name = 'b' |
| 1024 build_number = 9 |
| 1025 analysis = WfAnalysis.Create(master_name, builder_name, build_number) |
| 1026 analysis.result = { |
| 1027 'failures': [ |
| 1028 { |
| 1029 'step_name': 'other_step', |
| 1030 'suspected_cls': [ |
| 1031 { |
| 1032 'repo_name': 'chromium', |
| 1033 'revision': 'rev1' |
| 1034 } |
| 1035 ] |
| 1036 } |
| 1037 ] |
| 1038 } |
| 1039 analysis.put() |
| 1040 |
| 1041 self.assertIsNone(identify_try_job_culprit_pipeline.\ |
| 1042 _GetSuspectedCLFoundByHeuristicForCompile(analysis)) |
| 1043 |
| 1044 def testNotifyCulpritsIfHeuristicFoundCulpritForCompile(self): |
| 1045 master_name = 'm' |
| 1046 builder_name = 'b' |
| 1047 build_number = 9 |
| 1048 heuristic_cls = [('chromium', 'rev1')] |
| 1049 compile_suspected_cl = { |
| 1050 'repo_name': 'chromium', |
| 1051 'revision': 'rev1' |
| 1052 } |
| 1053 |
| 1054 instances = [] |
| 1055 class Mocked_SendNotificationForCulpritPipeline(object): |
| 1056 def __init__(self, *args): |
| 1057 self.args = args |
| 1058 self.started = False |
| 1059 instances.append(self) |
| 1060 |
| 1061 def start(self): |
| 1062 self.started = True |
| 1063 |
| 1064 self.mock( |
| 1065 identify_try_job_culprit_pipeline, 'SendNotificationForCulpritPipeline', |
| 1066 Mocked_SendNotificationForCulpritPipeline) |
| 1067 |
| 1068 identify_try_job_culprit_pipeline._NotifyCulprits( |
| 1069 master_name, builder_name, build_number, None, |
| 1070 heuristic_cls, compile_suspected_cl) |
| 1071 self.assertEqual(1, len(instances)) |
| 1072 self.assertTrue(instances[0].started) |
| OLD | NEW |