| 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 import json | 5 import json |
| 6 import os | 6 import os |
| 7 | 7 |
| 8 from common import constants | 8 from common import constants |
| 9 from common.pipeline_wrapper import pipeline_handlers | 9 from common.pipeline_wrapper import pipeline_handlers |
| 10 from crash import fracas_crash_pipeline | 10 from crash import fracas_crash_pipeline |
| 11 from crash.test.crash_testcase import CrashTestCase | 11 from crash.test.crash_testcase import CrashTestCase |
| 12 from model import analysis_status | 12 from model import analysis_status |
| 13 from model import result_status | 13 from model import result_status |
| 14 from model.crash.fracas_crash_analysis import FracasCrashAnalysis | 14 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 15 from waterfall.test import wf_testcase | 15 from waterfall.test import wf_testcase |
| 16 | 16 |
| 17 | 17 |
| 18 class FracasCrashPipelineTest(CrashTestCase): | 18 class FracasCrashPipelineTest(CrashTestCase): |
| 19 app_module = pipeline_handlers._APP | 19 app_module = pipeline_handlers._APP |
| 20 | 20 |
| 21 def testNoAnalysisIfLastOneIsNotFailed(self): | 21 def testNoAnalysisIfLastOneIsNotFailed(self): |
| 22 channel = 'canary' | 22 chrome_version = '1' |
| 23 signature = 'signature' |
| 23 platform = 'win' | 24 platform = 'win' |
| 24 signature = 'signature' | 25 crash_identifiers = { |
| 26 'chrome_version': chrome_version, |
| 27 'signature': signature, |
| 28 'channel': 'canary', |
| 29 'platform': platform, |
| 30 'process_type': 'browser', |
| 31 } |
| 25 for status in (analysis_status.PENDING, analysis_status.RUNNING, | 32 for status in (analysis_status.PENDING, analysis_status.RUNNING, |
| 26 analysis_status.COMPLETED, analysis_status.SKIPPED): | 33 analysis_status.COMPLETED, analysis_status.SKIPPED): |
| 27 analysis = FracasCrashAnalysis.Create(channel, platform, signature) | 34 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 28 analysis.status = status | 35 analysis.status = status |
| 29 analysis.put() | 36 analysis.put() |
| 30 self.assertFalse(fracas_crash_pipeline._NeedsNewAnalysis( | 37 self.assertFalse(fracas_crash_pipeline._NeedsNewAnalysis( |
| 31 channel, platform, signature, None, None, None)) | 38 crash_identifiers, chrome_version, signature, 'fracas', |
| 39 platform, None, None, None)) |
| 32 | 40 |
| 33 def testAnalysisNeededIfLastOneFailed(self): | 41 def testAnalysisNeededIfLastOneFailed(self): |
| 34 channel = 'canary' | 42 chrome_version = '1' |
| 43 signature = 'signature' |
| 35 platform = 'win' | 44 platform = 'win' |
| 36 signature = 'signature' | 45 crash_identifiers = { |
| 37 analysis = FracasCrashAnalysis.Create(channel, platform, signature) | 46 'chrome_version': chrome_version, |
| 47 'signature': signature, |
| 48 'channel': 'canary', |
| 49 'platform': platform, |
| 50 'process_type': 'browser', |
| 51 } |
| 52 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 38 analysis.status = analysis_status.ERROR | 53 analysis.status = analysis_status.ERROR |
| 39 analysis.put() | 54 analysis.put() |
| 40 self.assertTrue(fracas_crash_pipeline._NeedsNewAnalysis( | 55 self.assertTrue(fracas_crash_pipeline._NeedsNewAnalysis( |
| 41 channel, platform, signature, None, None, None)) | 56 crash_identifiers, chrome_version, signature, 'fracas', |
| 57 platform, None, None, None)) |
| 42 | 58 |
| 43 def testAnalysisNeededIfNoAnalysisYet(self): | 59 def testAnalysisNeededIfNoAnalysisYet(self): |
| 44 channel = 'canary' | 60 chrome_version = '1' |
| 61 signature = 'signature' |
| 45 platform = 'win' | 62 platform = 'win' |
| 46 signature = 'signature' | 63 crash_identifiers = { |
| 64 'chrome_version': chrome_version, |
| 65 'signature': signature, |
| 66 'channel': 'canary', |
| 67 'platform': platform, |
| 68 'process_type': 'browser', |
| 69 } |
| 47 self.assertTrue(fracas_crash_pipeline._NeedsNewAnalysis( | 70 self.assertTrue(fracas_crash_pipeline._NeedsNewAnalysis( |
| 48 channel, platform, signature, None, None, None)) | 71 crash_identifiers, chrome_version, signature, 'fracas', |
| 72 platform, None, None, None)) |
| 49 | 73 |
| 50 def testUnsupportedChannelOrPlatformSkipped(self): | 74 def testUnsupportedChannelOrPlatformSkipped(self): |
| 51 self.assertFalse( | 75 self.assertFalse( |
| 52 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( | 76 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( |
| 53 'unsupported_channel', 'win', None, None, None, None)) | 77 {}, None, None, 'fracas', 'win', |
| 78 None, 'unsupported_channel', None)) |
| 54 self.assertFalse( | 79 self.assertFalse( |
| 55 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( | 80 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( |
| 56 'supported_channel', 'unsupported_platform', | 81 {}, None, None, 'fracas', 'unsupported_platform', |
| 57 None, None, None, None)) | 82 None, 'unsupported_channel', None)) |
| 58 | 83 |
| 59 def testNoAnalysisNeeded(self): | 84 def testNoAnalysisNeeded(self): |
| 60 channel = 'supported_channel' | 85 chrome_version = '1' |
| 61 platform = 'supported_platform' | |
| 62 signature = 'signature' | 86 signature = 'signature' |
| 63 analysis = FracasCrashAnalysis.Create(channel, platform, signature) | 87 platform = 'win' |
| 88 channel = 'canary' |
| 89 crash_identifiers = { |
| 90 'chrome_version': chrome_version, |
| 91 'signature': signature, |
| 92 'channel': channel, |
| 93 'platform': platform, |
| 94 'process_type': 'browser', |
| 95 } |
| 96 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 64 analysis.status = analysis_status.COMPLETED | 97 analysis.status = analysis_status.COMPLETED |
| 65 analysis.put() | 98 analysis.put() |
| 66 | 99 |
| 67 self.assertFalse( | 100 self.assertFalse( |
| 68 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( | 101 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( |
| 69 channel, platform, signature, None, None, None)) | 102 crash_identifiers, chrome_version, signature, 'fracas', |
| 103 platform, None, channel, None)) |
| 70 | 104 |
| 71 def testRunningAnalysis(self): | 105 def testRunningAnalysis(self): |
| 72 pubsub_publish_requests = [] | 106 pubsub_publish_requests = [] |
| 73 def Mocked_PublishMessagesToTopic(messages_data, topic): | 107 def Mocked_PublishMessagesToTopic(messages_data, topic): |
| 74 pubsub_publish_requests.append((messages_data, topic)) | 108 pubsub_publish_requests.append((messages_data, topic)) |
| 75 self.mock(fracas_crash_pipeline.pubsub_util, 'PublishMessagesToTopic', | 109 self.mock(fracas_crash_pipeline.pubsub_util, 'PublishMessagesToTopic', |
| 76 Mocked_PublishMessagesToTopic) | 110 Mocked_PublishMessagesToTopic) |
| 77 | 111 |
| 78 analysis_result = { | 112 analysis_result = { |
| 79 'found': True, | 113 'found': True, |
| 80 'other_data': 'data', | 114 'other_data': 'data', |
| 81 } | 115 } |
| 82 analysis_tags = { | 116 analysis_tags = { |
| 83 'found_suspects': True, | 117 'found_suspects': True, |
| 84 'has_regression_range': True, | 118 'has_regression_range': True, |
| 85 'solution': 'core', | 119 'solution': 'core', |
| 86 'unsupported_tag': '', | 120 'unsupported_tag': '', |
| 87 } | 121 } |
| 88 analyzed_crashes = [] | 122 analyzed_crashes = [] |
| 89 def Mocked_FindCulpritForChromeCrash(*args): | 123 def Mocked_FindCulpritForChromeCrash(*args): |
| 90 analyzed_crashes.append(args) | 124 analyzed_crashes.append(args) |
| 91 return analysis_result, analysis_tags | 125 return analysis_result, analysis_tags |
| 92 self.mock(fracas_crash_pipeline.fracas, 'FindCulpritForChromeCrash', | 126 self.mock(fracas_crash_pipeline.fracas, 'FindCulpritForChromeCrash', |
| 93 Mocked_FindCulpritForChromeCrash) | 127 Mocked_FindCulpritForChromeCrash) |
| 94 | 128 chrome_version = '1' |
| 95 channel = 'supported_channel' | 129 signature = 'signature' |
| 96 platform = 'supported_platform' | 130 platform = 'win' |
| 97 signature = 'signature/here' | 131 channel = 'canary' |
| 132 crash_identifiers = { |
| 133 'chrome_version': chrome_version, |
| 134 'signature': signature, |
| 135 'channel': channel, |
| 136 'platform': platform, |
| 137 'process_type': 'browser', |
| 138 } |
| 98 stack_trace = 'frame1\nframe2\nframe3' | 139 stack_trace = 'frame1\nframe2\nframe3' |
| 99 chrome_version = '50.2500.0.0' | 140 chrome_version = '50.2500.0.0' |
| 100 versions_to_cpm = {'50.2500.0.0': 1.0} | 141 historic_metadata = {'50.2500.0.0': 1.0} |
| 101 | 142 |
| 102 self.assertTrue( | 143 self.assertTrue( |
| 103 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( | 144 fracas_crash_pipeline.ScheduleNewAnalysisForCrash( |
| 104 channel, platform, signature, stack_trace, | 145 crash_identifiers, chrome_version, signature, 'fracas', |
| 105 chrome_version, versions_to_cpm)) | 146 platform, stack_trace, channel, historic_metadata)) |
| 106 | 147 |
| 107 self.execute_queued_tasks() | 148 self.execute_queued_tasks() |
| 108 | 149 |
| 109 self.assertEqual(1, len(pubsub_publish_requests)) | 150 self.assertEqual(1, len(pubsub_publish_requests)) |
| 110 expected_messages_data = [json.dumps({ | 151 expected_messages_data = [json.dumps({ |
| 111 'channel': channel, | 152 'crash_identifiers': crash_identifiers, |
| 112 'platform': platform, | 153 'result': analysis_result, |
| 113 'signature': signature, | |
| 114 'result': analysis_result, | |
| 115 }, sort_keys=True)] | 154 }, sort_keys=True)] |
| 116 self.assertEqual(expected_messages_data, pubsub_publish_requests[0][0]) | 155 self.assertEqual(expected_messages_data, pubsub_publish_requests[0][0]) |
| 117 | 156 |
| 118 self.assertEqual(1, len(analyzed_crashes)) | 157 self.assertEqual(1, len(analyzed_crashes)) |
| 119 self.assertEqual( | 158 self.assertEqual( |
| 120 (channel, platform, signature, stack_trace, | 159 (channel, platform, signature, stack_trace, |
| 121 chrome_version, versions_to_cpm), | 160 chrome_version, historic_metadata), |
| 122 analyzed_crashes[0]) | 161 analyzed_crashes[0]) |
| 123 | 162 |
| 124 analysis = FracasCrashAnalysis.Get(channel, platform, signature) | 163 analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| 125 self.assertEqual(analysis_result, analysis.result) | 164 self.assertEqual(analysis_result, analysis.result) |
| 126 self.assertTrue(analysis.has_regression_range) | 165 self.assertTrue(analysis.has_regression_range) |
| 127 self.assertTrue(analysis.found_suspects) | 166 self.assertTrue(analysis.found_suspects) |
| 128 self.assertEqual('core', analysis.solution) | 167 self.assertEqual('core', analysis.solution) |
| 129 | 168 |
| 130 def testAnalysisAborted(self): | 169 def testAnalysisAborted(self): |
| 131 channel = 'canary' | 170 chrome_version = '1' |
| 171 signature = 'signature' |
| 132 platform = 'win' | 172 platform = 'win' |
| 133 signature = 'signature' | 173 crash_identifiers = { |
| 134 analysis = FracasCrashAnalysis.Create(channel, platform, signature) | 174 'chrome_version': chrome_version, |
| 175 'signature': signature, |
| 176 'channel': 'canary', |
| 177 'platform': platform, |
| 178 'process_type': 'browser', |
| 179 } |
| 180 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 135 analysis.status = analysis_status.RUNNING | 181 analysis.status = analysis_status.RUNNING |
| 136 analysis.put() | 182 analysis.put() |
| 137 | 183 |
| 138 pipeline = fracas_crash_pipeline.FracasAnalysisPipeline( | 184 pipeline = fracas_crash_pipeline.FracasAnalysisPipeline(crash_identifiers) |
| 139 channel, platform, signature) | |
| 140 pipeline._SetErrorIfAborted(True) | 185 pipeline._SetErrorIfAborted(True) |
| 141 analysis = FracasCrashAnalysis.Get(channel, platform, signature) | 186 analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| 142 self.assertEqual(analysis_status.ERROR, analysis.status) | 187 self.assertEqual(analysis_status.ERROR, analysis.status) |
| OLD | NEW |