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 |
10 from model.test import configured_test_case | |
12 from model.wf_try_job import WfTryJob | 11 from model.wf_try_job import WfTryJob |
13 from pipeline_wrapper import pipeline_handlers | 12 from pipeline_wrapper import pipeline_handlers |
14 from waterfall import waterfall_config | |
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(configured_test_case.ConfiguredTestCase): |
20 app_module = pipeline_handlers._APP | 18 app_module = pipeline_handlers._APP |
21 | 19 |
22 def _MockGetTrybotForWaterfallBuilder(self, *_): | 20 def setUp(self): |
23 def MockedGetTrybotForWaterfallBuilder(*_): | 21 super(TryJobPipelineTest, self).setUp() |
stgao
2016/03/30 01:06:30
Could be removed too.
lijeffrey
2016/03/30 23:28:34
Done.
| |
24 return 'linux_chromium_variable', 'master.tryserver.chromium.linux' | |
25 self.mock(waterfall_config, 'GetTrybotForWaterfallBuilder', | |
26 MockedGetTrybotForWaterfallBuilder) | |
27 | 22 |
28 def _Mock_TriggerTryJobs(self, responses): | 23 def _Mock_TriggerTryJobs(self, responses): |
29 def MockedTriggerTryJobs(*_): | 24 def MockedTriggerTryJobs(*_): |
30 try_job_results = [] | 25 try_job_results = [] |
31 for response in responses: | 26 for response in responses: |
32 if response.get('error'): # pragma: no cover | 27 if response.get('error'): # pragma: no cover |
33 try_job_results.append(( | 28 try_job_results.append(( |
34 buildbucket_client.BuildbucketError(response['error']), None)) | 29 buildbucket_client.BuildbucketError(response['error']), None)) |
35 else: | 30 else: |
36 try_job_results.append(( | 31 try_job_results.append(( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 | 80 |
86 def __init__(self, commit_position, code_review_url): | 81 def __init__(self, commit_position, code_review_url): |
87 self.commit_position = commit_position | 82 self.commit_position = commit_position |
88 self.code_review_url = code_review_url | 83 self.code_review_url = code_review_url |
89 | 84 |
90 mock_change_logs = {} | 85 mock_change_logs = {} |
91 mock_change_logs['rev2'] = MockedChangeLog('2', 'url_2') | 86 mock_change_logs['rev2'] = MockedChangeLog('2', 'url_2') |
92 return mock_change_logs.get(revision) | 87 return mock_change_logs.get(revision) |
93 self.mock(GitRepository, 'GetChangeLog', MockedGetChangeLog) | 88 self.mock(GitRepository, 'GetChangeLog', MockedGetChangeLog) |
94 | 89 |
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): | 90 def testSuccessfullyScheduleNewTryJobForCompile(self): |
105 master_name = 'm' | 91 master_name = 'm' |
106 builder_name = 'b' | 92 builder_name = 'b' |
107 build_number = 1 | 93 build_number = 1 |
108 | 94 |
109 responses = [ | 95 responses = [ |
110 { | 96 { |
111 'build': { | 97 'build': { |
112 'id': '1', | 98 'id': '1', |
113 'url': 'url', | 99 'url': 'url', |
114 'status': 'SCHEDULED', | 100 'status': 'SCHEDULED', |
115 } | 101 } |
116 } | 102 } |
117 ] | 103 ] |
118 self._MockGetTrybotForWaterfallBuilder(master_name, builder_name) | 104 |
119 self._Mock_TriggerTryJobs(responses) | 105 self._Mock_TriggerTryJobs(responses) |
120 self._Mock_GetTryJobs('1') | 106 self._Mock_GetTryJobs('1') |
121 self._Mock_GetChangeLog('rev2') | 107 self._Mock_GetChangeLog('rev2') |
122 self._MockGetTryJobSettings() | |
123 | 108 |
124 WfTryJob.Create(master_name, builder_name, build_number).put() | 109 WfTryJob.Create(master_name, builder_name, build_number).put() |
125 | 110 |
126 root_pipeline = TryJobPipeline( | 111 root_pipeline = TryJobPipeline( |
127 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], | 112 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], |
128 TryJobType.COMPILE, []) | 113 TryJobType.COMPILE, []) |
129 root_pipeline.start() | 114 root_pipeline.start() |
130 self.execute_queued_tasks() | 115 self.execute_queued_tasks() |
131 | 116 |
132 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 117 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 | 161 build_number = 1 |
177 | 162 |
178 root_pipeline = TryJobPipeline( | 163 root_pipeline = TryJobPipeline( |
179 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], | 164 master_name, builder_name, build_number, 'rev1', 'rev2', ['rev2'], |
180 TryJobType.COMPILE, []) | 165 TryJobType.COMPILE, []) |
181 root_pipeline._LogUnexpectedAbort(True) | 166 root_pipeline._LogUnexpectedAbort(True) |
182 | 167 |
183 try_job = WfTryJob.Get(master_name, builder_name, build_number) | 168 try_job = WfTryJob.Get(master_name, builder_name, build_number) |
184 | 169 |
185 self.assertIsNone(try_job) | 170 self.assertIsNone(try_job) |
OLD | NEW |