| 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 import copy |
| 5 import json | 5 import json |
| 6 | 6 |
| 7 from common.pipeline_wrapper import pipeline_handlers | 7 from common.pipeline_wrapper import pipeline_handlers |
| 8 from crash import fracas_crash_pipeline | 8 from crash import fracas_crash_pipeline |
| 9 from crash.test.crash_testcase import CrashTestCase | 9 from crash.test.crash_testcase import CrashTestCase |
| 10 from model import analysis_status | 10 from model import analysis_status |
| 11 from model.crash.fracas_crash_analysis import FracasCrashAnalysis | 11 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 12 | 12 |
| 13 | 13 |
| 14 class FracasCrashPipelineTest(CrashTestCase): | 14 class FracasCrashPipelineTest(CrashTestCase): |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 analysis = FracasCrashAnalysis.Create(crash_identifiers) | 111 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 112 analysis.status = analysis_status.COMPLETED | 112 analysis.status = analysis_status.COMPLETED |
| 113 analysis.put() | 113 analysis.put() |
| 114 | 114 |
| 115 self.assertFalse( | 115 self.assertFalse( |
| 116 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( | 116 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( |
| 117 crash_identifiers, chrome_version, signature, 'fracas', | 117 crash_identifiers, chrome_version, signature, 'fracas', |
| 118 platform, None, channel, None)) | 118 platform, None, channel, None)) |
| 119 | 119 |
| 120 def testRunningAnalysis(self): | 120 def _TestRunningAnalysisForResult(self, analysis_result, analysis_tags): |
| 121 pubsub_publish_requests = [] | 121 pubsub_publish_requests = [] |
| 122 def Mocked_PublishMessagesToTopic(messages_data, topic): | 122 def Mocked_PublishMessagesToTopic(messages_data, topic): |
| 123 pubsub_publish_requests.append((messages_data, topic)) | 123 pubsub_publish_requests.append((messages_data, topic)) |
| 124 self.mock(fracas_crash_pipeline.pubsub_util, 'PublishMessagesToTopic', | 124 self.mock(fracas_crash_pipeline.pubsub_util, 'PublishMessagesToTopic', |
| 125 Mocked_PublishMessagesToTopic) | 125 Mocked_PublishMessagesToTopic) |
| 126 | 126 |
| 127 analysis_result = { | |
| 128 'found': True, | |
| 129 'other_data': 'data', | |
| 130 } | |
| 131 analysis_tags = { | |
| 132 'found_suspects': True, | |
| 133 'has_regression_range': True, | |
| 134 'solution': 'core', | |
| 135 'unsupported_tag': '', | |
| 136 } | |
| 137 analyzed_crashes = [] | 127 analyzed_crashes = [] |
| 138 def Mocked_FindCulpritForChromeCrash(*args): | 128 def Mocked_FindCulpritForChromeCrash(*args): |
| 139 analyzed_crashes.append(args) | 129 analyzed_crashes.append(args) |
| 140 return analysis_result, analysis_tags | 130 return analysis_result, analysis_tags |
| 141 self.mock(fracas_crash_pipeline.fracas, 'FindCulpritForChromeCrash', | 131 self.mock(fracas_crash_pipeline.fracas, 'FindCulpritForChromeCrash', |
| 142 Mocked_FindCulpritForChromeCrash) | 132 Mocked_FindCulpritForChromeCrash) |
| 143 chrome_version = '1' | 133 chrome_version = '1' |
| 144 signature = 'signature' | 134 signature = 'signature' |
| 145 platform = 'win' | 135 platform = 'win' |
| 146 channel = 'canary' | 136 channel = 'canary' |
| 147 crash_identifiers = { | 137 crash_identifiers = { |
| 148 'chrome_version': chrome_version, | 138 'chrome_version': chrome_version, |
| 149 'signature': signature, | 139 'signature': signature, |
| 150 'channel': channel, | 140 'channel': channel, |
| 151 'platform': platform, | 141 'platform': platform, |
| 152 'process_type': 'browser', | 142 'process_type': 'browser', |
| 153 } | 143 } |
| 154 stack_trace = 'frame1\nframe2\nframe3' | 144 stack_trace = 'frame1\nframe2\nframe3' |
| 155 chrome_version = '50.2500.0.0' | 145 chrome_version = '50.2500.0.0' |
| 156 historic_metadata = {'50.2500.0.0': 1.0} | 146 historic_metadata = {'50.2500.0.0': 1.0} |
| 157 | 147 |
| 158 self.assertTrue( | 148 self.assertTrue( |
| 159 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( | 149 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( |
| 160 crash_identifiers, chrome_version, signature, 'fracas', | 150 crash_identifiers, chrome_version, signature, 'fracas', |
| 161 platform, stack_trace, channel, historic_metadata)) | 151 platform, stack_trace, channel, historic_metadata)) |
| 162 | 152 |
| 163 self.execute_queued_tasks() | 153 self.execute_queued_tasks() |
| 164 | 154 |
| 165 self.assertEqual(1, len(pubsub_publish_requests)) | 155 self.assertEqual(1, len(pubsub_publish_requests)) |
| 156 |
| 157 processed_analysis_result = copy.deepcopy(analysis_result) |
| 158 processed_analysis_result['feedback_url'] = ( |
| 159 'https://findit-for-me.googleplex.com/crash/fracas-result-feedback?' |
| 160 'key=agx0ZXN0YmVkLXRlc3RyQQsSE0ZyYWNhc0NyYXNoQW5hbHlzaXMiKGU2ZWIyNj' |
| 161 'A2OTBlYTAyMjVjNWNjYTM3ZTNjYTlmYWExOGVmYjVlM2UM') |
| 162 |
| 163 if 'suspected_cls' in processed_analysis_result: |
| 164 for cl in processed_analysis_result['suspected_cls']: |
| 165 cl['confidence'] = round(cl['confidence'], 2) |
| 166 cl.pop('reason', None) |
| 167 |
| 166 expected_messages_data = [json.dumps({ | 168 expected_messages_data = [json.dumps({ |
| 167 'crash_identifiers': crash_identifiers, | 169 'crash_identifiers': crash_identifiers, |
| 168 'client_id': 'fracas', | 170 'client_id': 'fracas', |
| 169 'result': analysis_result, | 171 'result': processed_analysis_result, |
| 170 }, sort_keys=True)] | 172 }, sort_keys=True)] |
| 171 self.assertEqual(expected_messages_data, pubsub_publish_requests[0][0]) | 173 self.assertEqual(expected_messages_data, pubsub_publish_requests[0][0]) |
| 172 | 174 |
| 173 self.assertEqual(1, len(analyzed_crashes)) | 175 self.assertEqual(1, len(analyzed_crashes)) |
| 174 self.assertEqual( | 176 self.assertEqual( |
| 175 (signature, platform, stack_trace, chrome_version, historic_metadata), | 177 (signature, platform, stack_trace, chrome_version, historic_metadata), |
| 176 analyzed_crashes[0]) | 178 analyzed_crashes[0]) |
| 177 | 179 |
| 178 analysis = FracasCrashAnalysis.Get(crash_identifiers) | 180 analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| 179 self.assertEqual(analysis_result, analysis.result) | 181 self.assertEqual(analysis_result, analysis.result) |
| 182 return analysis |
| 183 |
| 184 |
| 185 def testRunningAnalysis(self): |
| 186 analysis_result = { |
| 187 'found': True, |
| 188 'suspected_cls': [], |
| 189 'other_data': 'data', |
| 190 } |
| 191 analysis_tags = { |
| 192 'found_suspects': True, |
| 193 'has_regression_range': True, |
| 194 'solution': 'core', |
| 195 'unsupported_tag': '', |
| 196 } |
| 197 |
| 198 analysis = self._TestRunningAnalysisForResult( |
| 199 analysis_result, analysis_tags) |
| 180 self.assertTrue(analysis.has_regression_range) | 200 self.assertTrue(analysis.has_regression_range) |
| 181 self.assertTrue(analysis.found_suspects) | 201 self.assertTrue(analysis.found_suspects) |
| 182 self.assertEqual('core', analysis.solution) | 202 self.assertEqual('core', analysis.solution) |
| 203 |
| 204 def testRunningAnalysisNoSuspectsFound(self): |
| 205 analysis_result = { |
| 206 'found': False |
| 207 } |
| 208 analysis_tags = { |
| 209 'found_suspects': False, |
| 210 'has_regression_range': False, |
| 211 'solution': 'core', |
| 212 'unsupported_tag': '', |
| 213 } |
| 214 |
| 215 analysis = self._TestRunningAnalysisForResult( |
| 216 analysis_result, analysis_tags) |
| 217 self.assertFalse(analysis.has_regression_range) |
| 218 self.assertFalse(analysis.found_suspects) |
| 219 self.assertEqual('core', analysis.solution) |
| 220 |
| 221 def testRunningAnalysisWithSuspectsCls(self): |
| 222 analysis_result = { |
| 223 'found': True, |
| 224 'suspected_cls': [ |
| 225 {'confidence': 0.21434, |
| 226 'reason': ['reason1', 'reason2'], |
| 227 'other': 'data'} |
| 228 ], |
| 229 'other_data': 'data', |
| 230 } |
| 231 analysis_tags = { |
| 232 'found_suspects': True, |
| 233 'has_regression_range': True, |
| 234 'solution': 'core', |
| 235 'unsupported_tag': '', |
| 236 } |
| 237 |
| 238 analysis = self._TestRunningAnalysisForResult( |
| 239 analysis_result, analysis_tags) |
| 240 self.assertTrue(analysis.has_regression_range) |
| 241 self.assertTrue(analysis.found_suspects) |
| 242 self.assertEqual('core', analysis.solution) |
| 183 | 243 |
| 184 def testAnalysisAborted(self): | 244 def testAnalysisAborted(self): |
| 185 chrome_version = '1' | 245 chrome_version = '1' |
| 186 signature = 'signature' | 246 signature = 'signature' |
| 187 platform = 'win' | 247 platform = 'win' |
| 188 crash_identifiers = { | 248 crash_identifiers = { |
| 189 'chrome_version': chrome_version, | 249 'chrome_version': chrome_version, |
| 190 'signature': signature, | 250 'signature': signature, |
| 191 'channel': 'canary', | 251 'channel': 'canary', |
| 192 'platform': platform, | 252 'platform': platform, |
| 193 'process_type': 'browser', | 253 'process_type': 'browser', |
| 194 } | 254 } |
| 195 analysis = FracasCrashAnalysis.Create(crash_identifiers) | 255 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 196 analysis.status = analysis_status.RUNNING | 256 analysis.status = analysis_status.RUNNING |
| 197 analysis.put() | 257 analysis.put() |
| 198 | 258 |
| 199 pipeline = fracas_crash_pipeline.FracasAnalysisPipeline(crash_identifiers) | 259 pipeline = fracas_crash_pipeline.FracasAnalysisPipeline(crash_identifiers) |
| 200 pipeline._SetErrorIfAborted(True) | 260 pipeline._SetErrorIfAborted(True) |
| 201 analysis = FracasCrashAnalysis.Get(crash_identifiers) | 261 analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| 202 self.assertEqual(analysis_status.ERROR, analysis.status) | 262 self.assertEqual(analysis_status.ERROR, analysis.status) |
| OLD | NEW |