James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 17 | import gc |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 18 | import json |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 19 | import textwrap |
| 20 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 21 | import os |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 22 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 23 | import time |
Clint Byrum | 03454a5 | 2017-05-26 17:14:02 -0700 | [diff] [blame] | 24 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 25 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 26 | import git |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 27 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 28 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 29 | import zuul.change_matcher |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 30 | from zuul.driver.gerrit import gerritreporter |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 31 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 32 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 33 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 34 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 35 | from tests.base import ( |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 36 | SSLZuulTestCase, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | ZuulTestCase, |
| 38 | repack_repo, |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 39 | simple_layout, |
James E. Blair | b4bed1d | 2018-02-06 13:43:50 -0800 | [diff] [blame] | 40 | iterate_timeout, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 41 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 42 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 43 | |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 44 | class TestSchedulerSSL(SSLZuulTestCase): |
| 45 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 46 | |
| 47 | def test_jobs_executed(self): |
| 48 | "Test that jobs are executed and a change is merged" |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 49 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 50 | A.addApproval('Code-Review', 2) |
| 51 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 52 | self.waitUntilSettled() |
| 53 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 54 | 'SUCCESS') |
| 55 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 56 | 'SUCCESS') |
| 57 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 58 | 'SUCCESS') |
| 59 | self.assertEqual(A.data['status'], 'MERGED') |
| 60 | self.assertEqual(A.reported, 2) |
| 61 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 62 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 63 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 64 | 'label1') |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 65 | |
| 66 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 67 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 68 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 69 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 70 | def test_jobs_executed(self): |
| 71 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 72 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 73 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 74 | A.addApproval('Code-Review', 2) |
| 75 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 76 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 77 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 78 | 'SUCCESS') |
| 79 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 80 | 'SUCCESS') |
| 81 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 82 | 'SUCCESS') |
| 83 | self.assertEqual(A.data['status'], 'MERGED') |
| 84 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 85 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 86 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 87 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 88 | 'label1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 89 | |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 90 | for stat in self.statsd.stats: |
| 91 | k, v = stat.decode('utf-8').split(':') |
| 92 | self.log.debug('stat %s:%s', k, v) |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 93 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 94 | # Per-driver |
| 95 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 96 | # Per-driver per-connection |
| 97 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 98 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 99 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 100 | 'zuul.tenant.tenant-one.pipeline.gate.current_changes', |
| 101 | value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 102 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 103 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 104 | 'org_project.master.job.project-merge.SUCCESS', kind='ms') |
| 105 | self.assertReportedStat( |
| 106 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 107 | 'org_project.master.job.project-merge.SUCCESS', value='1|c') |
| 108 | self.assertReportedStat( |
| 109 | 'zuul.tenant.tenant-one.pipeline.gate.resident_time', kind='ms') |
| 110 | self.assertReportedStat( |
| 111 | 'zuul.tenant.tenant-one.pipeline.gate.total_changes', value='1|c') |
| 112 | self.assertReportedStat( |
| 113 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 114 | 'org_project.master.resident_time', kind='ms') |
| 115 | self.assertReportedStat( |
| 116 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 117 | 'org_project.master.total_changes', value='1|c') |
James E. Blair | faf8198 | 2017-10-10 15:42:26 -0700 | [diff] [blame] | 118 | exec_key = 'zuul.executor.%s' % self.executor_server.hostname |
| 119 | self.assertReportedStat(exec_key + '.builds', value='1|c') |
James E. Blair | 4f1731b | 2017-10-10 18:11:42 -0700 | [diff] [blame] | 120 | self.assertReportedStat('zuul.nodepool.requested', value='1|c') |
| 121 | self.assertReportedStat('zuul.nodepool.requested.label.label1', |
| 122 | value='1|c') |
| 123 | self.assertReportedStat('zuul.nodepool.fulfilled.label.label1', |
| 124 | value='1|c') |
| 125 | self.assertReportedStat('zuul.nodepool.requested.size.1', value='1|c') |
| 126 | self.assertReportedStat('zuul.nodepool.fulfilled.size.1', value='1|c') |
| 127 | self.assertReportedStat('zuul.nodepool.current_requests', value='1|g') |
James E. Blair | bdd50e6 | 2017-10-21 08:18:55 -0700 | [diff] [blame] | 128 | self.assertReportedStat('zuul.executors.online', value='1|g') |
| 129 | self.assertReportedStat('zuul.executors.accepting', value='1|g') |
| 130 | self.assertReportedStat('zuul.mergers.online', value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 131 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 132 | for build in self.history: |
| 133 | self.assertTrue(build.parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 134 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 135 | def test_initial_pipeline_gauges(self): |
| 136 | "Test that each pipeline reported its length on start" |
James E. Blair | 57bf14d | 2017-10-21 09:09:48 -0700 | [diff] [blame] | 137 | self.assertReportedStat('zuul.tenant.tenant-one.pipeline.gate.' |
| 138 | 'current_changes', |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 139 | value='0|g') |
James E. Blair | 57bf14d | 2017-10-21 09:09:48 -0700 | [diff] [blame] | 140 | self.assertReportedStat('zuul.tenant.tenant-one.pipeline.check.' |
| 141 | 'current_changes', |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 142 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 143 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 144 | def test_job_branch(self): |
| 145 | "Test the correct variant of a job runs on a branch" |
| 146 | self.create_branch('org/project', 'stable') |
| 147 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 148 | A.addApproval('Code-Review', 2) |
| 149 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 150 | self.waitUntilSettled() |
| 151 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 152 | 'SUCCESS') |
| 153 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 154 | 'SUCCESS') |
| 155 | self.assertEqual(A.data['status'], 'MERGED') |
| 156 | self.assertEqual(A.reported, 2, |
| 157 | "A should report start and success") |
| 158 | self.assertIn('gate', A.messages[1], |
| 159 | "A should transit gate") |
| 160 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 161 | 'label2') |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 162 | |
James E. Blair | da5bb7e | 2018-01-22 16:12:17 -0800 | [diff] [blame] | 163 | @simple_layout('layouts/branch-deletion.yaml') |
| 164 | def test_branch_deletion(self): |
| 165 | "Test the correct variant of a job runs on a branch" |
| 166 | self._startMerger() |
| 167 | for f in list(self.executor_server.merger_worker.functions.keys()): |
| 168 | f = str(f) |
| 169 | if f.startswith('merger:'): |
| 170 | self.executor_server.merger_worker.unRegisterFunction(f) |
| 171 | |
| 172 | self.create_branch('org/project', 'stable') |
| 173 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 174 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 175 | self.waitUntilSettled() |
| 176 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 177 | 'SUCCESS') |
| 178 | |
| 179 | self.delete_branch('org/project', 'stable') |
| 180 | path = os.path.join(self.executor_src_root, 'review.example.com') |
| 181 | shutil.rmtree(path) |
| 182 | |
| 183 | self.executor_server.hold_jobs_in_build = True |
| 184 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 185 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 186 | self.waitUntilSettled() |
| 187 | build = self.builds[0] |
| 188 | |
| 189 | # Make sure there is no stable branch in the checked out git repo. |
| 190 | pname = 'review.example.com/org/project' |
| 191 | work = build.getWorkspaceRepos([pname]) |
| 192 | work = work[pname] |
| 193 | heads = set([str(x) for x in work.heads]) |
| 194 | self.assertEqual(heads, set(['master'])) |
| 195 | self.executor_server.hold_jobs_in_build = False |
| 196 | build.release() |
| 197 | self.waitUntilSettled() |
| 198 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 199 | 'SUCCESS') |
| 200 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 201 | def test_parallel_changes(self): |
| 202 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 203 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 204 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 205 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 206 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 207 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 208 | A.addApproval('Code-Review', 2) |
| 209 | B.addApproval('Code-Review', 2) |
| 210 | C.addApproval('Code-Review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 211 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 212 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 213 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 214 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 215 | |
| 216 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 217 | self.assertEqual(len(self.builds), 1) |
| 218 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 219 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 220 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 221 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 222 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 223 | self.assertEqual(len(self.builds), 3) |
| 224 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 225 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 226 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 227 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 228 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 229 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 230 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 231 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 232 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 233 | self.assertEqual(len(self.builds), 5) |
| 234 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 235 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 236 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 237 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 238 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 239 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 240 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 241 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 242 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 243 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 244 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 245 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 246 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 247 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 248 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 249 | self.assertEqual(len(self.builds), 6) |
| 250 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 251 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 252 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 253 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 254 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 255 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 256 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 257 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 258 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 259 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 260 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 261 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 262 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 263 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 264 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 265 | self.executor_server.hold_jobs_in_build = False |
| 266 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 267 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 268 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 269 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 270 | self.assertEqual(len(self.history), 9) |
| 271 | self.assertEqual(A.data['status'], 'MERGED') |
| 272 | self.assertEqual(B.data['status'], 'MERGED') |
| 273 | self.assertEqual(C.data['status'], 'MERGED') |
| 274 | self.assertEqual(A.reported, 2) |
| 275 | self.assertEqual(B.reported, 2) |
| 276 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 277 | |
| 278 | def test_failed_changes(self): |
| 279 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 280 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 281 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 282 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 283 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 284 | A.addApproval('Code-Review', 2) |
| 285 | B.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 286 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 287 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 288 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 289 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 290 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 291 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 292 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 293 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 294 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 295 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 296 | # A/project-merge is complete |
| 297 | self.assertBuilds([ |
| 298 | dict(name='project-test1', changes='1,1'), |
| 299 | dict(name='project-test2', changes='1,1'), |
| 300 | dict(name='project-merge', changes='1,1 2,1'), |
| 301 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 302 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 303 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 304 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 305 | # A/project-merge is complete |
| 306 | # B/project-merge is complete |
| 307 | self.assertBuilds([ |
| 308 | dict(name='project-test1', changes='1,1'), |
| 309 | dict(name='project-test2', changes='1,1'), |
| 310 | dict(name='project-test1', changes='1,1 2,1'), |
| 311 | dict(name='project-test2', changes='1,1 2,1'), |
| 312 | ]) |
| 313 | |
| 314 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 315 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 316 | self.builds[0].release() |
| 317 | self.waitUntilSettled() |
| 318 | |
| 319 | self.orderedRelease() |
| 320 | self.assertHistory([ |
| 321 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 322 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 323 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 324 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 325 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 326 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 327 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 328 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 329 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 330 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 331 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 332 | self.assertEqual(A.data['status'], 'NEW') |
| 333 | self.assertEqual(B.data['status'], 'MERGED') |
| 334 | self.assertEqual(A.reported, 2) |
| 335 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 336 | |
| 337 | def test_independent_queues(self): |
| 338 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 339 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 340 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 341 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 342 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 343 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 344 | A.addApproval('Code-Review', 2) |
| 345 | B.addApproval('Code-Review', 2) |
| 346 | C.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 347 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 348 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 349 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 350 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 351 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 352 | self.waitUntilSettled() |
| 353 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 354 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 355 | self.waitUntilSettled() |
| 356 | |
| 357 | # There should be one merge job at the head of each queue running |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 358 | self.assertBuilds([ |
| 359 | dict(name='project-merge', changes='1,1'), |
| 360 | dict(name='project-merge', changes='2,1'), |
| 361 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 362 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 363 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 364 | self.builds[0].release() |
| 365 | self.waitUntilSettled() |
| 366 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 367 | self.waitUntilSettled() |
| 368 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 369 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 370 | self.waitUntilSettled() |
| 371 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 372 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 373 | self.assertBuilds([ |
| 374 | dict(name='project-test1', changes='1,1'), |
| 375 | dict(name='project-test2', changes='1,1'), |
| 376 | dict(name='project-test1', changes='2,1'), |
| 377 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 378 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 379 | dict(name='project-test1', changes='2,1 3,1'), |
| 380 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 381 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 382 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 383 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 384 | self.orderedRelease() |
| 385 | self.assertHistory([ |
| 386 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 387 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 388 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 389 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 390 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 391 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 392 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 393 | dict( |
| 394 | name='project1-project2-integration', |
| 395 | result='SUCCESS', |
| 396 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 397 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 398 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 399 | dict(name='project1-project2-integration', |
| 400 | result='SUCCESS', |
| 401 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 402 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 403 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 404 | self.assertEqual(A.data['status'], 'MERGED') |
| 405 | self.assertEqual(B.data['status'], 'MERGED') |
| 406 | self.assertEqual(C.data['status'], 'MERGED') |
| 407 | self.assertEqual(A.reported, 2) |
| 408 | self.assertEqual(B.reported, 2) |
| 409 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 410 | |
| 411 | def test_failed_change_at_head(self): |
| 412 | "Test that if a change at the head fails, jobs behind it are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 413 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 414 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 415 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 416 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 417 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 418 | A.addApproval('Code-Review', 2) |
| 419 | B.addApproval('Code-Review', 2) |
| 420 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 421 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 422 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 423 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 424 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 425 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 426 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 427 | |
| 428 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 429 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 430 | self.assertBuilds([ |
| 431 | dict(name='project-merge', changes='1,1'), |
| 432 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 433 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 434 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 435 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 436 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 437 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 438 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 439 | self.waitUntilSettled() |
| 440 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 441 | self.assertBuilds([ |
| 442 | dict(name='project-test1', changes='1,1'), |
| 443 | dict(name='project-test2', changes='1,1'), |
| 444 | dict(name='project-test1', changes='1,1 2,1'), |
| 445 | dict(name='project-test2', changes='1,1 2,1'), |
| 446 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 447 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 448 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 449 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 450 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 451 | self.waitUntilSettled() |
| 452 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 453 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 454 | self.assertBuilds([ |
| 455 | dict(name='project-test2', changes='1,1'), |
| 456 | dict(name='project-merge', changes='2,1'), |
| 457 | ]) |
| 458 | # Unordered history comparison because the aborts can finish |
| 459 | # in any order. |
| 460 | self.assertHistory([ |
| 461 | dict(name='project-merge', result='SUCCESS', |
| 462 | changes='1,1'), |
| 463 | dict(name='project-merge', result='SUCCESS', |
| 464 | changes='1,1 2,1'), |
| 465 | dict(name='project-merge', result='SUCCESS', |
| 466 | changes='1,1 2,1 3,1'), |
| 467 | dict(name='project-test1', result='FAILURE', |
| 468 | changes='1,1'), |
| 469 | dict(name='project-test1', result='ABORTED', |
| 470 | changes='1,1 2,1'), |
| 471 | dict(name='project-test2', result='ABORTED', |
| 472 | changes='1,1 2,1'), |
| 473 | dict(name='project-test1', result='ABORTED', |
| 474 | changes='1,1 2,1 3,1'), |
| 475 | dict(name='project-test2', result='ABORTED', |
| 476 | changes='1,1 2,1 3,1'), |
| 477 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 478 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 479 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 480 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 481 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 482 | self.waitUntilSettled() |
| 483 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 484 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 485 | self.assertBuilds([]) |
| 486 | self.assertHistory([ |
| 487 | dict(name='project-merge', result='SUCCESS', |
| 488 | changes='1,1'), |
| 489 | dict(name='project-merge', result='SUCCESS', |
| 490 | changes='1,1 2,1'), |
| 491 | dict(name='project-merge', result='SUCCESS', |
| 492 | changes='1,1 2,1 3,1'), |
| 493 | dict(name='project-test1', result='FAILURE', |
| 494 | changes='1,1'), |
| 495 | dict(name='project-test1', result='ABORTED', |
| 496 | changes='1,1 2,1'), |
| 497 | dict(name='project-test2', result='ABORTED', |
| 498 | changes='1,1 2,1'), |
| 499 | dict(name='project-test1', result='ABORTED', |
| 500 | changes='1,1 2,1 3,1'), |
| 501 | dict(name='project-test2', result='ABORTED', |
| 502 | changes='1,1 2,1 3,1'), |
| 503 | dict(name='project-merge', result='SUCCESS', |
| 504 | changes='2,1'), |
| 505 | dict(name='project-merge', result='SUCCESS', |
| 506 | changes='2,1 3,1'), |
| 507 | dict(name='project-test2', result='SUCCESS', |
| 508 | changes='1,1'), |
| 509 | dict(name='project-test1', result='SUCCESS', |
| 510 | changes='2,1'), |
| 511 | dict(name='project-test2', result='SUCCESS', |
| 512 | changes='2,1'), |
| 513 | dict(name='project-test1', result='SUCCESS', |
| 514 | changes='2,1 3,1'), |
| 515 | dict(name='project-test2', result='SUCCESS', |
| 516 | changes='2,1 3,1'), |
| 517 | ], ordered=False) |
| 518 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 519 | self.assertEqual(A.data['status'], 'NEW') |
| 520 | self.assertEqual(B.data['status'], 'MERGED') |
| 521 | self.assertEqual(C.data['status'], 'MERGED') |
| 522 | self.assertEqual(A.reported, 2) |
| 523 | self.assertEqual(B.reported, 2) |
| 524 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 525 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 526 | def test_failed_change_in_middle(self): |
| 527 | "Test a failed change in the middle of the queue" |
| 528 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 529 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 530 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 531 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 532 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 533 | A.addApproval('Code-Review', 2) |
| 534 | B.addApproval('Code-Review', 2) |
| 535 | C.addApproval('Code-Review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 536 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 537 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 538 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 539 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 540 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 541 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 542 | |
| 543 | self.waitUntilSettled() |
| 544 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 545 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 546 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 547 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 548 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 549 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 550 | self.waitUntilSettled() |
| 551 | |
| 552 | self.assertEqual(len(self.builds), 6) |
| 553 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 554 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 555 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 556 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 557 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 558 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 559 | |
| 560 | self.release(self.builds[2]) |
| 561 | self.waitUntilSettled() |
| 562 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 563 | # project-test1 and project-test2 for A |
| 564 | # project-test2 for B |
| 565 | # project-merge for C (without B) |
| 566 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 567 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 568 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 569 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 570 | self.waitUntilSettled() |
| 571 | |
| 572 | # project-test1 and project-test2 for A |
| 573 | # project-test2 for B |
| 574 | # project-test1 and project-test2 for C |
| 575 | self.assertEqual(len(self.builds), 5) |
| 576 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 577 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 578 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 579 | builds = items[0].current_build_set.getBuilds() |
| 580 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 581 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 582 | builds = items[1].current_build_set.getBuilds() |
| 583 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 584 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 585 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 586 | builds = items[2].current_build_set.getBuilds() |
| 587 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 588 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 589 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 590 | self.executor_server.hold_jobs_in_build = False |
| 591 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 592 | self.waitUntilSettled() |
| 593 | |
| 594 | self.assertEqual(len(self.builds), 0) |
| 595 | self.assertEqual(len(self.history), 12) |
| 596 | self.assertEqual(A.data['status'], 'MERGED') |
| 597 | self.assertEqual(B.data['status'], 'NEW') |
| 598 | self.assertEqual(C.data['status'], 'MERGED') |
| 599 | self.assertEqual(A.reported, 2) |
| 600 | self.assertEqual(B.reported, 2) |
| 601 | self.assertEqual(C.reported, 2) |
| 602 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 603 | def test_failed_change_at_head_with_queue(self): |
| 604 | "Test that if a change at the head fails, queued jobs are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 605 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 606 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 607 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 608 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 609 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 610 | A.addApproval('Code-Review', 2) |
| 611 | B.addApproval('Code-Review', 2) |
| 612 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 613 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 614 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 615 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 616 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 617 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 618 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 619 | |
| 620 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 621 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 622 | self.assertEqual(len(self.builds), 0) |
| 623 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 624 | self.assertEqual(queue[0].name, b'executor:execute') |
| 625 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 626 | self.assertEqual(job_args['job'], 'project-merge') |
| 627 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 628 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 629 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 630 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 631 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 632 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 633 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 634 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 635 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 636 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 637 | self.assertEqual(len(self.builds), 0) |
| 638 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 639 | |
| 640 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 641 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 642 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 643 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 644 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 645 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 646 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 647 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 648 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 649 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 650 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 651 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 652 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 653 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 654 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 655 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 656 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 657 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 658 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 659 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 660 | self.waitUntilSettled() |
| 661 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 662 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 663 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 664 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 665 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 666 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 667 | self.gearman_server.hold_jobs_in_queue = False |
| 668 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 669 | self.waitUntilSettled() |
| 670 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 671 | self.assertEqual(len(self.builds), 0) |
| 672 | self.assertEqual(len(self.history), 11) |
| 673 | self.assertEqual(A.data['status'], 'NEW') |
| 674 | self.assertEqual(B.data['status'], 'MERGED') |
| 675 | self.assertEqual(C.data['status'], 'MERGED') |
| 676 | self.assertEqual(A.reported, 2) |
| 677 | self.assertEqual(B.reported, 2) |
| 678 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 679 | |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 680 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 681 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 682 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 683 | A.addApproval('Code-Review', 2) |
| 684 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 685 | self.waitUntilSettled() |
| 686 | time.sleep(2) |
| 687 | |
James E. Blair | ae0f23c | 2017-09-13 10:55:15 -0600 | [diff] [blame] | 688 | data = json.loads(self.sched.formatStatusJSON('tenant-one')) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 689 | found_job = None |
| 690 | for pipeline in data['pipelines']: |
| 691 | if pipeline['name'] != 'gate': |
| 692 | continue |
| 693 | for queue in pipeline['change_queues']: |
| 694 | for head in queue['heads']: |
| 695 | for item in head: |
| 696 | for job in item['jobs']: |
| 697 | if job['name'] == 'project-merge': |
| 698 | found_job = job |
| 699 | break |
| 700 | |
| 701 | self.assertIsNotNone(found_job) |
| 702 | if iteration == 1: |
| 703 | self.assertIsNotNone(found_job['estimated_time']) |
| 704 | self.assertIsNone(found_job['remaining_time']) |
| 705 | else: |
| 706 | self.assertIsNotNone(found_job['estimated_time']) |
| 707 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 708 | self.assertIsNotNone(found_job['remaining_time']) |
| 709 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 710 | self.executor_server.hold_jobs_in_build = False |
| 711 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 712 | self.waitUntilSettled() |
| 713 | |
| 714 | def test_time_database(self): |
| 715 | "Test the time database" |
| 716 | |
| 717 | self._test_time_database(1) |
| 718 | self._test_time_database(2) |
| 719 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 720 | def test_two_failed_changes_at_head(self): |
| 721 | "Test that changes are reparented correctly if 2 fail at head" |
| 722 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 723 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 724 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 725 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 726 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 727 | A.addApproval('Code-Review', 2) |
| 728 | B.addApproval('Code-Review', 2) |
| 729 | C.addApproval('Code-Review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 730 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 731 | self.executor_server.failJob('project-test1', A) |
| 732 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 733 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 734 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 735 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 736 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 737 | self.waitUntilSettled() |
| 738 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 739 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 740 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 741 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 742 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 743 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 744 | self.waitUntilSettled() |
| 745 | |
| 746 | self.assertEqual(len(self.builds), 6) |
| 747 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 748 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 749 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 750 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 751 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 752 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 753 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 754 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 755 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 756 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 757 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 758 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 759 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 760 | |
| 761 | # Fail change B first |
| 762 | self.release(self.builds[2]) |
| 763 | self.waitUntilSettled() |
| 764 | |
| 765 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 766 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 767 | self.waitUntilSettled() |
| 768 | |
| 769 | self.assertEqual(len(self.builds), 5) |
| 770 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 771 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 772 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 773 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 774 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 775 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 776 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 777 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 778 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 779 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 780 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 781 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 782 | |
| 783 | # Finish running all passing jobs for change A |
| 784 | self.release(self.builds[1]) |
| 785 | self.waitUntilSettled() |
| 786 | # Fail and report change A |
| 787 | self.release(self.builds[0]) |
| 788 | self.waitUntilSettled() |
| 789 | |
| 790 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 791 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 792 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 793 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 794 | self.waitUntilSettled() |
| 795 | |
| 796 | self.assertEqual(len(self.builds), 4) |
| 797 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 798 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 799 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 800 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 801 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 802 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 803 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 804 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 805 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 806 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 807 | # After A failed and B and C restarted, B should be back in |
| 808 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 809 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 810 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 811 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 812 | self.executor_server.hold_jobs_in_build = False |
| 813 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 814 | self.waitUntilSettled() |
| 815 | |
| 816 | self.assertEqual(len(self.builds), 0) |
| 817 | self.assertEqual(len(self.history), 21) |
| 818 | self.assertEqual(A.data['status'], 'NEW') |
| 819 | self.assertEqual(B.data['status'], 'NEW') |
| 820 | self.assertEqual(C.data['status'], 'MERGED') |
| 821 | self.assertEqual(A.reported, 2) |
| 822 | self.assertEqual(B.reported, 2) |
| 823 | self.assertEqual(C.reported, 2) |
| 824 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 825 | def test_patch_order(self): |
| 826 | "Test that dependent patches are tested in the right order" |
| 827 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 828 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 829 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 830 | A.addApproval('Code-Review', 2) |
| 831 | B.addApproval('Code-Review', 2) |
| 832 | C.addApproval('Code-Review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 833 | |
| 834 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 835 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 836 | M2.setMerged() |
| 837 | M1.setMerged() |
| 838 | |
| 839 | # C -> B -> A -> M1 -> M2 |
| 840 | # M2 is here to make sure it is never queried. If it is, it |
| 841 | # means zuul is walking down the entire history of merged |
| 842 | # changes. |
| 843 | |
| 844 | C.setDependsOn(B, 1) |
| 845 | B.setDependsOn(A, 1) |
| 846 | A.setDependsOn(M1, 1) |
| 847 | M1.setDependsOn(M2, 1) |
| 848 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 849 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 850 | |
| 851 | self.waitUntilSettled() |
| 852 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 853 | self.assertEqual(A.data['status'], 'NEW') |
| 854 | self.assertEqual(B.data['status'], 'NEW') |
| 855 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 856 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 857 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 858 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 859 | |
| 860 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 861 | self.assertEqual(M2.queried, 0) |
| 862 | self.assertEqual(A.data['status'], 'MERGED') |
| 863 | self.assertEqual(B.data['status'], 'MERGED') |
| 864 | self.assertEqual(C.data['status'], 'MERGED') |
| 865 | self.assertEqual(A.reported, 2) |
| 866 | self.assertEqual(B.reported, 2) |
| 867 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 868 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 869 | def test_needed_changes_enqueue(self): |
| 870 | "Test that a needed change is enqueued ahead" |
| 871 | # A Given a git tree like this, if we enqueue |
| 872 | # / \ change C, we should walk up and down the tree |
| 873 | # B G and enqueue changes in the order ABCDEFG. |
| 874 | # /|\ This is also the order that you would get if |
| 875 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 876 | # / the ordering is stable across re-enqueue events. |
| 877 | # D |
| 878 | |
| 879 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 880 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 881 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 882 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 883 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 884 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 885 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 886 | B.setDependsOn(A, 1) |
| 887 | C.setDependsOn(B, 1) |
| 888 | D.setDependsOn(C, 1) |
| 889 | E.setDependsOn(B, 1) |
| 890 | F.setDependsOn(B, 1) |
| 891 | G.setDependsOn(A, 1) |
| 892 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 893 | A.addApproval('Code-Review', 2) |
| 894 | B.addApproval('Code-Review', 2) |
| 895 | C.addApproval('Code-Review', 2) |
| 896 | D.addApproval('Code-Review', 2) |
| 897 | E.addApproval('Code-Review', 2) |
| 898 | F.addApproval('Code-Review', 2) |
| 899 | G.addApproval('Code-Review', 2) |
| 900 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 901 | |
| 902 | self.waitUntilSettled() |
| 903 | |
| 904 | self.assertEqual(A.data['status'], 'NEW') |
| 905 | self.assertEqual(B.data['status'], 'NEW') |
| 906 | self.assertEqual(C.data['status'], 'NEW') |
| 907 | self.assertEqual(D.data['status'], 'NEW') |
| 908 | self.assertEqual(E.data['status'], 'NEW') |
| 909 | self.assertEqual(F.data['status'], 'NEW') |
| 910 | self.assertEqual(G.data['status'], 'NEW') |
| 911 | |
| 912 | # We're about to add approvals to changes without adding the |
| 913 | # triggering events to Zuul, so that we can be sure that it is |
| 914 | # enqueing the changes based on dependencies, not because of |
| 915 | # triggering events. Since it will have the changes cached |
| 916 | # already (without approvals), we need to clear the cache |
| 917 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 918 | for connection in self.connections.connections.values(): |
James E. Blair | b0a95ab | 2017-10-18 09:39:18 -0700 | [diff] [blame] | 919 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 920 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 921 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 922 | A.addApproval('Approved', 1) |
| 923 | B.addApproval('Approved', 1) |
| 924 | D.addApproval('Approved', 1) |
| 925 | E.addApproval('Approved', 1) |
| 926 | F.addApproval('Approved', 1) |
| 927 | G.addApproval('Approved', 1) |
| 928 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 929 | |
| 930 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 931 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 932 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 933 | self.executor_server.hold_jobs_in_build = False |
| 934 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 935 | self.waitUntilSettled() |
| 936 | |
| 937 | self.assertEqual(A.data['status'], 'MERGED') |
| 938 | self.assertEqual(B.data['status'], 'MERGED') |
| 939 | self.assertEqual(C.data['status'], 'MERGED') |
| 940 | self.assertEqual(D.data['status'], 'MERGED') |
| 941 | self.assertEqual(E.data['status'], 'MERGED') |
| 942 | self.assertEqual(F.data['status'], 'MERGED') |
| 943 | self.assertEqual(G.data['status'], 'MERGED') |
| 944 | self.assertEqual(A.reported, 2) |
| 945 | self.assertEqual(B.reported, 2) |
| 946 | self.assertEqual(C.reported, 2) |
| 947 | self.assertEqual(D.reported, 2) |
| 948 | self.assertEqual(E.reported, 2) |
| 949 | self.assertEqual(F.reported, 2) |
| 950 | self.assertEqual(G.reported, 2) |
| 951 | self.assertEqual(self.history[6].changes, |
| 952 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 953 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 954 | def test_source_cache(self): |
| 955 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 956 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 957 | |
| 958 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 959 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 960 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 961 | A.addApproval('Code-Review', 2) |
| 962 | B.addApproval('Code-Review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 963 | |
| 964 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 965 | M1.setMerged() |
| 966 | |
| 967 | B.setDependsOn(A, 1) |
| 968 | A.setDependsOn(M1, 1) |
| 969 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 970 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 971 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 972 | |
| 973 | self.waitUntilSettled() |
| 974 | |
| 975 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 976 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 977 | build.release() |
| 978 | self.waitUntilSettled() |
| 979 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 980 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 981 | build.release() |
| 982 | self.waitUntilSettled() |
| 983 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 984 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 985 | self.waitUntilSettled() |
| 986 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 987 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 988 | # there should still be changes in the cache |
James E. Blair | b0a95ab | 2017-10-18 09:39:18 -0700 | [diff] [blame] | 989 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 990 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 991 | self.executor_server.hold_jobs_in_build = False |
| 992 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 993 | self.waitUntilSettled() |
| 994 | |
| 995 | self.assertEqual(A.data['status'], 'MERGED') |
| 996 | self.assertEqual(B.data['status'], 'MERGED') |
| 997 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 998 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 999 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1000 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1001 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1002 | # TODO: move to test_gerrit (this is a unit test!) |
| 1003 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 1004 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 1005 | (trusted, project) = tenant.getProject('org/project') |
| 1006 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 1007 | |
| 1008 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 1009 | # it easier for users to create events for testing. |
| 1010 | event = zuul.model.TriggerEvent() |
| 1011 | event.trigger_name = 'gerrit' |
| 1012 | event.change_number = '1' |
| 1013 | event.patch_number = '2' |
| 1014 | |
| 1015 | a = source.getChange(event) |
| 1016 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1017 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1018 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1019 | A.addApproval('Code-Review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 1020 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1021 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1022 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1023 | A.addApproval('Approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 1024 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1025 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1026 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1027 | def test_project_merge_conflict(self): |
| 1028 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1029 | |
| 1030 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1031 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1032 | 'master', 'A', |
| 1033 | files={'conflict': 'foo'}) |
| 1034 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1035 | 'master', 'B', |
| 1036 | files={'conflict': 'bar'}) |
| 1037 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1038 | 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1039 | A.addApproval('Code-Review', 2) |
| 1040 | B.addApproval('Code-Review', 2) |
| 1041 | C.addApproval('Code-Review', 2) |
| 1042 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1043 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1044 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1045 | self.waitUntilSettled() |
| 1046 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1047 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1048 | self.assertEqual(C.reported, 1) |
| 1049 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1050 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1051 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1052 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1053 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1054 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1055 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1056 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1057 | self.gearman_server.hold_jobs_in_queue = False |
| 1058 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1059 | self.waitUntilSettled() |
| 1060 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1061 | self.assertEqual(A.data['status'], 'MERGED') |
| 1062 | self.assertEqual(B.data['status'], 'NEW') |
| 1063 | self.assertEqual(C.data['status'], 'MERGED') |
| 1064 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1065 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1066 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1067 | |
| 1068 | self.assertHistory([ |
| 1069 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1070 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1071 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1072 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1073 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1074 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1075 | ], ordered=False) |
| 1076 | |
| 1077 | def test_delayed_merge_conflict(self): |
| 1078 | "Test that delayed check merge conflicts are handled properly" |
| 1079 | |
| 1080 | # Hold jobs in the gearman queue so that we can test whether |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1081 | # the executor sucesfully merges a change based on an old |
| 1082 | # repo state (frozen by the scheduler) which would otherwise |
| 1083 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1084 | self.gearman_server.hold_jobs_in_queue = True |
| 1085 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1086 | 'master', 'A', |
| 1087 | files={'conflict': 'foo'}) |
| 1088 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1089 | 'master', 'B', |
| 1090 | files={'conflict': 'bar'}) |
| 1091 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1092 | 'master', 'C') |
| 1093 | C.setDependsOn(B, 1) |
| 1094 | |
| 1095 | # A enters the gate queue; B and C enter the check queue |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1096 | A.addApproval('Code-Review', 2) |
| 1097 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1098 | self.waitUntilSettled() |
| 1099 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1100 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1101 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1102 | self.waitUntilSettled() |
| 1103 | |
| 1104 | self.assertEqual(A.reported, 1) |
| 1105 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1106 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1107 | |
| 1108 | # A merges while B and C are queued in check |
| 1109 | # Release A project-merge |
| 1110 | queue = self.gearman_server.getQueue() |
| 1111 | self.release(queue[0]) |
| 1112 | self.waitUntilSettled() |
| 1113 | |
| 1114 | # Release A project-test* |
| 1115 | # gate has higher precedence, so A's test jobs are added in |
| 1116 | # front of the merge jobs for B and C |
| 1117 | queue = self.gearman_server.getQueue() |
| 1118 | self.release(queue[0]) |
| 1119 | self.release(queue[1]) |
| 1120 | self.waitUntilSettled() |
| 1121 | |
| 1122 | self.assertEqual(A.data['status'], 'MERGED') |
| 1123 | self.assertEqual(B.data['status'], 'NEW') |
| 1124 | self.assertEqual(C.data['status'], 'NEW') |
| 1125 | self.assertEqual(A.reported, 2) |
| 1126 | self.assertEqual(B.reported, 0) |
| 1127 | self.assertEqual(C.reported, 0) |
| 1128 | self.assertHistory([ |
| 1129 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1130 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1131 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1132 | ], ordered=False) |
| 1133 | |
| 1134 | # B and C report merge conflicts |
| 1135 | # Release B project-merge |
| 1136 | queue = self.gearman_server.getQueue() |
| 1137 | self.release(queue[0]) |
| 1138 | self.waitUntilSettled() |
| 1139 | |
| 1140 | # Release C |
| 1141 | self.gearman_server.hold_jobs_in_queue = False |
| 1142 | self.gearman_server.release() |
| 1143 | self.waitUntilSettled() |
| 1144 | |
| 1145 | self.assertEqual(A.data['status'], 'MERGED') |
| 1146 | self.assertEqual(B.data['status'], 'NEW') |
| 1147 | self.assertEqual(C.data['status'], 'NEW') |
| 1148 | self.assertEqual(A.reported, 2) |
| 1149 | self.assertEqual(B.reported, 1) |
| 1150 | self.assertEqual(C.reported, 1) |
| 1151 | |
| 1152 | self.assertHistory([ |
| 1153 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1154 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1155 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1156 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1157 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1158 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1159 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1160 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1161 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1162 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1163 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1164 | def test_post(self): |
| 1165 | "Test that post jobs run" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1166 | p = "review.example.com/org/project" |
| 1167 | upstream = self.getUpstreamRepos([p]) |
| 1168 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1169 | A.setMerged() |
| 1170 | A_commit = str(upstream[p].commit('master')) |
| 1171 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1172 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1173 | e = { |
| 1174 | "type": "ref-updated", |
| 1175 | "submitter": { |
| 1176 | "name": "User Name", |
| 1177 | }, |
| 1178 | "refUpdate": { |
| 1179 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1180 | "newRev": A_commit, |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1181 | "refName": "master", |
| 1182 | "project": "org/project", |
| 1183 | } |
| 1184 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1185 | self.fake_gerrit.addEvent(e) |
| 1186 | self.waitUntilSettled() |
| 1187 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1188 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1189 | self.assertEqual(len(self.history), 1) |
| 1190 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1191 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1192 | def test_post_ignore_deletes(self): |
| 1193 | "Test that deleting refs does not trigger post jobs" |
| 1194 | |
| 1195 | e = { |
| 1196 | "type": "ref-updated", |
| 1197 | "submitter": { |
| 1198 | "name": "User Name", |
| 1199 | }, |
| 1200 | "refUpdate": { |
| 1201 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1202 | "newRev": "0000000000000000000000000000000000000000", |
| 1203 | "refName": "master", |
| 1204 | "project": "org/project", |
| 1205 | } |
| 1206 | } |
| 1207 | self.fake_gerrit.addEvent(e) |
| 1208 | self.waitUntilSettled() |
| 1209 | |
| 1210 | job_names = [x.name for x in self.history] |
| 1211 | self.assertEqual(len(self.history), 0) |
| 1212 | self.assertNotIn('project-post', job_names) |
| 1213 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1214 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1215 | def test_post_ignore_deletes_negative(self): |
| 1216 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1217 | e = { |
| 1218 | "type": "ref-updated", |
| 1219 | "submitter": { |
| 1220 | "name": "User Name", |
| 1221 | }, |
| 1222 | "refUpdate": { |
| 1223 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1224 | "newRev": "0000000000000000000000000000000000000000", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1225 | "refName": "testbranch", |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1226 | "project": "org/project", |
| 1227 | } |
| 1228 | } |
| 1229 | self.fake_gerrit.addEvent(e) |
| 1230 | self.waitUntilSettled() |
| 1231 | |
| 1232 | job_names = [x.name for x in self.history] |
| 1233 | self.assertEqual(len(self.history), 1) |
| 1234 | self.assertIn('project-post', job_names) |
| 1235 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1236 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1237 | def test_build_configuration_branch_interaction(self): |
| 1238 | "Test that switching between branches works" |
| 1239 | self.test_build_configuration() |
| 1240 | self.test_build_configuration_branch() |
| 1241 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1242 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1243 | repo = git.Repo(path) |
| 1244 | repo.heads.master.commit = repo.commit('init') |
| 1245 | self.test_build_configuration() |
| 1246 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1247 | def test_dependent_changes_rebase(self): |
| 1248 | # Test that no errors occur when we walk a dependency tree |
| 1249 | # with an unused leaf node due to a rebase. |
| 1250 | # Start by constructing: C -> B -> A |
| 1251 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1252 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1253 | B.setDependsOn(A, 1) |
| 1254 | |
| 1255 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1256 | C.setDependsOn(B, 1) |
| 1257 | |
| 1258 | # Then rebase to form: D -> C -> A |
| 1259 | C.addPatchset() # C,2 |
| 1260 | C.setDependsOn(A, 1) |
| 1261 | |
| 1262 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1263 | D.setDependsOn(C, 2) |
| 1264 | |
| 1265 | # Walk the entire tree |
| 1266 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1267 | self.waitUntilSettled() |
| 1268 | self.assertEqual(len(self.history), 3) |
| 1269 | |
| 1270 | # Verify that walking just part of the tree still works |
| 1271 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1272 | self.waitUntilSettled() |
| 1273 | self.assertEqual(len(self.history), 6) |
| 1274 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1275 | def test_dependent_changes_dequeue(self): |
| 1276 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1277 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1278 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1279 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1280 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1281 | A.addApproval('Code-Review', 2) |
| 1282 | B.addApproval('Code-Review', 2) |
| 1283 | C.addApproval('Code-Review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1284 | |
| 1285 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1286 | M1.setMerged() |
| 1287 | |
| 1288 | # C -> B -> A -> M1 |
| 1289 | |
| 1290 | C.setDependsOn(B, 1) |
| 1291 | B.setDependsOn(A, 1) |
| 1292 | A.setDependsOn(M1, 1) |
| 1293 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1294 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1295 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1296 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1297 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1298 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1299 | |
| 1300 | self.waitUntilSettled() |
| 1301 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1302 | self.assertEqual(A.data['status'], 'NEW') |
| 1303 | self.assertEqual(A.reported, 2) |
| 1304 | self.assertEqual(B.data['status'], 'NEW') |
| 1305 | self.assertEqual(B.reported, 2) |
| 1306 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1307 | self.assertIn('This change depends on a change that failed to merge.', |
| 1308 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1309 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1310 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1311 | def test_failing_dependent_changes(self): |
| 1312 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1313 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1314 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1315 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1316 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1317 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1318 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1319 | A.addApproval('Code-Review', 2) |
| 1320 | B.addApproval('Code-Review', 2) |
| 1321 | C.addApproval('Code-Review', 2) |
| 1322 | D.addApproval('Code-Review', 2) |
| 1323 | E.addApproval('Code-Review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1324 | |
| 1325 | # E, D -> C -> B, A |
| 1326 | |
| 1327 | D.setDependsOn(C, 1) |
| 1328 | C.setDependsOn(B, 1) |
| 1329 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1330 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1331 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1332 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1333 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
| 1334 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1335 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1336 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1337 | |
| 1338 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1339 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1340 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1341 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1342 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1343 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1344 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1345 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1346 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1347 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1348 | self.waitUntilSettled() |
| 1349 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1350 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1351 | for build in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 1352 | if build.parameters['zuul']['change'] != '1': |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1353 | build.release() |
| 1354 | self.waitUntilSettled() |
| 1355 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1356 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1357 | self.waitUntilSettled() |
| 1358 | |
| 1359 | self.assertEqual(A.data['status'], 'MERGED') |
| 1360 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1361 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1362 | self.assertEqual(B.data['status'], 'NEW') |
| 1363 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1364 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1365 | self.assertEqual(C.data['status'], 'NEW') |
| 1366 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1367 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1368 | self.assertEqual(D.data['status'], 'NEW') |
| 1369 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1370 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1371 | self.assertEqual(E.data['status'], 'MERGED') |
| 1372 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1373 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1374 | self.assertEqual(len(self.history), 18) |
| 1375 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1376 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1377 | "Test that if a change at the head fails it is dequeued only once" |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1378 | # If it's dequeued more than once, we should see extra |
| 1379 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1380 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1381 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1382 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1383 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1384 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1385 | A.addApproval('Code-Review', 2) |
| 1386 | B.addApproval('Code-Review', 2) |
| 1387 | C.addApproval('Code-Review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1388 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1389 | self.executor_server.failJob('project-test1', A) |
| 1390 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1391 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1392 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1393 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1394 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1395 | |
| 1396 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1397 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1398 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1399 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1400 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1401 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1402 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1403 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1404 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1405 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1406 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1407 | self.waitUntilSettled() |
| 1408 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1409 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1410 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1411 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1412 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1413 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1414 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1415 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1416 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1417 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1418 | self.waitUntilSettled() |
| 1419 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1420 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1421 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1422 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1423 | self.executor_server.hold_jobs_in_build = False |
| 1424 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1425 | self.waitUntilSettled() |
| 1426 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1427 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1428 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1429 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1430 | self.assertEqual(A.data['status'], 'NEW') |
| 1431 | self.assertEqual(B.data['status'], 'MERGED') |
| 1432 | self.assertEqual(C.data['status'], 'MERGED') |
| 1433 | self.assertEqual(A.reported, 2) |
| 1434 | self.assertEqual(B.reported, 2) |
| 1435 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1436 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1437 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1438 | def test_nonvoting_job(self): |
| 1439 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1440 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1441 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1442 | 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1443 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1444 | self.executor_server.failJob('nonvoting-project-test2', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1445 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1446 | |
| 1447 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1448 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1449 | self.assertEqual(A.data['status'], 'MERGED') |
| 1450 | self.assertEqual(A.reported, 2) |
| 1451 | self.assertEqual( |
| 1452 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1453 | 'SUCCESS') |
| 1454 | self.assertEqual( |
| 1455 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1456 | 'SUCCESS') |
| 1457 | self.assertEqual( |
| 1458 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1459 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1460 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 1461 | self.assertTrue(self.getJobFromHistory('nonvoting-project-merge'). |
| 1462 | parameters['zuul']['voting']) |
| 1463 | self.assertTrue(self.getJobFromHistory('nonvoting-project-test1'). |
| 1464 | parameters['zuul']['voting']) |
| 1465 | self.assertFalse(self.getJobFromHistory('nonvoting-project-test2'). |
| 1466 | parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1467 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1468 | def test_check_queue_success(self): |
| 1469 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1470 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1471 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1472 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1473 | |
| 1474 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1475 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1476 | self.assertEqual(A.data['status'], 'NEW') |
| 1477 | self.assertEqual(A.reported, 1) |
| 1478 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1479 | 'SUCCESS') |
| 1480 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1481 | 'SUCCESS') |
| 1482 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1483 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1484 | |
| 1485 | def test_check_queue_failure(self): |
| 1486 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1487 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1488 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1489 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1490 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1491 | |
| 1492 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1493 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1494 | self.assertEqual(A.data['status'], 'NEW') |
| 1495 | self.assertEqual(A.reported, 1) |
| 1496 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1497 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1498 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1499 | 'SUCCESS') |
| 1500 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1501 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1502 | |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1503 | @simple_layout('layouts/autohold.yaml') |
| 1504 | def test_autohold(self): |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1505 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1506 | self.gearman_server.port) |
| 1507 | self.addCleanup(client.shutdown) |
David Shrewsbury | 36b2adf | 2017-07-31 15:40:13 -0400 | [diff] [blame] | 1508 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
Krzysztof Klimonda | 37d5403 | 2017-10-25 12:16:47 +0200 | [diff] [blame] | 1509 | "", "", "reason text", 1) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1510 | self.assertTrue(r) |
| 1511 | |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1512 | # First check that successful jobs do not autohold |
| 1513 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1514 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1515 | |
| 1516 | self.waitUntilSettled() |
| 1517 | |
| 1518 | self.assertEqual(A.data['status'], 'NEW') |
| 1519 | self.assertEqual(A.reported, 1) |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1520 | # project-test2 |
| 1521 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 1522 | |
| 1523 | # Check nodepool for a held node |
| 1524 | held_node = None |
| 1525 | for node in self.fake_nodepool.getNodes(): |
| 1526 | if node['state'] == zuul.model.STATE_HOLD: |
| 1527 | held_node = node |
| 1528 | break |
| 1529 | self.assertIsNone(held_node) |
| 1530 | |
| 1531 | # Now test that failed jobs are autoheld |
| 1532 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1533 | self.executor_server.failJob('project-test2', B) |
| 1534 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1535 | |
| 1536 | self.waitUntilSettled() |
| 1537 | |
| 1538 | self.assertEqual(B.data['status'], 'NEW') |
| 1539 | self.assertEqual(B.reported, 1) |
| 1540 | # project-test2 |
| 1541 | self.assertEqual(self.history[1].result, 'FAILURE') |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1542 | |
| 1543 | # Check nodepool for a held node |
| 1544 | held_node = None |
| 1545 | for node in self.fake_nodepool.getNodes(): |
| 1546 | if node['state'] == zuul.model.STATE_HOLD: |
| 1547 | held_node = node |
| 1548 | break |
| 1549 | self.assertIsNotNone(held_node) |
| 1550 | |
| 1551 | # Validate node has recorded the failed job |
| 1552 | self.assertEqual( |
| 1553 | held_node['hold_job'], |
| 1554 | " ".join(['tenant-one', |
| 1555 | 'review.example.com/org/project', |
Krzysztof Klimonda | 37d5403 | 2017-10-25 12:16:47 +0200 | [diff] [blame] | 1556 | 'project-test2', '.*']) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1557 | ) |
David Shrewsbury | f9af9df | 2017-08-01 15:19:26 -0400 | [diff] [blame] | 1558 | self.assertEqual(held_node['comment'], "reason text") |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1559 | |
| 1560 | # Another failed change should not hold any more nodes |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1561 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1562 | self.executor_server.failJob('project-test2', C) |
| 1563 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1564 | self.waitUntilSettled() |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1565 | self.assertEqual(C.data['status'], 'NEW') |
| 1566 | self.assertEqual(C.reported, 1) |
| 1567 | # project-test2 |
| 1568 | self.assertEqual(self.history[2].result, 'FAILURE') |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1569 | |
| 1570 | held_nodes = 0 |
| 1571 | for node in self.fake_nodepool.getNodes(): |
| 1572 | if node['state'] == zuul.model.STATE_HOLD: |
| 1573 | held_nodes += 1 |
| 1574 | self.assertEqual(held_nodes, 1) |
| 1575 | |
Krzysztof Klimonda | 37d5403 | 2017-10-25 12:16:47 +0200 | [diff] [blame] | 1576 | def _test_autohold_scoped(self, change_obj, change, ref): |
| 1577 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1578 | self.gearman_server.port) |
| 1579 | self.addCleanup(client.shutdown) |
| 1580 | |
| 1581 | # create two changes on the same project, and autohold request |
| 1582 | # for one of them. |
| 1583 | other = self.fake_gerrit.addFakeChange( |
| 1584 | 'org/project', 'master', 'other' |
| 1585 | ) |
| 1586 | |
| 1587 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1588 | str(change), ref, "reason text", 1) |
| 1589 | self.assertTrue(r) |
| 1590 | |
| 1591 | # First, check that an unrelated job does not trigger autohold, even |
| 1592 | # when it failed |
| 1593 | self.executor_server.failJob('project-test2', other) |
| 1594 | self.fake_gerrit.addEvent(other.getPatchsetCreatedEvent(1)) |
| 1595 | |
| 1596 | self.waitUntilSettled() |
| 1597 | |
| 1598 | self.assertEqual(other.data['status'], 'NEW') |
| 1599 | self.assertEqual(other.reported, 1) |
| 1600 | # project-test2 |
| 1601 | self.assertEqual(self.history[0].result, 'FAILURE') |
| 1602 | |
| 1603 | # Check nodepool for a held node |
| 1604 | held_node = None |
| 1605 | for node in self.fake_nodepool.getNodes(): |
| 1606 | if node['state'] == zuul.model.STATE_HOLD: |
| 1607 | held_node = node |
| 1608 | break |
| 1609 | self.assertIsNone(held_node) |
| 1610 | |
| 1611 | # And then verify that failed job for the defined change |
| 1612 | # triggers the autohold |
| 1613 | |
| 1614 | self.executor_server.failJob('project-test2', change_obj) |
| 1615 | self.fake_gerrit.addEvent(change_obj.getPatchsetCreatedEvent(1)) |
| 1616 | |
| 1617 | self.waitUntilSettled() |
| 1618 | |
| 1619 | self.assertEqual(change_obj.data['status'], 'NEW') |
| 1620 | self.assertEqual(change_obj.reported, 1) |
| 1621 | # project-test2 |
| 1622 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 1623 | |
| 1624 | # Check nodepool for a held node |
| 1625 | held_node = None |
| 1626 | for node in self.fake_nodepool.getNodes(): |
| 1627 | if node['state'] == zuul.model.STATE_HOLD: |
| 1628 | held_node = node |
| 1629 | break |
| 1630 | self.assertIsNotNone(held_node) |
| 1631 | |
| 1632 | # Validate node has recorded the failed job |
| 1633 | if change != "": |
| 1634 | ref = "refs/changes/%s/%s/.*" % ( |
| 1635 | str(change_obj.number)[-1:], str(change_obj.number) |
| 1636 | ) |
| 1637 | |
| 1638 | self.assertEqual( |
| 1639 | held_node['hold_job'], |
| 1640 | " ".join(['tenant-one', |
| 1641 | 'review.example.com/org/project', |
| 1642 | 'project-test2', ref]) |
| 1643 | ) |
| 1644 | self.assertEqual(held_node['comment'], "reason text") |
| 1645 | |
| 1646 | @simple_layout('layouts/autohold.yaml') |
| 1647 | def test_autohold_change(self): |
| 1648 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1649 | |
| 1650 | self._test_autohold_scoped(A, change=A.number, ref="") |
| 1651 | |
| 1652 | @simple_layout('layouts/autohold.yaml') |
| 1653 | def test_autohold_ref(self): |
| 1654 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1655 | ref = A.data['currentPatchSet']['ref'] |
| 1656 | self._test_autohold_scoped(A, change="", ref=ref) |
| 1657 | |
| 1658 | @simple_layout('layouts/autohold.yaml') |
| 1659 | def test_autohold_scoping(self): |
| 1660 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1661 | self.gearman_server.port) |
| 1662 | self.addCleanup(client.shutdown) |
| 1663 | |
| 1664 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1665 | |
| 1666 | # create three autohold requests, scoped to job, change and |
| 1667 | # a specific ref |
| 1668 | change = str(A.number) |
| 1669 | ref = A.data['currentPatchSet']['ref'] |
| 1670 | r1 = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1671 | "", "", "reason text", 1) |
| 1672 | self.assertTrue(r1) |
| 1673 | r2 = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1674 | change, "", "reason text", 1) |
| 1675 | self.assertTrue(r2) |
| 1676 | r3 = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1677 | "", ref, "reason text", 1) |
| 1678 | self.assertTrue(r3) |
| 1679 | |
| 1680 | # Fail 3 jobs for the same change, and verify that the autohold |
| 1681 | # requests are fullfilled in the expected order: from the most |
| 1682 | # specific towards the most generic one. |
| 1683 | |
| 1684 | def _fail_job_and_verify_autohold_request(change_obj, ref_filter): |
| 1685 | self.executor_server.failJob('project-test2', change_obj) |
| 1686 | self.fake_gerrit.addEvent(change_obj.getPatchsetCreatedEvent(1)) |
| 1687 | |
| 1688 | self.waitUntilSettled() |
| 1689 | |
| 1690 | # Check nodepool for a held node |
| 1691 | held_node = None |
| 1692 | for node in self.fake_nodepool.getNodes(): |
| 1693 | if node['state'] == zuul.model.STATE_HOLD: |
| 1694 | held_node = node |
| 1695 | break |
| 1696 | self.assertIsNotNone(held_node) |
| 1697 | |
| 1698 | self.assertEqual( |
| 1699 | held_node['hold_job'], |
| 1700 | " ".join(['tenant-one', |
| 1701 | 'review.example.com/org/project', |
| 1702 | 'project-test2', ref_filter]) |
| 1703 | ) |
| 1704 | self.assertFalse(held_node['_lock'], "Node %s is locked" % |
| 1705 | (node['_oid'],)) |
| 1706 | self.fake_nodepool.removeNode(held_node) |
| 1707 | |
| 1708 | _fail_job_and_verify_autohold_request(A, ref) |
| 1709 | |
| 1710 | ref = "refs/changes/%s/%s/.*" % (str(change)[-1:], str(change)) |
| 1711 | _fail_job_and_verify_autohold_request(A, ref) |
| 1712 | _fail_job_and_verify_autohold_request(A, ".*") |
| 1713 | |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1714 | @simple_layout('layouts/autohold.yaml') |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1715 | def test_autohold_ignores_aborted_jobs(self): |
| 1716 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1717 | self.gearman_server.port) |
| 1718 | self.addCleanup(client.shutdown) |
| 1719 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
Krzysztof Klimonda | 37d5403 | 2017-10-25 12:16:47 +0200 | [diff] [blame] | 1720 | "", "", "reason text", 1) |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1721 | self.assertTrue(r) |
| 1722 | |
| 1723 | self.executor_server.hold_jobs_in_build = True |
| 1724 | |
| 1725 | # Create a change that will have its job aborted |
| 1726 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1727 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1728 | self.waitUntilSettled() |
| 1729 | |
| 1730 | # Creating new patchset on change A will abort A,1's job because |
| 1731 | # a new patchset arrived replacing A,1 with A,2. |
| 1732 | A.addPatchset() |
| 1733 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1734 | |
| 1735 | self.waitUntilSettled() |
| 1736 | self.executor_server.hold_jobs_in_build = False |
| 1737 | self.executor_server.release() |
| 1738 | self.waitUntilSettled() |
| 1739 | |
| 1740 | self.assertEqual(A.data['status'], 'NEW') |
| 1741 | # Note only the successful job for A,2 will report as we don't |
| 1742 | # report aborted builds for old patchsets. |
| 1743 | self.assertEqual(A.reported, 1) |
| 1744 | # A,1 project-test2 |
| 1745 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1746 | # A,2 project-test2 |
| 1747 | self.assertEqual(self.history[1].result, 'SUCCESS') |
| 1748 | |
| 1749 | # Check nodepool for a held node |
| 1750 | held_node = None |
| 1751 | for node in self.fake_nodepool.getNodes(): |
| 1752 | if node['state'] == zuul.model.STATE_HOLD: |
| 1753 | held_node = node |
| 1754 | break |
| 1755 | self.assertIsNone(held_node) |
| 1756 | |
| 1757 | @simple_layout('layouts/autohold.yaml') |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1758 | def test_autohold_list(self): |
| 1759 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1760 | self.gearman_server.port) |
| 1761 | self.addCleanup(client.shutdown) |
| 1762 | |
| 1763 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
Krzysztof Klimonda | 37d5403 | 2017-10-25 12:16:47 +0200 | [diff] [blame] | 1764 | "", "", "reason text", 1) |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1765 | self.assertTrue(r) |
| 1766 | |
| 1767 | autohold_requests = client.autohold_list() |
| 1768 | self.assertNotEqual({}, autohold_requests) |
| 1769 | self.assertEqual(1, len(autohold_requests.keys())) |
| 1770 | |
| 1771 | # The single dict key should be a CSV string value |
| 1772 | key = list(autohold_requests.keys())[0] |
Krzysztof Klimonda | 37d5403 | 2017-10-25 12:16:47 +0200 | [diff] [blame] | 1773 | tenant, project, job, ref_filter = key.split(',') |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1774 | |
| 1775 | self.assertEqual('tenant-one', tenant) |
| 1776 | self.assertIn('org/project', project) |
| 1777 | self.assertEqual('project-test2', job) |
Krzysztof Klimonda | 37d5403 | 2017-10-25 12:16:47 +0200 | [diff] [blame] | 1778 | self.assertEqual(".*", ref_filter) |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1779 | |
| 1780 | # Note: the value is converted from set to list by json. |
| 1781 | self.assertEqual([1, "reason text"], autohold_requests[key]) |
| 1782 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1783 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1784 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1785 | # This particular test does a large amount of merges and needs a little |
| 1786 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1787 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1788 | "test that dependent changes behind dequeued changes work" |
| 1789 | # This complicated test is a reproduction of a real life bug |
| 1790 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1791 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1792 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1793 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1794 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1795 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1796 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1797 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1798 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1799 | D.setDependsOn(C, 1) |
| 1800 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1801 | A.addApproval('Code-Review', 2) |
| 1802 | B.addApproval('Code-Review', 2) |
| 1803 | C.addApproval('Code-Review', 2) |
| 1804 | D.addApproval('Code-Review', 2) |
| 1805 | E.addApproval('Code-Review', 2) |
| 1806 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1807 | |
| 1808 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1809 | |
| 1810 | # Change object re-use in the gerrit trigger is hidden if |
| 1811 | # changes are added in quick succession; waiting makes it more |
| 1812 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1813 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1814 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1815 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1816 | self.waitUntilSettled() |
| 1817 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1818 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1819 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1820 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1821 | self.waitUntilSettled() |
| 1822 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1823 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1824 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1825 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1826 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1827 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1828 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1829 | self.fake_gerrit.addEvent(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1830 | self.waitUntilSettled() |
| 1831 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1832 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1833 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1834 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1835 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1836 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1837 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1838 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1839 | self.waitUntilSettled() |
| 1840 | |
| 1841 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1842 | |
| 1843 | # Grab pointers to the jobs we want to release before |
| 1844 | # releasing any, because list indexes may change as |
| 1845 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1846 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1847 | a.release() |
| 1848 | b.release() |
| 1849 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1850 | self.waitUntilSettled() |
| 1851 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1852 | self.executor_server.hold_jobs_in_build = False |
| 1853 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1854 | self.waitUntilSettled() |
| 1855 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1856 | self.assertEqual(A.data['status'], 'NEW') |
| 1857 | self.assertEqual(B.data['status'], 'MERGED') |
| 1858 | self.assertEqual(C.data['status'], 'MERGED') |
| 1859 | self.assertEqual(D.data['status'], 'MERGED') |
| 1860 | self.assertEqual(E.data['status'], 'MERGED') |
| 1861 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1862 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1863 | self.assertEqual(A.reported, 2) |
| 1864 | self.assertEqual(B.reported, 2) |
| 1865 | self.assertEqual(C.reported, 2) |
| 1866 | self.assertEqual(D.reported, 2) |
| 1867 | self.assertEqual(E.reported, 2) |
| 1868 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1869 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1870 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1871 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1872 | |
| 1873 | def test_merger_repack(self): |
| 1874 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1875 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1876 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1877 | A.addApproval('Code-Review', 2) |
| 1878 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1879 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1880 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1881 | 'SUCCESS') |
| 1882 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1883 | 'SUCCESS') |
| 1884 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1885 | 'SUCCESS') |
| 1886 | self.assertEqual(A.data['status'], 'MERGED') |
| 1887 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1888 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1889 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1890 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1891 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1892 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1893 | if os.path.exists(path): |
| 1894 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1895 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1896 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1897 | if os.path.exists(path): |
| 1898 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1899 | |
| 1900 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1901 | A.addApproval('Code-Review', 2) |
| 1902 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1903 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1904 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1905 | 'SUCCESS') |
| 1906 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1907 | 'SUCCESS') |
| 1908 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1909 | 'SUCCESS') |
| 1910 | self.assertEqual(A.data['status'], 'MERGED') |
| 1911 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1912 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1913 | def test_merger_repack_large_change(self): |
| 1914 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1915 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1916 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1917 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1918 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1919 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1920 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1921 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1922 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1923 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1924 | # TODOv3(jeblair): add hostname to upstream root |
| 1925 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1926 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1927 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1928 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1929 | if os.path.exists(path): |
| 1930 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1931 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1932 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1933 | if os.path.exists(path): |
| 1934 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1935 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1936 | A.addApproval('Code-Review', 2) |
| 1937 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1938 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1939 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1940 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1941 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1942 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1943 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1944 | 'SUCCESS') |
| 1945 | self.assertEqual(A.data['status'], 'MERGED') |
| 1946 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1947 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1948 | def test_new_patchset_dequeues_old(self): |
| 1949 | "Test that a new patchset causes the old to be dequeued" |
| 1950 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1951 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1952 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1953 | M.setMerged() |
| 1954 | |
| 1955 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1956 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1957 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1958 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1959 | A.addApproval('Code-Review', 2) |
| 1960 | B.addApproval('Code-Review', 2) |
| 1961 | C.addApproval('Code-Review', 2) |
| 1962 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1963 | |
| 1964 | C.setDependsOn(B, 1) |
| 1965 | B.setDependsOn(A, 1) |
| 1966 | A.setDependsOn(M, 1) |
| 1967 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1968 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1969 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1970 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1971 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1972 | self.waitUntilSettled() |
| 1973 | |
| 1974 | B.addPatchset() |
| 1975 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1976 | self.waitUntilSettled() |
| 1977 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1978 | self.executor_server.hold_jobs_in_build = False |
| 1979 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1980 | self.waitUntilSettled() |
| 1981 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1982 | self.assertEqual(A.data['status'], 'MERGED') |
| 1983 | self.assertEqual(A.reported, 2) |
| 1984 | self.assertEqual(B.data['status'], 'NEW') |
| 1985 | self.assertEqual(B.reported, 2) |
| 1986 | self.assertEqual(C.data['status'], 'NEW') |
| 1987 | self.assertEqual(C.reported, 2) |
| 1988 | self.assertEqual(D.data['status'], 'MERGED') |
| 1989 | self.assertEqual(D.reported, 2) |
| 1990 | self.assertEqual(len(self.history), 9) # 3 each for A, B, D. |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1991 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1992 | def test_new_patchset_check(self): |
| 1993 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1994 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1995 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1996 | |
| 1997 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1998 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1999 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2000 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2001 | |
| 2002 | # Add two git-dependent changes |
| 2003 | B.setDependsOn(A, 1) |
| 2004 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2005 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 2006 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2007 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2008 | |
| 2009 | # A live item, and a non-live/live pair |
| 2010 | items = check_pipeline.getAllItems() |
| 2011 | self.assertEqual(len(items), 3) |
| 2012 | |
| 2013 | self.assertEqual(items[0].change.number, '1') |
| 2014 | self.assertEqual(items[0].change.patchset, '1') |
| 2015 | self.assertFalse(items[0].live) |
| 2016 | |
| 2017 | self.assertEqual(items[1].change.number, '2') |
| 2018 | self.assertEqual(items[1].change.patchset, '1') |
| 2019 | self.assertTrue(items[1].live) |
| 2020 | |
| 2021 | self.assertEqual(items[2].change.number, '1') |
| 2022 | self.assertEqual(items[2].change.patchset, '1') |
| 2023 | self.assertTrue(items[2].live) |
| 2024 | |
| 2025 | # Add a new patchset to A |
| 2026 | A.addPatchset() |
| 2027 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2028 | self.waitUntilSettled() |
| 2029 | |
| 2030 | # The live copy of A,1 should be gone, but the non-live and B |
| 2031 | # should continue, and we should have a new A,2 |
| 2032 | items = check_pipeline.getAllItems() |
| 2033 | self.assertEqual(len(items), 3) |
| 2034 | |
| 2035 | self.assertEqual(items[0].change.number, '1') |
| 2036 | self.assertEqual(items[0].change.patchset, '1') |
| 2037 | self.assertFalse(items[0].live) |
| 2038 | |
| 2039 | self.assertEqual(items[1].change.number, '2') |
| 2040 | self.assertEqual(items[1].change.patchset, '1') |
| 2041 | self.assertTrue(items[1].live) |
| 2042 | |
| 2043 | self.assertEqual(items[2].change.number, '1') |
| 2044 | self.assertEqual(items[2].change.patchset, '2') |
| 2045 | self.assertTrue(items[2].live) |
| 2046 | |
| 2047 | # Add a new patchset to B |
| 2048 | B.addPatchset() |
| 2049 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2050 | self.waitUntilSettled() |
| 2051 | |
| 2052 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 2053 | # but we should have a new B,2 (still based on A,1) |
| 2054 | items = check_pipeline.getAllItems() |
| 2055 | self.assertEqual(len(items), 3) |
| 2056 | |
| 2057 | self.assertEqual(items[0].change.number, '1') |
| 2058 | self.assertEqual(items[0].change.patchset, '2') |
| 2059 | self.assertTrue(items[0].live) |
| 2060 | |
| 2061 | self.assertEqual(items[1].change.number, '1') |
| 2062 | self.assertEqual(items[1].change.patchset, '1') |
| 2063 | self.assertFalse(items[1].live) |
| 2064 | |
| 2065 | self.assertEqual(items[2].change.number, '2') |
| 2066 | self.assertEqual(items[2].change.patchset, '2') |
| 2067 | self.assertTrue(items[2].live) |
| 2068 | |
| 2069 | self.builds[0].release() |
| 2070 | self.waitUntilSettled() |
| 2071 | self.builds[0].release() |
| 2072 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2073 | self.executor_server.hold_jobs_in_build = False |
| 2074 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2075 | self.waitUntilSettled() |
| 2076 | |
| 2077 | self.assertEqual(A.reported, 1) |
| 2078 | self.assertEqual(B.reported, 1) |
| 2079 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 2080 | self.assertEqual(self.history[0].changes, '1,1') |
| 2081 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 2082 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 2083 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2084 | self.assertEqual(self.history[2].changes, '1,2') |
| 2085 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2086 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 2087 | |
| 2088 | def test_abandoned_gate(self): |
| 2089 | "Test that an abandoned change is dequeued from gate" |
| 2090 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2091 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2092 | |
| 2093 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2094 | A.addApproval('Code-Review', 2) |
| 2095 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2096 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 2097 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 2098 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 2099 | |
| 2100 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2101 | self.waitUntilSettled() |
| 2102 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2103 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 2104 | self.waitUntilSettled() |
| 2105 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 2106 | self.assertBuilds([]) |
| 2107 | self.assertHistory([ |
| 2108 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 2109 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2110 | self.assertEqual(A.reported, 1, |
| 2111 | "Abandoned gate change should report only start") |
| 2112 | |
| 2113 | def test_abandoned_check(self): |
| 2114 | "Test that an abandoned change is dequeued from check" |
| 2115 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2116 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2117 | |
| 2118 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2119 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 2120 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2121 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2122 | |
| 2123 | # Add two git-dependent changes |
| 2124 | B.setDependsOn(A, 1) |
| 2125 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2126 | self.waitUntilSettled() |
| 2127 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2128 | self.waitUntilSettled() |
| 2129 | # A live item, and a non-live/live pair |
| 2130 | items = check_pipeline.getAllItems() |
| 2131 | self.assertEqual(len(items), 3) |
| 2132 | |
| 2133 | self.assertEqual(items[0].change.number, '1') |
| 2134 | self.assertFalse(items[0].live) |
| 2135 | |
| 2136 | self.assertEqual(items[1].change.number, '2') |
| 2137 | self.assertTrue(items[1].live) |
| 2138 | |
| 2139 | self.assertEqual(items[2].change.number, '1') |
| 2140 | self.assertTrue(items[2].live) |
| 2141 | |
| 2142 | # Abandon A |
| 2143 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2144 | self.waitUntilSettled() |
| 2145 | |
| 2146 | # The live copy of A should be gone, but the non-live and B |
| 2147 | # should continue |
| 2148 | items = check_pipeline.getAllItems() |
| 2149 | self.assertEqual(len(items), 2) |
| 2150 | |
| 2151 | self.assertEqual(items[0].change.number, '1') |
| 2152 | self.assertFalse(items[0].live) |
| 2153 | |
| 2154 | self.assertEqual(items[1].change.number, '2') |
| 2155 | self.assertTrue(items[1].live) |
| 2156 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2157 | self.executor_server.hold_jobs_in_build = False |
| 2158 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2159 | self.waitUntilSettled() |
| 2160 | |
| 2161 | self.assertEqual(len(self.history), 4) |
| 2162 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 2163 | 'Build should have been aborted') |
| 2164 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2165 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 2166 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2167 | def test_abandoned_not_timer(self): |
| 2168 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2169 | # This test can not use simple_layout because it must start |
| 2170 | # with a configuration which does not include a |
| 2171 | # timer-triggered job so that we have an opportunity to set |
| 2172 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2173 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2174 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2175 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2176 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2177 | # The pipeline triggers every second, so we should have seen |
| 2178 | # several by now. |
| 2179 | time.sleep(5) |
| 2180 | self.waitUntilSettled() |
| 2181 | # Stop queuing timer triggered jobs so that the assertions |
| 2182 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 2183 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2184 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2185 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 2186 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2187 | # If APScheduler is in mid-event when we remove the job, we |
| 2188 | # can end up with one more event firing, so give it an extra |
| 2189 | # second to settle. |
| 2190 | time.sleep(1) |
| 2191 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2192 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2193 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2194 | |
| 2195 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2196 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2197 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2198 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2199 | |
| 2200 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2201 | self.waitUntilSettled() |
| 2202 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2203 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2204 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2205 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2206 | self.waitUntilSettled() |
| 2207 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2208 | def test_new_patchset_dequeues_old_on_head(self): |
| 2209 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 2210 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2211 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2212 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 2213 | M.setMerged() |
| 2214 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2215 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2216 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2217 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2218 | A.addApproval('Code-Review', 2) |
| 2219 | B.addApproval('Code-Review', 2) |
| 2220 | C.addApproval('Code-Review', 2) |
| 2221 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2222 | |
| 2223 | C.setDependsOn(B, 1) |
| 2224 | B.setDependsOn(A, 1) |
| 2225 | A.setDependsOn(M, 1) |
| 2226 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2227 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2228 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2229 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2230 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2231 | self.waitUntilSettled() |
| 2232 | |
| 2233 | A.addPatchset() |
| 2234 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2235 | self.waitUntilSettled() |
| 2236 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2237 | self.executor_server.hold_jobs_in_build = False |
| 2238 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2239 | self.waitUntilSettled() |
| 2240 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2241 | self.assertEqual(A.data['status'], 'NEW') |
| 2242 | self.assertEqual(A.reported, 2) |
| 2243 | self.assertEqual(B.data['status'], 'NEW') |
| 2244 | self.assertEqual(B.reported, 2) |
| 2245 | self.assertEqual(C.data['status'], 'NEW') |
| 2246 | self.assertEqual(C.reported, 2) |
| 2247 | self.assertEqual(D.data['status'], 'MERGED') |
| 2248 | self.assertEqual(D.reported, 2) |
| 2249 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2250 | |
| 2251 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2252 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2253 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2254 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2255 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2256 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2257 | A.addApproval('Code-Review', 2) |
| 2258 | B.addApproval('Code-Review', 2) |
| 2259 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2260 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2261 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2262 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2263 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2264 | self.waitUntilSettled() |
| 2265 | |
| 2266 | B.addPatchset() |
| 2267 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2268 | self.waitUntilSettled() |
| 2269 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2270 | self.executor_server.hold_jobs_in_build = False |
| 2271 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2272 | self.waitUntilSettled() |
| 2273 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2274 | self.assertEqual(A.data['status'], 'MERGED') |
| 2275 | self.assertEqual(A.reported, 2) |
| 2276 | self.assertEqual(B.data['status'], 'NEW') |
| 2277 | self.assertEqual(B.reported, 2) |
| 2278 | self.assertEqual(C.data['status'], 'MERGED') |
| 2279 | self.assertEqual(C.reported, 2) |
| 2280 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2281 | |
| 2282 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2283 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2284 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2285 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2286 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2287 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2288 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2289 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2290 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2291 | self.waitUntilSettled() |
| 2292 | |
| 2293 | B.addPatchset() |
| 2294 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2295 | self.waitUntilSettled() |
| 2296 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2297 | self.executor_server.hold_jobs_in_build = False |
| 2298 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2299 | self.waitUntilSettled() |
| 2300 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2301 | self.assertEqual(A.data['status'], 'NEW') |
| 2302 | self.assertEqual(A.reported, 1) |
| 2303 | self.assertEqual(B.data['status'], 'NEW') |
| 2304 | self.assertEqual(B.reported, 1) |
| 2305 | self.assertEqual(C.data['status'], 'NEW') |
| 2306 | self.assertEqual(C.reported, 1) |
| 2307 | self.assertEqual(len(self.history), 10) |
| 2308 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2309 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2310 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2311 | def test_noop_job(self): |
| 2312 | "Test that the internal noop job works" |
| 2313 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2314 | A.addApproval('Code-Review', 2) |
| 2315 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2316 | self.waitUntilSettled() |
| 2317 | |
| 2318 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2319 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2320 | self.assertEqual(len(self.history), 0) |
| 2321 | self.assertEqual(A.data['status'], 'MERGED') |
| 2322 | self.assertEqual(A.reported, 2) |
| 2323 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2324 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2325 | def test_no_job_project(self): |
| 2326 | "Test that reports with no jobs don't get sent" |
| 2327 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2328 | 'master', 'A') |
| 2329 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2330 | self.waitUntilSettled() |
| 2331 | |
| 2332 | # Change wasn't reported to |
| 2333 | self.assertEqual(A.reported, False) |
| 2334 | |
| 2335 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2336 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2337 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2338 | items = check_pipeline.getAllItems() |
| 2339 | self.assertEqual(len(items), 0) |
| 2340 | |
| 2341 | self.assertEqual(len(self.history), 0) |
| 2342 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2343 | def test_zuul_refs(self): |
| 2344 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2345 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2346 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2347 | M1.setMerged() |
| 2348 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2349 | M2.setMerged() |
| 2350 | |
| 2351 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2352 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2353 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2354 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2355 | A.addApproval('Code-Review', 2) |
| 2356 | B.addApproval('Code-Review', 2) |
| 2357 | C.addApproval('Code-Review', 2) |
| 2358 | D.addApproval('Code-Review', 2) |
| 2359 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2360 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2361 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2362 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2363 | |
| 2364 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2365 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2366 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2367 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2368 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2369 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2370 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2371 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2372 | self.waitUntilSettled() |
| 2373 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2374 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2375 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2376 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2377 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2378 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2379 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2380 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2381 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2382 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2383 | d_build = x |
| 2384 | if a_build and b_build and c_build and d_build: |
| 2385 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2386 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2387 | # should have a, not b, and should not be in project2 |
| 2388 | self.assertTrue(a_build.hasChanges(A)) |
| 2389 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2390 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2391 | # should have a and b, and should not be in project2 |
| 2392 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2393 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2394 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2395 | # should have a and b in 1, c in 2 |
| 2396 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2397 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2398 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2399 | # should have a and b in 1, c and d in 2 |
| 2400 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2401 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2402 | self.executor_server.hold_jobs_in_build = False |
| 2403 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2404 | self.waitUntilSettled() |
| 2405 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2406 | self.assertEqual(A.data['status'], 'MERGED') |
| 2407 | self.assertEqual(A.reported, 2) |
| 2408 | self.assertEqual(B.data['status'], 'MERGED') |
| 2409 | self.assertEqual(B.reported, 2) |
| 2410 | self.assertEqual(C.data['status'], 'MERGED') |
| 2411 | self.assertEqual(C.reported, 2) |
| 2412 | self.assertEqual(D.data['status'], 'MERGED') |
| 2413 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2414 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2415 | def test_rerun_on_error(self): |
| 2416 | "Test that if a worker fails to run a job, it is run again" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2417 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2418 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2419 | A.addApproval('Code-Review', 2) |
| 2420 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2421 | self.waitUntilSettled() |
| 2422 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2423 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2424 | self.executor_server.hold_jobs_in_build = False |
| 2425 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2426 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2427 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2428 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2429 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2430 | def test_statsd(self): |
| 2431 | "Test each of the statsd methods used in the scheduler" |
James E. Blair | ded241e | 2017-10-10 13:22:40 -0700 | [diff] [blame] | 2432 | statsd = self.sched.statsd |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2433 | statsd.incr('test-incr') |
| 2434 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2435 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2436 | self.assertReportedStat('test-incr', '1|c') |
| 2437 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2438 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2439 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2440 | def test_stuck_job_cleanup(self): |
| 2441 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2442 | |
| 2443 | # We want to hold the project-merge job that the fake change enqueues |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2444 | self.gearman_server.hold_jobs_in_queue = True |
| 2445 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2446 | A.addApproval('Code-Review', 2) |
| 2447 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2448 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2449 | # The assertion is that we have one job in the queue, project-merge |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2450 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2451 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2452 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2453 | self.sched.reconfigure(self.config) |
| 2454 | self.waitUntilSettled() |
| 2455 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2456 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2457 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2458 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2459 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2460 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2461 | |
| 2462 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2463 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2464 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2465 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2466 | def test_file_head(self): |
| 2467 | # This is a regression test for an observed bug. A change |
| 2468 | # with a file named "HEAD" in the root directory of the repo |
| 2469 | # was processed by a merger. It then was unable to reset the |
| 2470 | # repo because of: |
| 2471 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2472 | # with exit code 128 |
| 2473 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2474 | # and filename |
| 2475 | # Use '--' to separate filenames from revisions' |
| 2476 | |
| 2477 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2478 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2479 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2480 | |
| 2481 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2482 | self.waitUntilSettled() |
| 2483 | |
| 2484 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2485 | self.waitUntilSettled() |
| 2486 | |
| 2487 | self.assertIn('Build succeeded', A.messages[0]) |
| 2488 | self.assertIn('Build succeeded', B.messages[0]) |
| 2489 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2490 | def test_file_jobs(self): |
| 2491 | "Test that file jobs run only when appropriate" |
| 2492 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2493 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2494 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2495 | A.addApproval('Code-Review', 2) |
| 2496 | B.addApproval('Code-Review', 2) |
| 2497 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2498 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2499 | self.waitUntilSettled() |
| 2500 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2501 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2502 | if x.name == 'project-testfile'] |
| 2503 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2504 | self.assertEqual(len(testfile_jobs), 1) |
| 2505 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2506 | self.assertEqual(A.data['status'], 'MERGED') |
| 2507 | self.assertEqual(A.reported, 2) |
| 2508 | self.assertEqual(B.data['status'], 'MERGED') |
| 2509 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2510 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2511 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2512 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2513 | if should_skip: |
| 2514 | files = {'ignoreme': 'ignored\n'} |
| 2515 | else: |
| 2516 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2517 | |
| 2518 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2519 | 'master', |
| 2520 | 'test irrelevant-files', |
| 2521 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2522 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2523 | self.waitUntilSettled() |
| 2524 | |
| 2525 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2526 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2527 | |
| 2528 | if should_skip: |
| 2529 | self.assertEqual([], tested_change_ids) |
| 2530 | else: |
| 2531 | self.assertIn(change.data['number'], tested_change_ids) |
| 2532 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2533 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2534 | def test_irrelevant_files_match_skips_job(self): |
| 2535 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2536 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2537 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2538 | def test_irrelevant_files_no_match_runs_job(self): |
| 2539 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2540 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2541 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2542 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2543 | files = {'ignoreme': 'ignored\n'} |
| 2544 | |
| 2545 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2546 | 'master', |
| 2547 | 'test irrelevant-files', |
| 2548 | files=files) |
| 2549 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2550 | self.waitUntilSettled() |
| 2551 | |
| 2552 | run_jobs = set([build.name for build in self.history]) |
| 2553 | |
| 2554 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2555 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2556 | |
James E. Blair | af8b208 | 2017-10-03 15:38:27 -0700 | [diff] [blame] | 2557 | @simple_layout('layouts/job-vars.yaml') |
| 2558 | def test_inherited_job_variables(self): |
| 2559 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2560 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2561 | self.waitUntilSettled() |
| 2562 | self.assertHistory([ |
| 2563 | dict(name='parentjob', result='SUCCESS'), |
| 2564 | dict(name='child1', result='SUCCESS'), |
| 2565 | dict(name='child2', result='SUCCESS'), |
| 2566 | dict(name='child3', result='SUCCESS'), |
| 2567 | ], ordered=False) |
| 2568 | j = self.getJobFromHistory('parentjob') |
| 2569 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2570 | self.assertEqual(j.parameters['vars']['override'], 0) |
| 2571 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2572 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2573 | self.assertFalse('child1' in j.parameters['vars']) |
| 2574 | self.assertFalse('child2' in j.parameters['vars']) |
| 2575 | self.assertFalse('child3' in j.parameters['vars']) |
| 2576 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2577 | 'org/project0'])) |
| 2578 | j = self.getJobFromHistory('child1') |
| 2579 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2580 | self.assertEqual(j.parameters['vars']['override'], 1) |
| 2581 | self.assertEqual(j.parameters['vars']['child1override'], 1) |
| 2582 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2583 | self.assertEqual(j.parameters['vars']['child1'], 1) |
| 2584 | self.assertFalse('child2' in j.parameters['vars']) |
| 2585 | self.assertFalse('child3' in j.parameters['vars']) |
| 2586 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2587 | 'org/project1'])) |
| 2588 | j = self.getJobFromHistory('child2') |
| 2589 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2590 | self.assertEqual(j.parameters['vars']['override'], 2) |
| 2591 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2592 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2593 | self.assertFalse('child1' in j.parameters['vars']) |
| 2594 | self.assertEqual(j.parameters['vars']['child2'], 2) |
| 2595 | self.assertFalse('child3' in j.parameters['vars']) |
| 2596 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2597 | 'org/project2'])) |
| 2598 | j = self.getJobFromHistory('child3') |
| 2599 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2600 | self.assertEqual(j.parameters['vars']['override'], 3) |
| 2601 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2602 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2603 | self.assertFalse('child1' in j.parameters['vars']) |
| 2604 | self.assertFalse('child2' in j.parameters['vars']) |
| 2605 | self.assertEqual(j.parameters['vars']['child3'], 3) |
| 2606 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2607 | 'org/project3'])) |
| 2608 | |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2609 | @simple_layout('layouts/job-variants.yaml') |
| 2610 | def test_job_branch_variants(self): |
| 2611 | self.create_branch('org/project', 'stable/diablo') |
| 2612 | self.create_branch('org/project', 'stable/essex') |
| 2613 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2614 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2615 | self.waitUntilSettled() |
| 2616 | |
| 2617 | B = self.fake_gerrit.addFakeChange('org/project', 'stable/diablo', 'B') |
| 2618 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2619 | self.waitUntilSettled() |
| 2620 | |
| 2621 | C = self.fake_gerrit.addFakeChange('org/project', 'stable/essex', 'C') |
| 2622 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2623 | self.waitUntilSettled() |
| 2624 | self.assertHistory([ |
| 2625 | dict(name='python27', result='SUCCESS'), |
| 2626 | dict(name='python27', result='SUCCESS'), |
| 2627 | dict(name='python27', result='SUCCESS'), |
| 2628 | ]) |
| 2629 | |
| 2630 | p = self.history[0].parameters |
| 2631 | self.assertEqual(p['timeout'], 40) |
| 2632 | self.assertEqual(len(p['nodes']), 1) |
| 2633 | self.assertEqual(p['nodes'][0]['label'], 'new') |
| 2634 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2635 | ['base-pre', 'py27-pre']) |
| 2636 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2637 | ['py27-post-a', 'py27-post-b', 'base-post']) |
| 2638 | self.assertEqual([x['path'] for x in p['playbooks']], |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 2639 | ['playbooks/python27.yaml']) |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2640 | |
| 2641 | p = self.history[1].parameters |
| 2642 | self.assertEqual(p['timeout'], 50) |
| 2643 | self.assertEqual(len(p['nodes']), 1) |
| 2644 | self.assertEqual(p['nodes'][0]['label'], 'old') |
| 2645 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2646 | ['base-pre', 'py27-pre', 'py27-diablo-pre']) |
| 2647 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2648 | ['py27-diablo-post', 'py27-post-a', 'py27-post-b', |
| 2649 | 'base-post']) |
| 2650 | self.assertEqual([x['path'] for x in p['playbooks']], |
| 2651 | ['py27-diablo']) |
| 2652 | |
| 2653 | p = self.history[2].parameters |
| 2654 | self.assertEqual(p['timeout'], 40) |
| 2655 | self.assertEqual(len(p['nodes']), 1) |
| 2656 | self.assertEqual(p['nodes'][0]['label'], 'new') |
| 2657 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2658 | ['base-pre', 'py27-pre', 'py27-essex-pre']) |
| 2659 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2660 | ['py27-essex-post', 'py27-post-a', 'py27-post-b', |
| 2661 | 'base-post']) |
| 2662 | self.assertEqual([x['path'] for x in p['playbooks']], |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 2663 | ['playbooks/python27.yaml']) |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2664 | |
James E. Blair | 0029267 | 2017-10-26 15:29:39 -0700 | [diff] [blame] | 2665 | @simple_layout("layouts/no-run.yaml") |
| 2666 | def test_job_without_run(self): |
| 2667 | "Test that a job without a run playbook errors" |
| 2668 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2669 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2670 | self.waitUntilSettled() |
| 2671 | self.assertIn('Job base does not specify a run playbook', |
| 2672 | A.messages[-1]) |
| 2673 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2674 | def test_queue_names(self): |
| 2675 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2676 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2677 | (trusted, project1) = tenant.getProject('org/project1') |
| 2678 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2679 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2680 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2681 | self.assertEqual(q1.name, 'integrated') |
| 2682 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2683 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2684 | def test_queue_precedence(self): |
| 2685 | "Test that queue precedence works" |
| 2686 | |
| 2687 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2688 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2689 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2690 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2691 | A.addApproval('Code-Review', 2) |
| 2692 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2693 | |
| 2694 | self.waitUntilSettled() |
| 2695 | self.gearman_server.hold_jobs_in_queue = False |
| 2696 | self.gearman_server.release() |
| 2697 | self.waitUntilSettled() |
| 2698 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2699 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2700 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2701 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2702 | self.waitUntilSettled() |
| 2703 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2704 | self.log.debug(self.history) |
| 2705 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2706 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2707 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2708 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2709 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2710 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2711 | |
James E. Blair | 419a867 | 2017-10-18 14:48:25 -0700 | [diff] [blame] | 2712 | def test_reconfigure_merge(self): |
| 2713 | """Test that two reconfigure events are merged""" |
| 2714 | |
| 2715 | tenant = self.sched.abide.tenants['tenant-one'] |
| 2716 | (trusted, project) = tenant.getProject('org/project') |
| 2717 | |
| 2718 | self.sched.run_handler_lock.acquire() |
| 2719 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2720 | |
| 2721 | self.sched.reconfigureTenant(tenant, project) |
| 2722 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2723 | |
| 2724 | self.sched.reconfigureTenant(tenant, project) |
| 2725 | # The second event should have been combined with the first |
| 2726 | # so we should still only have one entry. |
| 2727 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2728 | |
| 2729 | self.sched.run_handler_lock.release() |
| 2730 | self.waitUntilSettled() |
| 2731 | |
| 2732 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2733 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2734 | def test_live_reconfiguration(self): |
| 2735 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2736 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2737 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2738 | A.addApproval('Code-Review', 2) |
| 2739 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2740 | self.waitUntilSettled() |
| 2741 | |
| 2742 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2743 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2744 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2745 | self.executor_server.hold_jobs_in_build = False |
| 2746 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2747 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2748 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2749 | 'SUCCESS') |
| 2750 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2751 | 'SUCCESS') |
| 2752 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2753 | 'SUCCESS') |
| 2754 | self.assertEqual(A.data['status'], 'MERGED') |
| 2755 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2756 | |
James E. Blair | 027ba99 | 2017-09-20 13:48:32 -0700 | [diff] [blame] | 2757 | def test_live_reconfiguration_abort(self): |
| 2758 | # Raise an exception during reconfiguration and verify we |
| 2759 | # still function. |
| 2760 | self.executor_server.hold_jobs_in_build = True |
| 2761 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2762 | A.addApproval('Code-Review', 2) |
| 2763 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2764 | self.waitUntilSettled() |
| 2765 | |
| 2766 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2767 | pipeline = tenant.layout.pipelines['gate'] |
| 2768 | change = pipeline.getAllItems()[0].change |
| 2769 | # Set this to an invalid value to cause an exception during |
| 2770 | # reconfiguration. |
| 2771 | change.branch = None |
| 2772 | |
| 2773 | self.sched.reconfigure(self.config) |
| 2774 | self.waitUntilSettled() |
| 2775 | |
| 2776 | self.executor_server.hold_jobs_in_build = False |
| 2777 | self.executor_server.release() |
| 2778 | |
| 2779 | self.waitUntilSettled() |
| 2780 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2781 | 'ABORTED') |
| 2782 | self.assertEqual(A.data['status'], 'NEW') |
| 2783 | # The final report fails because of the invalid value set above. |
| 2784 | self.assertEqual(A.reported, 1) |
| 2785 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2786 | def test_live_reconfiguration_merge_conflict(self): |
| 2787 | # A real-world bug: a change in a gate queue has a merge |
| 2788 | # conflict and a job is added to its project while it's |
| 2789 | # sitting in the queue. The job gets added to the change and |
| 2790 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2791 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2792 | |
| 2793 | # This change is fine. It's here to stop the queue long |
| 2794 | # enough for the next change to be subject to the |
| 2795 | # reconfiguration, as well as to provide a conflict for the |
| 2796 | # next change. This change will succeed and merge. |
| 2797 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2798 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2799 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2800 | |
| 2801 | # This change will be in merge conflict. During the |
| 2802 | # reconfiguration, we will add a job. We want to make sure |
| 2803 | # that doesn't cause it to get stuck. |
| 2804 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2805 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2806 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2807 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2808 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2809 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2810 | |
| 2811 | self.waitUntilSettled() |
| 2812 | |
| 2813 | # No jobs have run yet |
| 2814 | self.assertEqual(A.data['status'], 'NEW') |
| 2815 | self.assertEqual(A.reported, 1) |
| 2816 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2817 | self.assertEqual(len(self.history), 0) |
| 2818 | |
| 2819 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2820 | self.commitConfigUpdate('common-config', |
| 2821 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2822 | self.sched.reconfigure(self.config) |
| 2823 | self.waitUntilSettled() |
| 2824 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2825 | self.executor_server.hold_jobs_in_build = False |
| 2826 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2827 | self.waitUntilSettled() |
| 2828 | |
| 2829 | self.assertEqual(A.data['status'], 'MERGED') |
| 2830 | self.assertEqual(A.reported, 2) |
| 2831 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2832 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2833 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2834 | 'SUCCESS') |
| 2835 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2836 | 'SUCCESS') |
| 2837 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2838 | 'SUCCESS') |
| 2839 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2840 | 'SUCCESS') |
| 2841 | self.assertEqual(len(self.history), 4) |
| 2842 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2843 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2844 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2845 | # that tests a job added to a job tree with a failed root does |
| 2846 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2847 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2848 | |
| 2849 | # This change is fine. It's here to stop the queue long |
| 2850 | # enough for the next change to be subject to the |
| 2851 | # reconfiguration. This change will succeed and merge. |
| 2852 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2853 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2854 | A.addApproval('Code-Review', 2) |
| 2855 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2856 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2857 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2858 | self.waitUntilSettled() |
| 2859 | |
| 2860 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2861 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2862 | B.addApproval('Code-Review', 2) |
| 2863 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2864 | self.waitUntilSettled() |
| 2865 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2866 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2867 | self.waitUntilSettled() |
| 2868 | |
| 2869 | # Both -merge jobs have run, but no others. |
| 2870 | self.assertEqual(A.data['status'], 'NEW') |
| 2871 | self.assertEqual(A.reported, 1) |
| 2872 | self.assertEqual(B.data['status'], 'NEW') |
| 2873 | self.assertEqual(B.reported, 1) |
| 2874 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2875 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2876 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2877 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2878 | self.assertEqual(len(self.history), 2) |
| 2879 | |
| 2880 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2881 | self.commitConfigUpdate('common-config', |
| 2882 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2883 | self.sched.reconfigure(self.config) |
| 2884 | self.waitUntilSettled() |
| 2885 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2886 | self.executor_server.hold_jobs_in_build = False |
| 2887 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2888 | self.waitUntilSettled() |
| 2889 | |
| 2890 | self.assertEqual(A.data['status'], 'MERGED') |
| 2891 | self.assertEqual(A.reported, 2) |
| 2892 | self.assertEqual(B.data['status'], 'NEW') |
| 2893 | self.assertEqual(B.reported, 2) |
| 2894 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2895 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2896 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2897 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2898 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2899 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2900 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2901 | self.assertEqual(len(self.history), 5) |
| 2902 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2903 | def test_live_reconfiguration_failed_job(self): |
| 2904 | # Test that a change with a removed failing job does not |
| 2905 | # disrupt reconfiguration. If a change has a failed job and |
| 2906 | # that job is removed during a reconfiguration, we observed a |
| 2907 | # bug where the code to re-set build statuses would run on |
| 2908 | # that build and raise an exception because the job no longer |
| 2909 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2910 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2911 | |
| 2912 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2913 | |
| 2914 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2915 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2916 | |
| 2917 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2918 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2919 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2920 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2921 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2922 | self.waitUntilSettled() |
| 2923 | |
| 2924 | self.assertEqual(A.data['status'], 'NEW') |
| 2925 | self.assertEqual(A.reported, 0) |
| 2926 | |
| 2927 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2928 | 'SUCCESS') |
| 2929 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2930 | 'FAILURE') |
| 2931 | self.assertEqual(len(self.history), 2) |
| 2932 | |
| 2933 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2934 | self.commitConfigUpdate('common-config', |
| 2935 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2936 | self.sched.reconfigure(self.config) |
| 2937 | self.waitUntilSettled() |
| 2938 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2939 | self.executor_server.hold_jobs_in_build = False |
| 2940 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2941 | self.waitUntilSettled() |
| 2942 | |
| 2943 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2944 | 'SUCCESS') |
| 2945 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2946 | 'SUCCESS') |
| 2947 | self.assertEqual(len(self.history), 4) |
| 2948 | |
| 2949 | self.assertEqual(A.data['status'], 'NEW') |
| 2950 | self.assertEqual(A.reported, 1) |
| 2951 | self.assertIn('Build succeeded', A.messages[0]) |
| 2952 | # Ensure the removed job was not included in the report. |
| 2953 | self.assertNotIn('project-test1', A.messages[0]) |
| 2954 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2955 | def test_live_reconfiguration_shared_queue(self): |
| 2956 | # Test that a change with a failing job which was removed from |
| 2957 | # this project but otherwise still exists in the system does |
| 2958 | # not disrupt reconfiguration. |
| 2959 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2960 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2961 | |
| 2962 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2963 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2964 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2965 | |
| 2966 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2967 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2968 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2969 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2970 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2971 | self.waitUntilSettled() |
| 2972 | |
| 2973 | self.assertEqual(A.data['status'], 'NEW') |
| 2974 | self.assertEqual(A.reported, 0) |
| 2975 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2976 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2977 | 'SUCCESS') |
| 2978 | self.assertEqual(self.getJobFromHistory( |
| 2979 | 'project1-project2-integration').result, 'FAILURE') |
| 2980 | self.assertEqual(len(self.history), 2) |
| 2981 | |
| 2982 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2983 | self.commitConfigUpdate( |
| 2984 | 'common-config', |
| 2985 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2986 | self.sched.reconfigure(self.config) |
| 2987 | self.waitUntilSettled() |
| 2988 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2989 | self.executor_server.hold_jobs_in_build = False |
| 2990 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2991 | self.waitUntilSettled() |
| 2992 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2993 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2994 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2995 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2996 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2997 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2998 | 'SUCCESS') |
| 2999 | self.assertEqual(self.getJobFromHistory( |
| 3000 | 'project1-project2-integration').result, 'FAILURE') |
| 3001 | self.assertEqual(len(self.history), 4) |
| 3002 | |
| 3003 | self.assertEqual(A.data['status'], 'NEW') |
| 3004 | self.assertEqual(A.reported, 1) |
| 3005 | self.assertIn('Build succeeded', A.messages[0]) |
| 3006 | # Ensure the removed job was not included in the report. |
| 3007 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 3008 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3009 | def test_double_live_reconfiguration_shared_queue(self): |
| 3010 | # This was a real-world regression. A change is added to |
| 3011 | # gate; a reconfigure happens, a second change which depends |
| 3012 | # on the first is added, and a second reconfiguration happens. |
| 3013 | # Ensure that both changes merge. |
| 3014 | |
| 3015 | # A failure may indicate incorrect caching or cleaning up of |
| 3016 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3017 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3018 | |
| 3019 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3020 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3021 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3022 | A.addApproval('Code-Review', 2) |
| 3023 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3024 | |
| 3025 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3026 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3027 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3028 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3029 | self.waitUntilSettled() |
| 3030 | |
| 3031 | # Reconfigure (with only one change in the pipeline). |
| 3032 | self.sched.reconfigure(self.config) |
| 3033 | self.waitUntilSettled() |
| 3034 | |
| 3035 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3036 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3037 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3038 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3039 | self.waitUntilSettled() |
| 3040 | |
| 3041 | # Reconfigure (with both in the pipeline). |
| 3042 | self.sched.reconfigure(self.config) |
| 3043 | self.waitUntilSettled() |
| 3044 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3045 | self.executor_server.hold_jobs_in_build = False |
| 3046 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3047 | self.waitUntilSettled() |
| 3048 | |
| 3049 | self.assertEqual(len(self.history), 8) |
| 3050 | |
| 3051 | self.assertEqual(A.data['status'], 'MERGED') |
| 3052 | self.assertEqual(A.reported, 2) |
| 3053 | self.assertEqual(B.data['status'], 'MERGED') |
| 3054 | self.assertEqual(B.reported, 2) |
| 3055 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3056 | def test_live_reconfiguration_del_project(self): |
| 3057 | # Test project deletion from layout |
| 3058 | # while changes are enqueued |
| 3059 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3060 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3061 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3062 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3063 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 3064 | |
| 3065 | # A Depends-On: B |
| 3066 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3067 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3068 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3069 | |
| 3070 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3071 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 3072 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3073 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3074 | self.waitUntilSettled() |
| 3075 | self.assertEqual(len(self.builds), 5) |
| 3076 | |
| 3077 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 3078 | self.commitConfigUpdate( |
| 3079 | 'common-config', |
| 3080 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3081 | self.sched.reconfigure(self.config) |
| 3082 | self.waitUntilSettled() |
| 3083 | |
| 3084 | # Builds for C aborted, builds for A succeed, |
| 3085 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 3086 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3087 | self.assertEqual(job_c.changes, '3,1') |
| 3088 | self.assertEqual(job_c.result, 'ABORTED') |
| 3089 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3090 | self.executor_server.hold_jobs_in_build = False |
| 3091 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3092 | self.waitUntilSettled() |
| 3093 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 3094 | self.assertEqual( |
| 3095 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 3096 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3097 | |
| 3098 | self.assertEqual(A.data['status'], 'NEW') |
| 3099 | self.assertEqual(B.data['status'], 'NEW') |
| 3100 | self.assertEqual(C.data['status'], 'NEW') |
| 3101 | self.assertEqual(A.reported, 1) |
| 3102 | self.assertEqual(B.reported, 0) |
| 3103 | self.assertEqual(C.reported, 0) |
| 3104 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 3105 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3106 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3107 | self.assertIn('Build succeeded', A.messages[0]) |
| 3108 | |
James E. Blair | 872738f | 2017-10-31 16:40:36 -0700 | [diff] [blame] | 3109 | @simple_layout("layouts/reconfigure-failed-head.yaml") |
| 3110 | def test_live_reconfiguration_failed_change_at_head(self): |
| 3111 | # Test that if we reconfigure with a failed change at head, |
| 3112 | # that the change behind it isn't reparented onto it. |
| 3113 | |
| 3114 | self.executor_server.hold_jobs_in_build = True |
| 3115 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3116 | A.addApproval('Code-Review', 2) |
| 3117 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3118 | B.addApproval('Code-Review', 2) |
| 3119 | |
| 3120 | self.executor_server.failJob('job1', A) |
| 3121 | |
| 3122 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3123 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3124 | |
| 3125 | self.waitUntilSettled() |
| 3126 | |
| 3127 | self.assertBuilds([ |
| 3128 | dict(name='job1', changes='1,1'), |
| 3129 | dict(name='job2', changes='1,1'), |
| 3130 | dict(name='job1', changes='1,1 2,1'), |
| 3131 | dict(name='job2', changes='1,1 2,1'), |
| 3132 | ]) |
| 3133 | |
| 3134 | self.release(self.builds[0]) |
| 3135 | self.waitUntilSettled() |
| 3136 | |
| 3137 | self.assertBuilds([ |
| 3138 | dict(name='job2', changes='1,1'), |
| 3139 | dict(name='job1', changes='2,1'), |
| 3140 | dict(name='job2', changes='2,1'), |
| 3141 | ]) |
| 3142 | |
| 3143 | # Unordered history comparison because the aborts can finish |
| 3144 | # in any order. |
| 3145 | self.assertHistory([ |
| 3146 | dict(name='job1', result='FAILURE', changes='1,1'), |
| 3147 | dict(name='job1', result='ABORTED', changes='1,1 2,1'), |
| 3148 | dict(name='job2', result='ABORTED', changes='1,1 2,1'), |
| 3149 | ], ordered=False) |
| 3150 | |
| 3151 | self.sched.reconfigure(self.config) |
| 3152 | self.waitUntilSettled() |
| 3153 | |
| 3154 | self.executor_server.hold_jobs_in_build = False |
| 3155 | self.executor_server.release() |
| 3156 | self.waitUntilSettled() |
| 3157 | |
| 3158 | self.assertBuilds([]) |
| 3159 | |
| 3160 | self.assertHistory([ |
| 3161 | dict(name='job1', result='FAILURE', changes='1,1'), |
| 3162 | dict(name='job1', result='ABORTED', changes='1,1 2,1'), |
| 3163 | dict(name='job2', result='ABORTED', changes='1,1 2,1'), |
| 3164 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3165 | dict(name='job1', result='SUCCESS', changes='2,1'), |
| 3166 | dict(name='job2', result='SUCCESS', changes='2,1'), |
| 3167 | ], ordered=False) |
| 3168 | self.assertEqual(A.data['status'], 'NEW') |
| 3169 | self.assertEqual(B.data['status'], 'MERGED') |
| 3170 | self.assertEqual(A.reported, 2) |
| 3171 | self.assertEqual(B.reported, 2) |
| 3172 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3173 | def test_delayed_repo_init(self): |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3174 | self.init_repo("org/new-project") |
Clint Byrum | 627ba36 | 2017-08-14 13:20:40 -0700 | [diff] [blame] | 3175 | files = {'README': ''} |
| 3176 | self.addCommitToRepo("org/new-project", 'Initial commit', |
| 3177 | files=files, tag='init') |
| 3178 | self.newTenantConfig('tenants/delayed-repo-init.yaml') |
| 3179 | self.commitConfigUpdate( |
| 3180 | 'common-config', |
| 3181 | 'layouts/delayed-repo-init.yaml') |
| 3182 | self.sched.reconfigure(self.config) |
| 3183 | self.waitUntilSettled() |
| 3184 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3185 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 3186 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3187 | A.addApproval('Code-Review', 2) |
| 3188 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3189 | self.waitUntilSettled() |
| 3190 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3191 | 'SUCCESS') |
| 3192 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3193 | 'SUCCESS') |
| 3194 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3195 | 'SUCCESS') |
| 3196 | self.assertEqual(A.data['status'], 'MERGED') |
| 3197 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3198 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 3199 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3200 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3201 | self.init_repo("org/delete-project") |
| 3202 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 3203 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3204 | A.addApproval('Code-Review', 2) |
| 3205 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3206 | self.waitUntilSettled() |
| 3207 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3208 | 'SUCCESS') |
| 3209 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3210 | 'SUCCESS') |
| 3211 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3212 | 'SUCCESS') |
| 3213 | self.assertEqual(A.data['status'], 'MERGED') |
| 3214 | self.assertEqual(A.reported, 2) |
| 3215 | |
| 3216 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 3217 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 3218 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 3219 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3220 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 3221 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3222 | |
| 3223 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 3224 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3225 | B.addApproval('Code-Review', 2) |
| 3226 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3227 | self.waitUntilSettled() |
| 3228 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3229 | 'SUCCESS') |
| 3230 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3231 | 'SUCCESS') |
| 3232 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3233 | 'SUCCESS') |
| 3234 | self.assertEqual(B.data['status'], 'MERGED') |
| 3235 | self.assertEqual(B.reported, 2) |
| 3236 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 3237 | @simple_layout('layouts/untrusted-secrets.yaml') |
| 3238 | def test_untrusted_secrets(self): |
| 3239 | "Test untrusted secrets" |
| 3240 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3241 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3242 | self.waitUntilSettled() |
| 3243 | |
| 3244 | self.assertHistory([]) |
| 3245 | self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") |
James E. Blair | 8eb564a | 2017-08-10 09:21:41 -0700 | [diff] [blame] | 3246 | self.assertIn('does not allow post-review job', |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 3247 | A.messages[0]) |
| 3248 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 3249 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3250 | def test_tags(self): |
| 3251 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3252 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3253 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3254 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3255 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3256 | self.waitUntilSettled() |
| 3257 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 3258 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3259 | |
| 3260 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3261 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3262 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3263 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3264 | |
| 3265 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3266 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3267 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3268 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3269 | def test_timer(self): |
| 3270 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3271 | # This test can not use simple_layout because it must start |
| 3272 | # with a configuration which does not include a |
| 3273 | # timer-triggered job so that we have an opportunity to set |
| 3274 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3275 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3276 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3277 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3278 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3279 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3280 | # The pipeline triggers every second, so we should have seen |
| 3281 | # several by now. |
| 3282 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3283 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3284 | |
| 3285 | self.assertEqual(len(self.builds), 2) |
| 3286 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3287 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3288 | # Stop queuing timer triggered jobs so that the assertions |
| 3289 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3290 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3291 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3292 | self.waitUntilSettled() |
| 3293 | # If APScheduler is in mid-event when we remove the job, we |
| 3294 | # can end up with one more event firing, so give it an extra |
| 3295 | # second to settle. |
| 3296 | time.sleep(1) |
| 3297 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3298 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3299 | self.waitUntilSettled() |
| 3300 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3301 | self.assertHistory([ |
| 3302 | dict(name='project-bitrot', result='SUCCESS', |
| 3303 | ref='refs/heads/master'), |
| 3304 | dict(name='project-bitrot', result='SUCCESS', |
| 3305 | ref='refs/heads/stable'), |
| 3306 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3307 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3308 | def test_idle(self): |
| 3309 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3310 | # This test can not use simple_layout because it must start |
| 3311 | # with a configuration which does not include a |
| 3312 | # timer-triggered job so that we have an opportunity to set |
| 3313 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3314 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3315 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3316 | for x in range(1, 3): |
| 3317 | # Test that timer triggers periodic jobs even across |
| 3318 | # layout config reloads. |
| 3319 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3320 | self.commitConfigUpdate('common-config', |
| 3321 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3322 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3323 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3324 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3325 | # The pipeline triggers every second, so we should have seen |
| 3326 | # several by now. |
| 3327 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3328 | |
| 3329 | # Stop queuing timer triggered jobs so that the assertions |
| 3330 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3331 | self.commitConfigUpdate('common-config', |
| 3332 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3333 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3334 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3335 | # If APScheduler is in mid-event when we remove the job, |
| 3336 | # we can end up with one more event firing, so give it an |
| 3337 | # extra second to settle. |
| 3338 | time.sleep(1) |
| 3339 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3340 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3341 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3342 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3343 | self.waitUntilSettled() |
| 3344 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3345 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3346 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3347 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3348 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3349 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3350 | self.waitUntilSettled() |
| 3351 | |
| 3352 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3353 | self.waitUntilSettled() |
| 3354 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3355 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3356 | |
| 3357 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3358 | # work on the knowledge of what the first message should be as |
| 3359 | # it is only configured to go to SMTP. |
| 3360 | |
| 3361 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3362 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3363 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3364 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3365 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3366 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3367 | |
| 3368 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3369 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3370 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3371 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3372 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3373 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3374 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3375 | def test_timer_smtp(self): |
| 3376 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3377 | # This test can not use simple_layout because it must start |
| 3378 | # with a configuration which does not include a |
| 3379 | # timer-triggered job so that we have an opportunity to set |
| 3380 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3381 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3382 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3383 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3384 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3385 | # The pipeline triggers every second, so we should have seen |
| 3386 | # several by now. |
| 3387 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3388 | self.waitUntilSettled() |
| 3389 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3390 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3391 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3392 | self.waitUntilSettled() |
| 3393 | self.assertEqual(len(self.history), 2) |
| 3394 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3395 | self.assertEqual(self.getJobFromHistory( |
| 3396 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3397 | self.assertEqual(self.getJobFromHistory( |
| 3398 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3399 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3400 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3401 | |
| 3402 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3403 | # work on the knowledge of what the first message should be as |
| 3404 | # it is only configured to go to SMTP. |
| 3405 | |
| 3406 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3407 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3408 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3409 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3410 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3411 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3412 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3413 | # Stop queuing timer triggered jobs and let any that may have |
| 3414 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3415 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3416 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3417 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3418 | # If APScheduler is in mid-event when we remove the job, we |
| 3419 | # can end up with one more event firing, so give it an extra |
| 3420 | # second to settle. |
| 3421 | time.sleep(1) |
| 3422 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3423 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3424 | self.waitUntilSettled() |
| 3425 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3426 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3427 | def test_timer_sshkey(self): |
| 3428 | "Test that a periodic job can setup SSH key authentication" |
| 3429 | self.worker.hold_jobs_in_build = True |
| 3430 | self.config.set('zuul', 'layout_config', |
| 3431 | 'tests/fixtures/layout-timer.yaml') |
| 3432 | self.sched.reconfigure(self.config) |
| 3433 | self.registerJobs() |
| 3434 | |
| 3435 | # The pipeline triggers every second, so we should have seen |
| 3436 | # several by now. |
| 3437 | time.sleep(5) |
| 3438 | self.waitUntilSettled() |
| 3439 | |
| 3440 | self.assertEqual(len(self.builds), 2) |
| 3441 | |
| 3442 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3443 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3444 | with open(ssh_wrapper) as f: |
| 3445 | ssh_wrapper_content = f.read() |
| 3446 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3447 | # In the unit tests Merger runs in the same process, |
| 3448 | # so we see its' environment variables |
| 3449 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3450 | |
| 3451 | self.worker.release('.*') |
| 3452 | self.waitUntilSettled() |
| 3453 | self.assertEqual(len(self.history), 2) |
| 3454 | |
| 3455 | self.assertEqual(self.getJobFromHistory( |
| 3456 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3457 | self.assertEqual(self.getJobFromHistory( |
| 3458 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3459 | |
| 3460 | # Stop queuing timer triggered jobs and let any that may have |
| 3461 | # queued through so that end of test assertions pass. |
| 3462 | self.config.set('zuul', 'layout_config', |
| 3463 | 'tests/fixtures/layout-no-timer.yaml') |
| 3464 | self.sched.reconfigure(self.config) |
| 3465 | self.registerJobs() |
| 3466 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3467 | # If APScheduler is in mid-event when we remove the job, we |
| 3468 | # can end up with one more event firing, so give it an extra |
| 3469 | # second to settle. |
| 3470 | time.sleep(1) |
| 3471 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3472 | self.worker.release('.*') |
| 3473 | self.waitUntilSettled() |
| 3474 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3475 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3476 | "Test that the RPC client can enqueue a change" |
| 3477 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3478 | A.addApproval('Code-Review', 2) |
| 3479 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3480 | |
| 3481 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3482 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3483 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3484 | r = client.enqueue(tenant='tenant-one', |
| 3485 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3486 | project='org/project', |
| 3487 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3488 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3489 | self.waitUntilSettled() |
| 3490 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3491 | 'SUCCESS') |
| 3492 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3493 | 'SUCCESS') |
| 3494 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3495 | 'SUCCESS') |
| 3496 | self.assertEqual(A.data['status'], 'MERGED') |
| 3497 | self.assertEqual(A.reported, 2) |
| 3498 | self.assertEqual(r, True) |
| 3499 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3500 | def test_client_enqueue_ref(self): |
| 3501 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3502 | p = "review.example.com/org/project" |
| 3503 | upstream = self.getUpstreamRepos([p]) |
| 3504 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3505 | A.setMerged() |
| 3506 | A_commit = str(upstream[p].commit('master')) |
| 3507 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3508 | |
| 3509 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3510 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3511 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3512 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3513 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3514 | pipeline='post', |
| 3515 | project='org/project', |
| 3516 | trigger='gerrit', |
| 3517 | ref='master', |
| 3518 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3519 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3520 | self.waitUntilSettled() |
| 3521 | job_names = [x.name for x in self.history] |
| 3522 | self.assertEqual(len(self.history), 1) |
| 3523 | self.assertIn('project-post', job_names) |
| 3524 | self.assertEqual(r, True) |
| 3525 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3526 | def test_client_enqueue_negative(self): |
| 3527 | "Test that the RPC client returns errors" |
| 3528 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3529 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3530 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3531 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3532 | "Invalid tenant"): |
| 3533 | r = client.enqueue(tenant='tenant-foo', |
| 3534 | pipeline='gate', |
| 3535 | project='org/project', |
| 3536 | trigger='gerrit', |
| 3537 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3538 | self.assertEqual(r, False) |
| 3539 | |
| 3540 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3541 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3542 | r = client.enqueue(tenant='tenant-one', |
| 3543 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3544 | project='project-does-not-exist', |
| 3545 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3546 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3547 | self.assertEqual(r, False) |
| 3548 | |
| 3549 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3550 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3551 | r = client.enqueue(tenant='tenant-one', |
| 3552 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3553 | project='org/project', |
| 3554 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3555 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3556 | self.assertEqual(r, False) |
| 3557 | |
| 3558 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3559 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3560 | r = client.enqueue(tenant='tenant-one', |
| 3561 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3562 | project='org/project', |
| 3563 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3564 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3565 | self.assertEqual(r, False) |
| 3566 | |
| 3567 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3568 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3569 | r = client.enqueue(tenant='tenant-one', |
| 3570 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3571 | project='org/project', |
| 3572 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3573 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3574 | self.assertEqual(r, False) |
| 3575 | |
| 3576 | self.waitUntilSettled() |
| 3577 | self.assertEqual(len(self.history), 0) |
| 3578 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3579 | |
Clark Boylan | 885e142 | 2018-02-20 16:29:02 -0800 | [diff] [blame] | 3580 | def test_client_enqueue_ref_negative(self): |
| 3581 | "Test that the RPC client returns errors" |
| 3582 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3583 | self.gearman_server.port) |
| 3584 | self.addCleanup(client.shutdown) |
| 3585 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3586 | "New rev must be 40 character sha1"): |
| 3587 | r = client.enqueue_ref( |
| 3588 | tenant='tenant-one', |
| 3589 | pipeline='post', |
| 3590 | project='org/project', |
| 3591 | trigger='gerrit', |
| 3592 | ref='master', |
| 3593 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3594 | newrev='10054041') |
| 3595 | self.assertEqual(r, False) |
| 3596 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3597 | "Old rev must be 40 character sha1"): |
| 3598 | r = client.enqueue_ref( |
| 3599 | tenant='tenant-one', |
| 3600 | pipeline='post', |
| 3601 | project='org/project', |
| 3602 | trigger='gerrit', |
| 3603 | ref='master', |
| 3604 | oldrev='10054041', |
| 3605 | newrev='90f173846e3af9154517b88543ffbd1691f31366') |
| 3606 | self.assertEqual(r, False) |
| 3607 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3608 | "New rev must be base16 hash"): |
| 3609 | r = client.enqueue_ref( |
| 3610 | tenant='tenant-one', |
| 3611 | pipeline='post', |
| 3612 | project='org/project', |
| 3613 | trigger='gerrit', |
| 3614 | ref='master', |
| 3615 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3616 | newrev='notbase16') |
| 3617 | self.assertEqual(r, False) |
| 3618 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3619 | "Old rev must be base16 hash"): |
| 3620 | r = client.enqueue_ref( |
| 3621 | tenant='tenant-one', |
| 3622 | pipeline='post', |
| 3623 | project='org/project', |
| 3624 | trigger='gerrit', |
| 3625 | ref='master', |
| 3626 | oldrev='notbase16', |
| 3627 | newrev='90f173846e3af9154517b88543ffbd1691f31366') |
| 3628 | self.assertEqual(r, False) |
| 3629 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3630 | def test_client_promote(self): |
| 3631 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3632 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3633 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3634 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3635 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3636 | A.addApproval('Code-Review', 2) |
| 3637 | B.addApproval('Code-Review', 2) |
| 3638 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3639 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3640 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3641 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3642 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3643 | |
| 3644 | self.waitUntilSettled() |
| 3645 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3646 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3647 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3648 | enqueue_times = {} |
| 3649 | for item in items: |
| 3650 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3651 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3652 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3653 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3654 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3655 | r = client.promote(tenant='tenant-one', |
| 3656 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3657 | change_ids=['2,1', '3,1']) |
| 3658 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3659 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3660 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3661 | for item in items: |
| 3662 | self.assertEqual( |
| 3663 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3664 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3665 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3666 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3667 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3668 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3669 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3670 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3671 | self.waitUntilSettled() |
| 3672 | |
| 3673 | self.assertEqual(len(self.builds), 6) |
| 3674 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3675 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3676 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3677 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3678 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3679 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3680 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3681 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3682 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3683 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3684 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3685 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3686 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3687 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3688 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3689 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3690 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3691 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3692 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3693 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3694 | self.waitUntilSettled() |
| 3695 | |
| 3696 | self.assertEqual(A.data['status'], 'MERGED') |
| 3697 | self.assertEqual(A.reported, 2) |
| 3698 | self.assertEqual(B.data['status'], 'MERGED') |
| 3699 | self.assertEqual(B.reported, 2) |
| 3700 | self.assertEqual(C.data['status'], 'MERGED') |
| 3701 | self.assertEqual(C.reported, 2) |
| 3702 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3703 | self.assertEqual(r, True) |
| 3704 | |
| 3705 | def test_client_promote_dependent(self): |
| 3706 | "Test that the RPC client can promote a dependent change" |
| 3707 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3708 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3709 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3710 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3711 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3712 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3713 | |
| 3714 | C.setDependsOn(B, 1) |
| 3715 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3716 | A.addApproval('Code-Review', 2) |
| 3717 | B.addApproval('Code-Review', 2) |
| 3718 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3719 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3720 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3721 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3722 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3723 | |
| 3724 | self.waitUntilSettled() |
| 3725 | |
| 3726 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3727 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3728 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3729 | r = client.promote(tenant='tenant-one', |
| 3730 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3731 | change_ids=['3,1']) |
| 3732 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3733 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3734 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3735 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3736 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3737 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3738 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3739 | self.waitUntilSettled() |
| 3740 | |
| 3741 | self.assertEqual(len(self.builds), 6) |
| 3742 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3743 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3744 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3745 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3746 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3747 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3748 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3749 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3750 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3751 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3752 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3753 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3754 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3755 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3756 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3757 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3758 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3759 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3760 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3761 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3762 | self.waitUntilSettled() |
| 3763 | |
| 3764 | self.assertEqual(A.data['status'], 'MERGED') |
| 3765 | self.assertEqual(A.reported, 2) |
| 3766 | self.assertEqual(B.data['status'], 'MERGED') |
| 3767 | self.assertEqual(B.reported, 2) |
| 3768 | self.assertEqual(C.data['status'], 'MERGED') |
| 3769 | self.assertEqual(C.reported, 2) |
| 3770 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3771 | self.assertEqual(r, True) |
| 3772 | |
| 3773 | def test_client_promote_negative(self): |
| 3774 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3775 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3776 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3777 | A.addApproval('Code-Review', 2) |
| 3778 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3779 | self.waitUntilSettled() |
| 3780 | |
| 3781 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3782 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3783 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3784 | |
| 3785 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3786 | r = client.promote(tenant='tenant-one', |
| 3787 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3788 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3789 | self.assertEqual(r, False) |
| 3790 | |
| 3791 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3792 | r = client.promote(tenant='tenant-one', |
| 3793 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3794 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3795 | self.assertEqual(r, False) |
| 3796 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3797 | self.executor_server.hold_jobs_in_build = False |
| 3798 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3799 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3800 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3801 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3802 | def test_queue_rate_limiting(self): |
| 3803 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3804 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3805 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3806 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3807 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3808 | |
| 3809 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3810 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3811 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3812 | A.addApproval('Code-Review', 2) |
| 3813 | B.addApproval('Code-Review', 2) |
| 3814 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3815 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3816 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3817 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3818 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3819 | self.waitUntilSettled() |
| 3820 | |
| 3821 | # Only A and B will have their merge jobs queued because |
| 3822 | # window is 2. |
| 3823 | self.assertEqual(len(self.builds), 2) |
| 3824 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3825 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3826 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3827 | # Release the merge jobs one at a time. |
| 3828 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3829 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3830 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3831 | self.waitUntilSettled() |
| 3832 | |
| 3833 | # Only A and B will have their test jobs queued because |
| 3834 | # window is 2. |
| 3835 | self.assertEqual(len(self.builds), 4) |
| 3836 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3837 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3838 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3839 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3840 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3841 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3842 | self.waitUntilSettled() |
| 3843 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3844 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3845 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3846 | # A failed so window is reduced by 1 to 1. |
| 3847 | self.assertEqual(queue.window, 1) |
| 3848 | self.assertEqual(queue.window_floor, 1) |
| 3849 | self.assertEqual(A.data['status'], 'NEW') |
| 3850 | |
| 3851 | # Gate is reset and only B's merge job is queued because |
| 3852 | # window shrunk to 1. |
| 3853 | self.assertEqual(len(self.builds), 1) |
| 3854 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3855 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3856 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3857 | self.waitUntilSettled() |
| 3858 | |
| 3859 | # Only B's test jobs are queued because window is still 1. |
| 3860 | self.assertEqual(len(self.builds), 2) |
| 3861 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3862 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3863 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3864 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3865 | self.waitUntilSettled() |
| 3866 | |
| 3867 | # B was successfully merged so window is increased to 2. |
| 3868 | self.assertEqual(queue.window, 2) |
| 3869 | self.assertEqual(queue.window_floor, 1) |
| 3870 | self.assertEqual(B.data['status'], 'MERGED') |
| 3871 | |
| 3872 | # Only C is left and its merge job is queued. |
| 3873 | self.assertEqual(len(self.builds), 1) |
| 3874 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3875 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3876 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3877 | self.waitUntilSettled() |
| 3878 | |
| 3879 | # After successful merge job the test jobs for C are queued. |
| 3880 | self.assertEqual(len(self.builds), 2) |
| 3881 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3882 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3883 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3884 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3885 | self.waitUntilSettled() |
| 3886 | |
| 3887 | # C successfully merged so window is bumped to 3. |
| 3888 | self.assertEqual(queue.window, 3) |
| 3889 | self.assertEqual(queue.window_floor, 1) |
| 3890 | self.assertEqual(C.data['status'], 'MERGED') |
| 3891 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3892 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3893 | def test_queue_rate_limiting_dependent(self): |
| 3894 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3895 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3896 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3897 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3898 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3899 | |
| 3900 | B.setDependsOn(A, 1) |
| 3901 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3902 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3903 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3904 | A.addApproval('Code-Review', 2) |
| 3905 | B.addApproval('Code-Review', 2) |
| 3906 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3907 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3908 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3909 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3910 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3911 | self.waitUntilSettled() |
| 3912 | |
| 3913 | # Only A and B will have their merge jobs queued because |
| 3914 | # window is 2. |
| 3915 | self.assertEqual(len(self.builds), 2) |
| 3916 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3917 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3918 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3919 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3920 | |
| 3921 | # Only A and B will have their test jobs queued because |
| 3922 | # window is 2. |
| 3923 | self.assertEqual(len(self.builds), 4) |
| 3924 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3925 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3926 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3927 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3928 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3929 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3930 | self.waitUntilSettled() |
| 3931 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3932 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3933 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3934 | # A failed so window is reduced by 1 to 1. |
| 3935 | self.assertEqual(queue.window, 1) |
| 3936 | self.assertEqual(queue.window_floor, 1) |
| 3937 | self.assertEqual(A.data['status'], 'NEW') |
| 3938 | self.assertEqual(B.data['status'], 'NEW') |
| 3939 | |
| 3940 | # Gate is reset and only C's merge job is queued because |
| 3941 | # window shrunk to 1 and A and B were dequeued. |
| 3942 | self.assertEqual(len(self.builds), 1) |
| 3943 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3944 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3945 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3946 | |
| 3947 | # Only C's test jobs are queued because window is still 1. |
| 3948 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3949 | builds = self.getSortedBuilds() |
| 3950 | self.assertEqual(builds[0].name, 'project-test1') |
| 3951 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3952 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3953 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3954 | self.waitUntilSettled() |
| 3955 | |
| 3956 | # C was successfully merged so window is increased to 2. |
| 3957 | self.assertEqual(queue.window, 2) |
| 3958 | self.assertEqual(queue.window_floor, 1) |
| 3959 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3960 | |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3961 | @simple_layout('layouts/reconfigure-window.yaml') |
| 3962 | def test_reconfigure_window_shrink(self): |
| 3963 | # Test the active window shrinking during reconfiguration |
| 3964 | self.executor_server.hold_jobs_in_build = True |
| 3965 | |
| 3966 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3967 | A.addApproval('Code-Review', 2) |
| 3968 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3969 | self.waitUntilSettled() |
| 3970 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3971 | B.addApproval('Code-Review', 2) |
| 3972 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3973 | self.waitUntilSettled() |
| 3974 | |
| 3975 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3976 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3977 | self.assertEqual(queue.window, 20) |
| 3978 | self.assertTrue(len(self.builds), 4) |
| 3979 | |
| 3980 | self.executor_server.release('job1') |
| 3981 | self.waitUntilSettled() |
| 3982 | self.commitConfigUpdate('org/common-config', |
| 3983 | 'layouts/reconfigure-window2.yaml') |
| 3984 | self.sched.reconfigure(self.config) |
| 3985 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3986 | queue = tenant.layout.pipelines['gate'].queues[0] |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3987 | # Even though we have configured a smaller window, the value |
| 3988 | # on the existing shared queue should be used. |
| 3989 | self.assertEqual(queue.window, 20) |
| 3990 | self.assertTrue(len(self.builds), 4) |
| 3991 | |
| 3992 | self.sched.reconfigure(self.config) |
| 3993 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3994 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3995 | self.assertEqual(queue.window, 20) |
| 3996 | self.assertTrue(len(self.builds), 4) |
| 3997 | |
| 3998 | self.executor_server.hold_jobs_in_build = False |
| 3999 | self.executor_server.release() |
| 4000 | |
| 4001 | self.waitUntilSettled() |
| 4002 | self.assertHistory([ |
| 4003 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 4004 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 4005 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 4006 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 4007 | ], ordered=False) |
| 4008 | |
| 4009 | @simple_layout('layouts/reconfigure-window-fixed.yaml') |
| 4010 | def test_reconfigure_window_fixed(self): |
| 4011 | # Test the active window shrinking during reconfiguration |
| 4012 | self.executor_server.hold_jobs_in_build = True |
| 4013 | |
| 4014 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4015 | A.addApproval('Code-Review', 2) |
| 4016 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4017 | self.waitUntilSettled() |
| 4018 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4019 | B.addApproval('Code-Review', 2) |
| 4020 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4021 | self.waitUntilSettled() |
| 4022 | |
| 4023 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4024 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 4025 | self.assertEqual(queue.window, 2) |
| 4026 | self.assertTrue(len(self.builds), 4) |
| 4027 | |
| 4028 | self.executor_server.release('job1') |
| 4029 | self.waitUntilSettled() |
| 4030 | self.commitConfigUpdate('org/common-config', |
| 4031 | 'layouts/reconfigure-window-fixed2.yaml') |
| 4032 | self.sched.reconfigure(self.config) |
| 4033 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4034 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 4035 | # Because we have configured a static window, it should |
| 4036 | # be allowed to shrink on reconfiguration. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 4037 | self.assertEqual(queue.window, 1) |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 4038 | # B is outside the window, but still marked active until the |
| 4039 | # next pass through the queue processor, so its builds haven't |
| 4040 | # been canceled. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 4041 | self.assertTrue(len(self.builds), 4) |
| 4042 | |
| 4043 | self.sched.reconfigure(self.config) |
| 4044 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4045 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 4046 | self.assertEqual(queue.window, 1) |
| 4047 | # B's builds have been canceled now |
| 4048 | self.assertTrue(len(self.builds), 2) |
| 4049 | |
| 4050 | self.executor_server.hold_jobs_in_build = False |
| 4051 | self.executor_server.release() |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 4052 | |
| 4053 | # B's builds will be restarted and will show up in our history |
| 4054 | # twice. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 4055 | self.waitUntilSettled() |
| 4056 | self.assertHistory([ |
| 4057 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 4058 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 4059 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 4060 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 4061 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 4062 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 4063 | ], ordered=False) |
| 4064 | |
| 4065 | @simple_layout('layouts/reconfigure-remove-add.yaml') |
| 4066 | def test_reconfigure_remove_add(self): |
| 4067 | # Test removing, then adding a job while in queue |
| 4068 | self.executor_server.hold_jobs_in_build = True |
| 4069 | |
| 4070 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4071 | A.addApproval('Code-Review', 2) |
| 4072 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4073 | self.waitUntilSettled() |
| 4074 | self.assertTrue(len(self.builds), 2) |
| 4075 | self.executor_server.release('job2') |
| 4076 | self.assertTrue(len(self.builds), 1) |
| 4077 | |
| 4078 | # Remove job2 |
| 4079 | self.commitConfigUpdate('org/common-config', |
| 4080 | 'layouts/reconfigure-remove-add2.yaml') |
| 4081 | self.sched.reconfigure(self.config) |
| 4082 | self.assertTrue(len(self.builds), 1) |
| 4083 | |
| 4084 | # Add job2 back |
| 4085 | self.commitConfigUpdate('org/common-config', |
| 4086 | 'layouts/reconfigure-remove-add.yaml') |
| 4087 | self.sched.reconfigure(self.config) |
| 4088 | self.assertTrue(len(self.builds), 2) |
| 4089 | |
| 4090 | self.executor_server.hold_jobs_in_build = False |
| 4091 | self.executor_server.release() |
| 4092 | # This will run new builds for B |
| 4093 | self.waitUntilSettled() |
| 4094 | self.assertHistory([ |
| 4095 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 4096 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 4097 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 4098 | ], ordered=False) |
| 4099 | |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4100 | def test_worker_update_metadata(self): |
| 4101 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4102 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4103 | |
| 4104 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4105 | A.addApproval('Code-Review', 2) |
| 4106 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4107 | self.waitUntilSettled() |
| 4108 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4109 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4110 | |
| 4111 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4112 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4113 | |
| 4114 | start = time.time() |
| 4115 | while True: |
| 4116 | if time.time() - start > 10: |
| 4117 | raise Exception("Timeout waiting for gearman server to report " |
| 4118 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4119 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4120 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4121 | break |
| 4122 | else: |
| 4123 | time.sleep(0) |
| 4124 | |
| 4125 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4126 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4127 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4128 | self.executor_server.hold_jobs_in_build = False |
| 4129 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4130 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4131 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 4132 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4133 | def test_footer_message(self): |
| 4134 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4135 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4136 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4137 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4138 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4139 | self.waitUntilSettled() |
| 4140 | |
| 4141 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4142 | B.addApproval('Code-Review', 2) |
| 4143 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4144 | self.waitUntilSettled() |
| 4145 | |
| 4146 | self.assertEqual(2, len(self.smtp_messages)) |
| 4147 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4148 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4149 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4150 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4151 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4152 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4153 | For CI problems and help debugging, contact ci@example.org""" |
| 4154 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4155 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 4156 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 4157 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 4158 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4159 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 4160 | @simple_layout('layouts/unmanaged-project.yaml') |
| 4161 | def test_unmanaged_project_start_message(self): |
| 4162 | "Test start reporting is not done for unmanaged projects." |
| 4163 | self.init_repo("org/project", tag='init') |
| 4164 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4165 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4166 | self.waitUntilSettled() |
| 4167 | |
| 4168 | self.assertEqual(0, len(A.messages)) |
| 4169 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4170 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4171 | def test_merge_failure_reporters(self): |
| 4172 | """Check that the config is set up correctly""" |
| 4173 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4174 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4175 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 4176 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 4177 | "dependencies was unable to be automatically merged with the " |
| 4178 | "current state of its repository. Please rebase the change and " |
| 4179 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4180 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4181 | self.assertEqual( |
| 4182 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4183 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4184 | |
| 4185 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4186 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4187 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4188 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4189 | |
| 4190 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4191 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 4192 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4193 | |
| 4194 | self.assertTrue( |
| 4195 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4196 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4197 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4198 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 4199 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4200 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4201 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4202 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4203 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4204 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4205 | gerritreporter.GerritReporter) and |
| 4206 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4207 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4208 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4209 | ) |
| 4210 | ) |
| 4211 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4212 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4213 | def test_merge_failure_reports(self): |
| 4214 | """Check that when a change fails to merge the correct message is sent |
| 4215 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4216 | self.updateConfigLayout( |
| 4217 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4218 | self.sched.reconfigure(self.config) |
| 4219 | self.registerJobs() |
| 4220 | |
| 4221 | # Check a test failure isn't reported to SMTP |
| 4222 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4223 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4224 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4225 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4226 | self.waitUntilSettled() |
| 4227 | |
| 4228 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 4229 | self.assertEqual(0, len(self.smtp_messages)) |
| 4230 | |
| 4231 | # Check a merge failure is reported to SMTP |
| 4232 | # B should be merged, but C will conflict with B |
| 4233 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4234 | B.addPatchset(['conflict']) |
| 4235 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4236 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4237 | B.addApproval('Code-Review', 2) |
| 4238 | C.addApproval('Code-Review', 2) |
| 4239 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4240 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4241 | self.waitUntilSettled() |
| 4242 | |
| 4243 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 4244 | self.assertEqual(1, len(self.smtp_messages)) |
| 4245 | self.assertEqual('The merge failed! For more information...', |
| 4246 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 4247 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4248 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 4249 | def test_default_merge_failure_reports(self): |
| 4250 | """Check that the default merge failure reports are correct.""" |
| 4251 | |
| 4252 | # A should report success, B should report merge failure. |
| 4253 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4254 | A.addPatchset(['conflict']) |
| 4255 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4256 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4257 | A.addApproval('Code-Review', 2) |
| 4258 | B.addApproval('Code-Review', 2) |
| 4259 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4260 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 4261 | self.waitUntilSettled() |
| 4262 | |
| 4263 | self.assertEqual(3, len(self.history)) # A jobs |
| 4264 | self.assertEqual(A.reported, 2) |
| 4265 | self.assertEqual(B.reported, 2) |
| 4266 | self.assertEqual(A.data['status'], 'MERGED') |
| 4267 | self.assertEqual(B.data['status'], 'NEW') |
| 4268 | self.assertIn('Build succeeded', A.messages[1]) |
| 4269 | self.assertIn('Merge Failed', B.messages[1]) |
| 4270 | self.assertIn('automatically merged', B.messages[1]) |
| 4271 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 4272 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 4273 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4274 | def test_client_get_running_jobs(self): |
| 4275 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4276 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4277 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4278 | A.addApproval('Code-Review', 2) |
| 4279 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4280 | self.waitUntilSettled() |
| 4281 | |
| 4282 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 4283 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 4284 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4285 | |
| 4286 | # Wait for gearman server to send the initial workData back to zuul |
| 4287 | start = time.time() |
| 4288 | while True: |
| 4289 | if time.time() - start > 10: |
| 4290 | raise Exception("Timeout waiting for gearman server to report " |
| 4291 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 4292 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4293 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4294 | break |
| 4295 | else: |
| 4296 | time.sleep(0) |
| 4297 | |
| 4298 | running_items = client.get_running_jobs() |
| 4299 | |
| 4300 | self.assertEqual(1, len(running_items)) |
| 4301 | running_item = running_items[0] |
| 4302 | self.assertEqual([], running_item['failing_reasons']) |
| 4303 | self.assertEqual([], running_item['items_behind']) |
James E. Blair | 0e4c791 | 2018-01-02 14:20:17 -0800 | [diff] [blame] | 4304 | self.assertEqual('https://review.example.com/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4305 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4306 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4307 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4308 | self.assertEqual(True, running_item['active']) |
| 4309 | self.assertEqual('1,1', running_item['id']) |
| 4310 | |
| 4311 | self.assertEqual(3, len(running_item['jobs'])) |
| 4312 | for job in running_item['jobs']: |
| 4313 | if job['name'] == 'project-merge': |
| 4314 | self.assertEqual('project-merge', job['name']) |
| 4315 | self.assertEqual('gate', job['pipeline']) |
| 4316 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4317 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 4318 | 'stream.html?uuid={uuid}&logfile=console.log' |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 4319 | .format(uuid=job['uuid']), job['url']) |
| 4320 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4321 | 'finger://{hostname}/{uuid}'.format( |
| 4322 | hostname=self.executor_server.hostname, |
| 4323 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 4324 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4325 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4326 | self.assertEqual(False, job['canceled']) |
| 4327 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4328 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4329 | self.assertEqual('gate', job['pipeline']) |
| 4330 | break |
| 4331 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4332 | self.executor_server.hold_jobs_in_build = False |
| 4333 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4334 | self.waitUntilSettled() |
| 4335 | |
| 4336 | running_items = client.get_running_jobs() |
| 4337 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4338 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 4339 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4340 | def test_nonvoting_pipeline(self): |
| 4341 | "Test that a nonvoting pipeline (experimental) can still report" |
| 4342 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 4343 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 4344 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4345 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4346 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 4347 | |
| 4348 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 4349 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 4350 | self.assertEqual( |
| 4351 | self.getJobFromHistory('experimental-project-test').result, |
| 4352 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4353 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4354 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4355 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4356 | def test_disable_at(self): |
| 4357 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4358 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4359 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4360 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4361 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4362 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4363 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4364 | |
| 4365 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4366 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4367 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4368 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4369 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4370 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4371 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4372 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4373 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4374 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4375 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4376 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4377 | self.executor_server.failJob('project-test1', A) |
| 4378 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4379 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4380 | self.executor_server.failJob('project-test1', D) |
| 4381 | self.executor_server.failJob('project-test1', E) |
| 4382 | self.executor_server.failJob('project-test1', F) |
| 4383 | self.executor_server.failJob('project-test1', G) |
| 4384 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4385 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4386 | self.executor_server.failJob('project-test1', J) |
| 4387 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4388 | |
| 4389 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4390 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4391 | self.waitUntilSettled() |
| 4392 | |
| 4393 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4394 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4395 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4396 | |
| 4397 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4398 | self.waitUntilSettled() |
| 4399 | |
| 4400 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4401 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4402 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4403 | |
| 4404 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4405 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4406 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4407 | self.waitUntilSettled() |
| 4408 | |
| 4409 | # We should be disabled now |
| 4410 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4411 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4412 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4413 | |
| 4414 | # We need to wait between each of these patches to make sure the |
| 4415 | # smtp messages come back in an expected order |
| 4416 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4417 | self.waitUntilSettled() |
| 4418 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4419 | self.waitUntilSettled() |
| 4420 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4421 | self.waitUntilSettled() |
| 4422 | |
| 4423 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4424 | # leaving a message on each change |
| 4425 | self.assertEqual(1, len(A.messages)) |
| 4426 | self.assertIn('Build failed.', A.messages[0]) |
| 4427 | self.assertEqual(1, len(B.messages)) |
| 4428 | self.assertIn('Build failed.', B.messages[0]) |
| 4429 | self.assertEqual(1, len(C.messages)) |
| 4430 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4431 | self.assertEqual(1, len(D.messages)) |
| 4432 | self.assertIn('Build failed.', D.messages[0]) |
| 4433 | self.assertEqual(1, len(E.messages)) |
| 4434 | self.assertIn('Build failed.', E.messages[0]) |
| 4435 | self.assertEqual(1, len(F.messages)) |
| 4436 | self.assertIn('Build failed.', F.messages[0]) |
| 4437 | |
| 4438 | # The last 3 (GHI) would have only reported via smtp. |
| 4439 | self.assertEqual(3, len(self.smtp_messages)) |
| 4440 | self.assertEqual(0, len(G.messages)) |
| 4441 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4442 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4443 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4444 | self.assertEqual(0, len(H.messages)) |
| 4445 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4446 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4447 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4448 | self.assertEqual(0, len(I.messages)) |
| 4449 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4450 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4451 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4452 | |
| 4453 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4454 | # comes out of disabled |
| 4455 | self.sched.reconfigure(self.config) |
| 4456 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4457 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4458 | |
| 4459 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4460 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4461 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4462 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4463 | |
| 4464 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4465 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4466 | self.waitUntilSettled() |
| 4467 | |
| 4468 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4469 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4470 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4471 | |
| 4472 | # J and K went back to gerrit |
| 4473 | self.assertEqual(1, len(J.messages)) |
| 4474 | self.assertIn('Build failed.', J.messages[0]) |
| 4475 | self.assertEqual(1, len(K.messages)) |
| 4476 | self.assertIn('Build failed.', K.messages[0]) |
| 4477 | # No more messages reported via smtp |
| 4478 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4479 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4480 | @simple_layout('layouts/one-job-project.yaml') |
| 4481 | def test_one_job_project(self): |
| 4482 | "Test that queueing works with one job" |
| 4483 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4484 | 'master', 'A') |
| 4485 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4486 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4487 | A.addApproval('Code-Review', 2) |
| 4488 | B.addApproval('Code-Review', 2) |
| 4489 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4490 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4491 | self.waitUntilSettled() |
| 4492 | |
| 4493 | self.assertEqual(A.data['status'], 'MERGED') |
| 4494 | self.assertEqual(A.reported, 2) |
| 4495 | self.assertEqual(B.data['status'], 'MERGED') |
| 4496 | self.assertEqual(B.reported, 2) |
| 4497 | |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4498 | def test_job_aborted(self): |
| 4499 | "Test that if a execute server aborts a job, it is run again" |
| 4500 | self.executor_server.hold_jobs_in_build = True |
| 4501 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4502 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4503 | self.waitUntilSettled() |
| 4504 | |
| 4505 | self.executor_server.release('.*-merge') |
| 4506 | self.waitUntilSettled() |
| 4507 | |
| 4508 | self.assertEqual(len(self.builds), 2) |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4509 | |
| 4510 | # first abort |
| 4511 | self.builds[0].aborted = True |
| 4512 | self.executor_server.release('.*-test*') |
| 4513 | self.waitUntilSettled() |
| 4514 | self.assertEqual(len(self.builds), 1) |
| 4515 | |
| 4516 | # second abort |
| 4517 | self.builds[0].aborted = True |
| 4518 | self.executor_server.release('.*-test*') |
| 4519 | self.waitUntilSettled() |
| 4520 | self.assertEqual(len(self.builds), 1) |
| 4521 | |
| 4522 | # third abort |
| 4523 | self.builds[0].aborted = True |
| 4524 | self.executor_server.release('.*-test*') |
| 4525 | self.waitUntilSettled() |
| 4526 | self.assertEqual(len(self.builds), 1) |
| 4527 | |
| 4528 | # fourth abort |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4529 | self.builds[0].aborted = True |
| 4530 | self.executor_server.release('.*-test*') |
| 4531 | self.waitUntilSettled() |
| 4532 | self.assertEqual(len(self.builds), 1) |
| 4533 | |
| 4534 | self.executor_server.hold_jobs_in_build = False |
| 4535 | self.executor_server.release() |
| 4536 | self.waitUntilSettled() |
| 4537 | |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4538 | self.assertEqual(len(self.history), 7) |
| 4539 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4540 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 4541 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4542 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4543 | "Test that if a execute server fails to run a job, it is run again" |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4544 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4545 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4546 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4547 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4548 | self.waitUntilSettled() |
| 4549 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4550 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4551 | self.waitUntilSettled() |
| 4552 | |
| 4553 | self.assertEqual(len(self.builds), 2) |
| 4554 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4555 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4556 | self.waitUntilSettled() |
| 4557 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4558 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4559 | self.assertEqual(len(self.builds), 1, |
| 4560 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4561 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4562 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4563 | self.waitUntilSettled() |
| 4564 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4565 | self.executor_server.hold_jobs_in_build = False |
| 4566 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4567 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4568 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4569 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4570 | self.assertEqual(A.reported, 1) |
| 4571 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4572 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4573 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4574 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4575 | |
| 4576 | self.fake_nodepool.paused = True |
| 4577 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4578 | A.addApproval('Code-Review', 2) |
| 4579 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4580 | self.waitUntilSettled() |
| 4581 | |
| 4582 | self.zk.client.stop() |
| 4583 | self.zk.client.start() |
| 4584 | self.fake_nodepool.paused = False |
| 4585 | self.waitUntilSettled() |
| 4586 | |
| 4587 | self.assertEqual(A.data['status'], 'MERGED') |
| 4588 | self.assertEqual(A.reported, 2) |
| 4589 | |
James E. Blair | b4bed1d | 2018-02-06 13:43:50 -0800 | [diff] [blame] | 4590 | def test_zookeeper_disconnect2(self): |
| 4591 | "Test that jobs are executed after a zookeeper disconnect" |
| 4592 | |
| 4593 | # This tests receiving a ZK disconnect between the arrival of |
| 4594 | # a fulfilled request and when we accept its nodes. |
| 4595 | self.fake_nodepool.paused = True |
| 4596 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4597 | A.addApproval('Code-Review', 2) |
| 4598 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4599 | self.waitUntilSettled() |
| 4600 | |
| 4601 | # We're waiting on the nodepool request to complete. Stop the |
| 4602 | # scheduler from processing further events, then fulfill the |
| 4603 | # nodepool request. |
| 4604 | self.sched.run_handler_lock.acquire() |
| 4605 | |
| 4606 | # Fulfill the nodepool request. |
| 4607 | self.fake_nodepool.paused = False |
| 4608 | requests = list(self.sched.nodepool.requests.values()) |
| 4609 | self.assertEqual(1, len(requests)) |
| 4610 | request = requests[0] |
| 4611 | for x in iterate_timeout(30, 'fulfill request'): |
| 4612 | if request.fulfilled: |
| 4613 | break |
| 4614 | id1 = request.id |
| 4615 | |
| 4616 | # The request is fulfilled, but the scheduler hasn't processed |
| 4617 | # it yet. Reconnect ZK. |
| 4618 | self.zk.client.stop() |
| 4619 | self.zk.client.start() |
| 4620 | |
| 4621 | # Allow the scheduler to continue and process the (now |
| 4622 | # out-of-date) notification that nodes are ready. |
| 4623 | self.sched.run_handler_lock.release() |
| 4624 | |
| 4625 | # It should resubmit the request, once it's fulfilled, we can |
| 4626 | # wait for it to run jobs and settle. |
| 4627 | for x in iterate_timeout(30, 'fulfill request'): |
| 4628 | if request.fulfilled: |
| 4629 | break |
| 4630 | self.waitUntilSettled() |
| 4631 | |
| 4632 | id2 = request.id |
| 4633 | self.assertEqual(A.data['status'], 'MERGED') |
| 4634 | self.assertEqual(A.reported, 2) |
| 4635 | # Make sure it was resubmitted (the id's should be different). |
| 4636 | self.assertNotEqual(id1, id2) |
| 4637 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4638 | def test_nodepool_failure(self): |
| 4639 | "Test that jobs are reported after a nodepool failure" |
| 4640 | |
| 4641 | self.fake_nodepool.paused = True |
| 4642 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4643 | A.addApproval('Code-Review', 2) |
| 4644 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4645 | self.waitUntilSettled() |
| 4646 | |
| 4647 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4648 | self.fake_nodepool.addFailRequest(req) |
| 4649 | |
| 4650 | self.fake_nodepool.paused = False |
| 4651 | self.waitUntilSettled() |
| 4652 | |
| 4653 | self.assertEqual(A.data['status'], 'NEW') |
| 4654 | self.assertEqual(A.reported, 2) |
| 4655 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4656 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4657 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4658 | |
Monty Taylor | 6dc5bc1 | 2017-09-29 15:47:31 -0500 | [diff] [blame] | 4659 | def test_nodepool_priority(self): |
| 4660 | "Test that nodes are requested at the correct priority" |
| 4661 | |
| 4662 | self.fake_nodepool.paused = True |
| 4663 | |
| 4664 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4665 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4666 | |
| 4667 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4668 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4669 | |
| 4670 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4671 | C.addApproval('Code-Review', 2) |
| 4672 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 4673 | |
| 4674 | self.waitUntilSettled() |
| 4675 | |
| 4676 | reqs = self.fake_nodepool.getNodeRequests() |
| 4677 | |
| 4678 | # The requests come back sorted by oid. Since we have three requests |
| 4679 | # for the three changes each with a different priority. |
| 4680 | # Also they get a serial number based on order they were received |
| 4681 | # so the number on the endof the oid should map to order submitted. |
| 4682 | |
| 4683 | # * gate first - high priority - change C |
| 4684 | self.assertEqual(reqs[0]['_oid'], '100-0000000002') |
| 4685 | self.assertEqual(reqs[0]['node_types'], ['label1']) |
| 4686 | # * check second - normal priority - change B |
| 4687 | self.assertEqual(reqs[1]['_oid'], '200-0000000001') |
| 4688 | self.assertEqual(reqs[1]['node_types'], ['label1']) |
| 4689 | # * post third - low priority - change A |
| 4690 | # additionally, the post job defined uses an ubuntu-xenial node, |
| 4691 | # so we include that check just as an extra verification |
| 4692 | self.assertEqual(reqs[2]['_oid'], '300-0000000000') |
| 4693 | self.assertEqual(reqs[2]['node_types'], ['ubuntu-xenial']) |
| 4694 | |
| 4695 | self.fake_nodepool.paused = False |
| 4696 | self.waitUntilSettled() |
| 4697 | |
James E. Blair | fceaf41 | 2017-09-29 13:44:57 -0700 | [diff] [blame] | 4698 | @simple_layout('layouts/multiple-templates.yaml') |
| 4699 | def test_multiple_project_templates(self): |
| 4700 | # Test that applying multiple project templates to a project |
| 4701 | # doesn't alter them when used for a second project. |
| 4702 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4703 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4704 | self.waitUntilSettled() |
| 4705 | |
| 4706 | build = self.getJobFromHistory('py27') |
| 4707 | self.assertEqual(build.parameters['zuul']['jobtags'], []) |
| 4708 | |
James E. Blair | 29c7700 | 2017-10-05 14:56:35 -0700 | [diff] [blame] | 4709 | def test_pending_merge_in_reconfig(self): |
| 4710 | # Test that if we are waiting for an outstanding merge on |
| 4711 | # reconfiguration that we continue to do so. |
| 4712 | self.gearman_server.hold_merge_jobs_in_queue = True |
| 4713 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4714 | A.setMerged() |
| 4715 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4716 | self.waitUntilSettled() |
| 4717 | # Reconfigure while we still have an outstanding merge job |
| 4718 | self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'], |
| 4719 | None) |
| 4720 | self.waitUntilSettled() |
| 4721 | # Verify the merge job is still running and that the item is |
| 4722 | # in the pipeline |
| 4723 | self.assertEqual(len(self.sched.merger.jobs), 1) |
| 4724 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4725 | pipeline = tenant.layout.pipelines['post'] |
| 4726 | self.assertEqual(len(pipeline.getAllItems()), 1) |
| 4727 | self.gearman_server.hold_merge_jobs_in_queue = False |
| 4728 | self.gearman_server.release() |
| 4729 | self.waitUntilSettled() |
| 4730 | |
James E. Blair | c32a835 | 2017-10-11 16:27:50 -0700 | [diff] [blame] | 4731 | @simple_layout('layouts/parent-matchers.yaml') |
| 4732 | def test_parent_matchers(self): |
| 4733 | "Test that if a job's parent does not match, the job does not run" |
| 4734 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4735 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4736 | self.waitUntilSettled() |
| 4737 | |
| 4738 | self.assertHistory([]) |
| 4739 | |
| 4740 | files = {'foo.txt': ''} |
| 4741 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B', |
| 4742 | files=files) |
| 4743 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4744 | self.waitUntilSettled() |
| 4745 | |
| 4746 | files = {'bar.txt': ''} |
| 4747 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C', |
| 4748 | files=files) |
| 4749 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4750 | self.waitUntilSettled() |
| 4751 | |
| 4752 | files = {'foo.txt': '', 'bar.txt': ''} |
| 4753 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D', |
| 4754 | files=files) |
| 4755 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4756 | self.waitUntilSettled() |
| 4757 | |
| 4758 | self.assertHistory([ |
| 4759 | dict(name='child-job', result='SUCCESS', changes='2,1'), |
| 4760 | dict(name='child-job', result='SUCCESS', changes='3,1'), |
| 4761 | dict(name='child-job', result='SUCCESS', changes='4,1'), |
| 4762 | ]) |
| 4763 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4764 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4765 | class TestExecutor(ZuulTestCase): |
| 4766 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4767 | |
| 4768 | def assertFinalState(self): |
| 4769 | # In this test, we expect to shut down in a non-final state, |
| 4770 | # so skip these checks. |
| 4771 | pass |
| 4772 | |
| 4773 | def assertCleanShutdown(self): |
| 4774 | self.log.debug("Assert clean shutdown") |
| 4775 | |
| 4776 | # After shutdown, make sure no jobs are running |
| 4777 | self.assertEqual({}, self.executor_server.job_workers) |
| 4778 | |
| 4779 | # Make sure that git.Repo objects have been garbage collected. |
| 4780 | repos = [] |
| 4781 | gc.collect() |
| 4782 | for obj in gc.get_objects(): |
| 4783 | if isinstance(obj, git.Repo): |
| 4784 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4785 | repos.append(obj) |
| 4786 | self.assertEqual(len(repos), 0) |
| 4787 | |
| 4788 | def test_executor_shutdown(self): |
| 4789 | "Test that the executor can shut down with jobs running" |
| 4790 | |
| 4791 | self.executor_server.hold_jobs_in_build = True |
| 4792 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4793 | A.addApproval('Code-Review', 2) |
| 4794 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4795 | self.waitUntilSettled() |
| 4796 | |
| 4797 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4798 | class TestDependencyGraph(ZuulTestCase): |
| 4799 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4800 | |
| 4801 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4802 | "Test a job in a dependency graph is queued only once" |
| 4803 | # Job dependencies, starting with A |
| 4804 | # A |
| 4805 | # / \ |
| 4806 | # B C |
| 4807 | # / \ / \ |
| 4808 | # D F E |
| 4809 | # | |
| 4810 | # G |
| 4811 | |
| 4812 | self.executor_server.hold_jobs_in_build = True |
| 4813 | change = self.fake_gerrit.addFakeChange( |
| 4814 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4815 | change.addApproval('Code-Review', 2) |
| 4816 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4817 | |
| 4818 | self.waitUntilSettled() |
| 4819 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4820 | |
| 4821 | self.executor_server.release('A') |
| 4822 | self.waitUntilSettled() |
| 4823 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4824 | |
| 4825 | self.executor_server.release('B') |
| 4826 | self.waitUntilSettled() |
| 4827 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4828 | |
| 4829 | self.executor_server.release('D') |
| 4830 | self.waitUntilSettled() |
| 4831 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4832 | |
| 4833 | self.executor_server.release('C') |
| 4834 | self.waitUntilSettled() |
| 4835 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4836 | |
| 4837 | self.executor_server.release('F') |
| 4838 | self.waitUntilSettled() |
| 4839 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4840 | |
| 4841 | self.executor_server.release('G') |
| 4842 | self.waitUntilSettled() |
| 4843 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4844 | |
| 4845 | self.executor_server.release('E') |
| 4846 | self.waitUntilSettled() |
| 4847 | self.assertEqual(len(self.builds), 0) |
| 4848 | |
| 4849 | self.executor_server.hold_jobs_in_build = False |
| 4850 | self.executor_server.release() |
| 4851 | self.waitUntilSettled() |
| 4852 | |
| 4853 | self.assertEqual(len(self.builds), 0) |
| 4854 | self.assertEqual(len(self.history), 7) |
| 4855 | |
| 4856 | self.assertEqual(change.data['status'], 'MERGED') |
| 4857 | self.assertEqual(change.reported, 2) |
| 4858 | |
| 4859 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4860 | "Test that a job waits till all dependencies are successful" |
| 4861 | # Job dependencies, starting with A |
| 4862 | # A |
| 4863 | # / \ |
| 4864 | # B C* |
| 4865 | # / \ / \ |
| 4866 | # D F E |
| 4867 | # | |
| 4868 | # G |
| 4869 | |
| 4870 | self.executor_server.hold_jobs_in_build = True |
| 4871 | change = self.fake_gerrit.addFakeChange( |
| 4872 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4873 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4874 | |
| 4875 | self.executor_server.failJob('C', change) |
| 4876 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4877 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4878 | |
| 4879 | self.waitUntilSettled() |
| 4880 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4881 | |
| 4882 | self.executor_server.release('A') |
| 4883 | self.waitUntilSettled() |
| 4884 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4885 | |
| 4886 | self.executor_server.release('B') |
| 4887 | self.waitUntilSettled() |
| 4888 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4889 | |
| 4890 | self.executor_server.release('D') |
| 4891 | self.waitUntilSettled() |
| 4892 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4893 | |
| 4894 | self.executor_server.release('C') |
| 4895 | self.waitUntilSettled() |
| 4896 | self.assertEqual(len(self.builds), 0) |
| 4897 | |
| 4898 | self.executor_server.hold_jobs_in_build = False |
| 4899 | self.executor_server.release() |
| 4900 | self.waitUntilSettled() |
| 4901 | |
| 4902 | self.assertEqual(len(self.builds), 0) |
| 4903 | self.assertEqual(len(self.history), 4) |
| 4904 | |
| 4905 | self.assertEqual(change.data['status'], 'NEW') |
| 4906 | self.assertEqual(change.reported, 2) |
| 4907 | |
| 4908 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4909 | class TestDuplicatePipeline(ZuulTestCase): |
| 4910 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4911 | |
| 4912 | def test_duplicate_pipelines(self): |
| 4913 | "Test that a change matching multiple pipelines works" |
| 4914 | |
| 4915 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4916 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4917 | self.waitUntilSettled() |
| 4918 | |
| 4919 | self.assertHistory([ |
| 4920 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4921 | pipeline='dup1'), |
| 4922 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4923 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4924 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4925 | |
| 4926 | self.assertEqual(len(A.messages), 2) |
| 4927 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4928 | if 'dup1' in A.messages[0]: |
| 4929 | self.assertIn('dup1', A.messages[0]) |
| 4930 | self.assertNotIn('dup2', A.messages[0]) |
| 4931 | self.assertIn('project-test1', A.messages[0]) |
| 4932 | self.assertIn('dup2', A.messages[1]) |
| 4933 | self.assertNotIn('dup1', A.messages[1]) |
| 4934 | self.assertIn('project-test1', A.messages[1]) |
| 4935 | else: |
| 4936 | self.assertIn('dup1', A.messages[1]) |
| 4937 | self.assertNotIn('dup2', A.messages[1]) |
| 4938 | self.assertIn('project-test1', A.messages[1]) |
| 4939 | self.assertIn('dup2', A.messages[0]) |
| 4940 | self.assertNotIn('dup1', A.messages[0]) |
| 4941 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4942 | |
| 4943 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4944 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4945 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4946 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4947 | def test_job_from_templates_executed(self): |
| 4948 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4949 | |
| 4950 | A = self.fake_gerrit.addFakeChange( |
| 4951 | 'org/templated-project', 'master', 'A') |
| 4952 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4953 | self.waitUntilSettled() |
| 4954 | |
| 4955 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4956 | 'SUCCESS') |
| 4957 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4958 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4959 | |
| 4960 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4961 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4962 | |
| 4963 | A = self.fake_gerrit.addFakeChange( |
| 4964 | 'org/layered-project', 'master', 'A') |
| 4965 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4966 | self.waitUntilSettled() |
| 4967 | |
| 4968 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4969 | 'SUCCESS') |
| 4970 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4971 | 'SUCCESS') |
| 4972 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4973 | ).result, 'SUCCESS') |
| 4974 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4975 | ).result, 'SUCCESS') |
| 4976 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4977 | ).result, 'SUCCESS') |
| 4978 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4979 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4980 | |
James E. Blair | e74f571 | 2017-09-29 15:14:31 -0700 | [diff] [blame] | 4981 | def test_unimplied_branch_matchers(self): |
| 4982 | # This tests that there are no implied branch matchers added |
| 4983 | # by project templates. |
| 4984 | self.create_branch('org/layered-project', 'stable') |
| 4985 | |
| 4986 | A = self.fake_gerrit.addFakeChange( |
| 4987 | 'org/layered-project', 'stable', 'A') |
| 4988 | |
| 4989 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4990 | self.waitUntilSettled() |
| 4991 | |
| 4992 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4993 | 'SUCCESS') |
| 4994 | print(self.getJobFromHistory('project-test1'). |
| 4995 | parameters['zuul']['_inheritance_path']) |
| 4996 | |
| 4997 | def test_implied_branch_matchers(self): |
| 4998 | # This tests that there is an implied branch matcher when a |
| 4999 | # template is used on an in-repo project pipeline definition. |
| 5000 | self.create_branch('untrusted-config', 'stable') |
| 5001 | self.fake_gerrit.addEvent( |
| 5002 | self.fake_gerrit.getFakeBranchCreatedEvent( |
| 5003 | 'untrusted-config', 'stable')) |
| 5004 | self.waitUntilSettled() |
| 5005 | |
| 5006 | A = self.fake_gerrit.addFakeChange( |
| 5007 | 'untrusted-config', 'stable', 'A') |
| 5008 | |
| 5009 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5010 | self.waitUntilSettled() |
| 5011 | |
| 5012 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5013 | 'SUCCESS') |
| 5014 | print(self.getJobFromHistory('project-test1'). |
| 5015 | parameters['zuul']['_inheritance_path']) |
| 5016 | |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5017 | |
| 5018 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 5019 | tenant_config_file = 'config/success-url/main.yaml' |
| 5020 | |
| 5021 | def test_success_url(self): |
| 5022 | "Ensure bad build params are ignored" |
| 5023 | self.sched.reconfigure(self.config) |
| 5024 | self.init_repo('org/docs') |
| 5025 | |
| 5026 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 5027 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5028 | self.waitUntilSettled() |
| 5029 | |
| 5030 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 5031 | self.assertEqual(len(self.history), 2) |
| 5032 | |
| 5033 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 5034 | for build in self.history: |
| 5035 | if build.name == 'docs-draft-test': |
| 5036 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5037 | elif build.name == 'docs-draft-test2': |
| 5038 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5039 | |
| 5040 | # Two msgs: 'Starting...' + results |
| 5041 | self.assertEqual(len(self.smtp_messages), 2) |
| 5042 | body = self.smtp_messages[1]['body'].splitlines() |
| 5043 | self.assertEqual('Build succeeded.', body[0]) |
| 5044 | |
| 5045 | self.assertIn( |
| 5046 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 5047 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 5048 | body[2]) |
| 5049 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5050 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5051 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 5052 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 5053 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5054 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5055 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5056 | |
| 5057 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5058 | class TestSchedulerMerges(ZuulTestCase): |
| 5059 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5060 | |
| 5061 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5062 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5063 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5064 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5065 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 5066 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 5067 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5068 | A.addApproval('Code-Review', 2) |
| 5069 | B.addApproval('Code-Review', 2) |
| 5070 | C.addApproval('Code-Review', 2) |
| 5071 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5072 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5073 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5074 | self.waitUntilSettled() |
| 5075 | |
| 5076 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5077 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5078 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5079 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5080 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5081 | repo_messages.reverse() |
| 5082 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5083 | self.executor_server.hold_jobs_in_build = False |
| 5084 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5085 | self.waitUntilSettled() |
| 5086 | |
| 5087 | return repo_messages |
| 5088 | |
| 5089 | def _test_merge(self, mode): |
James E. Blair | da5bb7e | 2018-01-22 16:12:17 -0800 | [diff] [blame] | 5090 | us_path = 'file://' + os.path.join( |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5091 | self.upstream_root, 'org/project-%s' % mode) |
| 5092 | expected_messages = [ |
| 5093 | 'initial commit', |
| 5094 | 'add content from fixture', |
| 5095 | # the intermediate commits order is nondeterministic |
| 5096 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 5097 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 5098 | ] |
| 5099 | result = self._test_project_merge_mode(mode) |
| 5100 | self.assertEqual(result[:2], expected_messages[:2]) |
| 5101 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 5102 | |
| 5103 | def test_project_merge_mode_merge(self): |
| 5104 | self._test_merge('merge') |
| 5105 | |
| 5106 | def test_project_merge_mode_merge_resolve(self): |
| 5107 | self._test_merge('merge-resolve') |
| 5108 | |
| 5109 | def test_project_merge_mode_cherrypick(self): |
| 5110 | expected_messages = [ |
| 5111 | 'initial commit', |
| 5112 | 'add content from fixture', |
| 5113 | 'A-1', |
| 5114 | 'B-1', |
| 5115 | 'C-1'] |
| 5116 | result = self._test_project_merge_mode('cherry-pick') |
| 5117 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5118 | |
| 5119 | def test_merge_branch(self): |
| 5120 | "Test that the right commits are on alternate branches" |
| 5121 | self.create_branch('org/project-merge-branches', 'mp') |
| 5122 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5123 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5124 | A = self.fake_gerrit.addFakeChange( |
| 5125 | 'org/project-merge-branches', 'mp', 'A') |
| 5126 | B = self.fake_gerrit.addFakeChange( |
| 5127 | 'org/project-merge-branches', 'mp', 'B') |
| 5128 | C = self.fake_gerrit.addFakeChange( |
| 5129 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5130 | A.addApproval('Code-Review', 2) |
| 5131 | B.addApproval('Code-Review', 2) |
| 5132 | C.addApproval('Code-Review', 2) |
| 5133 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5134 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5135 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5136 | self.waitUntilSettled() |
| 5137 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5138 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5139 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5140 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5141 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5142 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5143 | self.waitUntilSettled() |
| 5144 | |
| 5145 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 5146 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5147 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5148 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5149 | repo = git.Repo(path) |
| 5150 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5151 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5152 | repo_messages.reverse() |
| 5153 | correct_messages = [ |
| 5154 | 'initial commit', |
| 5155 | 'add content from fixture', |
| 5156 | 'mp commit', |
| 5157 | 'A-1', 'B-1', 'C-1'] |
| 5158 | self.assertEqual(repo_messages, correct_messages) |
| 5159 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5160 | self.executor_server.hold_jobs_in_build = False |
| 5161 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5162 | self.waitUntilSettled() |
| 5163 | |
| 5164 | def test_merge_multi_branch(self): |
| 5165 | "Test that dependent changes on multiple branches are merged" |
| 5166 | self.create_branch('org/project-merge-branches', 'mp') |
| 5167 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5168 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5169 | A = self.fake_gerrit.addFakeChange( |
| 5170 | 'org/project-merge-branches', 'master', 'A') |
| 5171 | B = self.fake_gerrit.addFakeChange( |
| 5172 | 'org/project-merge-branches', 'mp', 'B') |
| 5173 | C = self.fake_gerrit.addFakeChange( |
| 5174 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5175 | A.addApproval('Code-Review', 2) |
| 5176 | B.addApproval('Code-Review', 2) |
| 5177 | C.addApproval('Code-Review', 2) |
| 5178 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5179 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5180 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5181 | self.waitUntilSettled() |
| 5182 | |
| 5183 | job_A = None |
| 5184 | for job in self.builds: |
| 5185 | if 'project-merge' in job.name: |
| 5186 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5187 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5188 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 5189 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5190 | repo = git.Repo(path) |
| 5191 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5192 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5193 | repo_messages.reverse() |
| 5194 | correct_messages = [ |
| 5195 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5196 | self.assertEqual(repo_messages, correct_messages) |
| 5197 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5198 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5199 | self.waitUntilSettled() |
| 5200 | |
| 5201 | job_B = None |
| 5202 | for job in self.builds: |
| 5203 | if 'project-merge' in job.name: |
| 5204 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5205 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5206 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 5207 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5208 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5209 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5210 | repo_messages.reverse() |
| 5211 | correct_messages = [ |
| 5212 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5213 | self.assertEqual(repo_messages, correct_messages) |
| 5214 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5215 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5216 | self.waitUntilSettled() |
| 5217 | |
| 5218 | job_C = None |
| 5219 | for job in self.builds: |
| 5220 | if 'project-merge' in job.name: |
| 5221 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 5222 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5223 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 5224 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5225 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5226 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5227 | |
| 5228 | repo_messages.reverse() |
| 5229 | correct_messages = [ |
| 5230 | 'initial commit', 'add content from fixture', |
| 5231 | 'A-1', 'C-1'] |
| 5232 | # Ensure the right commits are in the history for this ref |
| 5233 | self.assertEqual(repo_messages, correct_messages) |
| 5234 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5235 | self.executor_server.hold_jobs_in_build = False |
| 5236 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5237 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5238 | |
| 5239 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5240 | class TestSemaphore(ZuulTestCase): |
| 5241 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5242 | |
| 5243 | def test_semaphore_one(self): |
| 5244 | "Test semaphores with max=1 (mutex)" |
| 5245 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5246 | |
| 5247 | self.executor_server.hold_jobs_in_build = True |
| 5248 | |
| 5249 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5250 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5251 | self.assertFalse('test-semaphore' in |
| 5252 | tenant.semaphore_handler.semaphores) |
| 5253 | |
| 5254 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5255 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5256 | self.waitUntilSettled() |
| 5257 | |
| 5258 | self.assertEqual(len(self.builds), 3) |
| 5259 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5260 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5261 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5262 | |
| 5263 | self.executor_server.release('semaphore-one-test1') |
| 5264 | self.waitUntilSettled() |
| 5265 | |
| 5266 | self.assertEqual(len(self.builds), 3) |
| 5267 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5268 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5269 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5270 | self.assertTrue('test-semaphore' in |
| 5271 | tenant.semaphore_handler.semaphores) |
| 5272 | |
| 5273 | self.executor_server.release('semaphore-one-test2') |
| 5274 | self.waitUntilSettled() |
| 5275 | |
| 5276 | self.assertEqual(len(self.builds), 3) |
| 5277 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5278 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5279 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5280 | self.assertTrue('test-semaphore' in |
| 5281 | tenant.semaphore_handler.semaphores) |
| 5282 | |
| 5283 | self.executor_server.release('semaphore-one-test1') |
| 5284 | self.waitUntilSettled() |
| 5285 | |
| 5286 | self.assertEqual(len(self.builds), 3) |
| 5287 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5288 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5289 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5290 | self.assertTrue('test-semaphore' in |
| 5291 | tenant.semaphore_handler.semaphores) |
| 5292 | |
| 5293 | self.executor_server.release('semaphore-one-test2') |
| 5294 | self.waitUntilSettled() |
| 5295 | |
| 5296 | self.assertEqual(len(self.builds), 2) |
| 5297 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5298 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5299 | self.assertFalse('test-semaphore' in |
| 5300 | tenant.semaphore_handler.semaphores) |
| 5301 | |
| 5302 | self.executor_server.hold_jobs_in_build = False |
| 5303 | self.executor_server.release() |
| 5304 | |
| 5305 | self.waitUntilSettled() |
| 5306 | self.assertEqual(len(self.builds), 0) |
| 5307 | |
| 5308 | self.assertEqual(A.reported, 1) |
| 5309 | self.assertEqual(B.reported, 1) |
| 5310 | self.assertFalse('test-semaphore' in |
| 5311 | tenant.semaphore_handler.semaphores) |
| 5312 | |
| 5313 | def test_semaphore_two(self): |
| 5314 | "Test semaphores with max>1" |
| 5315 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5316 | |
| 5317 | self.executor_server.hold_jobs_in_build = True |
| 5318 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5319 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5320 | self.assertFalse('test-semaphore-two' in |
| 5321 | tenant.semaphore_handler.semaphores) |
| 5322 | |
| 5323 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5324 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5325 | self.waitUntilSettled() |
| 5326 | |
| 5327 | self.assertEqual(len(self.builds), 4) |
| 5328 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5329 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5330 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5331 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5332 | self.assertTrue('test-semaphore-two' in |
| 5333 | tenant.semaphore_handler.semaphores) |
| 5334 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5335 | 'test-semaphore-two', [])), 2) |
| 5336 | |
| 5337 | self.executor_server.release('semaphore-two-test1') |
| 5338 | self.waitUntilSettled() |
| 5339 | |
| 5340 | self.assertEqual(len(self.builds), 4) |
| 5341 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5342 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5343 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5344 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5345 | self.assertTrue('test-semaphore-two' in |
| 5346 | tenant.semaphore_handler.semaphores) |
| 5347 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5348 | 'test-semaphore-two', [])), 2) |
| 5349 | |
| 5350 | self.executor_server.release('semaphore-two-test2') |
| 5351 | self.waitUntilSettled() |
| 5352 | |
| 5353 | self.assertEqual(len(self.builds), 4) |
| 5354 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5355 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5356 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5357 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5358 | self.assertTrue('test-semaphore-two' in |
| 5359 | tenant.semaphore_handler.semaphores) |
| 5360 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5361 | 'test-semaphore-two', [])), 2) |
| 5362 | |
| 5363 | self.executor_server.release('semaphore-two-test1') |
| 5364 | self.waitUntilSettled() |
| 5365 | |
| 5366 | self.assertEqual(len(self.builds), 3) |
| 5367 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5368 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5369 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5370 | self.assertTrue('test-semaphore-two' in |
| 5371 | tenant.semaphore_handler.semaphores) |
| 5372 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5373 | 'test-semaphore-two', [])), 1) |
| 5374 | |
| 5375 | self.executor_server.release('semaphore-two-test2') |
| 5376 | self.waitUntilSettled() |
| 5377 | |
| 5378 | self.assertEqual(len(self.builds), 2) |
| 5379 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5380 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5381 | self.assertFalse('test-semaphore-two' in |
| 5382 | tenant.semaphore_handler.semaphores) |
| 5383 | |
| 5384 | self.executor_server.hold_jobs_in_build = False |
| 5385 | self.executor_server.release() |
| 5386 | |
| 5387 | self.waitUntilSettled() |
| 5388 | self.assertEqual(len(self.builds), 0) |
| 5389 | |
| 5390 | self.assertEqual(A.reported, 1) |
| 5391 | self.assertEqual(B.reported, 1) |
| 5392 | |
| 5393 | def test_semaphore_abandon(self): |
| 5394 | "Test abandon with job semaphores" |
| 5395 | self.executor_server.hold_jobs_in_build = True |
| 5396 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5397 | check_pipeline = tenant.layout.pipelines['check'] |
| 5398 | |
| 5399 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5400 | self.assertFalse('test-semaphore' in |
| 5401 | tenant.semaphore_handler.semaphores) |
| 5402 | |
| 5403 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5404 | self.waitUntilSettled() |
| 5405 | |
| 5406 | self.assertTrue('test-semaphore' in |
| 5407 | tenant.semaphore_handler.semaphores) |
| 5408 | |
| 5409 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5410 | self.waitUntilSettled() |
| 5411 | |
| 5412 | # The check pipeline should be empty |
| 5413 | items = check_pipeline.getAllItems() |
| 5414 | self.assertEqual(len(items), 0) |
| 5415 | |
| 5416 | # The semaphore should be released |
| 5417 | self.assertFalse('test-semaphore' in |
| 5418 | tenant.semaphore_handler.semaphores) |
| 5419 | |
| 5420 | self.executor_server.hold_jobs_in_build = False |
| 5421 | self.executor_server.release() |
| 5422 | self.waitUntilSettled() |
| 5423 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5424 | def test_semaphore_new_patchset(self): |
| 5425 | "Test new patchset with job semaphores" |
| 5426 | self.executor_server.hold_jobs_in_build = True |
| 5427 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5428 | check_pipeline = tenant.layout.pipelines['check'] |
| 5429 | |
| 5430 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5431 | self.assertFalse('test-semaphore' in |
| 5432 | tenant.semaphore_handler.semaphores) |
| 5433 | |
| 5434 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5435 | self.waitUntilSettled() |
| 5436 | |
| 5437 | self.assertTrue('test-semaphore' in |
| 5438 | tenant.semaphore_handler.semaphores) |
| 5439 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5440 | self.assertEqual(len(semaphore), 1) |
| 5441 | |
| 5442 | A.addPatchset() |
| 5443 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5444 | self.waitUntilSettled() |
| 5445 | |
| 5446 | self.assertTrue('test-semaphore' in |
| 5447 | tenant.semaphore_handler.semaphores) |
| 5448 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5449 | self.assertEqual(len(semaphore), 1) |
| 5450 | |
| 5451 | items = check_pipeline.getAllItems() |
| 5452 | self.assertEqual(items[0].change.number, '1') |
| 5453 | self.assertEqual(items[0].change.patchset, '2') |
| 5454 | self.assertTrue(items[0].live) |
| 5455 | |
| 5456 | self.executor_server.hold_jobs_in_build = False |
| 5457 | self.executor_server.release() |
| 5458 | self.waitUntilSettled() |
| 5459 | |
| 5460 | # The semaphore should be released |
| 5461 | self.assertFalse('test-semaphore' in |
| 5462 | tenant.semaphore_handler.semaphores) |
| 5463 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5464 | def test_semaphore_reconfigure(self): |
| 5465 | "Test reconfigure with job semaphores" |
| 5466 | self.executor_server.hold_jobs_in_build = True |
| 5467 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5468 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5469 | self.assertFalse('test-semaphore' in |
| 5470 | tenant.semaphore_handler.semaphores) |
| 5471 | |
| 5472 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5473 | self.waitUntilSettled() |
| 5474 | |
| 5475 | self.assertTrue('test-semaphore' in |
| 5476 | tenant.semaphore_handler.semaphores) |
| 5477 | |
| 5478 | # reconfigure without layout change |
| 5479 | self.sched.reconfigure(self.config) |
| 5480 | self.waitUntilSettled() |
| 5481 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5482 | |
| 5483 | # semaphore still must be held |
| 5484 | self.assertTrue('test-semaphore' in |
| 5485 | tenant.semaphore_handler.semaphores) |
| 5486 | |
| 5487 | self.commitConfigUpdate( |
| 5488 | 'common-config', |
| 5489 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5490 | self.sched.reconfigure(self.config) |
| 5491 | self.waitUntilSettled() |
| 5492 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5493 | |
| 5494 | self.executor_server.release('project-test1') |
| 5495 | self.waitUntilSettled() |
| 5496 | |
| 5497 | # There should be no builds anymore |
| 5498 | self.assertEqual(len(self.builds), 0) |
| 5499 | |
| 5500 | # The semaphore should be released |
| 5501 | self.assertFalse('test-semaphore' in |
| 5502 | tenant.semaphore_handler.semaphores) |
| 5503 | |
| 5504 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5505 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5506 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5507 | |
| 5508 | def test_semaphore_tenant_isolation(self): |
| 5509 | "Test semaphores in multiple tenants" |
| 5510 | |
| 5511 | self.waitUntilSettled() |
| 5512 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5513 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5514 | |
| 5515 | self.executor_server.hold_jobs_in_build = True |
| 5516 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5517 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5518 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5519 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5520 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5521 | self.assertFalse('test-semaphore' in |
| 5522 | tenant_one.semaphore_handler.semaphores) |
| 5523 | self.assertFalse('test-semaphore' in |
| 5524 | tenant_two.semaphore_handler.semaphores) |
| 5525 | |
| 5526 | # add patches to project1 of tenant-one |
| 5527 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5528 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5529 | self.waitUntilSettled() |
| 5530 | |
| 5531 | # one build of project1-test1 must run |
| 5532 | # semaphore of tenant-one must be acquired once |
| 5533 | # semaphore of tenant-two must not be acquired |
| 5534 | self.assertEqual(len(self.builds), 1) |
| 5535 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5536 | self.assertTrue('test-semaphore' in |
| 5537 | tenant_one.semaphore_handler.semaphores) |
| 5538 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5539 | 'test-semaphore', [])), 1) |
| 5540 | self.assertFalse('test-semaphore' in |
| 5541 | tenant_two.semaphore_handler.semaphores) |
| 5542 | |
| 5543 | # add patches to project2 of tenant-two |
| 5544 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5545 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5546 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5547 | self.waitUntilSettled() |
| 5548 | |
| 5549 | # one build of project1-test1 must run |
| 5550 | # two builds of project2-test1 must run |
| 5551 | # semaphore of tenant-one must be acquired once |
| 5552 | # semaphore of tenant-two must be acquired twice |
| 5553 | self.assertEqual(len(self.builds), 3) |
| 5554 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5555 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5556 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5557 | self.assertTrue('test-semaphore' in |
| 5558 | tenant_one.semaphore_handler.semaphores) |
| 5559 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5560 | 'test-semaphore', [])), 1) |
| 5561 | self.assertTrue('test-semaphore' in |
| 5562 | tenant_two.semaphore_handler.semaphores) |
| 5563 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5564 | 'test-semaphore', [])), 2) |
| 5565 | |
| 5566 | self.executor_server.release('project1-test1') |
| 5567 | self.waitUntilSettled() |
| 5568 | |
| 5569 | # one build of project1-test1 must run |
| 5570 | # two builds of project2-test1 must run |
| 5571 | # semaphore of tenant-one must be acquired once |
| 5572 | # semaphore of tenant-two must be acquired twice |
| 5573 | self.assertEqual(len(self.builds), 3) |
| 5574 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5575 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5576 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5577 | self.assertTrue('test-semaphore' in |
| 5578 | tenant_one.semaphore_handler.semaphores) |
| 5579 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5580 | 'test-semaphore', [])), 1) |
| 5581 | self.assertTrue('test-semaphore' in |
| 5582 | tenant_two.semaphore_handler.semaphores) |
| 5583 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5584 | 'test-semaphore', [])), 2) |
| 5585 | |
| 5586 | self.executor_server.release('project2-test1') |
| 5587 | self.waitUntilSettled() |
| 5588 | |
| 5589 | # one build of project1-test1 must run |
| 5590 | # one build of project2-test1 must run |
| 5591 | # semaphore of tenant-one must be acquired once |
| 5592 | # semaphore of tenant-two must be acquired once |
| 5593 | self.assertEqual(len(self.builds), 2) |
| 5594 | self.assertTrue('test-semaphore' in |
| 5595 | tenant_one.semaphore_handler.semaphores) |
| 5596 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5597 | 'test-semaphore', [])), 1) |
| 5598 | self.assertTrue('test-semaphore' in |
| 5599 | tenant_two.semaphore_handler.semaphores) |
| 5600 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5601 | 'test-semaphore', [])), 1) |
| 5602 | |
| 5603 | self.executor_server.hold_jobs_in_build = False |
| 5604 | self.executor_server.release() |
| 5605 | |
| 5606 | self.waitUntilSettled() |
| 5607 | |
| 5608 | # no build must run |
| 5609 | # semaphore of tenant-one must not be acquired |
| 5610 | # semaphore of tenant-two must not be acquired |
| 5611 | self.assertEqual(len(self.builds), 0) |
| 5612 | self.assertFalse('test-semaphore' in |
| 5613 | tenant_one.semaphore_handler.semaphores) |
| 5614 | self.assertFalse('test-semaphore' in |
| 5615 | tenant_two.semaphore_handler.semaphores) |
| 5616 | |
| 5617 | self.assertEqual(A.reported, 1) |
| 5618 | self.assertEqual(B.reported, 1) |
| 5619 | |
| 5620 | |
Tobias Henkel | e9a2251 | 2017-12-22 08:36:12 +0100 | [diff] [blame] | 5621 | class TestImplicitProject(ZuulTestCase): |
| 5622 | tenant_config_file = 'config/implicit-project/main.yaml' |
| 5623 | |
| 5624 | def test_implicit_project(self): |
| 5625 | # config project should work with implicit project name |
| 5626 | A = self.fake_gerrit.addFakeChange('common-config', 'master', 'A') |
| 5627 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5628 | |
| 5629 | # untrusted project should work with implicit project name |
| 5630 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5631 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5632 | |
| 5633 | self.waitUntilSettled() |
| 5634 | |
| 5635 | self.assertEqual(A.data['status'], 'NEW') |
| 5636 | self.assertEqual(A.reported, 1) |
| 5637 | self.assertEqual(B.data['status'], 'NEW') |
| 5638 | self.assertEqual(B.reported, 1) |
| 5639 | self.assertHistory([ |
| 5640 | dict(name='test-common', result='SUCCESS', changes='1,1'), |
| 5641 | dict(name='test-common', result='SUCCESS', changes='2,1'), |
| 5642 | dict(name='test-project', result='SUCCESS', changes='2,1'), |
| 5643 | ], ordered=False) |
| 5644 | |
| 5645 | # now test adding a further project in repo |
| 5646 | in_repo_conf = textwrap.dedent( |
| 5647 | """ |
| 5648 | - job: |
| 5649 | name: test-project |
| 5650 | run: playbooks/test-project.yaml |
| 5651 | - job: |
| 5652 | name: test2-project |
| 5653 | run: playbooks/test-project.yaml |
| 5654 | |
| 5655 | - project: |
| 5656 | check: |
| 5657 | jobs: |
| 5658 | - test-project |
| 5659 | gate: |
| 5660 | jobs: |
| 5661 | - test-project |
| 5662 | |
| 5663 | - project: |
| 5664 | check: |
| 5665 | jobs: |
| 5666 | - test2-project |
| 5667 | gate: |
| 5668 | jobs: |
| 5669 | - test2-project |
| 5670 | |
| 5671 | """) |
| 5672 | file_dict = {'.zuul.yaml': in_repo_conf} |
| 5673 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5674 | files=file_dict) |
| 5675 | C.addApproval('Code-Review', 2) |
| 5676 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 5677 | self.waitUntilSettled() |
| 5678 | |
| 5679 | # change C must be merged |
| 5680 | self.assertEqual(C.data['status'], 'MERGED') |
| 5681 | self.assertEqual(C.reported, 2) |
| 5682 | self.assertHistory([ |
| 5683 | dict(name='test-common', result='SUCCESS', changes='1,1'), |
| 5684 | dict(name='test-common', result='SUCCESS', changes='2,1'), |
| 5685 | dict(name='test-project', result='SUCCESS', changes='2,1'), |
| 5686 | dict(name='test-common', result='SUCCESS', changes='3,1'), |
| 5687 | dict(name='test-project', result='SUCCESS', changes='3,1'), |
| 5688 | dict(name='test2-project', result='SUCCESS', changes='3,1'), |
| 5689 | ], ordered=False) |
| 5690 | |
| 5691 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5692 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5693 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5694 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5695 | |
| 5696 | def test_semaphore_in_repo(self): |
| 5697 | "Test semaphores in repo config" |
| 5698 | |
| 5699 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5700 | # max value should not be evaluated dynamically but must be updated |
| 5701 | # after the change lands. |
| 5702 | |
| 5703 | self.waitUntilSettled() |
| 5704 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5705 | |
| 5706 | in_repo_conf = textwrap.dedent( |
| 5707 | """ |
| 5708 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5709 | name: project-test1 |
| 5710 | |
| 5711 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5712 | name: project-test2 |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 5713 | run: playbooks/project-test2.yaml |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5714 | semaphore: test-semaphore |
| 5715 | |
| 5716 | - project: |
| 5717 | name: org/project |
| 5718 | tenant-one-gate: |
| 5719 | jobs: |
| 5720 | - project-test2 |
| 5721 | |
| 5722 | # the max value in dynamic layout must be ignored |
| 5723 | - semaphore: |
| 5724 | name: test-semaphore |
| 5725 | max: 2 |
| 5726 | """) |
| 5727 | |
| 5728 | in_repo_playbook = textwrap.dedent( |
| 5729 | """ |
| 5730 | - hosts: all |
| 5731 | tasks: [] |
| 5732 | """) |
| 5733 | |
| 5734 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5735 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5736 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5737 | files=file_dict) |
| 5738 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5739 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5740 | B.setDependsOn(A, 1) |
| 5741 | C.setDependsOn(A, 1) |
| 5742 | |
| 5743 | self.executor_server.hold_jobs_in_build = True |
| 5744 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5745 | A.addApproval('Code-Review', 2) |
| 5746 | B.addApproval('Code-Review', 2) |
| 5747 | C.addApproval('Code-Review', 2) |
| 5748 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5749 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5750 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5751 | self.waitUntilSettled() |
| 5752 | |
| 5753 | # check that the layout in a queue item still has max value of 1 |
| 5754 | # for test-semaphore |
| 5755 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5756 | queue = None |
| 5757 | for queue_candidate in pipeline.queues: |
| 5758 | if queue_candidate.name == 'org/project': |
| 5759 | queue = queue_candidate |
| 5760 | break |
| 5761 | queue_item = queue.queue[0] |
James E. Blair | 29a24fd | 2017-10-02 15:04:56 -0700 | [diff] [blame] | 5762 | item_dynamic_layout = queue_item.layout |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5763 | dynamic_test_semaphore = \ |
| 5764 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5765 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5766 | |
| 5767 | # one build must be in queue, one semaphores acquired |
| 5768 | self.assertEqual(len(self.builds), 1) |
| 5769 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5770 | self.assertTrue('test-semaphore' in |
| 5771 | tenant.semaphore_handler.semaphores) |
| 5772 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5773 | 'test-semaphore', [])), 1) |
| 5774 | |
| 5775 | self.executor_server.release('project-test2') |
| 5776 | self.waitUntilSettled() |
| 5777 | |
| 5778 | # change A must be merged |
| 5779 | self.assertEqual(A.data['status'], 'MERGED') |
| 5780 | self.assertEqual(A.reported, 2) |
| 5781 | |
| 5782 | # send change-merged event as the gerrit mock doesn't send it |
| 5783 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5784 | self.waitUntilSettled() |
| 5785 | |
| 5786 | # now that change A was merged, the new semaphore max must be effective |
| 5787 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5788 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5789 | |
| 5790 | # two builds must be in queue, two semaphores acquired |
| 5791 | self.assertEqual(len(self.builds), 2) |
| 5792 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5793 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5794 | self.assertTrue('test-semaphore' in |
| 5795 | tenant.semaphore_handler.semaphores) |
| 5796 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5797 | 'test-semaphore', [])), 2) |
| 5798 | |
| 5799 | self.executor_server.release('project-test2') |
| 5800 | self.waitUntilSettled() |
| 5801 | |
| 5802 | self.assertEqual(len(self.builds), 0) |
| 5803 | self.assertFalse('test-semaphore' in |
| 5804 | tenant.semaphore_handler.semaphores) |
| 5805 | |
| 5806 | self.executor_server.hold_jobs_in_build = False |
| 5807 | self.executor_server.release() |
| 5808 | |
| 5809 | self.waitUntilSettled() |
| 5810 | self.assertEqual(len(self.builds), 0) |
| 5811 | |
| 5812 | self.assertEqual(A.reported, 2) |
| 5813 | self.assertEqual(B.reported, 2) |
| 5814 | self.assertEqual(C.reported, 2) |
David Shrewsbury | f6dc176 | 2017-10-02 13:34:37 -0400 | [diff] [blame] | 5815 | |
| 5816 | |
| 5817 | class TestSchedulerBranchMatcher(ZuulTestCase): |
| 5818 | |
| 5819 | @simple_layout('layouts/matcher-test.yaml') |
| 5820 | def test_job_branch_ignored(self): |
| 5821 | ''' |
| 5822 | Test that branch matching logic works. |
| 5823 | |
| 5824 | The 'ignore-branch' job has a branch matcher that is supposed to |
| 5825 | match every branch except for the 'featureA' branch, so it should |
| 5826 | not be run on a change to that branch. |
| 5827 | ''' |
| 5828 | self.create_branch('org/project', 'featureA') |
| 5829 | A = self.fake_gerrit.addFakeChange('org/project', 'featureA', 'A') |
| 5830 | A.addApproval('Code-Review', 2) |
| 5831 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5832 | self.waitUntilSettled() |
| 5833 | self.printHistory() |
| 5834 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5835 | 'SUCCESS') |
| 5836 | self.assertJobNotInHistory('ignore-branch') |
| 5837 | self.assertEqual(A.data['status'], 'MERGED') |
| 5838 | self.assertEqual(A.reported, 2, |
| 5839 | "A should report start and success") |
| 5840 | self.assertIn('gate', A.messages[1], |
| 5841 | "A should transit gate") |