| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import wf_analysis_status | 9 from model import wf_analysis_status |
| 12 from model.wf_try_job import WfTryJob | 10 from model.wf_try_job import WfTryJob |
| 13 from pipeline_wrapper import pipeline_handlers | 11 from pipeline_wrapper import pipeline_handlers |
| 14 from waterfall import waterfall_config | 12 from waterfall.test import wf_testcase |
| 15 from waterfall.try_job_pipeline import TryJobPipeline | 13 from waterfall.try_job_pipeline import TryJobPipeline |
| 16 from waterfall.try_job_type import TryJobType | 14 from waterfall.try_job_type import TryJobType |
| 17 | 15 |
| 18 | 16 |
| 19 class TryJobPipelineTest(testing.AppengineTestCase): | 17 class TryJobPipelineTest(wf_testcase.WaterfallTestCase): |
| 20 app_module = pipeline_handlers._APP | 18 app_module = pipeline_handlers._APP |
| 21 | 19 |
| 22 def _MockGetTrybotForWaterfallBuilder(self, *_): | |
| 23 def MockedGetTrybotForWaterfallBuilder(*_): | |
| 24 return 'linux_chromium_variable', 'master.tryserver.chromium.linux' | |
| 25 self.mock(waterfall_config, 'GetTrybotForWaterfallBuilder', | |
| 26 MockedGetTrybotForWaterfallBuilder) | |
| 27 | |
| 28 def _Mock_TriggerTryJobs(self, responses): | 20 def _Mock_TriggerTryJobs(self, responses): |
| 29 def MockedTriggerTryJobs(*_): | 21 def MockedTriggerTryJobs(*_): |
| 30 try_job_results = [] | 22 try_job_results = [] |
| 31 for response in responses: | 23 for response in responses: |
| 32 if response.get('error'): # pragma: no cover | 24 if response.get('error'): # pragma: no cover |
| 33 try_job_results.append(( | 25 try_job_results.append(( |
| 34 buildbucket_client.BuildbucketError(response['error']), None)) | 26 buildbucket_client.BuildbucketError(response['error']), None)) |
| 35 else: | 27 else: |
| 36 try_job_results.append(( | 28 try_job_results.append(( |
| 37 None, buildbucket_client.BuildbucketBuild(response['build']))) | 29 None, buildbucket_client.BuildbucketBuild(response['build']))) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 77 |
| 86 def __init__(self, commit_position, code_review_url): | 78 def __init__(self, commit_position, code_review_url): |
| 87 self.commit_position = commit_position | 79 self.commit_position = commit_position |
| 88 self.code_review_url = code_review_url | 80 self.code_review_url = code_review_url |
| 89 | 81 |
| 90 mock_change_logs = {} | 82 mock_change_logs = {} |
| 91 mock_change_logs['rev2'] = MockedChangeLog('2', 'url_2') | 83 mock_change_logs['rev2'] = MockedChangeLog('2', 'url_2') |
| 92 return mock_change_logs.get(revision) | 84 return mock_change_logs.get(revision) |
| 93 self.mock(GitRepository, 'GetChangeLog', MockedGetChangeLog) | 85 self.mock(GitRepository, 'GetChangeLog', MockedGetChangeLog) |
| 94 | 86 |
| 95 def _MockGetTryJobSettings(self): | |
| 96 def _GetMockTryJobSettings(): | |
| 97 return { | |
| 98 'server_query_interval_seconds': 60, | |
| 99 'job_timeout_hours': 5, | |
| 100 'allowed_response_error_times': 1 | |
| 101 } | |
| 102 self.mock(waterfall_config, 'GetTryJobSettings', _GetMockTryJobSettings) | |
| 103 | |
| 104 def testSuccessfullyScheduleNewTryJobForCompile(self): | 87 def testSuccessfullyScheduleNewTryJobForCompile(self): |
| 105 master_name = 'm' | 88 master_name = 'm' |
| 106 builder_name = 'b' | 89 builder_name = 'b' |
| 107 build_number = 1 | 90 build_number = 1 |
| 108 | 91 |
| 109 responses = [ | 92 responses = [ |
| 110 { | 93 { |
| 111 'build': { | 94 'build': { |
| 112 'id': '1', | 95 'id': '1', |
| 113 'url': 'url', | 96 'url': 'url', |
| 114 'status': 'SCHEDULED', | 97 'status': 'SCHEDULED', |
| 115 } | 98 } |
| 116 } | 99 } |
| 117 ] | 100 ] |
| 118 self._MockGetTrybotForWaterfallBuilder(master_name, builder_name) | 101 |
| 119 self._Mock_TriggerTryJobs(responses) | 102 self._Mock_TriggerTryJobs(responses) |
| 120 self._Mock_GetTryJobs('1') | 103 self._Mock_GetTryJobs('1') |
| 121 self._Mock_GetChangeLog('rev2') | 104 self._Mock_GetChangeLog('rev2') |
| 122 self._MockGetTryJobSettings() | |
| 123 | 105 |
| 124 WfTryJob.Create(master_name, builder_name, build_number).put() | 106 WfTryJob.Create(master_name, builder_name, build_number).put() |
| 125 | 107 |
| 126 root_pipeline = TryJobPipeline( | 108 root_pipeline = TryJobPipeline( |
| 127 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], | 109 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], |
| 128 TryJobType.COMPILE, []) | 110 TryJobType.COMPILE, []) |
| 129 root_pipeline.start() | 111 root_pipeline.start() |
| 130 self.execute_queued_tasks() | 112 self.execute_queued_tasks() |
| 131 | 113 |
| 132 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 114 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 build_number = 1 | 158 build_number = 1 |
| 177 | 159 |
| 178 root_pipeline = TryJobPipeline( | 160 root_pipeline = TryJobPipeline( |
| 179 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], | 161 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], |
| 180 TryJobType.COMPILE, []) | 162 TryJobType.COMPILE, []) |
| 181 root_pipeline._LogUnexpectedAbort(True) | 163 root_pipeline._LogUnexpectedAbort(True) |
| 182 | 164 |
| 183 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 165 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
| 184 | 166 |
| 185 self.assertIsNone(try_job) | 167 self.assertIsNone(try_job) |
| OLD | NEW |