blob: 4979087b200d45abd1a456f57b22fedb5437a4a5 [file] [log] [blame]
Gregory Haynes4fc12542015-04-22 20:38:06 -07001# Copyright 2015 GoodData
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Jan Hrubane252a732017-01-03 15:03:09 +010015import re
Jamie Lennox3f16de52017-05-09 14:24:11 +100016from testtools.matchers import MatchesRegex, StartsWith
Jan Hruban324ca5b2015-11-05 19:28:54 +010017import time
Gregory Haynes4fc12542015-04-22 20:38:06 -070018
Wayne1a78c612015-06-11 17:14:13 -070019from tests.base import ZuulTestCase, simple_layout, random_sha1
Gregory Haynes4fc12542015-04-22 20:38:06 -070020
Gregory Haynes4fc12542015-04-22 20:38:06 -070021
22class TestGithubDriver(ZuulTestCase):
23 config_file = 'zuul-github-driver.conf'
24
25 @simple_layout('layouts/basic-github.yaml', driver='github')
26 def test_pull_event(self):
27 self.executor_server.hold_jobs_in_build = True
28
Jan Hruban37615e52015-11-19 14:30:49 +010029 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
30 self.fake_github.emitEvent(A.getPullRequestOpenedEvent())
Gregory Haynes4fc12542015-04-22 20:38:06 -070031 self.waitUntilSettled()
32
33 build_params = self.builds[0].parameters
34 self.assertEqual('master', build_params['ZUUL_BRANCH'])
Jan Hruban37615e52015-11-19 14:30:49 +010035 self.assertEqual(str(A.number), build_params['ZUUL_CHANGE'])
36 self.assertEqual(A.head_sha, build_params['ZUUL_PATCHSET'])
Gregory Haynes4fc12542015-04-22 20:38:06 -070037
38 self.executor_server.hold_jobs_in_build = False
39 self.executor_server.release()
40 self.waitUntilSettled()
41
42 self.assertEqual('SUCCESS',
43 self.getJobFromHistory('project-test1').result)
44 self.assertEqual('SUCCESS',
45 self.getJobFromHistory('project-test2').result)
46
47 job = self.getJobFromHistory('project-test2')
48 zuulvars = job.parameters['vars']['zuul']
Jan Hruban37615e52015-11-19 14:30:49 +010049 self.assertEqual(A.number, zuulvars['change'])
50 self.assertEqual(A.head_sha, zuulvars['patchset'])
51 self.assertEqual(1, len(A.comments))
Jan Hruband4edee82015-12-16 12:49:51 +010052 self.assertEqual(2, len(self.history))
53
54 # test_pull_unmatched_branch_event(self):
55 self.create_branch('org/project', 'unmatched_branch')
56 B = self.fake_github.openFakePullRequest(
57 'org/project', 'unmatched_branch', 'B')
58 self.fake_github.emitEvent(B.getPullRequestOpenedEvent())
59 self.waitUntilSettled()
60
61 self.assertEqual(2, len(self.history))
Wayne1a78c612015-06-11 17:14:13 -070062
Jan Hruban570d01c2016-03-10 21:51:32 +010063 @simple_layout('layouts/files-github.yaml', driver='github')
64 def test_pull_matched_file_event(self):
65 A = self.fake_github.openFakePullRequest(
66 'org/project', 'master', 'A',
67 files=['random.txt', 'build-requires'])
68 self.fake_github.emitEvent(A.getPullRequestOpenedEvent())
69 self.waitUntilSettled()
70 self.assertEqual(1, len(self.history))
71
72 # test_pull_unmatched_file_event
73 B = self.fake_github.openFakePullRequest('org/project', 'master', 'B',
74 files=['random.txt'])
75 self.fake_github.emitEvent(B.getPullRequestOpenedEvent())
76 self.waitUntilSettled()
77 self.assertEqual(1, len(self.history))
78
Jan Hrubanc7ab1602015-10-14 15:29:33 +020079 @simple_layout('layouts/basic-github.yaml', driver='github')
80 def test_comment_event(self):
Jan Hruban37615e52015-11-19 14:30:49 +010081 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
82 self.fake_github.emitEvent(A.getCommentAddedEvent('test me'))
Jan Hrubanc7ab1602015-10-14 15:29:33 +020083 self.waitUntilSettled()
84 self.assertEqual(2, len(self.history))
85
86 # Test an unmatched comment, history should remain the same
Jan Hruban37615e52015-11-19 14:30:49 +010087 B = self.fake_github.openFakePullRequest('org/project', 'master', 'B')
88 self.fake_github.emitEvent(B.getCommentAddedEvent('casual comment'))
Jan Hrubanc7ab1602015-10-14 15:29:33 +020089 self.waitUntilSettled()
90 self.assertEqual(2, len(self.history))
91
Wayne1a78c612015-06-11 17:14:13 -070092 @simple_layout('layouts/push-tag-github.yaml', driver='github')
93 def test_tag_event(self):
94 self.executor_server.hold_jobs_in_build = True
95
96 sha = random_sha1()
97 self.fake_github.emitEvent(
98 self.fake_github.getPushEvent('org/project', 'refs/tags/newtag',
99 new_rev=sha))
100 self.waitUntilSettled()
101
102 build_params = self.builds[0].parameters
103 self.assertEqual('refs/tags/newtag', build_params['ZUUL_REF'])
104 self.assertEqual('00000000000000000000000000000000',
105 build_params['ZUUL_OLDREV'])
106 self.assertEqual(sha, build_params['ZUUL_NEWREV'])
107
108 self.executor_server.hold_jobs_in_build = False
109 self.executor_server.release()
110 self.waitUntilSettled()
111
112 self.assertEqual('SUCCESS',
113 self.getJobFromHistory('project-tag').result)
114
115 @simple_layout('layouts/push-tag-github.yaml', driver='github')
116 def test_push_event(self):
117 self.executor_server.hold_jobs_in_build = True
118
119 old_sha = random_sha1()
120 new_sha = random_sha1()
121 self.fake_github.emitEvent(
122 self.fake_github.getPushEvent('org/project', 'refs/heads/master',
123 old_sha, new_sha))
124 self.waitUntilSettled()
125
126 build_params = self.builds[0].parameters
127 self.assertEqual('refs/heads/master', build_params['ZUUL_REF'])
128 self.assertEqual(old_sha, build_params['ZUUL_OLDREV'])
129 self.assertEqual(new_sha, build_params['ZUUL_NEWREV'])
130
131 self.executor_server.hold_jobs_in_build = False
132 self.executor_server.release()
133 self.waitUntilSettled()
134
135 self.assertEqual('SUCCESS',
136 self.getJobFromHistory('project-post').result)
Jan Hruband4edee82015-12-16 12:49:51 +0100137 self.assertEqual(1, len(self.history))
138
139 # test unmatched push event
140 old_sha = random_sha1()
141 new_sha = random_sha1()
142 self.fake_github.emitEvent(
143 self.fake_github.getPushEvent('org/project',
144 'refs/heads/unmatched_branch',
145 old_sha, new_sha))
146 self.waitUntilSettled()
147
148 self.assertEqual(1, len(self.history))
Jan Hruban6d53c5e2015-10-24 03:03:34 +0200149
Jan Hruban16ad31f2015-11-07 14:39:07 +0100150 @simple_layout('layouts/labeling-github.yaml', driver='github')
151 def test_labels(self):
Jan Hruban37615e52015-11-19 14:30:49 +0100152 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
Jan Hruban16ad31f2015-11-07 14:39:07 +0100153 self.fake_github.emitEvent(A.addLabel('test'))
154 self.waitUntilSettled()
155 self.assertEqual(1, len(self.history))
156 self.assertEqual('project-labels', self.history[0].name)
157 self.assertEqual(['tests passed'], A.labels)
158
159 # test label removed
Jan Hruban37615e52015-11-19 14:30:49 +0100160 B = self.fake_github.openFakePullRequest('org/project', 'master', 'B')
Jan Hruban16ad31f2015-11-07 14:39:07 +0100161 B.addLabel('do not test')
162 self.fake_github.emitEvent(B.removeLabel('do not test'))
163 self.waitUntilSettled()
164 self.assertEqual(2, len(self.history))
165 self.assertEqual('project-labels', self.history[1].name)
166 self.assertEqual(['tests passed'], B.labels)
167
168 # test unmatched label
Jan Hruban37615e52015-11-19 14:30:49 +0100169 C = self.fake_github.openFakePullRequest('org/project', 'master', 'C')
Jan Hruban16ad31f2015-11-07 14:39:07 +0100170 self.fake_github.emitEvent(C.addLabel('other label'))
171 self.waitUntilSettled()
172 self.assertEqual(2, len(self.history))
173 self.assertEqual(['other label'], C.labels)
174
Jesse Keating5c05a9f2017-01-12 14:44:58 -0800175 @simple_layout('layouts/reviews-github.yaml', driver='github')
176 def test_review_event(self):
177 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
178 self.fake_github.emitEvent(A.getReviewAddedEvent('approve'))
179 self.waitUntilSettled()
180 self.assertEqual(1, len(self.history))
181 self.assertEqual('project-reviews', self.history[0].name)
182 self.assertEqual(['tests passed'], A.labels)
183
184 # test_review_unmatched_event
185 B = self.fake_github.openFakePullRequest('org/project', 'master', 'B')
186 self.fake_github.emitEvent(B.getReviewAddedEvent('comment'))
187 self.waitUntilSettled()
188 self.assertEqual(1, len(self.history))
189
Jan Hruban324ca5b2015-11-05 19:28:54 +0100190 @simple_layout('layouts/dequeue-github.yaml', driver='github')
191 def test_dequeue_pull_synchronized(self):
192 self.executor_server.hold_jobs_in_build = True
193
Jan Hruban37615e52015-11-19 14:30:49 +0100194 A = self.fake_github.openFakePullRequest(
195 'org/one-job-project', 'master', 'A')
196 self.fake_github.emitEvent(A.getPullRequestOpenedEvent())
Jan Hruban324ca5b2015-11-05 19:28:54 +0100197 self.waitUntilSettled()
198
199 # event update stamp has resolution one second, wait so the latter
200 # one has newer timestamp
201 time.sleep(1)
Jan Hruban37615e52015-11-19 14:30:49 +0100202 A.addCommit()
203 self.fake_github.emitEvent(A.getPullRequestSynchronizeEvent())
Jan Hruban324ca5b2015-11-05 19:28:54 +0100204 self.waitUntilSettled()
205
206 self.executor_server.hold_jobs_in_build = False
207 self.executor_server.release()
208 self.waitUntilSettled()
209
210 self.assertEqual(2, len(self.history))
211 self.assertEqual(1, self.countJobResults(self.history, 'ABORTED'))
212
213 @simple_layout('layouts/dequeue-github.yaml', driver='github')
214 def test_dequeue_pull_abandoned(self):
215 self.executor_server.hold_jobs_in_build = True
216
Jan Hruban37615e52015-11-19 14:30:49 +0100217 A = self.fake_github.openFakePullRequest(
218 'org/one-job-project', 'master', 'A')
219 self.fake_github.emitEvent(A.getPullRequestOpenedEvent())
Jan Hruban324ca5b2015-11-05 19:28:54 +0100220 self.waitUntilSettled()
Jan Hruban37615e52015-11-19 14:30:49 +0100221 self.fake_github.emitEvent(A.getPullRequestClosedEvent())
Jan Hruban324ca5b2015-11-05 19:28:54 +0100222 self.waitUntilSettled()
223
224 self.executor_server.hold_jobs_in_build = False
225 self.executor_server.release()
226 self.waitUntilSettled()
227
228 self.assertEqual(1, len(self.history))
229 self.assertEqual(1, self.countJobResults(self.history, 'ABORTED'))
230
Jan Hruban6d53c5e2015-10-24 03:03:34 +0200231 @simple_layout('layouts/basic-github.yaml', driver='github')
232 def test_git_https_url(self):
233 """Test that git_ssh option gives git url with ssh"""
234 url = self.fake_github.real_getGitUrl('org/project')
235 self.assertEqual('https://github.com/org/project', url)
236
237 @simple_layout('layouts/basic-github.yaml', driver='github')
238 def test_git_ssh_url(self):
239 """Test that git_ssh option gives git url with ssh"""
240 url = self.fake_github_ssh.real_getGitUrl('org/project')
241 self.assertEqual('ssh://git@github.com/org/project.git', url)
Jan Hrubane252a732017-01-03 15:03:09 +0100242
Jesse Keatingbe4ef8a2016-12-06 11:29:13 -0800243 @simple_layout('layouts/basic-github.yaml', driver='github')
244 def test_git_enterprise_url(self):
245 """Test that git_url option gives git url with proper host"""
246 url = self.fake_github_ent.real_getGitUrl('org/project')
247 self.assertEqual('ssh://git@github.enterprise.io/org/project.git', url)
248
Jan Hrubane252a732017-01-03 15:03:09 +0100249 @simple_layout('layouts/reporting-github.yaml', driver='github')
250 def test_reporting(self):
251 # pipeline reports pull status both on start and success
252 self.executor_server.hold_jobs_in_build = True
Jan Hruban37615e52015-11-19 14:30:49 +0100253 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
254 self.fake_github.emitEvent(A.getPullRequestOpenedEvent())
Jan Hrubane252a732017-01-03 15:03:09 +0100255 self.waitUntilSettled()
Jesse Keatingd96e5882017-01-19 13:55:50 -0800256 # We should have a status container for the head sha
257 self.assertIn(A.head_sha, A.statuses.keys())
258 # We should only have one status for the head sha
259 self.assertEqual(1, len(A.statuses[A.head_sha]))
260 check_status = A.statuses[A.head_sha][0]
Jan Hrubanddeb95a2017-01-03 15:12:41 +0100261 check_url = ('http://zuul.example.com/status/#%s,%s' %
262 (A.number, A.head_sha))
Jamie Lennox18bc7ed2017-05-10 10:37:55 +1000263 self.assertEqual('tenant-one/check', check_status['context'])
Jan Hrubane252a732017-01-03 15:03:09 +0100264 self.assertEqual('Standard check', check_status['description'])
265 self.assertEqual('pending', check_status['state'])
Jan Hrubanddeb95a2017-01-03 15:12:41 +0100266 self.assertEqual(check_url, check_status['url'])
Jan Hruban37615e52015-11-19 14:30:49 +0100267 self.assertEqual(0, len(A.comments))
Jan Hrubane252a732017-01-03 15:03:09 +0100268
269 self.executor_server.hold_jobs_in_build = False
270 self.executor_server.release()
271 self.waitUntilSettled()
Jesse Keatingd96e5882017-01-19 13:55:50 -0800272 # We should only have two statuses for the head sha
273 self.assertEqual(2, len(A.statuses[A.head_sha]))
274 check_status = A.statuses[A.head_sha][0]
275 check_url = ('http://zuul.example.com/status/#%s,%s' %
276 (A.number, A.head_sha))
Jamie Lennox18bc7ed2017-05-10 10:37:55 +1000277 self.assertEqual('tenant-one/check', check_status['context'])
Jan Hrubane252a732017-01-03 15:03:09 +0100278 self.assertEqual('success', check_status['state'])
Jan Hrubanddeb95a2017-01-03 15:12:41 +0100279 self.assertEqual(check_url, check_status['url'])
Jan Hruban37615e52015-11-19 14:30:49 +0100280 self.assertEqual(1, len(A.comments))
281 self.assertThat(A.comments[0],
Jan Hrubane252a732017-01-03 15:03:09 +0100282 MatchesRegex('.*Build succeeded.*', re.DOTALL))
283
284 # pipeline does not report any status but does comment
285 self.executor_server.hold_jobs_in_build = True
286 self.fake_github.emitEvent(
Jan Hruban37615e52015-11-19 14:30:49 +0100287 A.getCommentAddedEvent('reporting check'))
Jan Hrubane252a732017-01-03 15:03:09 +0100288 self.waitUntilSettled()
Jesse Keatingd96e5882017-01-19 13:55:50 -0800289 self.assertEqual(2, len(A.statuses[A.head_sha]))
Jan Hrubane252a732017-01-03 15:03:09 +0100290 # comments increased by one for the start message
Jan Hruban37615e52015-11-19 14:30:49 +0100291 self.assertEqual(2, len(A.comments))
292 self.assertThat(A.comments[1],
Jan Hrubane252a732017-01-03 15:03:09 +0100293 MatchesRegex('.*Starting reporting jobs.*', re.DOTALL))
294 self.executor_server.hold_jobs_in_build = False
295 self.executor_server.release()
296 self.waitUntilSettled()
Jesse Keatingd96e5882017-01-19 13:55:50 -0800297 # pipeline reports success status
298 self.assertEqual(3, len(A.statuses[A.head_sha]))
299 report_status = A.statuses[A.head_sha][0]
Jamie Lennox18bc7ed2017-05-10 10:37:55 +1000300 self.assertEqual('tenant-one/reporting', report_status['context'])
Jesse Keatingd96e5882017-01-19 13:55:50 -0800301 self.assertEqual('success', report_status['state'])
Jan Hruban37615e52015-11-19 14:30:49 +0100302 self.assertEqual(2, len(A.comments))
Jamie Lennox3f16de52017-05-09 14:24:11 +1000303
304 base = 'http://logs.example.com/tenant-one/reporting/%s/%s/' % (
305 A.project, A.number)
306
307 # Deconstructing the URL because we don't save the BuildSet UUID
308 # anywhere to do a direct comparison and doing regexp matches on a full
309 # URL is painful.
310
311 # The first part of the URL matches the easy base string
312 self.assertThat(report_status['url'], StartsWith(base))
313
314 # The rest of the URL is a UUID and a trailing slash.
315 self.assertThat(report_status['url'][len(base):],
316 MatchesRegex('^[a-fA-F0-9]{32}\/$'))
Jan Hruban49bff072015-11-03 11:45:46 +0100317
318 @simple_layout('layouts/merging-github.yaml', driver='github')
319 def test_report_pull_merge(self):
320 # pipeline merges the pull request on success
Jan Hruban3b415922016-02-03 13:10:22 +0100321 A = self.fake_github.openFakePullRequest('org/project', 'master',
322 'PR title')
Jan Hruban49bff072015-11-03 11:45:46 +0100323 self.fake_github.emitEvent(A.getCommentAddedEvent('merge me'))
324 self.waitUntilSettled()
325 self.assertTrue(A.is_merged)
Jan Hruban3b415922016-02-03 13:10:22 +0100326 self.assertThat(A.merge_message,
327 MatchesRegex('.*PR title.*Reviewed-by.*', re.DOTALL))
Jan Hruban49bff072015-11-03 11:45:46 +0100328
329 # pipeline merges the pull request on success after failure
330 self.fake_github.merge_failure = True
Jan Hruban37615e52015-11-19 14:30:49 +0100331 B = self.fake_github.openFakePullRequest('org/project', 'master', 'B')
Jan Hruban49bff072015-11-03 11:45:46 +0100332 self.fake_github.emitEvent(B.getCommentAddedEvent('merge me'))
333 self.waitUntilSettled()
334 self.assertFalse(B.is_merged)
335 self.fake_github.merge_failure = False
336
337 # pipeline merges the pull request on second run of merge
338 # first merge failed on 405 Method Not Allowed error
339 self.fake_github.merge_not_allowed_count = 1
Jan Hruban37615e52015-11-19 14:30:49 +0100340 C = self.fake_github.openFakePullRequest('org/project', 'master', 'C')
Jan Hruban49bff072015-11-03 11:45:46 +0100341 self.fake_github.emitEvent(C.getCommentAddedEvent('merge me'))
342 self.waitUntilSettled()
343 self.assertTrue(C.is_merged)
344
345 # pipeline does not merge the pull request
346 # merge failed on 405 Method Not Allowed error - twice
347 self.fake_github.merge_not_allowed_count = 2
Jan Hruban37615e52015-11-19 14:30:49 +0100348 D = self.fake_github.openFakePullRequest('org/project', 'master', 'D')
Jan Hruban49bff072015-11-03 11:45:46 +0100349 self.fake_github.emitEvent(D.getCommentAddedEvent('merge me'))
350 self.waitUntilSettled()
351 self.assertFalse(D.is_merged)
Adam Gandelman62198cb2017-02-14 16:11:02 -0800352 self.assertEqual(len(D.comments), 1)
353 self.assertEqual(D.comments[0], 'Merge failed')
Jan Hruban37615e52015-11-19 14:30:49 +0100354
355 @simple_layout('layouts/dependent-github.yaml', driver='github')
356 def test_parallel_changes(self):
357 "Test that changes are tested in parallel and merged in series"
358
359 self.executor_server.hold_jobs_in_build = True
360 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
361 B = self.fake_github.openFakePullRequest('org/project', 'master', 'B')
362 C = self.fake_github.openFakePullRequest('org/project', 'master', 'C')
363
364 self.fake_github.emitEvent(A.addLabel('merge'))
365 self.fake_github.emitEvent(B.addLabel('merge'))
366 self.fake_github.emitEvent(C.addLabel('merge'))
367
368 self.waitUntilSettled()
369 self.assertEqual(len(self.builds), 1)
370 self.assertEqual(self.builds[0].name, 'project-merge')
371 self.assertTrue(self.builds[0].hasChanges(A))
372
373 self.executor_server.release('.*-merge')
374 self.waitUntilSettled()
375 self.assertEqual(len(self.builds), 3)
376 self.assertEqual(self.builds[0].name, 'project-test1')
377 self.assertTrue(self.builds[0].hasChanges(A))
378 self.assertEqual(self.builds[1].name, 'project-test2')
379 self.assertTrue(self.builds[1].hasChanges(A))
380 self.assertEqual(self.builds[2].name, 'project-merge')
381 self.assertTrue(self.builds[2].hasChanges(A, B))
382
383 self.executor_server.release('.*-merge')
384 self.waitUntilSettled()
385 self.assertEqual(len(self.builds), 5)
386 self.assertEqual(self.builds[0].name, 'project-test1')
387 self.assertTrue(self.builds[0].hasChanges(A))
388 self.assertEqual(self.builds[1].name, 'project-test2')
389 self.assertTrue(self.builds[1].hasChanges(A))
390
391 self.assertEqual(self.builds[2].name, 'project-test1')
392 self.assertTrue(self.builds[2].hasChanges(A))
393 self.assertEqual(self.builds[3].name, 'project-test2')
394 self.assertTrue(self.builds[3].hasChanges(A, B))
395
396 self.assertEqual(self.builds[4].name, 'project-merge')
397 self.assertTrue(self.builds[4].hasChanges(A, B, C))
398
399 self.executor_server.release('.*-merge')
400 self.waitUntilSettled()
401 self.assertEqual(len(self.builds), 6)
402 self.assertEqual(self.builds[0].name, 'project-test1')
403 self.assertTrue(self.builds[0].hasChanges(A))
404 self.assertEqual(self.builds[1].name, 'project-test2')
405 self.assertTrue(self.builds[1].hasChanges(A))
406
407 self.assertEqual(self.builds[2].name, 'project-test1')
408 self.assertTrue(self.builds[2].hasChanges(A, B))
409 self.assertEqual(self.builds[3].name, 'project-test2')
410 self.assertTrue(self.builds[3].hasChanges(A, B))
411
412 self.assertEqual(self.builds[4].name, 'project-test1')
413 self.assertTrue(self.builds[4].hasChanges(A, B, C))
414 self.assertEqual(self.builds[5].name, 'project-test2')
415 self.assertTrue(self.builds[5].hasChanges(A, B, C))
416
417 all_builds = self.builds[:]
418 self.release(all_builds[2])
419 self.release(all_builds[3])
420 self.waitUntilSettled()
421 self.assertFalse(A.is_merged)
422 self.assertFalse(B.is_merged)
423 self.assertFalse(C.is_merged)
424
425 self.release(all_builds[0])
426 self.release(all_builds[1])
427 self.waitUntilSettled()
428 self.assertTrue(A.is_merged)
429 self.assertTrue(B.is_merged)
430 self.assertFalse(C.is_merged)
431
432 self.executor_server.hold_jobs_in_build = False
433 self.executor_server.release()
434 self.waitUntilSettled()
435 self.assertEqual(len(self.builds), 0)
436 self.assertEqual(len(self.history), 9)
437 self.assertTrue(C.is_merged)
438
439 self.assertNotIn('merge', A.labels)
440 self.assertNotIn('merge', B.labels)
441 self.assertNotIn('merge', C.labels)
442
443 @simple_layout('layouts/dependent-github.yaml', driver='github')
444 def test_failed_changes(self):
445 "Test that a change behind a failed change is retested"
446 self.executor_server.hold_jobs_in_build = True
447
448 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
449 B = self.fake_github.openFakePullRequest('org/project', 'master', 'B')
450
451 self.executor_server.failJob('project-test1', A)
452
453 self.fake_github.emitEvent(A.addLabel('merge'))
454 self.fake_github.emitEvent(B.addLabel('merge'))
455 self.waitUntilSettled()
456
457 self.executor_server.release('.*-merge')
458 self.waitUntilSettled()
459
460 self.executor_server.hold_jobs_in_build = False
461 self.executor_server.release()
462
463 self.waitUntilSettled()
464 # It's certain that the merge job for change 2 will run, but
465 # the test1 and test2 jobs may or may not run.
466 self.assertTrue(len(self.history) > 6)
467 self.assertFalse(A.is_merged)
468 self.assertTrue(B.is_merged)
469 self.assertNotIn('merge', A.labels)
470 self.assertNotIn('merge', B.labels)
471
472 @simple_layout('layouts/dependent-github.yaml', driver='github')
473 def test_failed_change_at_head(self):
474 "Test that if a change at the head fails, jobs behind it are canceled"
475
476 self.executor_server.hold_jobs_in_build = True
477 A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
478 B = self.fake_github.openFakePullRequest('org/project', 'master', 'B')
479 C = self.fake_github.openFakePullRequest('org/project', 'master', 'C')
480
481 self.executor_server.failJob('project-test1', A)
482
483 self.fake_github.emitEvent(A.addLabel('merge'))
484 self.fake_github.emitEvent(B.addLabel('merge'))
485 self.fake_github.emitEvent(C.addLabel('merge'))
486
487 self.waitUntilSettled()
488
489 self.assertEqual(len(self.builds), 1)
490 self.assertEqual(self.builds[0].name, 'project-merge')
491 self.assertTrue(self.builds[0].hasChanges(A))
492
493 self.executor_server.release('.*-merge')
494 self.waitUntilSettled()
495 self.executor_server.release('.*-merge')
496 self.waitUntilSettled()
497 self.executor_server.release('.*-merge')
498 self.waitUntilSettled()
499
500 self.assertEqual(len(self.builds), 6)
501 self.assertEqual(self.builds[0].name, 'project-test1')
502 self.assertEqual(self.builds[1].name, 'project-test2')
503 self.assertEqual(self.builds[2].name, 'project-test1')
504 self.assertEqual(self.builds[3].name, 'project-test2')
505 self.assertEqual(self.builds[4].name, 'project-test1')
506 self.assertEqual(self.builds[5].name, 'project-test2')
507
508 self.release(self.builds[0])
509 self.waitUntilSettled()
510
511 # project-test2, project-merge for B
512 self.assertEqual(len(self.builds), 2)
513 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4)
514
515 self.executor_server.hold_jobs_in_build = False
516 self.executor_server.release()
517 self.waitUntilSettled()
518
519 self.assertEqual(len(self.builds), 0)
520 self.assertEqual(len(self.history), 15)
521 self.assertFalse(A.is_merged)
522 self.assertTrue(B.is_merged)
523 self.assertTrue(C.is_merged)
524 self.assertNotIn('merge', A.labels)
525 self.assertNotIn('merge', B.labels)
526 self.assertNotIn('merge', C.labels)
Jesse Keating71a47ff2017-06-06 11:36:43 -0700527
528 @simple_layout('layouts/basic-github.yaml', driver='github')
529 def test_push_event_reconfigure(self):
530 pevent = self.fake_github.getPushEvent(project='common-config',
531 ref='refs/heads/master',
532 modified_files=['zuul.yaml'])
533
534 # record previous tenant reconfiguration time, which may not be set
535 old = self.sched.tenant_last_reconfigured.get('tenant-one', 0)
536 time.sleep(1)
537 self.fake_github.emitEvent(pevent)
538 self.waitUntilSettled()
539 new = self.sched.tenant_last_reconfigured.get('tenant-one', 0)
540 # New timestamp should be greater than the old timestamp
541 self.assertLess(old, new)