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