| 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 | 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_configured_test_case |
| 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 Loading... |
| 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( |
| 97 'server_query_interval_seconds': 60, | 85 wf_configured_test_case.WaterfallTestCase): |
| 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 | 86 app_module = pipeline_handlers._APP |
| 105 | 87 |
| 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): | 88 def _MockTriggerTryJobs(self, responses): |
| 113 def MockedTriggerTryJobs(*_): | 89 def MockedTriggerTryJobs(*_): |
| 114 try_job_results = [] | 90 try_job_results = [] |
| 115 for response in responses: | 91 for response in responses: |
| 116 if response.get('error'): # pragma: no cover | 92 if response.get('error'): # pragma: no cover |
| 117 try_job_results.append(( | 93 try_job_results.append(( |
| 118 buildbucket_client.BuildbucketError(response['error']), None)) | 94 buildbucket_client.BuildbucketError(response['error']), None)) |
| 119 else: | 95 else: |
| 120 try_job_results.append(( | 96 try_job_results.append(( |
| 121 None, buildbucket_client.BuildbucketBuild(response['build']))) | 97 None, buildbucket_client.BuildbucketBuild(response['build']))) |
| 122 return try_job_results | 98 return try_job_results |
| 123 self.mock(buildbucket_client, 'TriggerTryJobs', MockedTriggerTryJobs) | 99 self.mock(buildbucket_client, 'TriggerTryJobs', MockedTriggerTryJobs) |
| 124 | 100 |
| 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): | 101 def _MockGetTryJobs(self, build_id): |
| 136 def MockedGetTryJobs(*_): | 102 def MockedGetTryJobs(*_): |
| 137 data = { | 103 data = { |
| 138 '1': { | 104 '1': { |
| 139 'build': { | 105 'build': { |
| 140 'id': '1', | 106 'id': '1', |
| 141 'url': 'url', | 107 'url': 'url', |
| 142 'status': 'COMPLETED', | 108 'status': 'COMPLETED', |
| 143 'result_details_json': json.dumps({ | 109 'result_details_json': json.dumps({ |
| 144 'properties': { | 110 'properties': { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 190 |
| 225 responses = [ | 191 responses = [ |
| 226 { | 192 { |
| 227 'build': { | 193 'build': { |
| 228 'id': '1', | 194 'id': '1', |
| 229 'url': 'url', | 195 'url': 'url', |
| 230 'status': 'SCHEDULED', | 196 'status': 'SCHEDULED', |
| 231 } | 197 } |
| 232 } | 198 } |
| 233 ] | 199 ] |
| 234 self._MockGetTrybotForWaterfallBuilder(master_name, builder_name) | |
| 235 self._MockTriggerTryJobs(responses) | 200 self._MockTriggerTryJobs(responses) |
| 236 self._MockGetTryJobs('1') | 201 self._MockGetTryJobs('1') |
| 237 self._MockGetChangeLog('rev2') | 202 self._MockGetChangeLog('rev2') |
| 238 self._MockGetTryJobSettings() | |
| 239 | 203 |
| 240 WfTryJob.Create(master_name, builder_name, build_number).put() | 204 WfTryJob.Create(master_name, builder_name, build_number).put() |
| 241 | 205 |
| 242 root_pipeline = SwarmingTasksToTryJobPipeline( | 206 root_pipeline = SwarmingTasksToTryJobPipeline( |
| 243 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], | 207 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], |
| 244 TryJobType.COMPILE) | 208 TryJobType.COMPILE) |
| 245 root_pipeline.start() | 209 root_pipeline.start() |
| 246 self.execute_queued_tasks() | 210 self.execute_queued_tasks() |
| 247 | 211 |
| 248 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 212 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 273 | 237 |
| 274 def testSuccessfullyScheduleNewTryJobForTest(self): | 238 def testSuccessfullyScheduleNewTryJobForTest(self): |
| 275 master_name = 'm' | 239 master_name = 'm' |
| 276 builder_name = 'b' | 240 builder_name = 'b' |
| 277 build_number = 1 | 241 build_number = 1 |
| 278 targeted_tests = { | 242 targeted_tests = { |
| 279 'a_test': ['TestSuite1.test1', 'TestSuite1.test3'], | 243 'a_test': ['TestSuite1.test1', 'TestSuite1.test3'], |
| 280 'b_test': [], # Non-swarming test. | 244 'b_test': [], # Non-swarming test. |
| 281 } | 245 } |
| 282 | 246 |
| 283 self._MockGetSwarmingSettings() | |
| 284 self._MockGetTryJobSettings() | |
| 285 | |
| 286 # Mocks for TriggerSwarmingTaskPipeline. | 247 # Mocks for TriggerSwarmingTaskPipeline. |
| 287 def MockedDownloadSwarmingTaskData(*_): | 248 def MockedDownloadSwarmingTaskData(*_): |
| 288 return [{'task_id': '1'}, {'task_id': '2'}] | 249 return [{'task_id': '1'}, {'task_id': '2'}] |
| 289 self.mock(swarming_util, 'ListSwarmingTasksDataByTags', | 250 self.mock(swarming_util, 'ListSwarmingTasksDataByTags', |
| 290 MockedDownloadSwarmingTaskData) | 251 MockedDownloadSwarmingTaskData) |
| 291 | 252 |
| 292 def MockedGetSwarmingTaskRequest(ref_task_id, *_): | 253 def MockedGetSwarmingTaskRequest(ref_task_id, *_): |
| 293 self.assertEqual('1', ref_task_id) | 254 self.assertEqual('1', ref_task_id) |
| 294 return SwarmingTaskRequest.Deserialize({ | 255 return SwarmingTaskRequest.Deserialize({ |
| 295 'expiration_secs': 3600, | 256 'expiration_secs': 3600, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 # Mocks for try job pipelines. | 315 # Mocks for try job pipelines. |
| 355 responses = [ | 316 responses = [ |
| 356 { | 317 { |
| 357 'build': { | 318 'build': { |
| 358 'id': '2', | 319 'id': '2', |
| 359 'url': 'url', | 320 'url': 'url', |
| 360 'status': 'SCHEDULED', | 321 'status': 'SCHEDULED', |
| 361 } | 322 } |
| 362 } | 323 } |
| 363 ] | 324 ] |
| 364 self._MockGetTrybotForWaterfallBuilder(master_name, builder_name) | |
| 365 self._MockTriggerTryJobs(responses) | 325 self._MockTriggerTryJobs(responses) |
| 366 self._MockGetTryJobs('2') | 326 self._MockGetTryJobs('2') |
| 367 self._MockGetChangeLog('rev1') | 327 self._MockGetChangeLog('rev1') |
| 368 | 328 |
| 369 WfTryJob.Create(master_name, builder_name, build_number).put() | 329 WfTryJob.Create(master_name, builder_name, build_number).put() |
| 370 | 330 |
| 371 root_pipeline = SwarmingTasksToTryJobPipeline( | 331 root_pipeline = SwarmingTasksToTryJobPipeline( |
| 372 master_name, builder_name, build_number, 'rev0', 'rev1', ['rev1'], | 332 master_name, builder_name, build_number, 'rev0', 'rev1', ['rev1'], |
| 373 TryJobType.TEST, None, targeted_tests) | 333 TryJobType.TEST, None, targeted_tests) |
| 374 root_pipeline.start() | 334 root_pipeline.start() |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 'commit_position': '1', | 367 'commit_position': '1', |
| 408 'review_url': 'url_1' | 368 'review_url': 'url_1' |
| 409 } | 369 } |
| 410 } | 370 } |
| 411 } | 371 } |
| 412 } | 372 } |
| 413 } | 373 } |
| 414 ] | 374 ] |
| 415 | 375 |
| 416 self.assertEqual(expected_try_job_results, try_job.test_results) | 376 self.assertEqual(expected_try_job_results, try_job.test_results) |
| OLD | NEW |