| 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 |
| 974 identify_try_job_culprit_pipeline._NotifyCulprits( |
| 975 'm', 'b', 1, culprits, heuristic_cls, None) |
| 957 self.assertEqual(1, len(instances)) | 976 self.assertEqual(1, len(instances)) |
| 958 self.assertTrue(instances[0].started) | 977 self.assertTrue(instances[0].started) |
| 959 | 978 |
| 960 def testReturnNoneIfNoTryJob(self): | 979 def testGetSuspectedCLFoundByHeuristicForCompile(self): |
| 961 master_name = 'm' | 980 master_name = 'm' |
| 962 builder_name = 'b' | 981 builder_name = 'b' |
| 963 build_number = 8 | 982 build_number = 9 |
| 983 analysis = WfAnalysis.Create(master_name, builder_name, build_number) |
| 984 analysis.result = { |
| 985 'failures': [ |
| 986 { |
| 987 'step_name': 'other_step', |
| 988 'suspected_cls': [ |
| 989 { |
| 990 'repo_name': 'chromium', |
| 991 'revision': 'rev1' |
| 992 } |
| 993 ] |
| 994 }, |
| 995 { |
| 996 'step_name': 'compile', |
| 997 'suspected_cls': [ |
| 998 { |
| 999 'repo_name': 'chromium', |
| 1000 'revision': 'rev1' |
| 1001 } |
| 1002 ] |
| 1003 } |
| 1004 ] |
| 1005 } |
| 1006 analysis.put() |
| 964 | 1007 |
| 965 try_job = WfTryJob.Create(master_name, builder_name, build_number).put() | 1008 cl = (identify_try_job_culprit_pipeline.\ |
| 966 pipeline = IdentifyTryJobCulpritPipeline() | 1009 _GetSuspectedCLFoundByHeuristicForCompile(analysis)) |
| 967 culprit = pipeline.run(master_name, builder_name, build_number, ['rev1'], | |
| 968 failure_type.TEST, None, None) | |
| 969 self.assertIsNone(culprit) | |
| 970 | 1010 |
| 971 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 1011 expected_cl = { |
| 972 self.assertEqual(try_job.test_results, []) | 1012 'repo_name': 'chromium', |
| 973 self.assertEqual(try_job.status, analysis_status.COMPLETED) | 1013 'revision': 'rev1' |
| 1014 } |
| 1015 |
| 1016 self.assertEqual(cl, expected_cl) |
| 1017 |
| 1018 |
| 1019 def testGetSuspectedCLFoundByHeuristicForCompileReturnNoneIfNoAnalysis(self): |
| 1020 self.assertIsNone(identify_try_job_culprit_pipeline.\ |
| 1021 _GetSuspectedCLFoundByHeuristicForCompile(None)) |
| 1022 |
| 1023 |
| 1024 def testGetSuspectedCLFoundByHeuristicForCompileReturnNone(self): |
| 1025 master_name = 'm' |
| 1026 builder_name = 'b' |
| 1027 build_number = 9 |
| 1028 analysis = WfAnalysis.Create(master_name, builder_name, build_number) |
| 1029 analysis.result = { |
| 1030 'failures': [ |
| 1031 { |
| 1032 'step_name': 'other_step', |
| 1033 'suspected_cls': [ |
| 1034 { |
| 1035 'repo_name': 'chromium', |
| 1036 'revision': 'rev1' |
| 1037 } |
| 1038 ] |
| 1039 } |
| 1040 ] |
| 1041 } |
| 1042 analysis.put() |
| 1043 |
| 1044 self.assertIsNone(identify_try_job_culprit_pipeline.\ |
| 1045 _GetSuspectedCLFoundByHeuristicForCompile(analysis)) |
| 1046 |
| 1047 |
| 1048 |
| 1049 def testNotifyCulpritsIfHeuristicFoundCulpritForCompile(self): |
| 1050 master_name = 'm' |
| 1051 builder_name = 'b' |
| 1052 build_number = 9 |
| 1053 heuristic_cls = [('chromium', 'rev1')] |
| 1054 compile_suspected_cl = { |
| 1055 'repo_name': 'chromium', |
| 1056 'revision': 'rev1' |
| 1057 } |
| 1058 |
| 1059 instances = [] |
| 1060 class Mocked_SendNotificationForCulpritPipeline(object): |
| 1061 def __init__(self, *args): |
| 1062 self.args = args |
| 1063 self.started = False |
| 1064 instances.append(self) |
| 1065 |
| 1066 def start(self): |
| 1067 self.started = True |
| 1068 |
| 1069 self.mock( |
| 1070 identify_try_job_culprit_pipeline, 'SendNotificationForCulpritPipeline', |
| 1071 Mocked_SendNotificationForCulpritPipeline) |
| 1072 |
| 1073 identify_try_job_culprit_pipeline._NotifyCulprits( |
| 1074 master_name, builder_name, build_number, None, |
| 1075 heuristic_cls, compile_suspected_cl) |
| 1076 self.assertEqual(1, len(instances)) |
| 1077 self.assertTrue(instances[0].started) |
| OLD | NEW |