Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: appengine/findit/crash/test/findit_for_chromecrash_test.py

Issue 2455053004: Moving ScheduleNewAnalysis to break the cycle (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 from common import chrome_dependency_fetcher 5 from common import chrome_dependency_fetcher
6 from common.dependency import DependencyRoll 6 from common.dependency import DependencyRoll
7 from common.http_client_appengine import HttpClientAppengine 7 from common.http_client_appengine import HttpClientAppengine
8 from crash import chromecrash_parser 8 from crash import chromecrash_parser
9 from crash import detect_regression_range 9 from crash import detect_regression_range
10 from crash import findit_for_chromecrash 10 from crash import findit_for_chromecrash
(...skipping 10 matching lines...) Expand all
21 from crash.stacktrace import CallStack 21 from crash.stacktrace import CallStack
22 from crash.stacktrace import Stacktrace 22 from crash.stacktrace import Stacktrace
23 from crash.test.crash_pipeline_test import DummyCrashData 23 from crash.test.crash_pipeline_test import DummyCrashData
24 from crash.test.crash_testcase import CrashTestCase 24 from crash.test.crash_testcase import CrashTestCase
25 from crash.type_enums import CrashClient 25 from crash.type_enums import CrashClient
26 from lib.gitiles import gitiles_repository 26 from lib.gitiles import gitiles_repository
27 from model import analysis_status 27 from model import analysis_status
28 from model.crash.crash_analysis import CrashAnalysis 28 from model.crash.crash_analysis import CrashAnalysis
29 from model.crash.fracas_crash_analysis import FracasCrashAnalysis 29 from model.crash.fracas_crash_analysis import FracasCrashAnalysis
30 30
31 # In production we'd use CrashWrapperPipeline. And that'd work fine here,
32 # since we never actually call the method that uses it. But just to be
33 # absolutely sure we don't go over the wire due to some mocking failure,
34 # we'll use this dummy class instead. (In fact, since it's never used,
35 # we don't even need to give a real class; ``None`` works just fine.)
36 MOCK_PIPELINE_CLS = None
37
38 MOCK_REPOSITORY = None 31 MOCK_REPOSITORY = None
39 32
40 class _FinditForChromeCrash(FinditForChromeCrash): 33 class _FinditForChromeCrash(FinditForChromeCrash):
41 # We allow overriding the default MOCK_REPOSITORY because one unittest 34 # We allow overriding the default MOCK_REPOSITORY because one unittest
42 # needs to. 35 # needs to.
43 def __init__(self, repository=MOCK_REPOSITORY): 36 def __init__(self, repository=MOCK_REPOSITORY):
44 super(_FinditForChromeCrash, self).__init__(repository, MOCK_PIPELINE_CLS) 37 super(_FinditForChromeCrash, self).__init__(repository)
45 38
46 @classmethod 39 @classmethod
47 def _ClientID(cls): # pragma: no cover 40 def _ClientID(cls): # pragma: no cover
48 """Avoid throwing a NotImplementedError. 41 """Avoid throwing a NotImplementedError.
49 42
50 Since this method is called from ``FinditForChromeCrash.__init__`` 43 Since this method is called from ``FinditForChromeCrash.__init__``
51 in order to construct the Azalea object, we need to not throw 44 in order to construct the Azalea object, we need to not throw
52 exceptions since we want to be able to test the FinditForChromeCrash 45 exceptions since we want to be able to test the FinditForChromeCrash
53 class itself. 46 class itself.
54 """ 47 """
55 return '' 48 return ''
56 49
57 @property 50 @property
58 def config(self): 51 def config(self):
59 """Avoid returning None. 52 """Avoid returning None.
60 53
61 The default ``Findit.config`` will return None if the client 54 The default ``Findit.config`` will return None if the client
62 id is not found in the CrashConfig. This in turn will cause 55 id is not found in the CrashConfig. This in turn will cause
63 ``FinditForChromeCrash.__init__`` to crash, since NoneType doesn't 56 ``FinditForChromeCrash.__init__`` to crash, since NoneType doesn't
64 have a ``get`` method. In general it's fine for things to crash, since 57 have a ``get`` method. In general it's fine for things to crash, since
65 noone should make instances of Findit subclasses which don't define 58 noone should make instances of Findit subclasses which don't define
66 ``_clientID``; but for this test suite, we want to permit instances 59 ``_clientID``; but for this test suite, we want to permit instances
67 of FinditForChromeCrash, so that we can test that class directly. 60 of FinditForChromeCrash, so that we can test that class directly.
68 """ 61 """
69 return {} 62 return {}
70 63
71 def _FinditForFracas(): 64 def _FinditForFracas():
72 """A helper to pass in the standard pipeline class.""" 65 """A helper to pass in the standard pipeline class."""
73 return FinditForFracas(MOCK_REPOSITORY, MOCK_PIPELINE_CLS) 66 return FinditForFracas(MOCK_REPOSITORY)
74 67
75 68
76 class FinditForChromeCrashTest(CrashTestCase): 69 class FinditForChromeCrashTest(CrashTestCase):
77 70
78 chrome_dep_fetcher = chrome_dependency_fetcher.ChromeDependencyFetcher( 71 chrome_dep_fetcher = chrome_dependency_fetcher.ChromeDependencyFetcher(
79 gitiles_repository.GitilesRepository(http_client=HttpClientAppengine())) 72 gitiles_repository.GitilesRepository(http_client=HttpClientAppengine()))
80 73
81 # TODO(wrengr): what was the purpose of this test? As written it's 74 # TODO(wrengr): what was the purpose of this test? As written it's
82 # just testing that mocking works. I'm guessing it was to check that 75 # just testing that mocking works. I'm guessing it was to check that
83 # we fail when the analysis is for the wrong client_id; but if so, 76 # we fail when the analysis is for the wrong client_id; but if so,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 findit_client = _FinditForFracas() 162 findit_client = _FinditForFracas()
170 crash_data = DummyCrashData() 163 crash_data = DummyCrashData()
171 crash_identifiers = crash_data['crash_identifiers'] 164 crash_identifiers = crash_data['crash_identifiers']
172 for status in (analysis_status.PENDING, analysis_status.RUNNING, 165 for status in (analysis_status.PENDING, analysis_status.RUNNING,
173 analysis_status.COMPLETED, analysis_status.SKIPPED): 166 analysis_status.COMPLETED, analysis_status.SKIPPED):
174 analysis = findit_client.CreateAnalysis(crash_identifiers) 167 analysis = findit_client.CreateAnalysis(crash_identifiers)
175 analysis.status = status 168 analysis.status = status
176 analysis.put() 169 analysis.put()
177 self.assertFalse(findit_client._NeedsNewAnalysis(crash_data)) 170 self.assertFalse(findit_client._NeedsNewAnalysis(crash_data))
178 171
179 def testScheduleNewAnalysisSkipsUnsupportedChannel(self):
180 self.assertFalse(_FinditForFracas().ScheduleNewAnalysis(DummyCrashData(
181 version = None,
182 signature = None,
183 crash_identifiers = {},
184 channel = 'unsupported_channel')))
185
186 def testScheduleNewAnalysisSkipsUnsupportedPlatform(self):
187 self.assertFalse(_FinditForFracas().ScheduleNewAnalysis(DummyCrashData(
188 version = None,
189 signature = None,
190 platform = 'unsupported_platform',
191 crash_identifiers = {})))
192
193 def testScheduleNewAnalysisSkipsBlackListSignature(self):
194 self.assertFalse(_FinditForFracas().ScheduleNewAnalysis(DummyCrashData(
195 version = None,
196 signature = 'Blacklist marker signature',
197 crash_identifiers = {})))
198
199 def testScheduleNewAnalysisSkipsIfAlreadyCompleted(self):
200 findit_client = _FinditForFracas()
201 crash_data = DummyCrashData()
202 crash_identifiers = crash_data['crash_identifiers']
203 analysis = findit_client.CreateAnalysis(crash_identifiers)
204 analysis.status = analysis_status.COMPLETED
205 analysis.put()
206 self.assertFalse(findit_client.ScheduleNewAnalysis(crash_data))
207
208 def testFindCulpritForChromeCrashEmptyStacktrace(self): 172 def testFindCulpritForChromeCrashEmptyStacktrace(self):
209 self.mock(chrome_dependency_fetcher.ChromeDependencyFetcher, 173 self.mock(chrome_dependency_fetcher.ChromeDependencyFetcher,
210 'GetDependency', lambda *_: {}) 174 'GetDependency', lambda *_: {})
211 self.mock(ChromeCrashParser, 'Parse', lambda *_: Stacktrace()) 175 self.mock(ChromeCrashParser, 'Parse', lambda *_: Stacktrace())
212 176
213 analysis = CrashAnalysis() 177 analysis = CrashAnalysis()
214 analysis.signature = 'signature' 178 analysis.signature = 'signature'
215 analysis.platform = 'win' 179 analysis.platform = 'win'
216 analysis.stack_trace = 'frame1\nframe2' 180 analysis.stack_trace = 'frame1\nframe2'
217 analysis.crashed_version = '50.0.1234.0' 181 analysis.crashed_version = '50.0.1234.0'
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 expected_tag = { 252 expected_tag = {
289 'found_suspects': False, 253 'found_suspects': False,
290 'found_project': False, 254 'found_project': False,
291 'found_components': False, 255 'found_components': False,
292 'has_regression_range': False, 256 'has_regression_range': False,
293 'solution': 'core_algorithm', 257 'solution': 'core_algorithm',
294 } 258 }
295 259
296 self.assertDictEqual(expected_results, results) 260 self.assertDictEqual(expected_results, results)
297 self.assertDictEqual(expected_tag, tag) 261 self.assertDictEqual(expected_tag, tag)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698