| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 import mock |
| 6 | 6 |
| 7 from common.pipeline_wrapper import pipeline_handlers | 7 from common.waterfall import failure_type |
| 8 from model.wf_analysis import WfAnalysis | 8 from model.wf_try_job import WfTryJob |
| 9 from waterfall import try_job_util | 9 from waterfall import start_try_job_on_demand_pipeline |
| 10 from waterfall.start_try_job_on_demand_pipeline import ( | 10 from waterfall.start_try_job_on_demand_pipeline import ( |
| 11 StartTryJobOnDemandPipeline) | 11 StartTryJobOnDemandPipeline) |
| 12 | 12 from waterfall.test import wf_testcase |
| 13 | 13 |
| 14 class StartTryJobOnDemandPipelineTest(testing.AppengineTestCase): | 14 class StartTryJobOnDemandPipelineTest(wf_testcase.WaterfallTestCase): |
| 15 app_module = pipeline_handlers._APP | 15 |
| 16 | 16 def testGetLastPassCurrentBuildIsNotFirstFailure(self): |
| 17 def _MockTryJobScheduling(self, requests): | 17 failure_info = { |
| 18 def Mocked_ScheduleTryJobIfNeeded(*args, **kwargs): | 18 'failed_steps': { |
| 19 requests.append((args, kwargs)) | 19 'a': { |
| 20 return {'compile': 'try-job-key'} | 20 'first_failure': 1, |
| 21 self.mock( | 21 'last_pass': 0 |
| 22 try_job_util, 'ScheduleTryJobIfNeeded', Mocked_ScheduleTryJobIfNeeded) | 22 } |
| 23 } |
| 24 } |
| 25 last_pass = start_try_job_on_demand_pipeline._GetLastPass( |
| 26 2, failure_info, failure_type.COMPILE) |
| 27 self.assertIsNone(last_pass) |
| 28 |
| 29 def testGetLastPassUnknownType(self): |
| 30 last_pass = start_try_job_on_demand_pipeline._GetLastPass( |
| 31 1, {}, failure_type.UNKNOWN) |
| 32 self.assertIsNone(last_pass) |
| 33 |
| 34 def testGetLastPassTestNoLastPass(self): |
| 35 try_job_type = failure_type.TEST |
| 36 failure_info = { |
| 37 'failure_type': try_job_type, |
| 38 'builds': { |
| 39 '0': { |
| 40 'blame_list': ['r0', 'r1'], |
| 41 'chromium_revision': 'r1' |
| 42 }, |
| 43 '1': { |
| 44 'blame_list': ['r2'], |
| 45 'chromium_revision': 'r2' |
| 46 } |
| 47 }, |
| 48 'failed_steps': { |
| 49 'a': { |
| 50 'first_failure': 1, |
| 51 'last_pass': 0, |
| 52 'tests': { |
| 53 'test1': { |
| 54 'first_failure': 1 |
| 55 } |
| 56 } |
| 57 } |
| 58 } |
| 59 } |
| 60 last_pass = start_try_job_on_demand_pipeline._GetLastPass( |
| 61 1, failure_info, try_job_type) |
| 62 self.assertIsNone(last_pass) |
| 63 |
| 64 def testGetSuspectsFromHeuristicResult(self): |
| 65 heuristic_result = { |
| 66 'failures': [ |
| 67 { |
| 68 'step_name': 'compile', |
| 69 'suspected_cls': [ |
| 70 { |
| 71 'revision': 'r1', |
| 72 }, |
| 73 { |
| 74 'revision': 'r2', |
| 75 }, |
| 76 ], |
| 77 }, |
| 78 ] |
| 79 } |
| 80 expected_suspected_revisions = ['r1', 'r2'] |
| 81 self.assertEqual( |
| 82 expected_suspected_revisions, |
| 83 start_try_job_on_demand_pipeline._GetSuspectsFromHeuristicResult( |
| 84 heuristic_result)) |
| 23 | 85 |
| 24 def testNotScheduleTryJobIfBuildNotCompleted(self): | 86 def testNotScheduleTryJobIfBuildNotCompleted(self): |
| 25 requests = [] | 87 pipeline = start_try_job_on_demand_pipeline.StartTryJobOnDemandPipeline() |
| 26 self._MockTryJobScheduling(requests) | 88 result = pipeline.run( |
| 89 'm', 'b', 1, {}, {}, {}, False, False) |
| 90 self.assertEqual(list(result), []) |
| 91 |
| 92 @mock.patch.object(start_try_job_on_demand_pipeline, 'try_job_util') |
| 93 def testNotScheduleTryJobIfDontNeedTryJob(self, mock_other): |
| 94 mock_other.NeedANewTryJob.return_value = False |
| 95 pipeline = start_try_job_on_demand_pipeline.StartTryJobOnDemandPipeline() |
| 96 result = pipeline.run( |
| 97 'm', 'b', 1, {}, {}, {}, True, False) |
| 98 self.assertEqual(list(result), []) |
| 99 |
| 100 @mock.patch.object(start_try_job_on_demand_pipeline, 'try_job_util') |
| 101 def testNotScheduleTryJobIfUnsupportedFailureType(self, mock_other): |
| 102 mock_other.NeedANewTryJob.return_value = True |
| 103 try_job_type = failure_type.UNKNOWN |
| 104 failure_info = { |
| 105 'failure_type': try_job_type, |
| 106 'builds': { |
| 107 '0': { |
| 108 'blame_list': ['r0', 'r1'], |
| 109 'chromium_revision': 'r1' |
| 110 }, |
| 111 '1': { |
| 112 'blame_list': ['r2'], |
| 113 'chromium_revision': 'r2' |
| 114 } |
| 115 }, |
| 116 'failed_steps': { |
| 117 'a': { |
| 118 'first_failure': 1, |
| 119 'last_pass': 0 |
| 120 } |
| 121 } |
| 122 } |
| 123 pipeline = start_try_job_on_demand_pipeline.StartTryJobOnDemandPipeline() |
| 124 result = pipeline.run( |
| 125 'm', 'b', 1, failure_info, {}, {}, True, False) |
| 126 self.assertEqual(list(result), []) |
| 127 |
| 128 @mock.patch.object(start_try_job_on_demand_pipeline, 'try_job_util') |
| 129 def testCompileTryJob(self, mock_other): |
| 130 |
| 131 master_name = 'm' |
| 132 builder_name = 'b' |
| 133 build_number = 1 |
| 134 try_job_type = failure_type.COMPILE |
| 135 failure_info = { |
| 136 'failure_type': try_job_type, |
| 137 'builds': { |
| 138 '0': { |
| 139 'blame_list': ['r0', 'r1'], |
| 140 'chromium_revision': 'r1' |
| 141 }, |
| 142 '1': { |
| 143 'blame_list': ['r2'], |
| 144 'chromium_revision': 'r2' |
| 145 } |
| 146 }, |
| 147 'failed_steps': { |
| 148 'compile': { |
| 149 'first_failure': 1, |
| 150 'last_pass': 0 |
| 151 } |
| 152 } |
| 153 } |
| 154 good_revision = 'r1' |
| 155 bad_revision = 'r2' |
| 156 WfTryJob.Create('m', 'b', 1).put() |
| 157 |
| 158 mock_other.NeedANewTryJob.return_value = True |
| 159 mock_other.GetFailedTargetsFromSignals.return_value = {} |
| 160 |
| 161 self.MockPipeline( |
| 162 start_try_job_on_demand_pipeline.ScheduleCompileTryJobPipeline, |
| 163 'try_job_id', |
| 164 expected_args=[ |
| 165 master_name, builder_name, build_number, good_revision, |
| 166 bad_revision, try_job_type, {}, []], |
| 167 expected_kwargs={}) |
| 168 self.MockPipeline( |
| 169 start_try_job_on_demand_pipeline.MonitorTryJobPipeline, |
| 170 'try_job_result', |
| 171 expected_args=[ |
| 172 master_name, builder_name, build_number, try_job_type, 'try_job_id' |
| 173 ], |
| 174 expected_kwargs={}) |
| 175 self.MockPipeline( |
| 176 start_try_job_on_demand_pipeline.IdentifyTryJobCulpritPipeline, |
| 177 'final_result', |
| 178 expected_args=[ |
| 179 master_name, builder_name, build_number, ['r2'], try_job_type, |
| 180 'try_job_id', 'try_job_result'], |
| 181 expected_kwargs={}) |
| 182 |
| 27 pipeline = StartTryJobOnDemandPipeline() | 183 pipeline = StartTryJobOnDemandPipeline() |
| 28 self.assertFalse(pipeline.run(None, None, False, False, None)) | 184 result = pipeline.run( |
| 29 self.assertEqual(0, len(requests)) | 185 'm', 'b', 1, failure_info, {}, {}, True, False) |
| 30 | 186 self.assertNotEqual(list(result), []) |
| 31 def testTryJobScheduled(self): | 187 |
| 32 master_name, builder_name, build_number = 'm', 'b', 123 | 188 @mock.patch.object(start_try_job_on_demand_pipeline, 'try_job_util') |
| 33 WfAnalysis.Create(master_name, builder_name, build_number).put() | 189 def testTestTryJob(self, mock_other): |
| 34 failure_info = { | 190 |
| 35 'master_name': master_name, | 191 master_name = 'm' |
| 36 'builder_name': builder_name, | 192 builder_name = 'b' |
| 37 'build_number': build_number, | 193 build_number = 1 |
| 38 } | 194 try_job_type = failure_type.TEST |
| 39 | 195 failure_info = { |
| 40 requests = [] | 196 'failure_type': try_job_type, |
| 41 self._MockTryJobScheduling(requests) | 197 'builds': { |
| 198 '0': { |
| 199 'blame_list': ['r0', 'r1'], |
| 200 'chromium_revision': 'r1' |
| 201 }, |
| 202 '1': { |
| 203 'blame_list': ['r2'], |
| 204 'chromium_revision': 'r2' |
| 205 } |
| 206 }, |
| 207 'failed_steps': { |
| 208 'a': { |
| 209 'first_failure': 1, |
| 210 'last_pass': 0, |
| 211 'tests': { |
| 212 'test1': { |
| 213 'first_failure': 1, |
| 214 'last_pass': 0 |
| 215 } |
| 216 } |
| 217 }, |
| 218 'b': { |
| 219 'first_failure': 0, |
| 220 'tests': { |
| 221 'b_test1': { |
| 222 'first_failure': 0 |
| 223 } |
| 224 } |
| 225 } |
| 226 } |
| 227 } |
| 228 good_revision = 'r1' |
| 229 bad_revision = 'r2' |
| 230 |
| 231 mock_other.NeedANewTryJob.return_value = True |
| 232 mock_other.GetFailedTargetsFromSignals.return_value = {} |
| 233 |
| 234 self.MockPipeline( |
| 235 start_try_job_on_demand_pipeline.ScheduleTestTryJobPipeline, |
| 236 'try_job_id', |
| 237 expected_args=[ |
| 238 master_name, builder_name, build_number, good_revision, |
| 239 bad_revision, try_job_type, 'targeted_tests', []], |
| 240 expected_kwargs={}) |
| 241 self.MockPipeline( |
| 242 start_try_job_on_demand_pipeline.MonitorTryJobPipeline, |
| 243 'try_job_result', |
| 244 expected_args=[ |
| 245 master_name, builder_name, build_number, try_job_type, 'try_job_id' |
| 246 ], |
| 247 expected_kwargs={}) |
| 248 self.MockPipeline( |
| 249 start_try_job_on_demand_pipeline.IdentifyTryJobCulpritPipeline, |
| 250 'final_result', |
| 251 expected_args=[ |
| 252 master_name, builder_name, build_number, ['r2'], try_job_type, |
| 253 'try_job_id', 'try_job_result'], |
| 254 expected_kwargs={}) |
| 42 | 255 |
| 43 pipeline = StartTryJobOnDemandPipeline() | 256 pipeline = StartTryJobOnDemandPipeline() |
| 44 self.assertTrue(pipeline.run(failure_info, None, True, False, None)) | 257 result = pipeline.run( |
| 45 self.assertEqual(1, len(requests)) | 258 'm', 'b', 1, failure_info, {}, {}, True, False) |
| 46 self.assertEqual( | 259 WfTryJob.Create('m', 'b', 1).put() |
| 47 {'compile': 'try-job-key'}, | 260 self.assertNotEqual(list(result), []) |
| 48 WfAnalysis.Get( | |
| 49 master_name, builder_name, build_number).failure_result_map) | |
| OLD | NEW |