Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import logging |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 16 | import re |
| 17 | from testtools.matchers import MatchesRegex |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 18 | import time |
Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 19 | |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 20 | from tests.base import ZuulTestCase, simple_layout, random_sha1 |
Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 21 | |
| 22 | logging.basicConfig(level=logging.DEBUG, |
| 23 | format='%(asctime)s %(name)-32s ' |
| 24 | '%(levelname)-8s %(message)s') |
| 25 | |
| 26 | |
| 27 | class TestGithubDriver(ZuulTestCase): |
| 28 | config_file = 'zuul-github-driver.conf' |
| 29 | |
| 30 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 31 | def test_pull_event(self): |
| 32 | self.executor_server.hold_jobs_in_build = True |
| 33 | |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 34 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 35 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 36 | self.waitUntilSettled() |
| 37 | |
| 38 | build_params = self.builds[0].parameters |
| 39 | self.assertEqual('master', build_params['ZUUL_BRANCH']) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 40 | self.assertEqual(str(A.number), build_params['ZUUL_CHANGE']) |
| 41 | self.assertEqual(A.head_sha, build_params['ZUUL_PATCHSET']) |
Gregory Haynes | 4fc1254 | 2015-04-22 20:38:06 -0700 | [diff] [blame] | 42 | |
| 43 | self.executor_server.hold_jobs_in_build = False |
| 44 | self.executor_server.release() |
| 45 | self.waitUntilSettled() |
| 46 | |
| 47 | self.assertEqual('SUCCESS', |
| 48 | self.getJobFromHistory('project-test1').result) |
| 49 | self.assertEqual('SUCCESS', |
| 50 | self.getJobFromHistory('project-test2').result) |
| 51 | |
| 52 | job = self.getJobFromHistory('project-test2') |
| 53 | zuulvars = job.parameters['vars']['zuul'] |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 54 | self.assertEqual(A.number, zuulvars['change']) |
| 55 | self.assertEqual(A.head_sha, zuulvars['patchset']) |
| 56 | self.assertEqual(1, len(A.comments)) |
Jan Hruban | d4edee8 | 2015-12-16 12:49:51 +0100 | [diff] [blame] | 57 | self.assertEqual(2, len(self.history)) |
| 58 | |
| 59 | # test_pull_unmatched_branch_event(self): |
| 60 | self.create_branch('org/project', 'unmatched_branch') |
| 61 | B = self.fake_github.openFakePullRequest( |
| 62 | 'org/project', 'unmatched_branch', 'B') |
| 63 | self.fake_github.emitEvent(B.getPullRequestOpenedEvent()) |
| 64 | self.waitUntilSettled() |
| 65 | |
| 66 | self.assertEqual(2, len(self.history)) |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 67 | |
Jan Hruban | 570d01c | 2016-03-10 21:51:32 +0100 | [diff] [blame] | 68 | @simple_layout('layouts/files-github.yaml', driver='github') |
| 69 | def test_pull_matched_file_event(self): |
| 70 | A = self.fake_github.openFakePullRequest( |
| 71 | 'org/project', 'master', 'A', |
| 72 | files=['random.txt', 'build-requires']) |
| 73 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
| 74 | self.waitUntilSettled() |
| 75 | self.assertEqual(1, len(self.history)) |
| 76 | |
| 77 | # test_pull_unmatched_file_event |
| 78 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B', |
| 79 | files=['random.txt']) |
| 80 | self.fake_github.emitEvent(B.getPullRequestOpenedEvent()) |
| 81 | self.waitUntilSettled() |
| 82 | self.assertEqual(1, len(self.history)) |
| 83 | |
Jan Hruban | c7ab160 | 2015-10-14 15:29:33 +0200 | [diff] [blame] | 84 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 85 | def test_comment_event(self): |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 86 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 87 | self.fake_github.emitEvent(A.getCommentAddedEvent('test me')) |
Jan Hruban | c7ab160 | 2015-10-14 15:29:33 +0200 | [diff] [blame] | 88 | self.waitUntilSettled() |
| 89 | self.assertEqual(2, len(self.history)) |
| 90 | |
| 91 | # Test an unmatched comment, history should remain the same |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 92 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
| 93 | self.fake_github.emitEvent(B.getCommentAddedEvent('casual comment')) |
Jan Hruban | c7ab160 | 2015-10-14 15:29:33 +0200 | [diff] [blame] | 94 | self.waitUntilSettled() |
| 95 | self.assertEqual(2, len(self.history)) |
| 96 | |
Wayne | 1a78c61 | 2015-06-11 17:14:13 -0700 | [diff] [blame] | 97 | @simple_layout('layouts/push-tag-github.yaml', driver='github') |
| 98 | def test_tag_event(self): |
| 99 | self.executor_server.hold_jobs_in_build = True |
| 100 | |
| 101 | sha = random_sha1() |
| 102 | self.fake_github.emitEvent( |
| 103 | self.fake_github.getPushEvent('org/project', 'refs/tags/newtag', |
| 104 | new_rev=sha)) |
| 105 | self.waitUntilSettled() |
| 106 | |
| 107 | build_params = self.builds[0].parameters |
| 108 | self.assertEqual('refs/tags/newtag', build_params['ZUUL_REF']) |
| 109 | self.assertEqual('00000000000000000000000000000000', |
| 110 | build_params['ZUUL_OLDREV']) |
| 111 | self.assertEqual(sha, build_params['ZUUL_NEWREV']) |
| 112 | |
| 113 | self.executor_server.hold_jobs_in_build = False |
| 114 | self.executor_server.release() |
| 115 | self.waitUntilSettled() |
| 116 | |
| 117 | self.assertEqual('SUCCESS', |
| 118 | self.getJobFromHistory('project-tag').result) |
| 119 | |
| 120 | @simple_layout('layouts/push-tag-github.yaml', driver='github') |
| 121 | def test_push_event(self): |
| 122 | self.executor_server.hold_jobs_in_build = True |
| 123 | |
| 124 | old_sha = random_sha1() |
| 125 | new_sha = random_sha1() |
| 126 | self.fake_github.emitEvent( |
| 127 | self.fake_github.getPushEvent('org/project', 'refs/heads/master', |
| 128 | old_sha, new_sha)) |
| 129 | self.waitUntilSettled() |
| 130 | |
| 131 | build_params = self.builds[0].parameters |
| 132 | self.assertEqual('refs/heads/master', build_params['ZUUL_REF']) |
| 133 | self.assertEqual(old_sha, build_params['ZUUL_OLDREV']) |
| 134 | self.assertEqual(new_sha, build_params['ZUUL_NEWREV']) |
| 135 | |
| 136 | self.executor_server.hold_jobs_in_build = False |
| 137 | self.executor_server.release() |
| 138 | self.waitUntilSettled() |
| 139 | |
| 140 | self.assertEqual('SUCCESS', |
| 141 | self.getJobFromHistory('project-post').result) |
Jan Hruban | d4edee8 | 2015-12-16 12:49:51 +0100 | [diff] [blame] | 142 | self.assertEqual(1, len(self.history)) |
| 143 | |
| 144 | # test unmatched push event |
| 145 | old_sha = random_sha1() |
| 146 | new_sha = random_sha1() |
| 147 | self.fake_github.emitEvent( |
| 148 | self.fake_github.getPushEvent('org/project', |
| 149 | 'refs/heads/unmatched_branch', |
| 150 | old_sha, new_sha)) |
| 151 | self.waitUntilSettled() |
| 152 | |
| 153 | self.assertEqual(1, len(self.history)) |
Jan Hruban | 6d53c5e | 2015-10-24 03:03:34 +0200 | [diff] [blame] | 154 | |
Jan Hruban | 16ad31f | 2015-11-07 14:39:07 +0100 | [diff] [blame] | 155 | @simple_layout('layouts/labeling-github.yaml', driver='github') |
| 156 | def test_labels(self): |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 157 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
Jan Hruban | 16ad31f | 2015-11-07 14:39:07 +0100 | [diff] [blame] | 158 | self.fake_github.emitEvent(A.addLabel('test')) |
| 159 | self.waitUntilSettled() |
| 160 | self.assertEqual(1, len(self.history)) |
| 161 | self.assertEqual('project-labels', self.history[0].name) |
| 162 | self.assertEqual(['tests passed'], A.labels) |
| 163 | |
| 164 | # test label removed |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 165 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
Jan Hruban | 16ad31f | 2015-11-07 14:39:07 +0100 | [diff] [blame] | 166 | B.addLabel('do not test') |
| 167 | self.fake_github.emitEvent(B.removeLabel('do not test')) |
| 168 | self.waitUntilSettled() |
| 169 | self.assertEqual(2, len(self.history)) |
| 170 | self.assertEqual('project-labels', self.history[1].name) |
| 171 | self.assertEqual(['tests passed'], B.labels) |
| 172 | |
| 173 | # test unmatched label |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 174 | C = self.fake_github.openFakePullRequest('org/project', 'master', 'C') |
Jan Hruban | 16ad31f | 2015-11-07 14:39:07 +0100 | [diff] [blame] | 175 | self.fake_github.emitEvent(C.addLabel('other label')) |
| 176 | self.waitUntilSettled() |
| 177 | self.assertEqual(2, len(self.history)) |
| 178 | self.assertEqual(['other label'], C.labels) |
| 179 | |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 180 | @simple_layout('layouts/dequeue-github.yaml', driver='github') |
| 181 | def test_dequeue_pull_synchronized(self): |
| 182 | self.executor_server.hold_jobs_in_build = True |
| 183 | |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 184 | A = self.fake_github.openFakePullRequest( |
| 185 | 'org/one-job-project', 'master', 'A') |
| 186 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 187 | self.waitUntilSettled() |
| 188 | |
| 189 | # event update stamp has resolution one second, wait so the latter |
| 190 | # one has newer timestamp |
| 191 | time.sleep(1) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 192 | A.addCommit() |
| 193 | self.fake_github.emitEvent(A.getPullRequestSynchronizeEvent()) |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 194 | self.waitUntilSettled() |
| 195 | |
| 196 | self.executor_server.hold_jobs_in_build = False |
| 197 | self.executor_server.release() |
| 198 | self.waitUntilSettled() |
| 199 | |
| 200 | self.assertEqual(2, len(self.history)) |
| 201 | self.assertEqual(1, self.countJobResults(self.history, 'ABORTED')) |
| 202 | |
| 203 | @simple_layout('layouts/dequeue-github.yaml', driver='github') |
| 204 | def test_dequeue_pull_abandoned(self): |
| 205 | self.executor_server.hold_jobs_in_build = True |
| 206 | |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 207 | A = self.fake_github.openFakePullRequest( |
| 208 | 'org/one-job-project', 'master', 'A') |
| 209 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 210 | self.waitUntilSettled() |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 211 | self.fake_github.emitEvent(A.getPullRequestClosedEvent()) |
Jan Hruban | 324ca5b | 2015-11-05 19:28:54 +0100 | [diff] [blame] | 212 | self.waitUntilSettled() |
| 213 | |
| 214 | self.executor_server.hold_jobs_in_build = False |
| 215 | self.executor_server.release() |
| 216 | self.waitUntilSettled() |
| 217 | |
| 218 | self.assertEqual(1, len(self.history)) |
| 219 | self.assertEqual(1, self.countJobResults(self.history, 'ABORTED')) |
| 220 | |
Jan Hruban | 6d53c5e | 2015-10-24 03:03:34 +0200 | [diff] [blame] | 221 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 222 | def test_git_https_url(self): |
| 223 | """Test that git_ssh option gives git url with ssh""" |
| 224 | url = self.fake_github.real_getGitUrl('org/project') |
| 225 | self.assertEqual('https://github.com/org/project', url) |
| 226 | |
| 227 | @simple_layout('layouts/basic-github.yaml', driver='github') |
| 228 | def test_git_ssh_url(self): |
| 229 | """Test that git_ssh option gives git url with ssh""" |
| 230 | url = self.fake_github_ssh.real_getGitUrl('org/project') |
| 231 | self.assertEqual('ssh://git@github.com/org/project.git', url) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 232 | |
| 233 | @simple_layout('layouts/reporting-github.yaml', driver='github') |
| 234 | def test_reporting(self): |
| 235 | # pipeline reports pull status both on start and success |
| 236 | self.executor_server.hold_jobs_in_build = True |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 237 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 238 | self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 239 | self.waitUntilSettled() |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 240 | self.assertIn('check', A.statuses) |
| 241 | check_status = A.statuses['check'] |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 242 | self.assertEqual('Standard check', check_status['description']) |
| 243 | self.assertEqual('pending', check_status['state']) |
| 244 | self.assertEqual('http://zuul.example.com/status', check_status['url']) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 245 | self.assertEqual(0, len(A.comments)) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 246 | |
| 247 | self.executor_server.hold_jobs_in_build = False |
| 248 | self.executor_server.release() |
| 249 | self.waitUntilSettled() |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 250 | check_status = A.statuses['check'] |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 251 | self.assertEqual('Standard check', check_status['description']) |
| 252 | self.assertEqual('success', check_status['state']) |
| 253 | self.assertEqual('http://zuul.example.com/status', check_status['url']) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 254 | self.assertEqual(1, len(A.comments)) |
| 255 | self.assertThat(A.comments[0], |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 256 | MatchesRegex('.*Build succeeded.*', re.DOTALL)) |
| 257 | |
| 258 | # pipeline does not report any status but does comment |
| 259 | self.executor_server.hold_jobs_in_build = True |
| 260 | self.fake_github.emitEvent( |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 261 | A.getCommentAddedEvent('reporting check')) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 262 | self.waitUntilSettled() |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 263 | self.assertNotIn('reporting', A.statuses) |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 264 | # comments increased by one for the start message |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 265 | self.assertEqual(2, len(A.comments)) |
| 266 | self.assertThat(A.comments[1], |
Jan Hruban | e252a73 | 2017-01-03 15:03:09 +0100 | [diff] [blame] | 267 | MatchesRegex('.*Starting reporting jobs.*', re.DOTALL)) |
| 268 | self.executor_server.hold_jobs_in_build = False |
| 269 | self.executor_server.release() |
| 270 | self.waitUntilSettled() |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 271 | self.assertNotIn('reporting', A.statuses) |
| 272 | self.assertEqual(2, len(A.comments)) |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 273 | |
| 274 | @simple_layout('layouts/merging-github.yaml', driver='github') |
| 275 | def test_report_pull_merge(self): |
| 276 | # pipeline merges the pull request on success |
Jan Hruban | 3b41592 | 2016-02-03 13:10:22 +0100 | [diff] [blame] | 277 | A = self.fake_github.openFakePullRequest('org/project', 'master', |
| 278 | 'PR title') |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 279 | self.fake_github.emitEvent(A.getCommentAddedEvent('merge me')) |
| 280 | self.waitUntilSettled() |
| 281 | self.assertTrue(A.is_merged) |
Jan Hruban | 3b41592 | 2016-02-03 13:10:22 +0100 | [diff] [blame] | 282 | self.assertThat(A.merge_message, |
| 283 | MatchesRegex('.*PR title.*Reviewed-by.*', re.DOTALL)) |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 284 | |
| 285 | # pipeline merges the pull request on success after failure |
| 286 | self.fake_github.merge_failure = True |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 287 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 288 | self.fake_github.emitEvent(B.getCommentAddedEvent('merge me')) |
| 289 | self.waitUntilSettled() |
| 290 | self.assertFalse(B.is_merged) |
| 291 | self.fake_github.merge_failure = False |
| 292 | |
| 293 | # pipeline merges the pull request on second run of merge |
| 294 | # first merge failed on 405 Method Not Allowed error |
| 295 | self.fake_github.merge_not_allowed_count = 1 |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 296 | C = self.fake_github.openFakePullRequest('org/project', 'master', 'C') |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 297 | self.fake_github.emitEvent(C.getCommentAddedEvent('merge me')) |
| 298 | self.waitUntilSettled() |
| 299 | self.assertTrue(C.is_merged) |
| 300 | |
| 301 | # pipeline does not merge the pull request |
| 302 | # merge failed on 405 Method Not Allowed error - twice |
| 303 | self.fake_github.merge_not_allowed_count = 2 |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 304 | D = self.fake_github.openFakePullRequest('org/project', 'master', 'D') |
Jan Hruban | 49bff07 | 2015-11-03 11:45:46 +0100 | [diff] [blame] | 305 | self.fake_github.emitEvent(D.getCommentAddedEvent('merge me')) |
| 306 | self.waitUntilSettled() |
| 307 | self.assertFalse(D.is_merged) |
Jan Hruban | 37615e5 | 2015-11-19 14:30:49 +0100 | [diff] [blame] | 308 | |
| 309 | @simple_layout('layouts/dependent-github.yaml', driver='github') |
| 310 | def test_parallel_changes(self): |
| 311 | "Test that changes are tested in parallel and merged in series" |
| 312 | |
| 313 | self.executor_server.hold_jobs_in_build = True |
| 314 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 315 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
| 316 | C = self.fake_github.openFakePullRequest('org/project', 'master', 'C') |
| 317 | |
| 318 | self.fake_github.emitEvent(A.addLabel('merge')) |
| 319 | self.fake_github.emitEvent(B.addLabel('merge')) |
| 320 | self.fake_github.emitEvent(C.addLabel('merge')) |
| 321 | |
| 322 | self.waitUntilSettled() |
| 323 | self.assertEqual(len(self.builds), 1) |
| 324 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 325 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 326 | |
| 327 | self.executor_server.release('.*-merge') |
| 328 | self.waitUntilSettled() |
| 329 | self.assertEqual(len(self.builds), 3) |
| 330 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 331 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 332 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 333 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 334 | self.assertEqual(self.builds[2].name, 'project-merge') |
| 335 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
| 336 | |
| 337 | self.executor_server.release('.*-merge') |
| 338 | self.waitUntilSettled() |
| 339 | self.assertEqual(len(self.builds), 5) |
| 340 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 341 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 342 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 343 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 344 | |
| 345 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 346 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 347 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 348 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
| 349 | |
| 350 | self.assertEqual(self.builds[4].name, 'project-merge') |
| 351 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
| 352 | |
| 353 | self.executor_server.release('.*-merge') |
| 354 | self.waitUntilSettled() |
| 355 | self.assertEqual(len(self.builds), 6) |
| 356 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 357 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 358 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 359 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 360 | |
| 361 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 362 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
| 363 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 364 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
| 365 | |
| 366 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 367 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
| 368 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 369 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
| 370 | |
| 371 | all_builds = self.builds[:] |
| 372 | self.release(all_builds[2]) |
| 373 | self.release(all_builds[3]) |
| 374 | self.waitUntilSettled() |
| 375 | self.assertFalse(A.is_merged) |
| 376 | self.assertFalse(B.is_merged) |
| 377 | self.assertFalse(C.is_merged) |
| 378 | |
| 379 | self.release(all_builds[0]) |
| 380 | self.release(all_builds[1]) |
| 381 | self.waitUntilSettled() |
| 382 | self.assertTrue(A.is_merged) |
| 383 | self.assertTrue(B.is_merged) |
| 384 | self.assertFalse(C.is_merged) |
| 385 | |
| 386 | self.executor_server.hold_jobs_in_build = False |
| 387 | self.executor_server.release() |
| 388 | self.waitUntilSettled() |
| 389 | self.assertEqual(len(self.builds), 0) |
| 390 | self.assertEqual(len(self.history), 9) |
| 391 | self.assertTrue(C.is_merged) |
| 392 | |
| 393 | self.assertNotIn('merge', A.labels) |
| 394 | self.assertNotIn('merge', B.labels) |
| 395 | self.assertNotIn('merge', C.labels) |
| 396 | |
| 397 | @simple_layout('layouts/dependent-github.yaml', driver='github') |
| 398 | def test_failed_changes(self): |
| 399 | "Test that a change behind a failed change is retested" |
| 400 | self.executor_server.hold_jobs_in_build = True |
| 401 | |
| 402 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 403 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
| 404 | |
| 405 | self.executor_server.failJob('project-test1', A) |
| 406 | |
| 407 | self.fake_github.emitEvent(A.addLabel('merge')) |
| 408 | self.fake_github.emitEvent(B.addLabel('merge')) |
| 409 | self.waitUntilSettled() |
| 410 | |
| 411 | self.executor_server.release('.*-merge') |
| 412 | self.waitUntilSettled() |
| 413 | |
| 414 | self.executor_server.hold_jobs_in_build = False |
| 415 | self.executor_server.release() |
| 416 | |
| 417 | self.waitUntilSettled() |
| 418 | # It's certain that the merge job for change 2 will run, but |
| 419 | # the test1 and test2 jobs may or may not run. |
| 420 | self.assertTrue(len(self.history) > 6) |
| 421 | self.assertFalse(A.is_merged) |
| 422 | self.assertTrue(B.is_merged) |
| 423 | self.assertNotIn('merge', A.labels) |
| 424 | self.assertNotIn('merge', B.labels) |
| 425 | |
| 426 | @simple_layout('layouts/dependent-github.yaml', driver='github') |
| 427 | def test_failed_change_at_head(self): |
| 428 | "Test that if a change at the head fails, jobs behind it are canceled" |
| 429 | |
| 430 | self.executor_server.hold_jobs_in_build = True |
| 431 | A = self.fake_github.openFakePullRequest('org/project', 'master', 'A') |
| 432 | B = self.fake_github.openFakePullRequest('org/project', 'master', 'B') |
| 433 | C = self.fake_github.openFakePullRequest('org/project', 'master', 'C') |
| 434 | |
| 435 | self.executor_server.failJob('project-test1', A) |
| 436 | |
| 437 | self.fake_github.emitEvent(A.addLabel('merge')) |
| 438 | self.fake_github.emitEvent(B.addLabel('merge')) |
| 439 | self.fake_github.emitEvent(C.addLabel('merge')) |
| 440 | |
| 441 | self.waitUntilSettled() |
| 442 | |
| 443 | self.assertEqual(len(self.builds), 1) |
| 444 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 445 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 446 | |
| 447 | self.executor_server.release('.*-merge') |
| 448 | self.waitUntilSettled() |
| 449 | self.executor_server.release('.*-merge') |
| 450 | self.waitUntilSettled() |
| 451 | self.executor_server.release('.*-merge') |
| 452 | self.waitUntilSettled() |
| 453 | |
| 454 | self.assertEqual(len(self.builds), 6) |
| 455 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 456 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 457 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 458 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 459 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 460 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 461 | |
| 462 | self.release(self.builds[0]) |
| 463 | self.waitUntilSettled() |
| 464 | |
| 465 | # project-test2, project-merge for B |
| 466 | self.assertEqual(len(self.builds), 2) |
| 467 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
| 468 | |
| 469 | self.executor_server.hold_jobs_in_build = False |
| 470 | self.executor_server.release() |
| 471 | self.waitUntilSettled() |
| 472 | |
| 473 | self.assertEqual(len(self.builds), 0) |
| 474 | self.assertEqual(len(self.history), 15) |
| 475 | self.assertFalse(A.is_merged) |
| 476 | self.assertTrue(B.is_merged) |
| 477 | self.assertTrue(C.is_merged) |
| 478 | self.assertNotIn('merge', A.labels) |
| 479 | self.assertNotIn('merge', B.labels) |
| 480 | self.assertNotIn('merge', C.labels) |