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

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

Issue 2673733002: [Predator] Add CrashData class to process raw json crash data. (Closed)
Patch Set: Rename CrashBuffer to CrashData Created 3 years, 10 months 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 import copy 5 import copy
6 import re 6 import re
7 7
8 import gae_ts_mon 8 import gae_ts_mon
9 from google.appengine.api import users 9 from google.appengine.api import users
10 10
11 from crash.crash_data import CrashData
12 from crash.findit import Findit
11 from gae_libs.testcase import TestCase 13 from gae_libs.testcase import TestCase
12 from libs.gitiles.change_log import ChangeLog 14 from libs.gitiles.change_log import ChangeLog
15 from libs.gitiles.gitiles_repository import GitilesRepository
13 from libs.http import retry_http_client 16 from libs.http import retry_http_client
14 from model.crash.crash_config import CrashConfig 17 from model.crash.crash_config import CrashConfig
18 from model.crash.crash_analysis import CrashAnalysis
15 19
16 20
17 DEFAULT_CONFIG_DATA = { 21 DEFAULT_CONFIG_DATA = {
18 'fracas': { 22 'fracas': {
19 'analysis_result_pubsub_topic': 'projects/project-name/topics/name', 23 'analysis_result_pubsub_topic': 'projects/project-name/topics/name',
20 'supported_platform_list_by_channel': { 24 'supported_platform_list_by_channel': {
21 'canary': ['win', 'mac', 'linux'], 25 'canary': ['win', 'mac', 'linux'],
22 'supported_channel': ['supported_platform'], 26 'supported_channel': ['supported_platform'],
23 }, 27 },
24 'platform_rename': {'linux': 'unix'}, 28 'platform_rename': {'linux': 'unix'},
25 'signature_blacklist_markers': ['Blacklist marker'], 29 'signature_blacklist_markers': ['Blacklist marker'],
26 'top_n': 7 30 'top_n': 7
27 }, 31 },
32 'cracas': {
33 'analysis_result_pubsub_topic': 'projects/project-name/topics/name',
34 'supported_platform_list_by_channel': {
35 'canary': ['win', 'mac', 'linux'],
36 'supported_channel': ['supported_platform'],
37 },
38 'platform_rename': {'linux': 'unix'},
39 'signature_blacklist_markers': ['Blacklist marker'],
40 'top_n': 7
41 },
28 'component_classifier': { 42 'component_classifier': {
29 'path_function_component': [ 43 'path_function_component': [
30 [ 44 [
31 'src/comp1.*', 45 'src/comp1.*',
32 '', 46 '',
33 'Comp1>Dummy' 47 'Comp1>Dummy'
34 ], 48 ],
35 [ 49 [
36 'src/comp2.*', 50 'src/comp2.*',
37 'func2.*', 51 'func2.*',
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 ], 95 ],
82 'commit_url': 96 'commit_url':
83 'https://repo.test/+/1', 97 'https://repo.test/+/1',
84 'code_review_url': 'https://codereview.chromium.org/3281', 98 'code_review_url': 'https://codereview.chromium.org/3281',
85 'revision': '1', 99 'revision': '1',
86 'reverted_revision': None 100 'reverted_revision': None
87 }) 101 })
88 102
89 103
90 104
91 class PredatorTestCase(TestCase): # pragma: no cover. 105 class PredatorTestCase(TestCase): # pragma: no cover
92 106
93 def setUp(self): 107 def setUp(self):
94 super(PredatorTestCase, self).setUp() 108 super(PredatorTestCase, self).setUp()
95 CrashConfig.Get().Update( 109 CrashConfig.Get().Update(
96 users.User(email='admin@chromium.org'), True, **DEFAULT_CONFIG_DATA) 110 users.User(email='admin@chromium.org'), True, **DEFAULT_CONFIG_DATA)
97 gae_ts_mon.reset_for_unittest(disable=True) 111 gae_ts_mon.reset_for_unittest(disable=True)
98 112
99 def GetDummyChangeLog(self): 113 def GetDummyChangeLog(self):
100 return DUMMY_CHANGELOG 114 return DUMMY_CHANGELOG
115
116 def GetMockFindit(self, get_repository=None, config=None,
117 client_id='mock_client'):
118 """Gets Mocked ``Findit`` object."""
119 get_repository = (get_repository or
120 GitilesRepository.Factory(self.GetMockHttpClient()))
121 config = config or CrashConfig.Get()
122
123 class MockFindit(Findit): # pylint: disable=W0223
124 """Overwrite abstract method of Findit for testing."""
125 def __init__(self):
126 super(MockFindit, self).__init__(get_repository, config)
127
128 @classmethod
129 def _ClientID(cls):
130 return client_id
131
132 def ProcessResultForPublishing(self, result, key):
133 return result
134
135 def GetAnalysis(self, crash_identifiers):
136 return CrashAnalysis.Get(crash_identifiers)
137
138 def CreateAnalysis(self, crash_identifiers):
139 return CrashAnalysis.Create(crash_identifiers)
140
141 return MockFindit()
142
143 def GetDummyCrashData(self, client_id='mock_client', version='1',
144 signature='signature', platform='win',
145 stack_trace=None, regression_range=None,
146 channel='canary', historical_metadata=None,
147 crash_identifiers=True, process_type='browser'):
148 """Gets Mocked crashed_data sent by clients."""
149 if crash_identifiers is True: # pragma: no cover
150 crash_identifiers = {
151 'chrome_version': version,
152 'signature': signature,
153 'channel': channel,
154 'platform': platform,
155 'process_type': process_type,
156 }
157 crash_data = {
158 'chrome_version': version,
159 'signature': signature,
160 'platform': platform,
161 'stack_trace': stack_trace,
162 'regression_range': regression_range,
163 'crash_identifiers': crash_identifiers,
164 'customized_data': {
165 'historical_metadata': historical_metadata,
166 'channel': channel,
167 },
168 }
169 # This insertion of client_id is used for debugging ScheduleNewAnalysis.
170 if client_id is not None: # pragma: no cover
171 crash_data['client_id'] = client_id
172 return crash_data
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698