| 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 model import wf_analysis_status | 8 from model import wf_analysis_status |
| 9 from model.wf_try_job import WfTryJob | 9 from model.wf_try_job import WfTryJob |
| 10 from waterfall.identify_try_job_culprit_pipeline import( | 10 from waterfall.identify_try_job_culprit_pipeline import( |
| 11 IdentifyTryJobCulpritPipeline) | 11 IdentifyTryJobCulpritPipeline) |
| 12 | 12 |
| 13 | 13 |
| 14 class IdentifyTryJobCulpritPipelineTest(testing.AppengineTestCase): | 14 class IdentifyTryJobCulpritPipelineTest(testing.AppengineTestCase): |
| 15 | 15 |
| 16 def _MockGetChangeLog(self, revision): | 16 def _MockGetChangeLog(self, revision): |
| 17 class MockedChangeLog(object): | 17 class MockedChangeLog(object): |
| 18 | 18 |
| 19 def __init__(self, commit_position, code_review_url): | 19 def __init__(self, commit_position, code_review_url): |
| 20 self.commit_position = commit_position | 20 self.commit_position = commit_position |
| 21 self.code_review_url = code_review_url | 21 self.code_review_url = code_review_url |
| 22 | 22 |
| 23 mock_change_logs = {} | 23 mock_change_logs = {} |
| 24 mock_change_logs['rev2'] = MockedChangeLog('2', 'url_2') | 24 mock_change_logs['rev2'] = MockedChangeLog('2', 'url_2') |
| 25 return mock_change_logs.get(revision) | 25 return mock_change_logs.get(revision) |
| 26 | 26 |
| 27 def testIdentifyCulpritForCompileReturnNoneIfNoCompileResult(self): | 27 def testGetFailedRevisionFromResultsDict(self): |
| 28 self.assertIsNone( |
| 29 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromResultsDict({})) |
| 30 self.assertEqual( |
| 31 None, |
| 32 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromResultsDict( |
| 33 {'rev1': 'passed'})) |
| 34 self.assertEqual( |
| 35 'rev1', |
| 36 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromResultsDict( |
| 37 {'rev1': 'failed'})) |
| 38 self.assertEqual( |
| 39 'rev2', |
| 40 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromResultsDict( |
| 41 {'rev1': 'passed', 'rev2': 'failed'})) |
| 42 |
| 43 def testGetFailedRevisionFromCompileResult(self): |
| 44 self.assertIsNone( |
| 45 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromCompileResult( |
| 46 None)) |
| 47 self.assertIsNone( |
| 48 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromCompileResult( |
| 49 {'report': {}})) |
| 50 self.assertIsNone( |
| 51 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromCompileResult( |
| 52 { |
| 53 'report': { |
| 54 'result': { |
| 55 'rev1': 'passed' |
| 56 } |
| 57 } |
| 58 })) |
| 59 self.assertEqual( |
| 60 'rev2', |
| 61 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromCompileResult( |
| 62 { |
| 63 'report': { |
| 64 'result': { |
| 65 'rev1': 'passed', |
| 66 'rev2': 'failed' |
| 67 } |
| 68 } |
| 69 })) |
| 70 self.assertEqual( |
| 71 'rev2', |
| 72 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromCompileResult( |
| 73 { |
| 74 'report': [ |
| 75 ['rev1', 'passed'], |
| 76 ['rev2', 'failed'] |
| 77 ] |
| 78 })) |
| 79 |
| 80 def testGetCulpritFromFailedRevision(self): |
| 81 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) |
| 82 self.assertIsNone( |
| 83 IdentifyTryJobCulpritPipeline._GetCulpritFromFailedRevision(None)) |
| 84 self.assertIsNone( |
| 85 IdentifyTryJobCulpritPipeline._GetCulpritFromFailedRevision( |
| 86 'revision_with_no_change_log')) |
| 87 self.assertEqual( |
| 88 { |
| 89 'revision': 'rev2', |
| 90 'commit_position': '2', |
| 91 'review_url': 'url_2' |
| 92 }, |
| 93 IdentifyTryJobCulpritPipeline._GetCulpritFromFailedRevision('rev2')) |
| 94 |
| 95 def testIdentifyCulpritForCompileTryJobNoCulprit(self): |
| 28 master_name = 'm' | 96 master_name = 'm' |
| 29 builder_name = 'b' | 97 builder_name = 'b' |
| 30 build_number = 1 | 98 build_number = 1 |
| 31 try_job_id = '1' | 99 try_job_id = '1' |
| 32 compile_result = None | |
| 33 | 100 |
| 34 WfTryJob.Create(master_name, builder_name, build_number).put() | 101 try_job = WfTryJob.Create(master_name, builder_name, build_number) |
| 35 pipeline = IdentifyTryJobCulpritPipeline() | 102 try_job.put() |
| 36 culprit = pipeline.run( | |
| 37 master_name, builder_name, build_number, try_job_id, compile_result) | |
| 38 try_job = WfTryJob.Get(master_name, builder_name, build_number) | |
| 39 | |
| 40 self.assertIsNone(culprit) | |
| 41 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) | |
| 42 | |
| 43 def testIdentifyCulpritForCompileReturnNoneIfNoTryJobResultForCompile(self): | |
| 44 master_name = 'm' | |
| 45 builder_name = 'b' | |
| 46 build_number = 1 | |
| 47 try_job_id = '1' | |
| 48 compile_result = { | |
| 49 'result': [], | |
| 50 'url': 'url', | |
| 51 'try_job_id': '1', | |
| 52 } | |
| 53 WfTryJob.Create(master_name, builder_name, build_number).put() | |
| 54 | 103 |
| 55 pipeline = IdentifyTryJobCulpritPipeline() | 104 pipeline = IdentifyTryJobCulpritPipeline() |
| 56 culprit = pipeline.run( | 105 culprit = pipeline.run( |
| 57 master_name, builder_name, build_number, try_job_id, compile_result) | 106 master_name, builder_name, build_number, try_job_id, None) |
| 58 try_job = WfTryJob.Get(master_name, builder_name, build_number) | |
| 59 | 107 |
| 108 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) |
| 109 self.assertEqual([], try_job.compile_results) |
| 60 self.assertIsNone(culprit) | 110 self.assertIsNone(culprit) |
| 61 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) | |
| 62 | |
| 63 def testIdentifyCulpritForCompileReturnNoneIfAllPassed(self): | |
| 64 master_name = 'm' | |
| 65 builder_name = 'b' | |
| 66 build_number = 1 | |
| 67 try_job_id = '1' | |
| 68 compile_result = { | |
| 69 'result': [ | |
| 70 ['rev1', 'passed'], | |
| 71 ['rev2', 'passed'] | |
| 72 ], | |
| 73 'url': 'url', | |
| 74 'try_job_id': '1', | |
| 75 } | |
| 76 WfTryJob.Create(master_name, builder_name, build_number).put() | |
| 77 | |
| 78 pipeline = IdentifyTryJobCulpritPipeline() | |
| 79 culprit = pipeline.run( | |
| 80 master_name, builder_name, build_number, try_job_id, compile_result) | |
| 81 try_job = WfTryJob.Get(master_name, builder_name, build_number) | |
| 82 | |
| 83 self.assertIsNone(culprit) | |
| 84 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) | |
| 85 | |
| 86 def testIdentifyCulpritForCompileReturnNoneIfNoChangeLog(self): | |
| 87 master_name = 'm' | |
| 88 builder_name = 'b' | |
| 89 build_number = 1 | |
| 90 try_job_id = '1' | |
| 91 compile_result = { | |
| 92 'result': [ | |
| 93 ['rev1', 'failed'] | |
| 94 ], | |
| 95 'url': 'url', | |
| 96 'try_job_id': '1', | |
| 97 } | |
| 98 | |
| 99 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) | |
| 100 WfTryJob.Create(master_name, builder_name, build_number).put() | |
| 101 | |
| 102 pipeline = IdentifyTryJobCulpritPipeline() | |
| 103 culprit = pipeline.run( | |
| 104 master_name, builder_name, build_number, try_job_id, compile_result) | |
| 105 try_job = WfTryJob.Get(master_name, builder_name, build_number) | |
| 106 | |
| 107 self.assertIsNone(culprit) | |
| 108 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) | |
| 109 | 111 |
| 110 def testIdentifyCulpritForCompileTryJobSuccess(self): | 112 def testIdentifyCulpritForCompileTryJobSuccess(self): |
| 111 master_name = 'm' | 113 master_name = 'm' |
| 112 builder_name = 'b' | 114 builder_name = 'b' |
| 113 build_number = 1 | 115 build_number = 1 |
| 114 try_job_id = '1' | 116 try_job_id = '1' |
| 115 compile_result = { | 117 compile_result = { |
| 116 'result': [ | 118 'report': { |
| 119 'result': { |
| 120 'rev1': 'passed', |
| 121 'rev2': 'failed' |
| 122 } |
| 123 }, |
| 124 } |
| 125 |
| 126 try_job = WfTryJob.Create(master_name, builder_name, build_number) |
| 127 try_job.status = wf_analysis_status.ANALYZING |
| 128 try_job.compile_results = [{ |
| 129 'report': { |
| 130 'result': { |
| 131 'rev1': 'passed', |
| 132 'rev2': 'failed' |
| 133 }, |
| 134 }, |
| 135 'try_job_id': '1', |
| 136 }] |
| 137 try_job.put() |
| 138 |
| 139 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) |
| 140 |
| 141 pipeline = IdentifyTryJobCulpritPipeline() |
| 142 culprit = pipeline.run( |
| 143 master_name, builder_name, build_number, try_job_id, compile_result) |
| 144 |
| 145 expected_compile_result = { |
| 146 'report': { |
| 147 'result': { |
| 148 'rev1': 'passed', |
| 149 'rev2': 'failed' |
| 150 } |
| 151 }, |
| 152 'try_job_id': '1', |
| 153 'culprit': { |
| 154 'revision': 'rev2', |
| 155 'commit_position': '2', |
| 156 'review_url': 'url_2' |
| 157 } |
| 158 } |
| 159 |
| 160 self.assertEqual(expected_compile_result['culprit'], culprit) |
| 161 |
| 162 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
| 163 self.assertEqual(expected_compile_result, try_job.compile_results[-1]) |
| 164 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) |
| 165 |
| 166 # TODO(lijeffrey): Deprecate all tests with compile_results whose 'result' |
| 167 # key is a list once it is returned as a dict from the recipe. |
| 168 def testIdentifyCulpritForCompileListTryJobSuccess(self): |
| 169 master_name = 'm' |
| 170 builder_name = 'b' |
| 171 build_number = 1 |
| 172 try_job_id = '1' |
| 173 compile_result = { |
| 174 'report': [ |
| 117 ['rev1', 'passed'], | 175 ['rev1', 'passed'], |
| 118 ['rev2', 'failed'] | 176 ['rev2', 'failed'] |
| 119 ], | 177 ], |
| 120 'url': 'url', | 178 'url': 'url', |
| 121 'try_job_id': '1', | 179 'try_job_id': '1', |
| 122 } | 180 } |
| 123 | 181 |
| 124 try_job = WfTryJob.Create(master_name, builder_name, build_number) | 182 try_job = WfTryJob.Create(master_name, builder_name, build_number) |
| 125 try_job.status = wf_analysis_status.ANALYZING | 183 try_job.status = wf_analysis_status.ANALYZING |
| 126 try_job.compile_results = [{ | 184 try_job.compile_results = [{ |
| 127 'result': [ | 185 'report': [ |
| 128 ['rev1', 'passed'], | 186 ['rev1', 'passed'], |
| 129 ['rev2', 'failed'] | 187 ['rev2', 'failed'] |
| 130 ], | 188 ], |
| 131 'url': 'url', | 189 'url': 'url', |
| 132 'try_job_id': '1', | 190 'try_job_id': '1', |
| 133 }] | 191 }] |
| 134 try_job.put() | 192 try_job.put() |
| 135 | 193 |
| 136 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) | 194 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) |
| 137 | 195 |
| 138 pipeline = IdentifyTryJobCulpritPipeline() | 196 pipeline = IdentifyTryJobCulpritPipeline() |
| 139 culprit = pipeline.run( | 197 culprit = pipeline.run( |
| 140 master_name, builder_name, build_number, try_job_id, compile_result) | 198 master_name, builder_name, build_number, try_job_id, compile_result) |
| 141 | 199 |
| 142 expected_compile_result = { | 200 expected_compile_result = { |
| 143 'result': [ | 201 'report': [ |
| 144 ['rev1', 'passed'], | 202 ['rev1', 'passed'], |
| 145 ['rev2', 'failed'] | 203 ['rev2', 'failed'] |
| 146 ], | 204 ], |
| 147 'url': 'url', | 205 'url': 'url', |
| 148 'try_job_id': '1', | 206 'try_job_id': '1', |
| 149 'culprit': { | 207 'culprit': { |
| 150 'revision': 'rev2', | 208 'revision': 'rev2', |
| 151 'commit_position': '2', | 209 'commit_position': '2', |
| 152 'review_url': 'url_2' | 210 'review_url': 'url_2' |
| 153 } | 211 } |
| 154 } | 212 } |
| 155 | 213 |
| 156 self.assertEqual(expected_compile_result['culprit'], culprit) | 214 self.assertEqual(expected_compile_result['culprit'], culprit) |
| 157 | 215 |
| 158 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 216 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
| 159 self.assertEqual(expected_compile_result, try_job.compile_results[-1]) | 217 self.assertEqual(expected_compile_result, try_job.compile_results[-1]) |
| 160 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) | 218 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) |
| OLD | NEW |