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

Side by Side Diff: appengine/findit/waterfall/test/swarming_tasks_to_try_job_pipeline_test.py

Issue 1836293002: [Findit] Adding central config test class for unit tests (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 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 json 5 import json
6 6
7 from testing_utils import testing
8
9 from common import buildbucket_client 7 from common import buildbucket_client
10 from common.git_repository import GitRepository 8 from common.git_repository import GitRepository
11 from model.wf_try_job import WfTryJob 9 from model.wf_try_job import WfTryJob
12 from pipeline_wrapper import pipeline_handlers 10 from pipeline_wrapper import pipeline_handlers
13 from waterfall import swarming_util 11 from waterfall import swarming_util
14 from waterfall import trigger_swarming_task_pipeline 12 from waterfall import trigger_swarming_task_pipeline
15 from waterfall import waterfall_config
16 from waterfall.swarming_task_request import SwarmingTaskRequest 13 from waterfall.swarming_task_request import SwarmingTaskRequest
17 from waterfall.swarming_tasks_to_try_job_pipeline import ( 14 from waterfall.swarming_tasks_to_try_job_pipeline import (
18 SwarmingTasksToTryJobPipeline) 15 SwarmingTasksToTryJobPipeline)
16 from waterfall.test import wf_testcase
19 from waterfall.try_job_type import TryJobType 17 from waterfall.try_job_type import TryJobType
20 18
21 19
22 _ISOLATED_SERVER = 'https://isolateserver.appspot.com' 20 _ISOLATED_SERVER = 'https://isolateserver.appspot.com'
23 _ISOLATED_STORAGE_URL = 'isolateserver.storage.googleapis.com' 21 _ISOLATED_STORAGE_URL = 'isolateserver.storage.googleapis.com'
24 _SAMPLE_FAILURE_LOG = { 22 _SAMPLE_FAILURE_LOG = {
25 'per_iteration_data': [ 23 'per_iteration_data': [
26 { 24 {
27 'TestSuite1.test1': [ 25 'TestSuite1.test1': [
28 { 26 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 'TestSuite1.test3': [ 73 'TestSuite1.test3': [
76 { 74 {
77 'status': 'FAILURE', 75 'status': 'FAILURE',
78 'other_info': 'N/A' 76 'other_info': 'N/A'
79 } 77 }
80 ] 78 ]
81 } 79 }
82 ] 80 ]
83 } 81 }
84 82
85 _MOCK_SWARMING_SETTINGS = {
86 'task_timeout_hours': 23,
87 'server_query_interval_seconds': 60,
88 'iterations_to_rerun': 10,
89 'server_host': 'chromium-swarm.appspot.com',
90 'default_request_priority': 150,
91 'isolated_storage_url': 'isolateserver.storage.googleapis.com',
92 'isolated_server': 'https://isolateserver.appspot.com',
93 'request_expiration_hours': 20
94 }
95 83
96 _MOCK_TRY_JOB_SETTINGS = { 84 class SwarmingTasksToTryJobPipelineTest(wf_testcase.WaterfallTestCase):
97 'server_query_interval_seconds': 60,
98 'job_timeout_hours': 5,
99 'allowed_response_error_times': 1
100 }
101
102
103 class SwarmingTasksToTryJobPipelineTest(testing.AppengineTestCase):
104 app_module = pipeline_handlers._APP 85 app_module = pipeline_handlers._APP
105 86
106 def _MockGetTrybotForWaterfallBuilder(self, *_):
107 def MockedGetTrybotForWaterfallBuilder(*_):
108 return 'linux_chromium_variable', 'master.tryserver.chromium.linux'
109 self.mock(waterfall_config, 'GetTrybotForWaterfallBuilder',
110 MockedGetTrybotForWaterfallBuilder)
111
112 def _MockTriggerTryJobs(self, responses): 87 def _MockTriggerTryJobs(self, responses):
113 def MockedTriggerTryJobs(*_): 88 def MockedTriggerTryJobs(*_):
114 try_job_results = [] 89 try_job_results = []
115 for response in responses: 90 for response in responses:
116 if response.get('error'): # pragma: no cover 91 if response.get('error'): # pragma: no cover
117 try_job_results.append(( 92 try_job_results.append((
118 buildbucket_client.BuildbucketError(response['error']), None)) 93 buildbucket_client.BuildbucketError(response['error']), None))
119 else: 94 else:
120 try_job_results.append(( 95 try_job_results.append((
121 None, buildbucket_client.BuildbucketBuild(response['build']))) 96 None, buildbucket_client.BuildbucketBuild(response['build'])))
122 return try_job_results 97 return try_job_results
123 self.mock(buildbucket_client, 'TriggerTryJobs', MockedTriggerTryJobs) 98 self.mock(buildbucket_client, 'TriggerTryJobs', MockedTriggerTryJobs)
124 99
125 def _MockGetSwarmingSettings(self):
126 def _GetMockSwarmingSettings():
127 return _MOCK_SWARMING_SETTINGS
128 self.mock(waterfall_config, 'GetSwarmingSettings', _GetMockSwarmingSettings)
129
130 def _MockGetTryJobSettings(self):
131 def _GetMockTryJobSettings():
132 return _MOCK_TRY_JOB_SETTINGS
133 self.mock(waterfall_config, 'GetTryJobSettings', _GetMockTryJobSettings)
134
135 def _MockGetTryJobs(self, build_id): 100 def _MockGetTryJobs(self, build_id):
136 def MockedGetTryJobs(*_): 101 def MockedGetTryJobs(*_):
137 data = { 102 data = {
138 '1': { 103 '1': {
139 'build': { 104 'build': {
140 'id': '1', 105 'id': '1',
141 'url': 'url', 106 'url': 'url',
142 'status': 'COMPLETED', 107 'status': 'COMPLETED',
143 'result_details_json': json.dumps({ 108 'result_details_json': json.dumps({
144 'properties': { 109 'properties': {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 189
225 responses = [ 190 responses = [
226 { 191 {
227 'build': { 192 'build': {
228 'id': '1', 193 'id': '1',
229 'url': 'url', 194 'url': 'url',
230 'status': 'SCHEDULED', 195 'status': 'SCHEDULED',
231 } 196 }
232 } 197 }
233 ] 198 ]
234 self._MockGetTrybotForWaterfallBuilder(master_name, builder_name)
235 self._MockTriggerTryJobs(responses) 199 self._MockTriggerTryJobs(responses)
236 self._MockGetTryJobs('1') 200 self._MockGetTryJobs('1')
237 self._MockGetChangeLog('rev2') 201 self._MockGetChangeLog('rev2')
238 self._MockGetTryJobSettings()
239 202
240 WfTryJob.Create(master_name, builder_name, build_number).put() 203 WfTryJob.Create(master_name, builder_name, build_number).put()
241 204
242 root_pipeline = SwarmingTasksToTryJobPipeline( 205 root_pipeline = SwarmingTasksToTryJobPipeline(
243 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], 206 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'],
244 TryJobType.COMPILE) 207 TryJobType.COMPILE)
245 root_pipeline.start() 208 root_pipeline.start()
246 self.execute_queued_tasks() 209 self.execute_queued_tasks()
247 210
248 try_job = WfTryJob.Get(master_name, builder_name, build_number) 211 try_job = WfTryJob.Get(master_name, builder_name, build_number)
(...skipping 24 matching lines...) Expand all
273 236
274 def testSuccessfullyScheduleNewTryJobForTest(self): 237 def testSuccessfullyScheduleNewTryJobForTest(self):
275 master_name = 'm' 238 master_name = 'm'
276 builder_name = 'b' 239 builder_name = 'b'
277 build_number = 1 240 build_number = 1
278 targeted_tests = { 241 targeted_tests = {
279 'a_test': ['TestSuite1.test1', 'TestSuite1.test3'], 242 'a_test': ['TestSuite1.test1', 'TestSuite1.test3'],
280 'b_test': [], # Non-swarming test. 243 'b_test': [], # Non-swarming test.
281 } 244 }
282 245
283 self._MockGetSwarmingSettings()
284 self._MockGetTryJobSettings()
285
286 # Mocks for TriggerSwarmingTaskPipeline. 246 # Mocks for TriggerSwarmingTaskPipeline.
287 def MockedDownloadSwarmingTaskData(*_): 247 def MockedDownloadSwarmingTaskData(*_):
288 return [{'task_id': '1'}, {'task_id': '2'}] 248 return [{'task_id': '1'}, {'task_id': '2'}]
289 self.mock(swarming_util, 'ListSwarmingTasksDataByTags', 249 self.mock(swarming_util, 'ListSwarmingTasksDataByTags',
290 MockedDownloadSwarmingTaskData) 250 MockedDownloadSwarmingTaskData)
291 251
292 def MockedGetSwarmingTaskRequest(ref_task_id, *_): 252 def MockedGetSwarmingTaskRequest(ref_task_id, *_):
293 self.assertEqual('1', ref_task_id) 253 self.assertEqual('1', ref_task_id)
294 return SwarmingTaskRequest.Deserialize({ 254 return SwarmingTaskRequest.Deserialize({
295 'expiration_secs': 3600, 255 'expiration_secs': 3600,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 # Mocks for try job pipelines. 314 # Mocks for try job pipelines.
355 responses = [ 315 responses = [
356 { 316 {
357 'build': { 317 'build': {
358 'id': '2', 318 'id': '2',
359 'url': 'url', 319 'url': 'url',
360 'status': 'SCHEDULED', 320 'status': 'SCHEDULED',
361 } 321 }
362 } 322 }
363 ] 323 ]
364 self._MockGetTrybotForWaterfallBuilder(master_name, builder_name)
365 self._MockTriggerTryJobs(responses) 324 self._MockTriggerTryJobs(responses)
366 self._MockGetTryJobs('2') 325 self._MockGetTryJobs('2')
367 self._MockGetChangeLog('rev1') 326 self._MockGetChangeLog('rev1')
368 327
369 WfTryJob.Create(master_name, builder_name, build_number).put() 328 WfTryJob.Create(master_name, builder_name, build_number).put()
370 329
371 root_pipeline = SwarmingTasksToTryJobPipeline( 330 root_pipeline = SwarmingTasksToTryJobPipeline(
372 master_name, builder_name, build_number, 'rev0', 'rev1', ['rev1'], 331 master_name, builder_name, build_number, 'rev0', 'rev1', ['rev1'],
373 TryJobType.TEST, None, targeted_tests) 332 TryJobType.TEST, None, targeted_tests)
374 root_pipeline.start() 333 root_pipeline.start()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 'commit_position': '1', 366 'commit_position': '1',
408 'review_url': 'url_1' 367 'review_url': 'url_1'
409 } 368 }
410 } 369 }
411 } 370 }
412 } 371 }
413 } 372 }
414 ] 373 ]
415 374
416 self.assertEqual(expected_try_job_results, try_job.test_results) 375 self.assertEqual(expected_try_job_results, try_job.test_results)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698