Chromium Code Reviews| 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 master_name = 'm' | 28 self.assertIsNone( |
| 29 builder_name = 'b' | 29 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromResultsDict({})) |
| 30 build_number = 1 | 30 self.assertEqual( |
| 31 try_job_id = '1' | 31 None, |
| 32 compile_result = 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'})) | |
| 33 | 42 |
| 34 WfTryJob.Create(master_name, builder_name, build_number).put() | 43 def testGetFailedRevisionFromCompileResult(self): |
| 35 pipeline = IdentifyTryJobCulpritPipeline() | 44 self.assertIsNone( |
| 36 culprit = pipeline.run( | 45 IdentifyTryJobCulpritPipeline._GetFailedRevisionFromCompileResult( |
| 37 master_name, builder_name, build_number, try_job_id, compile_result) | 46 None)) |
| 38 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 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 })) | |
| 39 | 79 |
| 40 self.assertIsNone(culprit) | 80 def testGetCulpritFromFailedRevision(self): |
| 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 | |
| 55 pipeline = IdentifyTryJobCulpritPipeline() | |
| 56 culprit = pipeline.run( | |
| 57 master_name, builder_name, build_number, try_job_id, compile_result) | |
| 58 try_job = WfTryJob.Get(master_name, builder_name, build_number) | |
| 59 | |
| 60 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) | 81 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) |
| 100 WfTryJob.Create(master_name, builder_name, build_number).put() | 82 self.assertIsNone( |
| 101 | 83 IdentifyTryJobCulpritPipeline._GetCulpritFromFailedRevision(None)) |
| 102 pipeline = IdentifyTryJobCulpritPipeline() | 84 self.assertIsNone( |
| 103 culprit = pipeline.run( | 85 IdentifyTryJobCulpritPipeline._GetCulpritFromFailedRevision( |
| 104 master_name, builder_name, build_number, try_job_id, compile_result) | 86 'revision_with_no_change_log')) |
| 105 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 87 self.assertEqual( |
| 106 | 88 { |
| 107 self.assertIsNone(culprit) | 89 'revision': 'rev2', |
| 108 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) | 90 'commit_position': '2', |
| 91 'review_url': 'url_2' | |
| 92 }, | |
| 93 IdentifyTryJobCulpritPipeline._GetCulpritFromFailedRevision('rev2')) | |
| 109 | 94 |
| 110 def testIdentifyCulpritForCompileTryJobSuccess(self): | 95 def testIdentifyCulpritForCompileTryJobSuccess(self): |
| 111 master_name = 'm' | 96 master_name = 'm' |
| 112 builder_name = 'b' | 97 builder_name = 'b' |
| 113 build_number = 1 | 98 build_number = 1 |
| 114 try_job_id = '1' | 99 try_job_id = '1' |
| 115 compile_result = { | 100 compile_result = { |
| 116 'result': [ | 101 'report': { |
| 102 'result': { | |
| 103 'rev1': 'passed', | |
| 104 'rev2': 'failed' | |
| 105 } | |
| 106 }, | |
| 107 'url': 'url', | |
|
stgao
2016/01/27 01:24:21
As 'url' is not used and 'try_job_id' is already p
lijeffrey
2016/01/28 02:14:35
Done.
chanli
2016/01/28 21:18:44
It is fine for the test but the real format have t
| |
| 108 'try_job_id': '1', | |
| 109 } | |
| 110 | |
| 111 try_job = WfTryJob.Create(master_name, builder_name, build_number) | |
| 112 try_job.status = wf_analysis_status.ANALYZING | |
| 113 try_job.compile_results = [{ | |
| 114 'report': { | |
| 115 'result': { | |
| 116 'rev1': 'passed', | |
| 117 'rev2': 'failed' | |
| 118 }, | |
| 119 }, | |
| 120 'url': 'url', | |
| 121 'try_job_id': '1', | |
| 122 }] | |
| 123 try_job.put() | |
| 124 | |
| 125 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) | |
| 126 | |
| 127 pipeline = IdentifyTryJobCulpritPipeline() | |
| 128 culprit = pipeline.run( | |
| 129 master_name, builder_name, build_number, try_job_id, compile_result) | |
| 130 | |
| 131 expected_compile_result = { | |
| 132 'report': { | |
| 133 'result': { | |
| 134 'rev1': 'passed', | |
| 135 'rev2': 'failed' | |
| 136 } | |
| 137 }, | |
| 138 'url': 'url', | |
| 139 'try_job_id': '1', | |
| 140 'culprit': { | |
| 141 'revision': 'rev2', | |
| 142 'commit_position': '2', | |
| 143 'review_url': 'url_2' | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 self.assertEqual(expected_compile_result['culprit'], culprit) | |
| 148 | |
| 149 try_job = WfTryJob.Get(master_name, builder_name, build_number) | |
| 150 self.assertEqual(expected_compile_result, try_job.compile_results[-1]) | |
| 151 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) | |
| 152 | |
| 153 # TODO(lijeffrey): Deprecate all tests with compile_results whose 'result' | |
| 154 # key is a list once it is returned as a dict from the recipe. | |
| 155 def testIdentifyCulpritForCompileListTryJobSuccess(self): | |
| 156 master_name = 'm' | |
| 157 builder_name = 'b' | |
| 158 build_number = 1 | |
| 159 try_job_id = '1' | |
| 160 compile_result = { | |
| 161 'report': [ | |
| 117 ['rev1', 'passed'], | 162 ['rev1', 'passed'], |
| 118 ['rev2', 'failed'] | 163 ['rev2', 'failed'] |
| 119 ], | 164 ], |
| 120 'url': 'url', | 165 'url': 'url', |
| 121 'try_job_id': '1', | 166 'try_job_id': '1', |
| 122 } | 167 } |
| 123 | 168 |
| 124 try_job = WfTryJob.Create(master_name, builder_name, build_number) | 169 try_job = WfTryJob.Create(master_name, builder_name, build_number) |
| 125 try_job.status = wf_analysis_status.ANALYZING | 170 try_job.status = wf_analysis_status.ANALYZING |
| 126 try_job.compile_results = [{ | 171 try_job.compile_results = [{ |
| 127 'result': [ | 172 'report': [ |
| 128 ['rev1', 'passed'], | 173 ['rev1', 'passed'], |
| 129 ['rev2', 'failed'] | 174 ['rev2', 'failed'] |
| 130 ], | 175 ], |
| 131 'url': 'url', | 176 'url': 'url', |
| 132 'try_job_id': '1', | 177 'try_job_id': '1', |
| 133 }] | 178 }] |
| 134 try_job.put() | 179 try_job.put() |
| 135 | 180 |
| 136 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) | 181 self.mock(GitRepository, 'GetChangeLog', self._MockGetChangeLog) |
| 137 | 182 |
| 138 pipeline = IdentifyTryJobCulpritPipeline() | 183 pipeline = IdentifyTryJobCulpritPipeline() |
| 139 culprit = pipeline.run( | 184 culprit = pipeline.run( |
| 140 master_name, builder_name, build_number, try_job_id, compile_result) | 185 master_name, builder_name, build_number, try_job_id, compile_result) |
| 141 | 186 |
| 142 expected_compile_result = { | 187 expected_compile_result = { |
| 143 'result': [ | 188 'report': [ |
| 144 ['rev1', 'passed'], | 189 ['rev1', 'passed'], |
| 145 ['rev2', 'failed'] | 190 ['rev2', 'failed'] |
| 146 ], | 191 ], |
| 147 'url': 'url', | 192 'url': 'url', |
| 148 'try_job_id': '1', | 193 'try_job_id': '1', |
| 149 'culprit': { | 194 'culprit': { |
| 150 'revision': 'rev2', | 195 'revision': 'rev2', |
| 151 'commit_position': '2', | 196 'commit_position': '2', |
| 152 'review_url': 'url_2' | 197 'review_url': 'url_2' |
| 153 } | 198 } |
| 154 } | 199 } |
| 155 | 200 |
| 156 self.assertEqual(expected_compile_result['culprit'], culprit) | 201 self.assertEqual(expected_compile_result['culprit'], culprit) |
| 157 | 202 |
| 158 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 203 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
| 159 self.assertEqual(expected_compile_result, try_job.compile_results[-1]) | 204 self.assertEqual(expected_compile_result, try_job.compile_results[-1]) |
| 160 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) | 205 self.assertEqual(wf_analysis_status.ANALYZED, try_job.status) |
| OLD | NEW |