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', |
| 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', |
| 1556 | 'project-test2']) |
| 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 | |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1576 | @simple_layout('layouts/autohold.yaml') |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1577 | def test_autohold_ignores_aborted_jobs(self): |
| 1578 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1579 | self.gearman_server.port) |
| 1580 | self.addCleanup(client.shutdown) |
| 1581 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1582 | "reason text", 1) |
| 1583 | self.assertTrue(r) |
| 1584 | |
| 1585 | self.executor_server.hold_jobs_in_build = True |
| 1586 | |
| 1587 | # Create a change that will have its job aborted |
| 1588 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1589 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1590 | self.waitUntilSettled() |
| 1591 | |
| 1592 | # Creating new patchset on change A will abort A,1's job because |
| 1593 | # a new patchset arrived replacing A,1 with A,2. |
| 1594 | A.addPatchset() |
| 1595 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1596 | |
| 1597 | self.waitUntilSettled() |
| 1598 | self.executor_server.hold_jobs_in_build = False |
| 1599 | self.executor_server.release() |
| 1600 | self.waitUntilSettled() |
| 1601 | |
| 1602 | self.assertEqual(A.data['status'], 'NEW') |
| 1603 | # Note only the successful job for A,2 will report as we don't |
| 1604 | # report aborted builds for old patchsets. |
| 1605 | self.assertEqual(A.reported, 1) |
| 1606 | # A,1 project-test2 |
| 1607 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1608 | # A,2 project-test2 |
| 1609 | self.assertEqual(self.history[1].result, 'SUCCESS') |
| 1610 | |
| 1611 | # Check nodepool for a held node |
| 1612 | held_node = None |
| 1613 | for node in self.fake_nodepool.getNodes(): |
| 1614 | if node['state'] == zuul.model.STATE_HOLD: |
| 1615 | held_node = node |
| 1616 | break |
| 1617 | self.assertIsNone(held_node) |
| 1618 | |
| 1619 | @simple_layout('layouts/autohold.yaml') |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1620 | def test_autohold_list(self): |
| 1621 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1622 | self.gearman_server.port) |
| 1623 | self.addCleanup(client.shutdown) |
| 1624 | |
| 1625 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1626 | "reason text", 1) |
| 1627 | self.assertTrue(r) |
| 1628 | |
| 1629 | autohold_requests = client.autohold_list() |
| 1630 | self.assertNotEqual({}, autohold_requests) |
| 1631 | self.assertEqual(1, len(autohold_requests.keys())) |
| 1632 | |
| 1633 | # The single dict key should be a CSV string value |
| 1634 | key = list(autohold_requests.keys())[0] |
| 1635 | tenant, project, job = key.split(',') |
| 1636 | |
| 1637 | self.assertEqual('tenant-one', tenant) |
| 1638 | self.assertIn('org/project', project) |
| 1639 | self.assertEqual('project-test2', job) |
| 1640 | |
| 1641 | # Note: the value is converted from set to list by json. |
| 1642 | self.assertEqual([1, "reason text"], autohold_requests[key]) |
| 1643 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1644 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1645 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1646 | # This particular test does a large amount of merges and needs a little |
| 1647 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1648 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1649 | "test that dependent changes behind dequeued changes work" |
| 1650 | # This complicated test is a reproduction of a real life bug |
| 1651 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1652 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1653 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1654 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1655 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1656 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1657 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1658 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1659 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1660 | D.setDependsOn(C, 1) |
| 1661 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1662 | A.addApproval('Code-Review', 2) |
| 1663 | B.addApproval('Code-Review', 2) |
| 1664 | C.addApproval('Code-Review', 2) |
| 1665 | D.addApproval('Code-Review', 2) |
| 1666 | E.addApproval('Code-Review', 2) |
| 1667 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1668 | |
| 1669 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1670 | |
| 1671 | # Change object re-use in the gerrit trigger is hidden if |
| 1672 | # changes are added in quick succession; waiting makes it more |
| 1673 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1674 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1675 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1676 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1677 | self.waitUntilSettled() |
| 1678 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1679 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1680 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1681 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1682 | self.waitUntilSettled() |
| 1683 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1684 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1685 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1686 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1687 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1688 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1689 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1690 | self.fake_gerrit.addEvent(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1691 | self.waitUntilSettled() |
| 1692 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1693 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1694 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1695 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1696 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1697 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1698 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1699 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1700 | self.waitUntilSettled() |
| 1701 | |
| 1702 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1703 | |
| 1704 | # Grab pointers to the jobs we want to release before |
| 1705 | # releasing any, because list indexes may change as |
| 1706 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1707 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1708 | a.release() |
| 1709 | b.release() |
| 1710 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1711 | self.waitUntilSettled() |
| 1712 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1713 | self.executor_server.hold_jobs_in_build = False |
| 1714 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1715 | self.waitUntilSettled() |
| 1716 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1717 | self.assertEqual(A.data['status'], 'NEW') |
| 1718 | self.assertEqual(B.data['status'], 'MERGED') |
| 1719 | self.assertEqual(C.data['status'], 'MERGED') |
| 1720 | self.assertEqual(D.data['status'], 'MERGED') |
| 1721 | self.assertEqual(E.data['status'], 'MERGED') |
| 1722 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1723 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1724 | self.assertEqual(A.reported, 2) |
| 1725 | self.assertEqual(B.reported, 2) |
| 1726 | self.assertEqual(C.reported, 2) |
| 1727 | self.assertEqual(D.reported, 2) |
| 1728 | self.assertEqual(E.reported, 2) |
| 1729 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1730 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1731 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1732 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1733 | |
| 1734 | def test_merger_repack(self): |
| 1735 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1736 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1737 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1738 | A.addApproval('Code-Review', 2) |
| 1739 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1740 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1741 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1742 | 'SUCCESS') |
| 1743 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1744 | 'SUCCESS') |
| 1745 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1746 | 'SUCCESS') |
| 1747 | self.assertEqual(A.data['status'], 'MERGED') |
| 1748 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1749 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1750 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1751 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1752 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1753 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1754 | if os.path.exists(path): |
| 1755 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1756 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1757 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1758 | if os.path.exists(path): |
| 1759 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1760 | |
| 1761 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1762 | A.addApproval('Code-Review', 2) |
| 1763 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1764 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1765 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1766 | 'SUCCESS') |
| 1767 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1768 | 'SUCCESS') |
| 1769 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1770 | 'SUCCESS') |
| 1771 | self.assertEqual(A.data['status'], 'MERGED') |
| 1772 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1773 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1774 | def test_merger_repack_large_change(self): |
| 1775 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1776 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1777 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1778 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1779 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1780 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1781 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1782 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1783 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1784 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1785 | # TODOv3(jeblair): add hostname to upstream root |
| 1786 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1787 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1788 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1789 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1790 | if os.path.exists(path): |
| 1791 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1792 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1793 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1794 | if os.path.exists(path): |
| 1795 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1796 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1797 | A.addApproval('Code-Review', 2) |
| 1798 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1799 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1800 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1801 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1802 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1803 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1804 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1805 | 'SUCCESS') |
| 1806 | self.assertEqual(A.data['status'], 'MERGED') |
| 1807 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1808 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1809 | def test_new_patchset_dequeues_old(self): |
| 1810 | "Test that a new patchset causes the old to be dequeued" |
| 1811 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1812 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1813 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1814 | M.setMerged() |
| 1815 | |
| 1816 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1817 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1818 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1819 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1820 | A.addApproval('Code-Review', 2) |
| 1821 | B.addApproval('Code-Review', 2) |
| 1822 | C.addApproval('Code-Review', 2) |
| 1823 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1824 | |
| 1825 | C.setDependsOn(B, 1) |
| 1826 | B.setDependsOn(A, 1) |
| 1827 | A.setDependsOn(M, 1) |
| 1828 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1829 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1830 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1831 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1832 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1833 | self.waitUntilSettled() |
| 1834 | |
| 1835 | B.addPatchset() |
| 1836 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1837 | self.waitUntilSettled() |
| 1838 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1839 | self.executor_server.hold_jobs_in_build = False |
| 1840 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1841 | self.waitUntilSettled() |
| 1842 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1843 | self.assertEqual(A.data['status'], 'MERGED') |
| 1844 | self.assertEqual(A.reported, 2) |
| 1845 | self.assertEqual(B.data['status'], 'NEW') |
| 1846 | self.assertEqual(B.reported, 2) |
| 1847 | self.assertEqual(C.data['status'], 'NEW') |
| 1848 | self.assertEqual(C.reported, 2) |
| 1849 | self.assertEqual(D.data['status'], 'MERGED') |
| 1850 | self.assertEqual(D.reported, 2) |
| 1851 | 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] | 1852 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1853 | def test_new_patchset_check(self): |
| 1854 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1855 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1856 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1857 | |
| 1858 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1859 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1860 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1861 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1862 | |
| 1863 | # Add two git-dependent changes |
| 1864 | B.setDependsOn(A, 1) |
| 1865 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1866 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1867 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1868 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1869 | |
| 1870 | # A live item, and a non-live/live pair |
| 1871 | items = check_pipeline.getAllItems() |
| 1872 | self.assertEqual(len(items), 3) |
| 1873 | |
| 1874 | self.assertEqual(items[0].change.number, '1') |
| 1875 | self.assertEqual(items[0].change.patchset, '1') |
| 1876 | self.assertFalse(items[0].live) |
| 1877 | |
| 1878 | self.assertEqual(items[1].change.number, '2') |
| 1879 | self.assertEqual(items[1].change.patchset, '1') |
| 1880 | self.assertTrue(items[1].live) |
| 1881 | |
| 1882 | self.assertEqual(items[2].change.number, '1') |
| 1883 | self.assertEqual(items[2].change.patchset, '1') |
| 1884 | self.assertTrue(items[2].live) |
| 1885 | |
| 1886 | # Add a new patchset to A |
| 1887 | A.addPatchset() |
| 1888 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1889 | self.waitUntilSettled() |
| 1890 | |
| 1891 | # The live copy of A,1 should be gone, but the non-live and B |
| 1892 | # should continue, and we should have a new A,2 |
| 1893 | items = check_pipeline.getAllItems() |
| 1894 | self.assertEqual(len(items), 3) |
| 1895 | |
| 1896 | self.assertEqual(items[0].change.number, '1') |
| 1897 | self.assertEqual(items[0].change.patchset, '1') |
| 1898 | self.assertFalse(items[0].live) |
| 1899 | |
| 1900 | self.assertEqual(items[1].change.number, '2') |
| 1901 | self.assertEqual(items[1].change.patchset, '1') |
| 1902 | self.assertTrue(items[1].live) |
| 1903 | |
| 1904 | self.assertEqual(items[2].change.number, '1') |
| 1905 | self.assertEqual(items[2].change.patchset, '2') |
| 1906 | self.assertTrue(items[2].live) |
| 1907 | |
| 1908 | # Add a new patchset to B |
| 1909 | B.addPatchset() |
| 1910 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1911 | self.waitUntilSettled() |
| 1912 | |
| 1913 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1914 | # but we should have a new B,2 (still based on A,1) |
| 1915 | items = check_pipeline.getAllItems() |
| 1916 | self.assertEqual(len(items), 3) |
| 1917 | |
| 1918 | self.assertEqual(items[0].change.number, '1') |
| 1919 | self.assertEqual(items[0].change.patchset, '2') |
| 1920 | self.assertTrue(items[0].live) |
| 1921 | |
| 1922 | self.assertEqual(items[1].change.number, '1') |
| 1923 | self.assertEqual(items[1].change.patchset, '1') |
| 1924 | self.assertFalse(items[1].live) |
| 1925 | |
| 1926 | self.assertEqual(items[2].change.number, '2') |
| 1927 | self.assertEqual(items[2].change.patchset, '2') |
| 1928 | self.assertTrue(items[2].live) |
| 1929 | |
| 1930 | self.builds[0].release() |
| 1931 | self.waitUntilSettled() |
| 1932 | self.builds[0].release() |
| 1933 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1934 | self.executor_server.hold_jobs_in_build = False |
| 1935 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1936 | self.waitUntilSettled() |
| 1937 | |
| 1938 | self.assertEqual(A.reported, 1) |
| 1939 | self.assertEqual(B.reported, 1) |
| 1940 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1941 | self.assertEqual(self.history[0].changes, '1,1') |
| 1942 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1943 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1944 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1945 | self.assertEqual(self.history[2].changes, '1,2') |
| 1946 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1947 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1948 | |
| 1949 | def test_abandoned_gate(self): |
| 1950 | "Test that an abandoned change is dequeued from gate" |
| 1951 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1952 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1953 | |
| 1954 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1955 | A.addApproval('Code-Review', 2) |
| 1956 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1957 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1958 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1959 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1960 | |
| 1961 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1962 | self.waitUntilSettled() |
| 1963 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1964 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1965 | self.waitUntilSettled() |
| 1966 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1967 | self.assertBuilds([]) |
| 1968 | self.assertHistory([ |
| 1969 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1970 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1971 | self.assertEqual(A.reported, 1, |
| 1972 | "Abandoned gate change should report only start") |
| 1973 | |
| 1974 | def test_abandoned_check(self): |
| 1975 | "Test that an abandoned change is dequeued from check" |
| 1976 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1977 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1978 | |
| 1979 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1980 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1981 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1982 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1983 | |
| 1984 | # Add two git-dependent changes |
| 1985 | B.setDependsOn(A, 1) |
| 1986 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1987 | self.waitUntilSettled() |
| 1988 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1989 | self.waitUntilSettled() |
| 1990 | # A live item, and a non-live/live pair |
| 1991 | items = check_pipeline.getAllItems() |
| 1992 | self.assertEqual(len(items), 3) |
| 1993 | |
| 1994 | self.assertEqual(items[0].change.number, '1') |
| 1995 | self.assertFalse(items[0].live) |
| 1996 | |
| 1997 | self.assertEqual(items[1].change.number, '2') |
| 1998 | self.assertTrue(items[1].live) |
| 1999 | |
| 2000 | self.assertEqual(items[2].change.number, '1') |
| 2001 | self.assertTrue(items[2].live) |
| 2002 | |
| 2003 | # Abandon A |
| 2004 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2005 | self.waitUntilSettled() |
| 2006 | |
| 2007 | # The live copy of A should be gone, but the non-live and B |
| 2008 | # should continue |
| 2009 | items = check_pipeline.getAllItems() |
| 2010 | self.assertEqual(len(items), 2) |
| 2011 | |
| 2012 | self.assertEqual(items[0].change.number, '1') |
| 2013 | self.assertFalse(items[0].live) |
| 2014 | |
| 2015 | self.assertEqual(items[1].change.number, '2') |
| 2016 | self.assertTrue(items[1].live) |
| 2017 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2018 | self.executor_server.hold_jobs_in_build = False |
| 2019 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2020 | self.waitUntilSettled() |
| 2021 | |
| 2022 | self.assertEqual(len(self.history), 4) |
| 2023 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 2024 | 'Build should have been aborted') |
| 2025 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2026 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 2027 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2028 | def test_abandoned_not_timer(self): |
| 2029 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2030 | # This test can not use simple_layout because it must start |
| 2031 | # with a configuration which does not include a |
| 2032 | # timer-triggered job so that we have an opportunity to set |
| 2033 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2034 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2035 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2036 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2037 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2038 | # The pipeline triggers every second, so we should have seen |
| 2039 | # several by now. |
| 2040 | time.sleep(5) |
| 2041 | self.waitUntilSettled() |
| 2042 | # Stop queuing timer triggered jobs so that the assertions |
| 2043 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 2044 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2045 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2046 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 2047 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2048 | # If APScheduler is in mid-event when we remove the job, we |
| 2049 | # can end up with one more event firing, so give it an extra |
| 2050 | # second to settle. |
| 2051 | time.sleep(1) |
| 2052 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2053 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2054 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2055 | |
| 2056 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2057 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2058 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2059 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2060 | |
| 2061 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2062 | self.waitUntilSettled() |
| 2063 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2064 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2065 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2066 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2067 | self.waitUntilSettled() |
| 2068 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2069 | def test_new_patchset_dequeues_old_on_head(self): |
| 2070 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 2071 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2072 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2073 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 2074 | M.setMerged() |
| 2075 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2076 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2077 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2078 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2079 | A.addApproval('Code-Review', 2) |
| 2080 | B.addApproval('Code-Review', 2) |
| 2081 | C.addApproval('Code-Review', 2) |
| 2082 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2083 | |
| 2084 | C.setDependsOn(B, 1) |
| 2085 | B.setDependsOn(A, 1) |
| 2086 | A.setDependsOn(M, 1) |
| 2087 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2088 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2089 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2090 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2091 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2092 | self.waitUntilSettled() |
| 2093 | |
| 2094 | A.addPatchset() |
| 2095 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2096 | self.waitUntilSettled() |
| 2097 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2098 | self.executor_server.hold_jobs_in_build = False |
| 2099 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2100 | self.waitUntilSettled() |
| 2101 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2102 | self.assertEqual(A.data['status'], 'NEW') |
| 2103 | self.assertEqual(A.reported, 2) |
| 2104 | self.assertEqual(B.data['status'], 'NEW') |
| 2105 | self.assertEqual(B.reported, 2) |
| 2106 | self.assertEqual(C.data['status'], 'NEW') |
| 2107 | self.assertEqual(C.reported, 2) |
| 2108 | self.assertEqual(D.data['status'], 'MERGED') |
| 2109 | self.assertEqual(D.reported, 2) |
| 2110 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2111 | |
| 2112 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2113 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2114 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2115 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2116 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2117 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2118 | A.addApproval('Code-Review', 2) |
| 2119 | B.addApproval('Code-Review', 2) |
| 2120 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2121 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2122 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2123 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2124 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2125 | self.waitUntilSettled() |
| 2126 | |
| 2127 | B.addPatchset() |
| 2128 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2129 | self.waitUntilSettled() |
| 2130 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2131 | self.executor_server.hold_jobs_in_build = False |
| 2132 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2133 | self.waitUntilSettled() |
| 2134 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2135 | self.assertEqual(A.data['status'], 'MERGED') |
| 2136 | self.assertEqual(A.reported, 2) |
| 2137 | self.assertEqual(B.data['status'], 'NEW') |
| 2138 | self.assertEqual(B.reported, 2) |
| 2139 | self.assertEqual(C.data['status'], 'MERGED') |
| 2140 | self.assertEqual(C.reported, 2) |
| 2141 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2142 | |
| 2143 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2144 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2145 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2146 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2147 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2148 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2149 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2150 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2151 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2152 | self.waitUntilSettled() |
| 2153 | |
| 2154 | B.addPatchset() |
| 2155 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2156 | self.waitUntilSettled() |
| 2157 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2158 | self.executor_server.hold_jobs_in_build = False |
| 2159 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2160 | self.waitUntilSettled() |
| 2161 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2162 | self.assertEqual(A.data['status'], 'NEW') |
| 2163 | self.assertEqual(A.reported, 1) |
| 2164 | self.assertEqual(B.data['status'], 'NEW') |
| 2165 | self.assertEqual(B.reported, 1) |
| 2166 | self.assertEqual(C.data['status'], 'NEW') |
| 2167 | self.assertEqual(C.reported, 1) |
| 2168 | self.assertEqual(len(self.history), 10) |
| 2169 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2170 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2171 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2172 | def test_noop_job(self): |
| 2173 | "Test that the internal noop job works" |
| 2174 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2175 | A.addApproval('Code-Review', 2) |
| 2176 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2177 | self.waitUntilSettled() |
| 2178 | |
| 2179 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2180 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2181 | self.assertEqual(len(self.history), 0) |
| 2182 | self.assertEqual(A.data['status'], 'MERGED') |
| 2183 | self.assertEqual(A.reported, 2) |
| 2184 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2185 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2186 | def test_no_job_project(self): |
| 2187 | "Test that reports with no jobs don't get sent" |
| 2188 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2189 | 'master', 'A') |
| 2190 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2191 | self.waitUntilSettled() |
| 2192 | |
| 2193 | # Change wasn't reported to |
| 2194 | self.assertEqual(A.reported, False) |
| 2195 | |
| 2196 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2197 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2198 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2199 | items = check_pipeline.getAllItems() |
| 2200 | self.assertEqual(len(items), 0) |
| 2201 | |
| 2202 | self.assertEqual(len(self.history), 0) |
| 2203 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2204 | def test_zuul_refs(self): |
| 2205 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2206 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2207 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2208 | M1.setMerged() |
| 2209 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2210 | M2.setMerged() |
| 2211 | |
| 2212 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2213 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2214 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2215 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2216 | A.addApproval('Code-Review', 2) |
| 2217 | B.addApproval('Code-Review', 2) |
| 2218 | C.addApproval('Code-Review', 2) |
| 2219 | D.addApproval('Code-Review', 2) |
| 2220 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2221 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2222 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2223 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2224 | |
| 2225 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2226 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2227 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2228 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2229 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2230 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2231 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2232 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2233 | self.waitUntilSettled() |
| 2234 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2235 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2236 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2237 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2238 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2239 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2240 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2241 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2242 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2243 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2244 | d_build = x |
| 2245 | if a_build and b_build and c_build and d_build: |
| 2246 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2247 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2248 | # should have a, not b, and should not be in project2 |
| 2249 | self.assertTrue(a_build.hasChanges(A)) |
| 2250 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2251 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2252 | # should have a and b, and should not be in project2 |
| 2253 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2254 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2255 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2256 | # should have a and b in 1, c in 2 |
| 2257 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2258 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2259 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2260 | # should have a and b in 1, c and d in 2 |
| 2261 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2262 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2263 | self.executor_server.hold_jobs_in_build = False |
| 2264 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2265 | self.waitUntilSettled() |
| 2266 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2267 | self.assertEqual(A.data['status'], 'MERGED') |
| 2268 | self.assertEqual(A.reported, 2) |
| 2269 | self.assertEqual(B.data['status'], 'MERGED') |
| 2270 | self.assertEqual(B.reported, 2) |
| 2271 | self.assertEqual(C.data['status'], 'MERGED') |
| 2272 | self.assertEqual(C.reported, 2) |
| 2273 | self.assertEqual(D.data['status'], 'MERGED') |
| 2274 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2275 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2276 | def test_rerun_on_error(self): |
| 2277 | "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] | 2278 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2279 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2280 | A.addApproval('Code-Review', 2) |
| 2281 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2282 | self.waitUntilSettled() |
| 2283 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2284 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2285 | self.executor_server.hold_jobs_in_build = False |
| 2286 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2287 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2288 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2289 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2290 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2291 | def test_statsd(self): |
| 2292 | "Test each of the statsd methods used in the scheduler" |
James E. Blair | ded241e | 2017-10-10 13:22:40 -0700 | [diff] [blame] | 2293 | statsd = self.sched.statsd |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2294 | statsd.incr('test-incr') |
| 2295 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2296 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2297 | self.assertReportedStat('test-incr', '1|c') |
| 2298 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2299 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2300 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2301 | def test_stuck_job_cleanup(self): |
| 2302 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2303 | |
| 2304 | # 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] | 2305 | self.gearman_server.hold_jobs_in_queue = True |
| 2306 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2307 | A.addApproval('Code-Review', 2) |
| 2308 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2309 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2310 | # 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] | 2311 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2312 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2313 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2314 | self.sched.reconfigure(self.config) |
| 2315 | self.waitUntilSettled() |
| 2316 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2317 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2318 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2319 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2320 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2321 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2322 | |
| 2323 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2324 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2325 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2326 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2327 | def test_file_head(self): |
| 2328 | # This is a regression test for an observed bug. A change |
| 2329 | # with a file named "HEAD" in the root directory of the repo |
| 2330 | # was processed by a merger. It then was unable to reset the |
| 2331 | # repo because of: |
| 2332 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2333 | # with exit code 128 |
| 2334 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2335 | # and filename |
| 2336 | # Use '--' to separate filenames from revisions' |
| 2337 | |
| 2338 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2339 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2340 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2341 | |
| 2342 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2343 | self.waitUntilSettled() |
| 2344 | |
| 2345 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2346 | self.waitUntilSettled() |
| 2347 | |
| 2348 | self.assertIn('Build succeeded', A.messages[0]) |
| 2349 | self.assertIn('Build succeeded', B.messages[0]) |
| 2350 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2351 | def test_file_jobs(self): |
| 2352 | "Test that file jobs run only when appropriate" |
| 2353 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2354 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2355 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2356 | A.addApproval('Code-Review', 2) |
| 2357 | B.addApproval('Code-Review', 2) |
| 2358 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2359 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2360 | self.waitUntilSettled() |
| 2361 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2362 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2363 | if x.name == 'project-testfile'] |
| 2364 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2365 | self.assertEqual(len(testfile_jobs), 1) |
| 2366 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2367 | self.assertEqual(A.data['status'], 'MERGED') |
| 2368 | self.assertEqual(A.reported, 2) |
| 2369 | self.assertEqual(B.data['status'], 'MERGED') |
| 2370 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2371 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2372 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2373 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2374 | if should_skip: |
| 2375 | files = {'ignoreme': 'ignored\n'} |
| 2376 | else: |
| 2377 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2378 | |
| 2379 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2380 | 'master', |
| 2381 | 'test irrelevant-files', |
| 2382 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2383 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2384 | self.waitUntilSettled() |
| 2385 | |
| 2386 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2387 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2388 | |
| 2389 | if should_skip: |
| 2390 | self.assertEqual([], tested_change_ids) |
| 2391 | else: |
| 2392 | self.assertIn(change.data['number'], tested_change_ids) |
| 2393 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2394 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2395 | def test_irrelevant_files_match_skips_job(self): |
| 2396 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2397 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2398 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2399 | def test_irrelevant_files_no_match_runs_job(self): |
| 2400 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2401 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2402 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2403 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2404 | files = {'ignoreme': 'ignored\n'} |
| 2405 | |
| 2406 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2407 | 'master', |
| 2408 | 'test irrelevant-files', |
| 2409 | files=files) |
| 2410 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2411 | self.waitUntilSettled() |
| 2412 | |
| 2413 | run_jobs = set([build.name for build in self.history]) |
| 2414 | |
| 2415 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2416 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2417 | |
James E. Blair | af8b208 | 2017-10-03 15:38:27 -0700 | [diff] [blame] | 2418 | @simple_layout('layouts/job-vars.yaml') |
| 2419 | def test_inherited_job_variables(self): |
| 2420 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2421 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2422 | self.waitUntilSettled() |
| 2423 | self.assertHistory([ |
| 2424 | dict(name='parentjob', result='SUCCESS'), |
| 2425 | dict(name='child1', result='SUCCESS'), |
| 2426 | dict(name='child2', result='SUCCESS'), |
| 2427 | dict(name='child3', result='SUCCESS'), |
| 2428 | ], ordered=False) |
| 2429 | j = self.getJobFromHistory('parentjob') |
| 2430 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2431 | self.assertEqual(j.parameters['vars']['override'], 0) |
| 2432 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2433 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2434 | self.assertFalse('child1' in j.parameters['vars']) |
| 2435 | self.assertFalse('child2' in j.parameters['vars']) |
| 2436 | self.assertFalse('child3' in j.parameters['vars']) |
| 2437 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2438 | 'org/project0'])) |
| 2439 | j = self.getJobFromHistory('child1') |
| 2440 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2441 | self.assertEqual(j.parameters['vars']['override'], 1) |
| 2442 | self.assertEqual(j.parameters['vars']['child1override'], 1) |
| 2443 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2444 | self.assertEqual(j.parameters['vars']['child1'], 1) |
| 2445 | self.assertFalse('child2' in j.parameters['vars']) |
| 2446 | self.assertFalse('child3' in j.parameters['vars']) |
| 2447 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2448 | 'org/project1'])) |
| 2449 | j = self.getJobFromHistory('child2') |
| 2450 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2451 | self.assertEqual(j.parameters['vars']['override'], 2) |
| 2452 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2453 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2454 | self.assertFalse('child1' in j.parameters['vars']) |
| 2455 | self.assertEqual(j.parameters['vars']['child2'], 2) |
| 2456 | self.assertFalse('child3' in j.parameters['vars']) |
| 2457 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2458 | 'org/project2'])) |
| 2459 | j = self.getJobFromHistory('child3') |
| 2460 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2461 | self.assertEqual(j.parameters['vars']['override'], 3) |
| 2462 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2463 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2464 | self.assertFalse('child1' in j.parameters['vars']) |
| 2465 | self.assertFalse('child2' in j.parameters['vars']) |
| 2466 | self.assertEqual(j.parameters['vars']['child3'], 3) |
| 2467 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2468 | 'org/project3'])) |
| 2469 | |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2470 | @simple_layout('layouts/job-variants.yaml') |
| 2471 | def test_job_branch_variants(self): |
| 2472 | self.create_branch('org/project', 'stable/diablo') |
| 2473 | self.create_branch('org/project', 'stable/essex') |
| 2474 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2475 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2476 | self.waitUntilSettled() |
| 2477 | |
| 2478 | B = self.fake_gerrit.addFakeChange('org/project', 'stable/diablo', 'B') |
| 2479 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2480 | self.waitUntilSettled() |
| 2481 | |
| 2482 | C = self.fake_gerrit.addFakeChange('org/project', 'stable/essex', 'C') |
| 2483 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2484 | self.waitUntilSettled() |
| 2485 | self.assertHistory([ |
| 2486 | dict(name='python27', result='SUCCESS'), |
| 2487 | dict(name='python27', result='SUCCESS'), |
| 2488 | dict(name='python27', result='SUCCESS'), |
| 2489 | ]) |
| 2490 | |
| 2491 | p = self.history[0].parameters |
| 2492 | self.assertEqual(p['timeout'], 40) |
| 2493 | self.assertEqual(len(p['nodes']), 1) |
| 2494 | self.assertEqual(p['nodes'][0]['label'], 'new') |
| 2495 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2496 | ['base-pre', 'py27-pre']) |
| 2497 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2498 | ['py27-post-a', 'py27-post-b', 'base-post']) |
| 2499 | self.assertEqual([x['path'] for x in p['playbooks']], |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 2500 | ['playbooks/python27.yaml']) |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2501 | |
| 2502 | p = self.history[1].parameters |
| 2503 | self.assertEqual(p['timeout'], 50) |
| 2504 | self.assertEqual(len(p['nodes']), 1) |
| 2505 | self.assertEqual(p['nodes'][0]['label'], 'old') |
| 2506 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2507 | ['base-pre', 'py27-pre', 'py27-diablo-pre']) |
| 2508 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2509 | ['py27-diablo-post', 'py27-post-a', 'py27-post-b', |
| 2510 | 'base-post']) |
| 2511 | self.assertEqual([x['path'] for x in p['playbooks']], |
| 2512 | ['py27-diablo']) |
| 2513 | |
| 2514 | p = self.history[2].parameters |
| 2515 | self.assertEqual(p['timeout'], 40) |
| 2516 | self.assertEqual(len(p['nodes']), 1) |
| 2517 | self.assertEqual(p['nodes'][0]['label'], 'new') |
| 2518 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2519 | ['base-pre', 'py27-pre', 'py27-essex-pre']) |
| 2520 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2521 | ['py27-essex-post', 'py27-post-a', 'py27-post-b', |
| 2522 | 'base-post']) |
| 2523 | self.assertEqual([x['path'] for x in p['playbooks']], |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 2524 | ['playbooks/python27.yaml']) |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2525 | |
James E. Blair | 0029267 | 2017-10-26 15:29:39 -0700 | [diff] [blame] | 2526 | @simple_layout("layouts/no-run.yaml") |
| 2527 | def test_job_without_run(self): |
| 2528 | "Test that a job without a run playbook errors" |
| 2529 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2530 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2531 | self.waitUntilSettled() |
| 2532 | self.assertIn('Job base does not specify a run playbook', |
| 2533 | A.messages[-1]) |
| 2534 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2535 | def test_queue_names(self): |
| 2536 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2537 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2538 | (trusted, project1) = tenant.getProject('org/project1') |
| 2539 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2540 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2541 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2542 | self.assertEqual(q1.name, 'integrated') |
| 2543 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2544 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2545 | def test_queue_precedence(self): |
| 2546 | "Test that queue precedence works" |
| 2547 | |
| 2548 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2549 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2550 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2551 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2552 | A.addApproval('Code-Review', 2) |
| 2553 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2554 | |
| 2555 | self.waitUntilSettled() |
| 2556 | self.gearman_server.hold_jobs_in_queue = False |
| 2557 | self.gearman_server.release() |
| 2558 | self.waitUntilSettled() |
| 2559 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2560 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2561 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2562 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2563 | self.waitUntilSettled() |
| 2564 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2565 | self.log.debug(self.history) |
| 2566 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2567 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2568 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2569 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2570 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2571 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2572 | |
James E. Blair | 419a867 | 2017-10-18 14:48:25 -0700 | [diff] [blame] | 2573 | def test_reconfigure_merge(self): |
| 2574 | """Test that two reconfigure events are merged""" |
| 2575 | |
| 2576 | tenant = self.sched.abide.tenants['tenant-one'] |
| 2577 | (trusted, project) = tenant.getProject('org/project') |
| 2578 | |
| 2579 | self.sched.run_handler_lock.acquire() |
| 2580 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2581 | |
| 2582 | self.sched.reconfigureTenant(tenant, project) |
| 2583 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2584 | |
| 2585 | self.sched.reconfigureTenant(tenant, project) |
| 2586 | # The second event should have been combined with the first |
| 2587 | # so we should still only have one entry. |
| 2588 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2589 | |
| 2590 | self.sched.run_handler_lock.release() |
| 2591 | self.waitUntilSettled() |
| 2592 | |
| 2593 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2594 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2595 | def test_live_reconfiguration(self): |
| 2596 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2597 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2598 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2599 | A.addApproval('Code-Review', 2) |
| 2600 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2601 | self.waitUntilSettled() |
| 2602 | |
| 2603 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2604 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2605 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2606 | self.executor_server.hold_jobs_in_build = False |
| 2607 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2608 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2609 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2610 | 'SUCCESS') |
| 2611 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2612 | 'SUCCESS') |
| 2613 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2614 | 'SUCCESS') |
| 2615 | self.assertEqual(A.data['status'], 'MERGED') |
| 2616 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2617 | |
James E. Blair | 027ba99 | 2017-09-20 13:48:32 -0700 | [diff] [blame] | 2618 | def test_live_reconfiguration_abort(self): |
| 2619 | # Raise an exception during reconfiguration and verify we |
| 2620 | # still function. |
| 2621 | self.executor_server.hold_jobs_in_build = True |
| 2622 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2623 | A.addApproval('Code-Review', 2) |
| 2624 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2625 | self.waitUntilSettled() |
| 2626 | |
| 2627 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2628 | pipeline = tenant.layout.pipelines['gate'] |
| 2629 | change = pipeline.getAllItems()[0].change |
| 2630 | # Set this to an invalid value to cause an exception during |
| 2631 | # reconfiguration. |
| 2632 | change.branch = None |
| 2633 | |
| 2634 | self.sched.reconfigure(self.config) |
| 2635 | self.waitUntilSettled() |
| 2636 | |
| 2637 | self.executor_server.hold_jobs_in_build = False |
| 2638 | self.executor_server.release() |
| 2639 | |
| 2640 | self.waitUntilSettled() |
| 2641 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2642 | 'ABORTED') |
| 2643 | self.assertEqual(A.data['status'], 'NEW') |
| 2644 | # The final report fails because of the invalid value set above. |
| 2645 | self.assertEqual(A.reported, 1) |
| 2646 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2647 | def test_live_reconfiguration_merge_conflict(self): |
| 2648 | # A real-world bug: a change in a gate queue has a merge |
| 2649 | # conflict and a job is added to its project while it's |
| 2650 | # sitting in the queue. The job gets added to the change and |
| 2651 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2652 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2653 | |
| 2654 | # This change is fine. It's here to stop the queue long |
| 2655 | # enough for the next change to be subject to the |
| 2656 | # reconfiguration, as well as to provide a conflict for the |
| 2657 | # next change. This change will succeed and merge. |
| 2658 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2659 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2660 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2661 | |
| 2662 | # This change will be in merge conflict. During the |
| 2663 | # reconfiguration, we will add a job. We want to make sure |
| 2664 | # that doesn't cause it to get stuck. |
| 2665 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2666 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2667 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2668 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2669 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2670 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2671 | |
| 2672 | self.waitUntilSettled() |
| 2673 | |
| 2674 | # No jobs have run yet |
| 2675 | self.assertEqual(A.data['status'], 'NEW') |
| 2676 | self.assertEqual(A.reported, 1) |
| 2677 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2678 | self.assertEqual(len(self.history), 0) |
| 2679 | |
| 2680 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2681 | self.commitConfigUpdate('common-config', |
| 2682 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2683 | self.sched.reconfigure(self.config) |
| 2684 | self.waitUntilSettled() |
| 2685 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2686 | self.executor_server.hold_jobs_in_build = False |
| 2687 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2688 | self.waitUntilSettled() |
| 2689 | |
| 2690 | self.assertEqual(A.data['status'], 'MERGED') |
| 2691 | self.assertEqual(A.reported, 2) |
| 2692 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2693 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2694 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2695 | 'SUCCESS') |
| 2696 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2697 | 'SUCCESS') |
| 2698 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2699 | 'SUCCESS') |
| 2700 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2701 | 'SUCCESS') |
| 2702 | self.assertEqual(len(self.history), 4) |
| 2703 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2704 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2705 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2706 | # that tests a job added to a job tree with a failed root does |
| 2707 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2708 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2709 | |
| 2710 | # This change is fine. It's here to stop the queue long |
| 2711 | # enough for the next change to be subject to the |
| 2712 | # reconfiguration. This change will succeed and merge. |
| 2713 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2714 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2715 | A.addApproval('Code-Review', 2) |
| 2716 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2717 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2718 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2719 | self.waitUntilSettled() |
| 2720 | |
| 2721 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2722 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2723 | B.addApproval('Code-Review', 2) |
| 2724 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2725 | self.waitUntilSettled() |
| 2726 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2727 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2728 | self.waitUntilSettled() |
| 2729 | |
| 2730 | # Both -merge jobs have run, but no others. |
| 2731 | self.assertEqual(A.data['status'], 'NEW') |
| 2732 | self.assertEqual(A.reported, 1) |
| 2733 | self.assertEqual(B.data['status'], 'NEW') |
| 2734 | self.assertEqual(B.reported, 1) |
| 2735 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2736 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2737 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2738 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2739 | self.assertEqual(len(self.history), 2) |
| 2740 | |
| 2741 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2742 | self.commitConfigUpdate('common-config', |
| 2743 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2744 | self.sched.reconfigure(self.config) |
| 2745 | self.waitUntilSettled() |
| 2746 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2747 | self.executor_server.hold_jobs_in_build = False |
| 2748 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2749 | self.waitUntilSettled() |
| 2750 | |
| 2751 | self.assertEqual(A.data['status'], 'MERGED') |
| 2752 | self.assertEqual(A.reported, 2) |
| 2753 | self.assertEqual(B.data['status'], 'NEW') |
| 2754 | self.assertEqual(B.reported, 2) |
| 2755 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2756 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2757 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2758 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2759 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2760 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2761 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2762 | self.assertEqual(len(self.history), 5) |
| 2763 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2764 | def test_live_reconfiguration_failed_job(self): |
| 2765 | # Test that a change with a removed failing job does not |
| 2766 | # disrupt reconfiguration. If a change has a failed job and |
| 2767 | # that job is removed during a reconfiguration, we observed a |
| 2768 | # bug where the code to re-set build statuses would run on |
| 2769 | # that build and raise an exception because the job no longer |
| 2770 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2771 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2772 | |
| 2773 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2774 | |
| 2775 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2776 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2777 | |
| 2778 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2779 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2780 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2781 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2782 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2783 | self.waitUntilSettled() |
| 2784 | |
| 2785 | self.assertEqual(A.data['status'], 'NEW') |
| 2786 | self.assertEqual(A.reported, 0) |
| 2787 | |
| 2788 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2789 | 'SUCCESS') |
| 2790 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2791 | 'FAILURE') |
| 2792 | self.assertEqual(len(self.history), 2) |
| 2793 | |
| 2794 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2795 | self.commitConfigUpdate('common-config', |
| 2796 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2797 | self.sched.reconfigure(self.config) |
| 2798 | self.waitUntilSettled() |
| 2799 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2800 | self.executor_server.hold_jobs_in_build = False |
| 2801 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2802 | self.waitUntilSettled() |
| 2803 | |
| 2804 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2805 | 'SUCCESS') |
| 2806 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2807 | 'SUCCESS') |
| 2808 | self.assertEqual(len(self.history), 4) |
| 2809 | |
| 2810 | self.assertEqual(A.data['status'], 'NEW') |
| 2811 | self.assertEqual(A.reported, 1) |
| 2812 | self.assertIn('Build succeeded', A.messages[0]) |
| 2813 | # Ensure the removed job was not included in the report. |
| 2814 | self.assertNotIn('project-test1', A.messages[0]) |
| 2815 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2816 | def test_live_reconfiguration_shared_queue(self): |
| 2817 | # Test that a change with a failing job which was removed from |
| 2818 | # this project but otherwise still exists in the system does |
| 2819 | # not disrupt reconfiguration. |
| 2820 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2821 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2822 | |
| 2823 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2824 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2825 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2826 | |
| 2827 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2828 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2829 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2830 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2831 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2832 | self.waitUntilSettled() |
| 2833 | |
| 2834 | self.assertEqual(A.data['status'], 'NEW') |
| 2835 | self.assertEqual(A.reported, 0) |
| 2836 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2837 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2838 | 'SUCCESS') |
| 2839 | self.assertEqual(self.getJobFromHistory( |
| 2840 | 'project1-project2-integration').result, 'FAILURE') |
| 2841 | self.assertEqual(len(self.history), 2) |
| 2842 | |
| 2843 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2844 | self.commitConfigUpdate( |
| 2845 | 'common-config', |
| 2846 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2847 | self.sched.reconfigure(self.config) |
| 2848 | self.waitUntilSettled() |
| 2849 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2850 | self.executor_server.hold_jobs_in_build = False |
| 2851 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2852 | self.waitUntilSettled() |
| 2853 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2854 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2855 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2856 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2857 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2858 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2859 | 'SUCCESS') |
| 2860 | self.assertEqual(self.getJobFromHistory( |
| 2861 | 'project1-project2-integration').result, 'FAILURE') |
| 2862 | self.assertEqual(len(self.history), 4) |
| 2863 | |
| 2864 | self.assertEqual(A.data['status'], 'NEW') |
| 2865 | self.assertEqual(A.reported, 1) |
| 2866 | self.assertIn('Build succeeded', A.messages[0]) |
| 2867 | # Ensure the removed job was not included in the report. |
| 2868 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2869 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2870 | def test_double_live_reconfiguration_shared_queue(self): |
| 2871 | # This was a real-world regression. A change is added to |
| 2872 | # gate; a reconfigure happens, a second change which depends |
| 2873 | # on the first is added, and a second reconfiguration happens. |
| 2874 | # Ensure that both changes merge. |
| 2875 | |
| 2876 | # A failure may indicate incorrect caching or cleaning up of |
| 2877 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2878 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2879 | |
| 2880 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2881 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2882 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2883 | A.addApproval('Code-Review', 2) |
| 2884 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2885 | |
| 2886 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2887 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2888 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2889 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2890 | self.waitUntilSettled() |
| 2891 | |
| 2892 | # Reconfigure (with only one change in the pipeline). |
| 2893 | self.sched.reconfigure(self.config) |
| 2894 | self.waitUntilSettled() |
| 2895 | |
| 2896 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2897 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2898 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2899 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2900 | self.waitUntilSettled() |
| 2901 | |
| 2902 | # Reconfigure (with both in the pipeline). |
| 2903 | self.sched.reconfigure(self.config) |
| 2904 | self.waitUntilSettled() |
| 2905 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2906 | self.executor_server.hold_jobs_in_build = False |
| 2907 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2908 | self.waitUntilSettled() |
| 2909 | |
| 2910 | self.assertEqual(len(self.history), 8) |
| 2911 | |
| 2912 | self.assertEqual(A.data['status'], 'MERGED') |
| 2913 | self.assertEqual(A.reported, 2) |
| 2914 | self.assertEqual(B.data['status'], 'MERGED') |
| 2915 | self.assertEqual(B.reported, 2) |
| 2916 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2917 | def test_live_reconfiguration_del_project(self): |
| 2918 | # Test project deletion from layout |
| 2919 | # while changes are enqueued |
| 2920 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2921 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2922 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2923 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2924 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2925 | |
| 2926 | # A Depends-On: B |
| 2927 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2928 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2929 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2930 | |
| 2931 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2932 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2933 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2934 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2935 | self.waitUntilSettled() |
| 2936 | self.assertEqual(len(self.builds), 5) |
| 2937 | |
| 2938 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2939 | self.commitConfigUpdate( |
| 2940 | 'common-config', |
| 2941 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2942 | self.sched.reconfigure(self.config) |
| 2943 | self.waitUntilSettled() |
| 2944 | |
| 2945 | # Builds for C aborted, builds for A succeed, |
| 2946 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2947 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2948 | self.assertEqual(job_c.changes, '3,1') |
| 2949 | self.assertEqual(job_c.result, 'ABORTED') |
| 2950 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2951 | self.executor_server.hold_jobs_in_build = False |
| 2952 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2953 | self.waitUntilSettled() |
| 2954 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2955 | self.assertEqual( |
| 2956 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2957 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2958 | |
| 2959 | self.assertEqual(A.data['status'], 'NEW') |
| 2960 | self.assertEqual(B.data['status'], 'NEW') |
| 2961 | self.assertEqual(C.data['status'], 'NEW') |
| 2962 | self.assertEqual(A.reported, 1) |
| 2963 | self.assertEqual(B.reported, 0) |
| 2964 | self.assertEqual(C.reported, 0) |
| 2965 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2966 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2967 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2968 | self.assertIn('Build succeeded', A.messages[0]) |
| 2969 | |
James E. Blair | 872738f | 2017-10-31 16:40:36 -0700 | [diff] [blame] | 2970 | @simple_layout("layouts/reconfigure-failed-head.yaml") |
| 2971 | def test_live_reconfiguration_failed_change_at_head(self): |
| 2972 | # Test that if we reconfigure with a failed change at head, |
| 2973 | # that the change behind it isn't reparented onto it. |
| 2974 | |
| 2975 | self.executor_server.hold_jobs_in_build = True |
| 2976 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2977 | A.addApproval('Code-Review', 2) |
| 2978 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2979 | B.addApproval('Code-Review', 2) |
| 2980 | |
| 2981 | self.executor_server.failJob('job1', A) |
| 2982 | |
| 2983 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2984 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2985 | |
| 2986 | self.waitUntilSettled() |
| 2987 | |
| 2988 | self.assertBuilds([ |
| 2989 | dict(name='job1', changes='1,1'), |
| 2990 | dict(name='job2', changes='1,1'), |
| 2991 | dict(name='job1', changes='1,1 2,1'), |
| 2992 | dict(name='job2', changes='1,1 2,1'), |
| 2993 | ]) |
| 2994 | |
| 2995 | self.release(self.builds[0]) |
| 2996 | self.waitUntilSettled() |
| 2997 | |
| 2998 | self.assertBuilds([ |
| 2999 | dict(name='job2', changes='1,1'), |
| 3000 | dict(name='job1', changes='2,1'), |
| 3001 | dict(name='job2', changes='2,1'), |
| 3002 | ]) |
| 3003 | |
| 3004 | # Unordered history comparison because the aborts can finish |
| 3005 | # in any order. |
| 3006 | self.assertHistory([ |
| 3007 | dict(name='job1', result='FAILURE', changes='1,1'), |
| 3008 | dict(name='job1', result='ABORTED', changes='1,1 2,1'), |
| 3009 | dict(name='job2', result='ABORTED', changes='1,1 2,1'), |
| 3010 | ], ordered=False) |
| 3011 | |
| 3012 | self.sched.reconfigure(self.config) |
| 3013 | self.waitUntilSettled() |
| 3014 | |
| 3015 | self.executor_server.hold_jobs_in_build = False |
| 3016 | self.executor_server.release() |
| 3017 | self.waitUntilSettled() |
| 3018 | |
| 3019 | self.assertBuilds([]) |
| 3020 | |
| 3021 | self.assertHistory([ |
| 3022 | dict(name='job1', result='FAILURE', changes='1,1'), |
| 3023 | dict(name='job1', result='ABORTED', changes='1,1 2,1'), |
| 3024 | dict(name='job2', result='ABORTED', changes='1,1 2,1'), |
| 3025 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3026 | dict(name='job1', result='SUCCESS', changes='2,1'), |
| 3027 | dict(name='job2', result='SUCCESS', changes='2,1'), |
| 3028 | ], ordered=False) |
| 3029 | self.assertEqual(A.data['status'], 'NEW') |
| 3030 | self.assertEqual(B.data['status'], 'MERGED') |
| 3031 | self.assertEqual(A.reported, 2) |
| 3032 | self.assertEqual(B.reported, 2) |
| 3033 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3034 | def test_delayed_repo_init(self): |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3035 | self.init_repo("org/new-project") |
Clint Byrum | 627ba36 | 2017-08-14 13:20:40 -0700 | [diff] [blame] | 3036 | files = {'README': ''} |
| 3037 | self.addCommitToRepo("org/new-project", 'Initial commit', |
| 3038 | files=files, tag='init') |
| 3039 | self.newTenantConfig('tenants/delayed-repo-init.yaml') |
| 3040 | self.commitConfigUpdate( |
| 3041 | 'common-config', |
| 3042 | 'layouts/delayed-repo-init.yaml') |
| 3043 | self.sched.reconfigure(self.config) |
| 3044 | self.waitUntilSettled() |
| 3045 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3046 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 3047 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3048 | A.addApproval('Code-Review', 2) |
| 3049 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3050 | self.waitUntilSettled() |
| 3051 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3052 | 'SUCCESS') |
| 3053 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3054 | 'SUCCESS') |
| 3055 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3056 | 'SUCCESS') |
| 3057 | self.assertEqual(A.data['status'], 'MERGED') |
| 3058 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3059 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 3060 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3061 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3062 | self.init_repo("org/delete-project") |
| 3063 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 3064 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3065 | A.addApproval('Code-Review', 2) |
| 3066 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3067 | self.waitUntilSettled() |
| 3068 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3069 | 'SUCCESS') |
| 3070 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3071 | 'SUCCESS') |
| 3072 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3073 | 'SUCCESS') |
| 3074 | self.assertEqual(A.data['status'], 'MERGED') |
| 3075 | self.assertEqual(A.reported, 2) |
| 3076 | |
| 3077 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 3078 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 3079 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 3080 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3081 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 3082 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3083 | |
| 3084 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 3085 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3086 | B.addApproval('Code-Review', 2) |
| 3087 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3088 | self.waitUntilSettled() |
| 3089 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3090 | 'SUCCESS') |
| 3091 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3092 | 'SUCCESS') |
| 3093 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3094 | 'SUCCESS') |
| 3095 | self.assertEqual(B.data['status'], 'MERGED') |
| 3096 | self.assertEqual(B.reported, 2) |
| 3097 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 3098 | @simple_layout('layouts/untrusted-secrets.yaml') |
| 3099 | def test_untrusted_secrets(self): |
| 3100 | "Test untrusted secrets" |
| 3101 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3102 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3103 | self.waitUntilSettled() |
| 3104 | |
| 3105 | self.assertHistory([]) |
| 3106 | self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") |
James E. Blair | 8eb564a | 2017-08-10 09:21:41 -0700 | [diff] [blame] | 3107 | self.assertIn('does not allow post-review job', |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 3108 | A.messages[0]) |
| 3109 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 3110 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3111 | def test_tags(self): |
| 3112 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3113 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3114 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3115 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3116 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3117 | self.waitUntilSettled() |
| 3118 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 3119 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3120 | |
| 3121 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3122 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3123 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3124 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3125 | |
| 3126 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3127 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3128 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3129 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3130 | def test_timer(self): |
| 3131 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3132 | # This test can not use simple_layout because it must start |
| 3133 | # with a configuration which does not include a |
| 3134 | # timer-triggered job so that we have an opportunity to set |
| 3135 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3136 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3137 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3138 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3139 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3140 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3141 | # The pipeline triggers every second, so we should have seen |
| 3142 | # several by now. |
| 3143 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3144 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3145 | |
| 3146 | self.assertEqual(len(self.builds), 2) |
| 3147 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3148 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3149 | # Stop queuing timer triggered jobs so that the assertions |
| 3150 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3151 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3152 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3153 | self.waitUntilSettled() |
| 3154 | # If APScheduler is in mid-event when we remove the job, we |
| 3155 | # can end up with one more event firing, so give it an extra |
| 3156 | # second to settle. |
| 3157 | time.sleep(1) |
| 3158 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3159 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3160 | self.waitUntilSettled() |
| 3161 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3162 | self.assertHistory([ |
| 3163 | dict(name='project-bitrot', result='SUCCESS', |
| 3164 | ref='refs/heads/master'), |
| 3165 | dict(name='project-bitrot', result='SUCCESS', |
| 3166 | ref='refs/heads/stable'), |
| 3167 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3168 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3169 | def test_idle(self): |
| 3170 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3171 | # This test can not use simple_layout because it must start |
| 3172 | # with a configuration which does not include a |
| 3173 | # timer-triggered job so that we have an opportunity to set |
| 3174 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3175 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3176 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3177 | for x in range(1, 3): |
| 3178 | # Test that timer triggers periodic jobs even across |
| 3179 | # layout config reloads. |
| 3180 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3181 | self.commitConfigUpdate('common-config', |
| 3182 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3183 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3184 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3185 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3186 | # The pipeline triggers every second, so we should have seen |
| 3187 | # several by now. |
| 3188 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3189 | |
| 3190 | # Stop queuing timer triggered jobs so that the assertions |
| 3191 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3192 | self.commitConfigUpdate('common-config', |
| 3193 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3194 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3195 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3196 | # If APScheduler is in mid-event when we remove the job, |
| 3197 | # we can end up with one more event firing, so give it an |
| 3198 | # extra second to settle. |
| 3199 | time.sleep(1) |
| 3200 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3201 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3202 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3203 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3204 | self.waitUntilSettled() |
| 3205 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3206 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3207 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3208 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3209 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3210 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3211 | self.waitUntilSettled() |
| 3212 | |
| 3213 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3214 | self.waitUntilSettled() |
| 3215 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3216 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3217 | |
| 3218 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3219 | # work on the knowledge of what the first message should be as |
| 3220 | # it is only configured to go to SMTP. |
| 3221 | |
| 3222 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3223 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3224 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3225 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3226 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3227 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3228 | |
| 3229 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3230 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3231 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3232 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3233 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3234 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3235 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3236 | def test_timer_smtp(self): |
| 3237 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3238 | # This test can not use simple_layout because it must start |
| 3239 | # with a configuration which does not include a |
| 3240 | # timer-triggered job so that we have an opportunity to set |
| 3241 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3242 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3243 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3244 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3245 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3246 | # The pipeline triggers every second, so we should have seen |
| 3247 | # several by now. |
| 3248 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3249 | self.waitUntilSettled() |
| 3250 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3251 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3252 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3253 | self.waitUntilSettled() |
| 3254 | self.assertEqual(len(self.history), 2) |
| 3255 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3256 | self.assertEqual(self.getJobFromHistory( |
| 3257 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3258 | self.assertEqual(self.getJobFromHistory( |
| 3259 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3260 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3261 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3262 | |
| 3263 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3264 | # work on the knowledge of what the first message should be as |
| 3265 | # it is only configured to go to SMTP. |
| 3266 | |
| 3267 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3268 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3269 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3270 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3271 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3272 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3273 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3274 | # Stop queuing timer triggered jobs and let any that may have |
| 3275 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3276 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3277 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3278 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3279 | # If APScheduler is in mid-event when we remove the job, we |
| 3280 | # can end up with one more event firing, so give it an extra |
| 3281 | # second to settle. |
| 3282 | time.sleep(1) |
| 3283 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3284 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3285 | self.waitUntilSettled() |
| 3286 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3287 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3288 | def test_timer_sshkey(self): |
| 3289 | "Test that a periodic job can setup SSH key authentication" |
| 3290 | self.worker.hold_jobs_in_build = True |
| 3291 | self.config.set('zuul', 'layout_config', |
| 3292 | 'tests/fixtures/layout-timer.yaml') |
| 3293 | self.sched.reconfigure(self.config) |
| 3294 | self.registerJobs() |
| 3295 | |
| 3296 | # The pipeline triggers every second, so we should have seen |
| 3297 | # several by now. |
| 3298 | time.sleep(5) |
| 3299 | self.waitUntilSettled() |
| 3300 | |
| 3301 | self.assertEqual(len(self.builds), 2) |
| 3302 | |
| 3303 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3304 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3305 | with open(ssh_wrapper) as f: |
| 3306 | ssh_wrapper_content = f.read() |
| 3307 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3308 | # In the unit tests Merger runs in the same process, |
| 3309 | # so we see its' environment variables |
| 3310 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3311 | |
| 3312 | self.worker.release('.*') |
| 3313 | self.waitUntilSettled() |
| 3314 | self.assertEqual(len(self.history), 2) |
| 3315 | |
| 3316 | self.assertEqual(self.getJobFromHistory( |
| 3317 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3318 | self.assertEqual(self.getJobFromHistory( |
| 3319 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3320 | |
| 3321 | # Stop queuing timer triggered jobs and let any that may have |
| 3322 | # queued through so that end of test assertions pass. |
| 3323 | self.config.set('zuul', 'layout_config', |
| 3324 | 'tests/fixtures/layout-no-timer.yaml') |
| 3325 | self.sched.reconfigure(self.config) |
| 3326 | self.registerJobs() |
| 3327 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3328 | # If APScheduler is in mid-event when we remove the job, we |
| 3329 | # can end up with one more event firing, so give it an extra |
| 3330 | # second to settle. |
| 3331 | time.sleep(1) |
| 3332 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3333 | self.worker.release('.*') |
| 3334 | self.waitUntilSettled() |
| 3335 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3336 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3337 | "Test that the RPC client can enqueue a change" |
| 3338 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3339 | A.addApproval('Code-Review', 2) |
| 3340 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3341 | |
| 3342 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3343 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3344 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3345 | r = client.enqueue(tenant='tenant-one', |
| 3346 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3347 | project='org/project', |
| 3348 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3349 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3350 | self.waitUntilSettled() |
| 3351 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3352 | 'SUCCESS') |
| 3353 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3354 | 'SUCCESS') |
| 3355 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3356 | 'SUCCESS') |
| 3357 | self.assertEqual(A.data['status'], 'MERGED') |
| 3358 | self.assertEqual(A.reported, 2) |
| 3359 | self.assertEqual(r, True) |
| 3360 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3361 | def test_client_enqueue_ref(self): |
| 3362 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3363 | p = "review.example.com/org/project" |
| 3364 | upstream = self.getUpstreamRepos([p]) |
| 3365 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3366 | A.setMerged() |
| 3367 | A_commit = str(upstream[p].commit('master')) |
| 3368 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3369 | |
| 3370 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3371 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3372 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3373 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3374 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3375 | pipeline='post', |
| 3376 | project='org/project', |
| 3377 | trigger='gerrit', |
| 3378 | ref='master', |
| 3379 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3380 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3381 | self.waitUntilSettled() |
| 3382 | job_names = [x.name for x in self.history] |
| 3383 | self.assertEqual(len(self.history), 1) |
| 3384 | self.assertIn('project-post', job_names) |
| 3385 | self.assertEqual(r, True) |
| 3386 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3387 | def test_client_enqueue_negative(self): |
| 3388 | "Test that the RPC client returns errors" |
| 3389 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3390 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3391 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3392 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3393 | "Invalid tenant"): |
| 3394 | r = client.enqueue(tenant='tenant-foo', |
| 3395 | pipeline='gate', |
| 3396 | project='org/project', |
| 3397 | trigger='gerrit', |
| 3398 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3399 | self.assertEqual(r, False) |
| 3400 | |
| 3401 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3402 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3403 | r = client.enqueue(tenant='tenant-one', |
| 3404 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3405 | project='project-does-not-exist', |
| 3406 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3407 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3408 | self.assertEqual(r, False) |
| 3409 | |
| 3410 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3411 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3412 | r = client.enqueue(tenant='tenant-one', |
| 3413 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3414 | project='org/project', |
| 3415 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3416 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3417 | self.assertEqual(r, False) |
| 3418 | |
| 3419 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3420 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3421 | r = client.enqueue(tenant='tenant-one', |
| 3422 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3423 | project='org/project', |
| 3424 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3425 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3426 | self.assertEqual(r, False) |
| 3427 | |
| 3428 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3429 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3430 | r = client.enqueue(tenant='tenant-one', |
| 3431 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3432 | project='org/project', |
| 3433 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3434 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3435 | self.assertEqual(r, False) |
| 3436 | |
| 3437 | self.waitUntilSettled() |
| 3438 | self.assertEqual(len(self.history), 0) |
| 3439 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3440 | |
| 3441 | def test_client_promote(self): |
| 3442 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3443 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3444 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3445 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3446 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3447 | A.addApproval('Code-Review', 2) |
| 3448 | B.addApproval('Code-Review', 2) |
| 3449 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3450 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3451 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3452 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3453 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3454 | |
| 3455 | self.waitUntilSettled() |
| 3456 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3457 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3458 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3459 | enqueue_times = {} |
| 3460 | for item in items: |
| 3461 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3462 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3463 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3464 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3465 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3466 | r = client.promote(tenant='tenant-one', |
| 3467 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3468 | change_ids=['2,1', '3,1']) |
| 3469 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3470 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3471 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3472 | for item in items: |
| 3473 | self.assertEqual( |
| 3474 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3475 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3476 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3477 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3478 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3479 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3480 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3481 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3482 | self.waitUntilSettled() |
| 3483 | |
| 3484 | self.assertEqual(len(self.builds), 6) |
| 3485 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3486 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3487 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3488 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3489 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3490 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3491 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3492 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3493 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3494 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3495 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3496 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3497 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3498 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3499 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3500 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3501 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3502 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3503 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3504 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3505 | self.waitUntilSettled() |
| 3506 | |
| 3507 | self.assertEqual(A.data['status'], 'MERGED') |
| 3508 | self.assertEqual(A.reported, 2) |
| 3509 | self.assertEqual(B.data['status'], 'MERGED') |
| 3510 | self.assertEqual(B.reported, 2) |
| 3511 | self.assertEqual(C.data['status'], 'MERGED') |
| 3512 | self.assertEqual(C.reported, 2) |
| 3513 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3514 | self.assertEqual(r, True) |
| 3515 | |
| 3516 | def test_client_promote_dependent(self): |
| 3517 | "Test that the RPC client can promote a dependent change" |
| 3518 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3519 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3520 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3521 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3522 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3523 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3524 | |
| 3525 | C.setDependsOn(B, 1) |
| 3526 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3527 | A.addApproval('Code-Review', 2) |
| 3528 | B.addApproval('Code-Review', 2) |
| 3529 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3530 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3531 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3532 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3533 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3534 | |
| 3535 | self.waitUntilSettled() |
| 3536 | |
| 3537 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3538 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3539 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3540 | r = client.promote(tenant='tenant-one', |
| 3541 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3542 | change_ids=['3,1']) |
| 3543 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3544 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3545 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3546 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3547 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3548 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3549 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3550 | self.waitUntilSettled() |
| 3551 | |
| 3552 | self.assertEqual(len(self.builds), 6) |
| 3553 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3554 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3555 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3556 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3557 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3558 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3559 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3560 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3561 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3562 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3563 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3564 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3565 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3566 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3567 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3568 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3569 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3570 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3571 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3572 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3573 | self.waitUntilSettled() |
| 3574 | |
| 3575 | self.assertEqual(A.data['status'], 'MERGED') |
| 3576 | self.assertEqual(A.reported, 2) |
| 3577 | self.assertEqual(B.data['status'], 'MERGED') |
| 3578 | self.assertEqual(B.reported, 2) |
| 3579 | self.assertEqual(C.data['status'], 'MERGED') |
| 3580 | self.assertEqual(C.reported, 2) |
| 3581 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3582 | self.assertEqual(r, True) |
| 3583 | |
| 3584 | def test_client_promote_negative(self): |
| 3585 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3586 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3587 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3588 | A.addApproval('Code-Review', 2) |
| 3589 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3590 | self.waitUntilSettled() |
| 3591 | |
| 3592 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3593 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3594 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3595 | |
| 3596 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3597 | r = client.promote(tenant='tenant-one', |
| 3598 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3599 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3600 | self.assertEqual(r, False) |
| 3601 | |
| 3602 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3603 | r = client.promote(tenant='tenant-one', |
| 3604 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3605 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3606 | self.assertEqual(r, False) |
| 3607 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3608 | self.executor_server.hold_jobs_in_build = False |
| 3609 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3610 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3611 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3612 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3613 | def test_queue_rate_limiting(self): |
| 3614 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3615 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3616 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3617 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3618 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3619 | |
| 3620 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3621 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3622 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3623 | A.addApproval('Code-Review', 2) |
| 3624 | B.addApproval('Code-Review', 2) |
| 3625 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3626 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3627 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3628 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3629 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3630 | self.waitUntilSettled() |
| 3631 | |
| 3632 | # Only A and B will have their merge jobs queued because |
| 3633 | # window is 2. |
| 3634 | self.assertEqual(len(self.builds), 2) |
| 3635 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3636 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3637 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3638 | # Release the merge jobs one at a time. |
| 3639 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3640 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3641 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3642 | self.waitUntilSettled() |
| 3643 | |
| 3644 | # Only A and B will have their test jobs queued because |
| 3645 | # window is 2. |
| 3646 | self.assertEqual(len(self.builds), 4) |
| 3647 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3648 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3649 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3650 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3651 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3652 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3653 | self.waitUntilSettled() |
| 3654 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3655 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3656 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3657 | # A failed so window is reduced by 1 to 1. |
| 3658 | self.assertEqual(queue.window, 1) |
| 3659 | self.assertEqual(queue.window_floor, 1) |
| 3660 | self.assertEqual(A.data['status'], 'NEW') |
| 3661 | |
| 3662 | # Gate is reset and only B's merge job is queued because |
| 3663 | # window shrunk to 1. |
| 3664 | self.assertEqual(len(self.builds), 1) |
| 3665 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3666 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3667 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3668 | self.waitUntilSettled() |
| 3669 | |
| 3670 | # Only B's test jobs are queued because window is still 1. |
| 3671 | self.assertEqual(len(self.builds), 2) |
| 3672 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3673 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3674 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3675 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3676 | self.waitUntilSettled() |
| 3677 | |
| 3678 | # B was successfully merged so window is increased to 2. |
| 3679 | self.assertEqual(queue.window, 2) |
| 3680 | self.assertEqual(queue.window_floor, 1) |
| 3681 | self.assertEqual(B.data['status'], 'MERGED') |
| 3682 | |
| 3683 | # Only C is left and its merge job is queued. |
| 3684 | self.assertEqual(len(self.builds), 1) |
| 3685 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3686 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3687 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3688 | self.waitUntilSettled() |
| 3689 | |
| 3690 | # After successful merge job the test jobs for C are queued. |
| 3691 | self.assertEqual(len(self.builds), 2) |
| 3692 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3693 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3694 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3695 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3696 | self.waitUntilSettled() |
| 3697 | |
| 3698 | # C successfully merged so window is bumped to 3. |
| 3699 | self.assertEqual(queue.window, 3) |
| 3700 | self.assertEqual(queue.window_floor, 1) |
| 3701 | self.assertEqual(C.data['status'], 'MERGED') |
| 3702 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3703 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3704 | def test_queue_rate_limiting_dependent(self): |
| 3705 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3706 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3707 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3708 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3709 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3710 | |
| 3711 | B.setDependsOn(A, 1) |
| 3712 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3713 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3714 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3715 | A.addApproval('Code-Review', 2) |
| 3716 | B.addApproval('Code-Review', 2) |
| 3717 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3718 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3719 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3720 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3721 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3722 | self.waitUntilSettled() |
| 3723 | |
| 3724 | # Only A and B will have their merge jobs queued because |
| 3725 | # window is 2. |
| 3726 | self.assertEqual(len(self.builds), 2) |
| 3727 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3728 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3729 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3730 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3731 | |
| 3732 | # Only A and B will have their test jobs queued because |
| 3733 | # window is 2. |
| 3734 | self.assertEqual(len(self.builds), 4) |
| 3735 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3736 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3737 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3738 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3739 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3740 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3741 | self.waitUntilSettled() |
| 3742 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3743 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3744 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3745 | # A failed so window is reduced by 1 to 1. |
| 3746 | self.assertEqual(queue.window, 1) |
| 3747 | self.assertEqual(queue.window_floor, 1) |
| 3748 | self.assertEqual(A.data['status'], 'NEW') |
| 3749 | self.assertEqual(B.data['status'], 'NEW') |
| 3750 | |
| 3751 | # Gate is reset and only C's merge job is queued because |
| 3752 | # window shrunk to 1 and A and B were dequeued. |
| 3753 | self.assertEqual(len(self.builds), 1) |
| 3754 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3755 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3756 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3757 | |
| 3758 | # Only C's test jobs are queued because window is still 1. |
| 3759 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3760 | builds = self.getSortedBuilds() |
| 3761 | self.assertEqual(builds[0].name, 'project-test1') |
| 3762 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3763 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3764 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3765 | self.waitUntilSettled() |
| 3766 | |
| 3767 | # C was successfully merged so window is increased to 2. |
| 3768 | self.assertEqual(queue.window, 2) |
| 3769 | self.assertEqual(queue.window_floor, 1) |
| 3770 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3771 | |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3772 | @simple_layout('layouts/reconfigure-window.yaml') |
| 3773 | def test_reconfigure_window_shrink(self): |
| 3774 | # Test the active window shrinking during reconfiguration |
| 3775 | self.executor_server.hold_jobs_in_build = True |
| 3776 | |
| 3777 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3778 | A.addApproval('Code-Review', 2) |
| 3779 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3780 | self.waitUntilSettled() |
| 3781 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3782 | B.addApproval('Code-Review', 2) |
| 3783 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3784 | self.waitUntilSettled() |
| 3785 | |
| 3786 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3787 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3788 | self.assertEqual(queue.window, 20) |
| 3789 | self.assertTrue(len(self.builds), 4) |
| 3790 | |
| 3791 | self.executor_server.release('job1') |
| 3792 | self.waitUntilSettled() |
| 3793 | self.commitConfigUpdate('org/common-config', |
| 3794 | 'layouts/reconfigure-window2.yaml') |
| 3795 | self.sched.reconfigure(self.config) |
| 3796 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3797 | queue = tenant.layout.pipelines['gate'].queues[0] |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3798 | # Even though we have configured a smaller window, the value |
| 3799 | # on the existing shared queue should be used. |
| 3800 | self.assertEqual(queue.window, 20) |
| 3801 | self.assertTrue(len(self.builds), 4) |
| 3802 | |
| 3803 | self.sched.reconfigure(self.config) |
| 3804 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3805 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3806 | self.assertEqual(queue.window, 20) |
| 3807 | self.assertTrue(len(self.builds), 4) |
| 3808 | |
| 3809 | self.executor_server.hold_jobs_in_build = False |
| 3810 | self.executor_server.release() |
| 3811 | |
| 3812 | self.waitUntilSettled() |
| 3813 | self.assertHistory([ |
| 3814 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 3815 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 3816 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3817 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 3818 | ], ordered=False) |
| 3819 | |
| 3820 | @simple_layout('layouts/reconfigure-window-fixed.yaml') |
| 3821 | def test_reconfigure_window_fixed(self): |
| 3822 | # Test the active window shrinking during reconfiguration |
| 3823 | self.executor_server.hold_jobs_in_build = True |
| 3824 | |
| 3825 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3826 | A.addApproval('Code-Review', 2) |
| 3827 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3828 | self.waitUntilSettled() |
| 3829 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3830 | B.addApproval('Code-Review', 2) |
| 3831 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3832 | self.waitUntilSettled() |
| 3833 | |
| 3834 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3835 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3836 | self.assertEqual(queue.window, 2) |
| 3837 | self.assertTrue(len(self.builds), 4) |
| 3838 | |
| 3839 | self.executor_server.release('job1') |
| 3840 | self.waitUntilSettled() |
| 3841 | self.commitConfigUpdate('org/common-config', |
| 3842 | 'layouts/reconfigure-window-fixed2.yaml') |
| 3843 | self.sched.reconfigure(self.config) |
| 3844 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3845 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3846 | # Because we have configured a static window, it should |
| 3847 | # be allowed to shrink on reconfiguration. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3848 | self.assertEqual(queue.window, 1) |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3849 | # B is outside the window, but still marked active until the |
| 3850 | # next pass through the queue processor, so its builds haven't |
| 3851 | # been canceled. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3852 | self.assertTrue(len(self.builds), 4) |
| 3853 | |
| 3854 | self.sched.reconfigure(self.config) |
| 3855 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3856 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3857 | self.assertEqual(queue.window, 1) |
| 3858 | # B's builds have been canceled now |
| 3859 | self.assertTrue(len(self.builds), 2) |
| 3860 | |
| 3861 | self.executor_server.hold_jobs_in_build = False |
| 3862 | self.executor_server.release() |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3863 | |
| 3864 | # B's builds will be restarted and will show up in our history |
| 3865 | # twice. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3866 | self.waitUntilSettled() |
| 3867 | self.assertHistory([ |
| 3868 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 3869 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 3870 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3871 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 3872 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 3873 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 3874 | ], ordered=False) |
| 3875 | |
| 3876 | @simple_layout('layouts/reconfigure-remove-add.yaml') |
| 3877 | def test_reconfigure_remove_add(self): |
| 3878 | # Test removing, then adding a job while in queue |
| 3879 | self.executor_server.hold_jobs_in_build = True |
| 3880 | |
| 3881 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3882 | A.addApproval('Code-Review', 2) |
| 3883 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3884 | self.waitUntilSettled() |
| 3885 | self.assertTrue(len(self.builds), 2) |
| 3886 | self.executor_server.release('job2') |
| 3887 | self.assertTrue(len(self.builds), 1) |
| 3888 | |
| 3889 | # Remove job2 |
| 3890 | self.commitConfigUpdate('org/common-config', |
| 3891 | 'layouts/reconfigure-remove-add2.yaml') |
| 3892 | self.sched.reconfigure(self.config) |
| 3893 | self.assertTrue(len(self.builds), 1) |
| 3894 | |
| 3895 | # Add job2 back |
| 3896 | self.commitConfigUpdate('org/common-config', |
| 3897 | 'layouts/reconfigure-remove-add.yaml') |
| 3898 | self.sched.reconfigure(self.config) |
| 3899 | self.assertTrue(len(self.builds), 2) |
| 3900 | |
| 3901 | self.executor_server.hold_jobs_in_build = False |
| 3902 | self.executor_server.release() |
| 3903 | # This will run new builds for B |
| 3904 | self.waitUntilSettled() |
| 3905 | self.assertHistory([ |
| 3906 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3907 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 3908 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3909 | ], ordered=False) |
| 3910 | |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3911 | def test_worker_update_metadata(self): |
| 3912 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3913 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3914 | |
| 3915 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3916 | A.addApproval('Code-Review', 2) |
| 3917 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3918 | self.waitUntilSettled() |
| 3919 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3920 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3921 | |
| 3922 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3923 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3924 | |
| 3925 | start = time.time() |
| 3926 | while True: |
| 3927 | if time.time() - start > 10: |
| 3928 | raise Exception("Timeout waiting for gearman server to report " |
| 3929 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3930 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3931 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3932 | break |
| 3933 | else: |
| 3934 | time.sleep(0) |
| 3935 | |
| 3936 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3937 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3938 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3939 | self.executor_server.hold_jobs_in_build = False |
| 3940 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3941 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3942 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3943 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3944 | def test_footer_message(self): |
| 3945 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3946 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3947 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3948 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3949 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3950 | self.waitUntilSettled() |
| 3951 | |
| 3952 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3953 | B.addApproval('Code-Review', 2) |
| 3954 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3955 | self.waitUntilSettled() |
| 3956 | |
| 3957 | self.assertEqual(2, len(self.smtp_messages)) |
| 3958 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3959 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3960 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3961 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3962 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3963 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3964 | For CI problems and help debugging, contact ci@example.org""" |
| 3965 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3966 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3967 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3968 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3969 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3970 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3971 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3972 | def test_unmanaged_project_start_message(self): |
| 3973 | "Test start reporting is not done for unmanaged projects." |
| 3974 | self.init_repo("org/project", tag='init') |
| 3975 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3976 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3977 | self.waitUntilSettled() |
| 3978 | |
| 3979 | self.assertEqual(0, len(A.messages)) |
| 3980 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3981 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3982 | def test_merge_failure_reporters(self): |
| 3983 | """Check that the config is set up correctly""" |
| 3984 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3985 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3986 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3987 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3988 | "dependencies was unable to be automatically merged with the " |
| 3989 | "current state of its repository. Please rebase the change and " |
| 3990 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3991 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3992 | self.assertEqual( |
| 3993 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3994 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3995 | |
| 3996 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3997 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3998 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3999 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4000 | |
| 4001 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4002 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 4003 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4004 | |
| 4005 | self.assertTrue( |
| 4006 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4007 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4008 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4009 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 4010 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4011 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4012 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4013 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4014 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4015 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4016 | gerritreporter.GerritReporter) and |
| 4017 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4018 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4019 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4020 | ) |
| 4021 | ) |
| 4022 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4023 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4024 | def test_merge_failure_reports(self): |
| 4025 | """Check that when a change fails to merge the correct message is sent |
| 4026 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4027 | self.updateConfigLayout( |
| 4028 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4029 | self.sched.reconfigure(self.config) |
| 4030 | self.registerJobs() |
| 4031 | |
| 4032 | # Check a test failure isn't reported to SMTP |
| 4033 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4034 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4035 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4036 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4037 | self.waitUntilSettled() |
| 4038 | |
| 4039 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 4040 | self.assertEqual(0, len(self.smtp_messages)) |
| 4041 | |
| 4042 | # Check a merge failure is reported to SMTP |
| 4043 | # B should be merged, but C will conflict with B |
| 4044 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4045 | B.addPatchset(['conflict']) |
| 4046 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4047 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4048 | B.addApproval('Code-Review', 2) |
| 4049 | C.addApproval('Code-Review', 2) |
| 4050 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4051 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4052 | self.waitUntilSettled() |
| 4053 | |
| 4054 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 4055 | self.assertEqual(1, len(self.smtp_messages)) |
| 4056 | self.assertEqual('The merge failed! For more information...', |
| 4057 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 4058 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4059 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 4060 | def test_default_merge_failure_reports(self): |
| 4061 | """Check that the default merge failure reports are correct.""" |
| 4062 | |
| 4063 | # A should report success, B should report merge failure. |
| 4064 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4065 | A.addPatchset(['conflict']) |
| 4066 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4067 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4068 | A.addApproval('Code-Review', 2) |
| 4069 | B.addApproval('Code-Review', 2) |
| 4070 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4071 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 4072 | self.waitUntilSettled() |
| 4073 | |
| 4074 | self.assertEqual(3, len(self.history)) # A jobs |
| 4075 | self.assertEqual(A.reported, 2) |
| 4076 | self.assertEqual(B.reported, 2) |
| 4077 | self.assertEqual(A.data['status'], 'MERGED') |
| 4078 | self.assertEqual(B.data['status'], 'NEW') |
| 4079 | self.assertIn('Build succeeded', A.messages[1]) |
| 4080 | self.assertIn('Merge Failed', B.messages[1]) |
| 4081 | self.assertIn('automatically merged', B.messages[1]) |
| 4082 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 4083 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 4084 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4085 | def test_client_get_running_jobs(self): |
| 4086 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4087 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4088 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4089 | A.addApproval('Code-Review', 2) |
| 4090 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4091 | self.waitUntilSettled() |
| 4092 | |
| 4093 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 4094 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 4095 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4096 | |
| 4097 | # Wait for gearman server to send the initial workData back to zuul |
| 4098 | start = time.time() |
| 4099 | while True: |
| 4100 | if time.time() - start > 10: |
| 4101 | raise Exception("Timeout waiting for gearman server to report " |
| 4102 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 4103 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4104 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4105 | break |
| 4106 | else: |
| 4107 | time.sleep(0) |
| 4108 | |
| 4109 | running_items = client.get_running_jobs() |
| 4110 | |
| 4111 | self.assertEqual(1, len(running_items)) |
| 4112 | running_item = running_items[0] |
| 4113 | self.assertEqual([], running_item['failing_reasons']) |
| 4114 | self.assertEqual([], running_item['items_behind']) |
James E. Blair | 0e4c791 | 2018-01-02 14:20:17 -0800 | [diff] [blame] | 4115 | self.assertEqual('https://review.example.com/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4116 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4117 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4118 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4119 | self.assertEqual(True, running_item['active']) |
| 4120 | self.assertEqual('1,1', running_item['id']) |
| 4121 | |
| 4122 | self.assertEqual(3, len(running_item['jobs'])) |
| 4123 | for job in running_item['jobs']: |
| 4124 | if job['name'] == 'project-merge': |
| 4125 | self.assertEqual('project-merge', job['name']) |
| 4126 | self.assertEqual('gate', job['pipeline']) |
| 4127 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4128 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 4129 | 'stream.html?uuid={uuid}&logfile=console.log' |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 4130 | .format(uuid=job['uuid']), job['url']) |
| 4131 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4132 | 'finger://{hostname}/{uuid}'.format( |
| 4133 | hostname=self.executor_server.hostname, |
| 4134 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 4135 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4136 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4137 | self.assertEqual(False, job['canceled']) |
| 4138 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4139 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4140 | self.assertEqual('gate', job['pipeline']) |
| 4141 | break |
| 4142 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4143 | self.executor_server.hold_jobs_in_build = False |
| 4144 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4145 | self.waitUntilSettled() |
| 4146 | |
| 4147 | running_items = client.get_running_jobs() |
| 4148 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4149 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 4150 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4151 | def test_nonvoting_pipeline(self): |
| 4152 | "Test that a nonvoting pipeline (experimental) can still report" |
| 4153 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 4154 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 4155 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4156 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4157 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 4158 | |
| 4159 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 4160 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 4161 | self.assertEqual( |
| 4162 | self.getJobFromHistory('experimental-project-test').result, |
| 4163 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4164 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4165 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4166 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4167 | def test_disable_at(self): |
| 4168 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4169 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4170 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4171 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4172 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4173 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4174 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4175 | |
| 4176 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4177 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4178 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4179 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4180 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4181 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4182 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4183 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4184 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4185 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4186 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4187 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4188 | self.executor_server.failJob('project-test1', A) |
| 4189 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4190 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4191 | self.executor_server.failJob('project-test1', D) |
| 4192 | self.executor_server.failJob('project-test1', E) |
| 4193 | self.executor_server.failJob('project-test1', F) |
| 4194 | self.executor_server.failJob('project-test1', G) |
| 4195 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4196 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4197 | self.executor_server.failJob('project-test1', J) |
| 4198 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4199 | |
| 4200 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4201 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4202 | self.waitUntilSettled() |
| 4203 | |
| 4204 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4205 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4206 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4207 | |
| 4208 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4209 | self.waitUntilSettled() |
| 4210 | |
| 4211 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4212 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4213 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4214 | |
| 4215 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4216 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4217 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4218 | self.waitUntilSettled() |
| 4219 | |
| 4220 | # We should be disabled now |
| 4221 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4222 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4223 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4224 | |
| 4225 | # We need to wait between each of these patches to make sure the |
| 4226 | # smtp messages come back in an expected order |
| 4227 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4228 | self.waitUntilSettled() |
| 4229 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4230 | self.waitUntilSettled() |
| 4231 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4232 | self.waitUntilSettled() |
| 4233 | |
| 4234 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4235 | # leaving a message on each change |
| 4236 | self.assertEqual(1, len(A.messages)) |
| 4237 | self.assertIn('Build failed.', A.messages[0]) |
| 4238 | self.assertEqual(1, len(B.messages)) |
| 4239 | self.assertIn('Build failed.', B.messages[0]) |
| 4240 | self.assertEqual(1, len(C.messages)) |
| 4241 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4242 | self.assertEqual(1, len(D.messages)) |
| 4243 | self.assertIn('Build failed.', D.messages[0]) |
| 4244 | self.assertEqual(1, len(E.messages)) |
| 4245 | self.assertIn('Build failed.', E.messages[0]) |
| 4246 | self.assertEqual(1, len(F.messages)) |
| 4247 | self.assertIn('Build failed.', F.messages[0]) |
| 4248 | |
| 4249 | # The last 3 (GHI) would have only reported via smtp. |
| 4250 | self.assertEqual(3, len(self.smtp_messages)) |
| 4251 | self.assertEqual(0, len(G.messages)) |
| 4252 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4253 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4254 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4255 | self.assertEqual(0, len(H.messages)) |
| 4256 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4257 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4258 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4259 | self.assertEqual(0, len(I.messages)) |
| 4260 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4261 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4262 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4263 | |
| 4264 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4265 | # comes out of disabled |
| 4266 | self.sched.reconfigure(self.config) |
| 4267 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4268 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4269 | |
| 4270 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4271 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4272 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4273 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4274 | |
| 4275 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4276 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4277 | self.waitUntilSettled() |
| 4278 | |
| 4279 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4280 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4281 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4282 | |
| 4283 | # J and K went back to gerrit |
| 4284 | self.assertEqual(1, len(J.messages)) |
| 4285 | self.assertIn('Build failed.', J.messages[0]) |
| 4286 | self.assertEqual(1, len(K.messages)) |
| 4287 | self.assertIn('Build failed.', K.messages[0]) |
| 4288 | # No more messages reported via smtp |
| 4289 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4290 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4291 | @simple_layout('layouts/one-job-project.yaml') |
| 4292 | def test_one_job_project(self): |
| 4293 | "Test that queueing works with one job" |
| 4294 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4295 | 'master', 'A') |
| 4296 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4297 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4298 | A.addApproval('Code-Review', 2) |
| 4299 | B.addApproval('Code-Review', 2) |
| 4300 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4301 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4302 | self.waitUntilSettled() |
| 4303 | |
| 4304 | self.assertEqual(A.data['status'], 'MERGED') |
| 4305 | self.assertEqual(A.reported, 2) |
| 4306 | self.assertEqual(B.data['status'], 'MERGED') |
| 4307 | self.assertEqual(B.reported, 2) |
| 4308 | |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4309 | def test_job_aborted(self): |
| 4310 | "Test that if a execute server aborts a job, it is run again" |
| 4311 | self.executor_server.hold_jobs_in_build = True |
| 4312 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4313 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4314 | self.waitUntilSettled() |
| 4315 | |
| 4316 | self.executor_server.release('.*-merge') |
| 4317 | self.waitUntilSettled() |
| 4318 | |
| 4319 | self.assertEqual(len(self.builds), 2) |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4320 | |
| 4321 | # first abort |
| 4322 | self.builds[0].aborted = True |
| 4323 | self.executor_server.release('.*-test*') |
| 4324 | self.waitUntilSettled() |
| 4325 | self.assertEqual(len(self.builds), 1) |
| 4326 | |
| 4327 | # second abort |
| 4328 | self.builds[0].aborted = True |
| 4329 | self.executor_server.release('.*-test*') |
| 4330 | self.waitUntilSettled() |
| 4331 | self.assertEqual(len(self.builds), 1) |
| 4332 | |
| 4333 | # third abort |
| 4334 | self.builds[0].aborted = True |
| 4335 | self.executor_server.release('.*-test*') |
| 4336 | self.waitUntilSettled() |
| 4337 | self.assertEqual(len(self.builds), 1) |
| 4338 | |
| 4339 | # fourth abort |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4340 | self.builds[0].aborted = True |
| 4341 | self.executor_server.release('.*-test*') |
| 4342 | self.waitUntilSettled() |
| 4343 | self.assertEqual(len(self.builds), 1) |
| 4344 | |
| 4345 | self.executor_server.hold_jobs_in_build = False |
| 4346 | self.executor_server.release() |
| 4347 | self.waitUntilSettled() |
| 4348 | |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4349 | self.assertEqual(len(self.history), 7) |
| 4350 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4351 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 4352 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4353 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4354 | "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] | 4355 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4356 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4357 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4358 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4359 | self.waitUntilSettled() |
| 4360 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4361 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4362 | self.waitUntilSettled() |
| 4363 | |
| 4364 | self.assertEqual(len(self.builds), 2) |
| 4365 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4366 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4367 | self.waitUntilSettled() |
| 4368 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4369 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4370 | self.assertEqual(len(self.builds), 1, |
| 4371 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4372 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4373 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4374 | self.waitUntilSettled() |
| 4375 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4376 | self.executor_server.hold_jobs_in_build = False |
| 4377 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4378 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4379 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4380 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4381 | self.assertEqual(A.reported, 1) |
| 4382 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4383 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4384 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4385 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4386 | |
| 4387 | self.fake_nodepool.paused = True |
| 4388 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4389 | A.addApproval('Code-Review', 2) |
| 4390 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4391 | self.waitUntilSettled() |
| 4392 | |
| 4393 | self.zk.client.stop() |
| 4394 | self.zk.client.start() |
| 4395 | self.fake_nodepool.paused = False |
| 4396 | self.waitUntilSettled() |
| 4397 | |
| 4398 | self.assertEqual(A.data['status'], 'MERGED') |
| 4399 | self.assertEqual(A.reported, 2) |
| 4400 | |
James E. Blair | b4bed1d | 2018-02-06 13:43:50 -0800 | [diff] [blame] | 4401 | def test_zookeeper_disconnect2(self): |
| 4402 | "Test that jobs are executed after a zookeeper disconnect" |
| 4403 | |
| 4404 | # This tests receiving a ZK disconnect between the arrival of |
| 4405 | # a fulfilled request and when we accept its nodes. |
| 4406 | self.fake_nodepool.paused = True |
| 4407 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4408 | A.addApproval('Code-Review', 2) |
| 4409 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4410 | self.waitUntilSettled() |
| 4411 | |
| 4412 | # We're waiting on the nodepool request to complete. Stop the |
| 4413 | # scheduler from processing further events, then fulfill the |
| 4414 | # nodepool request. |
| 4415 | self.sched.run_handler_lock.acquire() |
| 4416 | |
| 4417 | # Fulfill the nodepool request. |
| 4418 | self.fake_nodepool.paused = False |
| 4419 | requests = list(self.sched.nodepool.requests.values()) |
| 4420 | self.assertEqual(1, len(requests)) |
| 4421 | request = requests[0] |
| 4422 | for x in iterate_timeout(30, 'fulfill request'): |
| 4423 | if request.fulfilled: |
| 4424 | break |
| 4425 | id1 = request.id |
| 4426 | |
| 4427 | # The request is fulfilled, but the scheduler hasn't processed |
| 4428 | # it yet. Reconnect ZK. |
| 4429 | self.zk.client.stop() |
| 4430 | self.zk.client.start() |
| 4431 | |
| 4432 | # Allow the scheduler to continue and process the (now |
| 4433 | # out-of-date) notification that nodes are ready. |
| 4434 | self.sched.run_handler_lock.release() |
| 4435 | |
| 4436 | # It should resubmit the request, once it's fulfilled, we can |
| 4437 | # wait for it to run jobs and settle. |
| 4438 | for x in iterate_timeout(30, 'fulfill request'): |
| 4439 | if request.fulfilled: |
| 4440 | break |
| 4441 | self.waitUntilSettled() |
| 4442 | |
| 4443 | id2 = request.id |
| 4444 | self.assertEqual(A.data['status'], 'MERGED') |
| 4445 | self.assertEqual(A.reported, 2) |
| 4446 | # Make sure it was resubmitted (the id's should be different). |
| 4447 | self.assertNotEqual(id1, id2) |
| 4448 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4449 | def test_nodepool_failure(self): |
| 4450 | "Test that jobs are reported after a nodepool failure" |
| 4451 | |
| 4452 | self.fake_nodepool.paused = True |
| 4453 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4454 | A.addApproval('Code-Review', 2) |
| 4455 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4456 | self.waitUntilSettled() |
| 4457 | |
| 4458 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4459 | self.fake_nodepool.addFailRequest(req) |
| 4460 | |
| 4461 | self.fake_nodepool.paused = False |
| 4462 | self.waitUntilSettled() |
| 4463 | |
| 4464 | self.assertEqual(A.data['status'], 'NEW') |
| 4465 | self.assertEqual(A.reported, 2) |
| 4466 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4467 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4468 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4469 | |
Monty Taylor | 6dc5bc1 | 2017-09-29 15:47:31 -0500 | [diff] [blame] | 4470 | def test_nodepool_priority(self): |
| 4471 | "Test that nodes are requested at the correct priority" |
| 4472 | |
| 4473 | self.fake_nodepool.paused = True |
| 4474 | |
| 4475 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4476 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4477 | |
| 4478 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4479 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4480 | |
| 4481 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4482 | C.addApproval('Code-Review', 2) |
| 4483 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 4484 | |
| 4485 | self.waitUntilSettled() |
| 4486 | |
| 4487 | reqs = self.fake_nodepool.getNodeRequests() |
| 4488 | |
| 4489 | # The requests come back sorted by oid. Since we have three requests |
| 4490 | # for the three changes each with a different priority. |
| 4491 | # Also they get a serial number based on order they were received |
| 4492 | # so the number on the endof the oid should map to order submitted. |
| 4493 | |
| 4494 | # * gate first - high priority - change C |
| 4495 | self.assertEqual(reqs[0]['_oid'], '100-0000000002') |
| 4496 | self.assertEqual(reqs[0]['node_types'], ['label1']) |
| 4497 | # * check second - normal priority - change B |
| 4498 | self.assertEqual(reqs[1]['_oid'], '200-0000000001') |
| 4499 | self.assertEqual(reqs[1]['node_types'], ['label1']) |
| 4500 | # * post third - low priority - change A |
| 4501 | # additionally, the post job defined uses an ubuntu-xenial node, |
| 4502 | # so we include that check just as an extra verification |
| 4503 | self.assertEqual(reqs[2]['_oid'], '300-0000000000') |
| 4504 | self.assertEqual(reqs[2]['node_types'], ['ubuntu-xenial']) |
| 4505 | |
| 4506 | self.fake_nodepool.paused = False |
| 4507 | self.waitUntilSettled() |
| 4508 | |
James E. Blair | fceaf41 | 2017-09-29 13:44:57 -0700 | [diff] [blame] | 4509 | @simple_layout('layouts/multiple-templates.yaml') |
| 4510 | def test_multiple_project_templates(self): |
| 4511 | # Test that applying multiple project templates to a project |
| 4512 | # doesn't alter them when used for a second project. |
| 4513 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4514 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4515 | self.waitUntilSettled() |
| 4516 | |
| 4517 | build = self.getJobFromHistory('py27') |
| 4518 | self.assertEqual(build.parameters['zuul']['jobtags'], []) |
| 4519 | |
James E. Blair | 29c7700 | 2017-10-05 14:56:35 -0700 | [diff] [blame] | 4520 | def test_pending_merge_in_reconfig(self): |
| 4521 | # Test that if we are waiting for an outstanding merge on |
| 4522 | # reconfiguration that we continue to do so. |
| 4523 | self.gearman_server.hold_merge_jobs_in_queue = True |
| 4524 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4525 | A.setMerged() |
| 4526 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4527 | self.waitUntilSettled() |
| 4528 | # Reconfigure while we still have an outstanding merge job |
| 4529 | self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'], |
| 4530 | None) |
| 4531 | self.waitUntilSettled() |
| 4532 | # Verify the merge job is still running and that the item is |
| 4533 | # in the pipeline |
| 4534 | self.assertEqual(len(self.sched.merger.jobs), 1) |
| 4535 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4536 | pipeline = tenant.layout.pipelines['post'] |
| 4537 | self.assertEqual(len(pipeline.getAllItems()), 1) |
| 4538 | self.gearman_server.hold_merge_jobs_in_queue = False |
| 4539 | self.gearman_server.release() |
| 4540 | self.waitUntilSettled() |
| 4541 | |
James E. Blair | c32a835 | 2017-10-11 16:27:50 -0700 | [diff] [blame] | 4542 | @simple_layout('layouts/parent-matchers.yaml') |
| 4543 | def test_parent_matchers(self): |
| 4544 | "Test that if a job's parent does not match, the job does not run" |
| 4545 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4546 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4547 | self.waitUntilSettled() |
| 4548 | |
| 4549 | self.assertHistory([]) |
| 4550 | |
| 4551 | files = {'foo.txt': ''} |
| 4552 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B', |
| 4553 | files=files) |
| 4554 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4555 | self.waitUntilSettled() |
| 4556 | |
| 4557 | files = {'bar.txt': ''} |
| 4558 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C', |
| 4559 | files=files) |
| 4560 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4561 | self.waitUntilSettled() |
| 4562 | |
| 4563 | files = {'foo.txt': '', 'bar.txt': ''} |
| 4564 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D', |
| 4565 | files=files) |
| 4566 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4567 | self.waitUntilSettled() |
| 4568 | |
| 4569 | self.assertHistory([ |
| 4570 | dict(name='child-job', result='SUCCESS', changes='2,1'), |
| 4571 | dict(name='child-job', result='SUCCESS', changes='3,1'), |
| 4572 | dict(name='child-job', result='SUCCESS', changes='4,1'), |
| 4573 | ]) |
| 4574 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4575 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4576 | class TestExecutor(ZuulTestCase): |
| 4577 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4578 | |
| 4579 | def assertFinalState(self): |
| 4580 | # In this test, we expect to shut down in a non-final state, |
| 4581 | # so skip these checks. |
| 4582 | pass |
| 4583 | |
| 4584 | def assertCleanShutdown(self): |
| 4585 | self.log.debug("Assert clean shutdown") |
| 4586 | |
| 4587 | # After shutdown, make sure no jobs are running |
| 4588 | self.assertEqual({}, self.executor_server.job_workers) |
| 4589 | |
| 4590 | # Make sure that git.Repo objects have been garbage collected. |
| 4591 | repos = [] |
| 4592 | gc.collect() |
| 4593 | for obj in gc.get_objects(): |
| 4594 | if isinstance(obj, git.Repo): |
| 4595 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4596 | repos.append(obj) |
| 4597 | self.assertEqual(len(repos), 0) |
| 4598 | |
| 4599 | def test_executor_shutdown(self): |
| 4600 | "Test that the executor can shut down with jobs running" |
| 4601 | |
| 4602 | self.executor_server.hold_jobs_in_build = True |
| 4603 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4604 | A.addApproval('Code-Review', 2) |
| 4605 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4606 | self.waitUntilSettled() |
| 4607 | |
| 4608 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4609 | class TestDependencyGraph(ZuulTestCase): |
| 4610 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4611 | |
| 4612 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4613 | "Test a job in a dependency graph is queued only once" |
| 4614 | # Job dependencies, starting with A |
| 4615 | # A |
| 4616 | # / \ |
| 4617 | # B C |
| 4618 | # / \ / \ |
| 4619 | # D F E |
| 4620 | # | |
| 4621 | # G |
| 4622 | |
| 4623 | self.executor_server.hold_jobs_in_build = True |
| 4624 | change = self.fake_gerrit.addFakeChange( |
| 4625 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4626 | change.addApproval('Code-Review', 2) |
| 4627 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4628 | |
| 4629 | self.waitUntilSettled() |
| 4630 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4631 | |
| 4632 | self.executor_server.release('A') |
| 4633 | self.waitUntilSettled() |
| 4634 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4635 | |
| 4636 | self.executor_server.release('B') |
| 4637 | self.waitUntilSettled() |
| 4638 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4639 | |
| 4640 | self.executor_server.release('D') |
| 4641 | self.waitUntilSettled() |
| 4642 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4643 | |
| 4644 | self.executor_server.release('C') |
| 4645 | self.waitUntilSettled() |
| 4646 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4647 | |
| 4648 | self.executor_server.release('F') |
| 4649 | self.waitUntilSettled() |
| 4650 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4651 | |
| 4652 | self.executor_server.release('G') |
| 4653 | self.waitUntilSettled() |
| 4654 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4655 | |
| 4656 | self.executor_server.release('E') |
| 4657 | self.waitUntilSettled() |
| 4658 | self.assertEqual(len(self.builds), 0) |
| 4659 | |
| 4660 | self.executor_server.hold_jobs_in_build = False |
| 4661 | self.executor_server.release() |
| 4662 | self.waitUntilSettled() |
| 4663 | |
| 4664 | self.assertEqual(len(self.builds), 0) |
| 4665 | self.assertEqual(len(self.history), 7) |
| 4666 | |
| 4667 | self.assertEqual(change.data['status'], 'MERGED') |
| 4668 | self.assertEqual(change.reported, 2) |
| 4669 | |
| 4670 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4671 | "Test that a job waits till all dependencies are successful" |
| 4672 | # Job dependencies, starting with A |
| 4673 | # A |
| 4674 | # / \ |
| 4675 | # B C* |
| 4676 | # / \ / \ |
| 4677 | # D F E |
| 4678 | # | |
| 4679 | # G |
| 4680 | |
| 4681 | self.executor_server.hold_jobs_in_build = True |
| 4682 | change = self.fake_gerrit.addFakeChange( |
| 4683 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4684 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4685 | |
| 4686 | self.executor_server.failJob('C', change) |
| 4687 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4688 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4689 | |
| 4690 | self.waitUntilSettled() |
| 4691 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4692 | |
| 4693 | self.executor_server.release('A') |
| 4694 | self.waitUntilSettled() |
| 4695 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4696 | |
| 4697 | self.executor_server.release('B') |
| 4698 | self.waitUntilSettled() |
| 4699 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4700 | |
| 4701 | self.executor_server.release('D') |
| 4702 | self.waitUntilSettled() |
| 4703 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4704 | |
| 4705 | self.executor_server.release('C') |
| 4706 | self.waitUntilSettled() |
| 4707 | self.assertEqual(len(self.builds), 0) |
| 4708 | |
| 4709 | self.executor_server.hold_jobs_in_build = False |
| 4710 | self.executor_server.release() |
| 4711 | self.waitUntilSettled() |
| 4712 | |
| 4713 | self.assertEqual(len(self.builds), 0) |
| 4714 | self.assertEqual(len(self.history), 4) |
| 4715 | |
| 4716 | self.assertEqual(change.data['status'], 'NEW') |
| 4717 | self.assertEqual(change.reported, 2) |
| 4718 | |
| 4719 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4720 | class TestDuplicatePipeline(ZuulTestCase): |
| 4721 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4722 | |
| 4723 | def test_duplicate_pipelines(self): |
| 4724 | "Test that a change matching multiple pipelines works" |
| 4725 | |
| 4726 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4727 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4728 | self.waitUntilSettled() |
| 4729 | |
| 4730 | self.assertHistory([ |
| 4731 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4732 | pipeline='dup1'), |
| 4733 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4734 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4735 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4736 | |
| 4737 | self.assertEqual(len(A.messages), 2) |
| 4738 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4739 | if 'dup1' in A.messages[0]: |
| 4740 | self.assertIn('dup1', A.messages[0]) |
| 4741 | self.assertNotIn('dup2', A.messages[0]) |
| 4742 | self.assertIn('project-test1', A.messages[0]) |
| 4743 | self.assertIn('dup2', A.messages[1]) |
| 4744 | self.assertNotIn('dup1', A.messages[1]) |
| 4745 | self.assertIn('project-test1', A.messages[1]) |
| 4746 | else: |
| 4747 | self.assertIn('dup1', A.messages[1]) |
| 4748 | self.assertNotIn('dup2', A.messages[1]) |
| 4749 | self.assertIn('project-test1', A.messages[1]) |
| 4750 | self.assertIn('dup2', A.messages[0]) |
| 4751 | self.assertNotIn('dup1', A.messages[0]) |
| 4752 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4753 | |
| 4754 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4755 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4756 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4757 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4758 | def test_job_from_templates_executed(self): |
| 4759 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4760 | |
| 4761 | A = self.fake_gerrit.addFakeChange( |
| 4762 | 'org/templated-project', 'master', 'A') |
| 4763 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4764 | self.waitUntilSettled() |
| 4765 | |
| 4766 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4767 | 'SUCCESS') |
| 4768 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4769 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4770 | |
| 4771 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4772 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4773 | |
| 4774 | A = self.fake_gerrit.addFakeChange( |
| 4775 | 'org/layered-project', 'master', 'A') |
| 4776 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4777 | self.waitUntilSettled() |
| 4778 | |
| 4779 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4780 | 'SUCCESS') |
| 4781 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4782 | 'SUCCESS') |
| 4783 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4784 | ).result, 'SUCCESS') |
| 4785 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4786 | ).result, 'SUCCESS') |
| 4787 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4788 | ).result, 'SUCCESS') |
| 4789 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4790 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4791 | |
James E. Blair | e74f571 | 2017-09-29 15:14:31 -0700 | [diff] [blame] | 4792 | def test_unimplied_branch_matchers(self): |
| 4793 | # This tests that there are no implied branch matchers added |
| 4794 | # by project templates. |
| 4795 | self.create_branch('org/layered-project', 'stable') |
| 4796 | |
| 4797 | A = self.fake_gerrit.addFakeChange( |
| 4798 | 'org/layered-project', 'stable', 'A') |
| 4799 | |
| 4800 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4801 | self.waitUntilSettled() |
| 4802 | |
| 4803 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4804 | 'SUCCESS') |
| 4805 | print(self.getJobFromHistory('project-test1'). |
| 4806 | parameters['zuul']['_inheritance_path']) |
| 4807 | |
| 4808 | def test_implied_branch_matchers(self): |
| 4809 | # This tests that there is an implied branch matcher when a |
| 4810 | # template is used on an in-repo project pipeline definition. |
| 4811 | self.create_branch('untrusted-config', 'stable') |
| 4812 | self.fake_gerrit.addEvent( |
| 4813 | self.fake_gerrit.getFakeBranchCreatedEvent( |
| 4814 | 'untrusted-config', 'stable')) |
| 4815 | self.waitUntilSettled() |
| 4816 | |
| 4817 | A = self.fake_gerrit.addFakeChange( |
| 4818 | 'untrusted-config', 'stable', 'A') |
| 4819 | |
| 4820 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4821 | self.waitUntilSettled() |
| 4822 | |
| 4823 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4824 | 'SUCCESS') |
| 4825 | print(self.getJobFromHistory('project-test1'). |
| 4826 | parameters['zuul']['_inheritance_path']) |
| 4827 | |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4828 | |
| 4829 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4830 | tenant_config_file = 'config/success-url/main.yaml' |
| 4831 | |
| 4832 | def test_success_url(self): |
| 4833 | "Ensure bad build params are ignored" |
| 4834 | self.sched.reconfigure(self.config) |
| 4835 | self.init_repo('org/docs') |
| 4836 | |
| 4837 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4838 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4839 | self.waitUntilSettled() |
| 4840 | |
| 4841 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4842 | self.assertEqual(len(self.history), 2) |
| 4843 | |
| 4844 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4845 | for build in self.history: |
| 4846 | if build.name == 'docs-draft-test': |
| 4847 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4848 | elif build.name == 'docs-draft-test2': |
| 4849 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4850 | |
| 4851 | # Two msgs: 'Starting...' + results |
| 4852 | self.assertEqual(len(self.smtp_messages), 2) |
| 4853 | body = self.smtp_messages[1]['body'].splitlines() |
| 4854 | self.assertEqual('Build succeeded.', body[0]) |
| 4855 | |
| 4856 | self.assertIn( |
| 4857 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4858 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4859 | body[2]) |
| 4860 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4861 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4862 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4863 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 4864 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4865 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4866 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4867 | |
| 4868 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4869 | class TestSchedulerMerges(ZuulTestCase): |
| 4870 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4871 | |
| 4872 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4873 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4874 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4875 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4876 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4877 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4878 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4879 | A.addApproval('Code-Review', 2) |
| 4880 | B.addApproval('Code-Review', 2) |
| 4881 | C.addApproval('Code-Review', 2) |
| 4882 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4883 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4884 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4885 | self.waitUntilSettled() |
| 4886 | |
| 4887 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4888 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4889 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4890 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4891 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4892 | repo_messages.reverse() |
| 4893 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4894 | self.executor_server.hold_jobs_in_build = False |
| 4895 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4896 | self.waitUntilSettled() |
| 4897 | |
| 4898 | return repo_messages |
| 4899 | |
| 4900 | def _test_merge(self, mode): |
James E. Blair | da5bb7e | 2018-01-22 16:12:17 -0800 | [diff] [blame] | 4901 | us_path = 'file://' + os.path.join( |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4902 | self.upstream_root, 'org/project-%s' % mode) |
| 4903 | expected_messages = [ |
| 4904 | 'initial commit', |
| 4905 | 'add content from fixture', |
| 4906 | # the intermediate commits order is nondeterministic |
| 4907 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4908 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4909 | ] |
| 4910 | result = self._test_project_merge_mode(mode) |
| 4911 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4912 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4913 | |
| 4914 | def test_project_merge_mode_merge(self): |
| 4915 | self._test_merge('merge') |
| 4916 | |
| 4917 | def test_project_merge_mode_merge_resolve(self): |
| 4918 | self._test_merge('merge-resolve') |
| 4919 | |
| 4920 | def test_project_merge_mode_cherrypick(self): |
| 4921 | expected_messages = [ |
| 4922 | 'initial commit', |
| 4923 | 'add content from fixture', |
| 4924 | 'A-1', |
| 4925 | 'B-1', |
| 4926 | 'C-1'] |
| 4927 | result = self._test_project_merge_mode('cherry-pick') |
| 4928 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4929 | |
| 4930 | def test_merge_branch(self): |
| 4931 | "Test that the right commits are on alternate branches" |
| 4932 | self.create_branch('org/project-merge-branches', 'mp') |
| 4933 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4934 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4935 | A = self.fake_gerrit.addFakeChange( |
| 4936 | 'org/project-merge-branches', 'mp', 'A') |
| 4937 | B = self.fake_gerrit.addFakeChange( |
| 4938 | 'org/project-merge-branches', 'mp', 'B') |
| 4939 | C = self.fake_gerrit.addFakeChange( |
| 4940 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4941 | A.addApproval('Code-Review', 2) |
| 4942 | B.addApproval('Code-Review', 2) |
| 4943 | C.addApproval('Code-Review', 2) |
| 4944 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4945 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4946 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4947 | self.waitUntilSettled() |
| 4948 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4949 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4950 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4951 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4952 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4953 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4954 | self.waitUntilSettled() |
| 4955 | |
| 4956 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 4957 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4958 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4959 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4960 | repo = git.Repo(path) |
| 4961 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4962 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4963 | repo_messages.reverse() |
| 4964 | correct_messages = [ |
| 4965 | 'initial commit', |
| 4966 | 'add content from fixture', |
| 4967 | 'mp commit', |
| 4968 | 'A-1', 'B-1', 'C-1'] |
| 4969 | self.assertEqual(repo_messages, correct_messages) |
| 4970 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4971 | self.executor_server.hold_jobs_in_build = False |
| 4972 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4973 | self.waitUntilSettled() |
| 4974 | |
| 4975 | def test_merge_multi_branch(self): |
| 4976 | "Test that dependent changes on multiple branches are merged" |
| 4977 | self.create_branch('org/project-merge-branches', 'mp') |
| 4978 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4979 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4980 | A = self.fake_gerrit.addFakeChange( |
| 4981 | 'org/project-merge-branches', 'master', 'A') |
| 4982 | B = self.fake_gerrit.addFakeChange( |
| 4983 | 'org/project-merge-branches', 'mp', 'B') |
| 4984 | C = self.fake_gerrit.addFakeChange( |
| 4985 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4986 | A.addApproval('Code-Review', 2) |
| 4987 | B.addApproval('Code-Review', 2) |
| 4988 | C.addApproval('Code-Review', 2) |
| 4989 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4990 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4991 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4992 | self.waitUntilSettled() |
| 4993 | |
| 4994 | job_A = None |
| 4995 | for job in self.builds: |
| 4996 | if 'project-merge' in job.name: |
| 4997 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4998 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4999 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 5000 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5001 | repo = git.Repo(path) |
| 5002 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5003 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5004 | repo_messages.reverse() |
| 5005 | correct_messages = [ |
| 5006 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5007 | self.assertEqual(repo_messages, correct_messages) |
| 5008 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5009 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5010 | self.waitUntilSettled() |
| 5011 | |
| 5012 | job_B = None |
| 5013 | for job in self.builds: |
| 5014 | if 'project-merge' in job.name: |
| 5015 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5016 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5017 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 5018 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5019 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5020 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5021 | repo_messages.reverse() |
| 5022 | correct_messages = [ |
| 5023 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5024 | self.assertEqual(repo_messages, correct_messages) |
| 5025 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5026 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5027 | self.waitUntilSettled() |
| 5028 | |
| 5029 | job_C = None |
| 5030 | for job in self.builds: |
| 5031 | if 'project-merge' in job.name: |
| 5032 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 5033 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5034 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 5035 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5036 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5037 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5038 | |
| 5039 | repo_messages.reverse() |
| 5040 | correct_messages = [ |
| 5041 | 'initial commit', 'add content from fixture', |
| 5042 | 'A-1', 'C-1'] |
| 5043 | # Ensure the right commits are in the history for this ref |
| 5044 | self.assertEqual(repo_messages, correct_messages) |
| 5045 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5046 | self.executor_server.hold_jobs_in_build = False |
| 5047 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5048 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5049 | |
| 5050 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5051 | class TestSemaphore(ZuulTestCase): |
| 5052 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5053 | |
| 5054 | def test_semaphore_one(self): |
| 5055 | "Test semaphores with max=1 (mutex)" |
| 5056 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5057 | |
| 5058 | self.executor_server.hold_jobs_in_build = True |
| 5059 | |
| 5060 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5061 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5062 | self.assertFalse('test-semaphore' in |
| 5063 | tenant.semaphore_handler.semaphores) |
| 5064 | |
| 5065 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5066 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5067 | self.waitUntilSettled() |
| 5068 | |
| 5069 | self.assertEqual(len(self.builds), 3) |
| 5070 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5071 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5072 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5073 | |
| 5074 | self.executor_server.release('semaphore-one-test1') |
| 5075 | self.waitUntilSettled() |
| 5076 | |
| 5077 | self.assertEqual(len(self.builds), 3) |
| 5078 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5079 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5080 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5081 | self.assertTrue('test-semaphore' in |
| 5082 | tenant.semaphore_handler.semaphores) |
| 5083 | |
| 5084 | self.executor_server.release('semaphore-one-test2') |
| 5085 | self.waitUntilSettled() |
| 5086 | |
| 5087 | self.assertEqual(len(self.builds), 3) |
| 5088 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5089 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5090 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5091 | self.assertTrue('test-semaphore' in |
| 5092 | tenant.semaphore_handler.semaphores) |
| 5093 | |
| 5094 | self.executor_server.release('semaphore-one-test1') |
| 5095 | self.waitUntilSettled() |
| 5096 | |
| 5097 | self.assertEqual(len(self.builds), 3) |
| 5098 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5099 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5100 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5101 | self.assertTrue('test-semaphore' in |
| 5102 | tenant.semaphore_handler.semaphores) |
| 5103 | |
| 5104 | self.executor_server.release('semaphore-one-test2') |
| 5105 | self.waitUntilSettled() |
| 5106 | |
| 5107 | self.assertEqual(len(self.builds), 2) |
| 5108 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5109 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5110 | self.assertFalse('test-semaphore' in |
| 5111 | tenant.semaphore_handler.semaphores) |
| 5112 | |
| 5113 | self.executor_server.hold_jobs_in_build = False |
| 5114 | self.executor_server.release() |
| 5115 | |
| 5116 | self.waitUntilSettled() |
| 5117 | self.assertEqual(len(self.builds), 0) |
| 5118 | |
| 5119 | self.assertEqual(A.reported, 1) |
| 5120 | self.assertEqual(B.reported, 1) |
| 5121 | self.assertFalse('test-semaphore' in |
| 5122 | tenant.semaphore_handler.semaphores) |
| 5123 | |
| 5124 | def test_semaphore_two(self): |
| 5125 | "Test semaphores with max>1" |
| 5126 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5127 | |
| 5128 | self.executor_server.hold_jobs_in_build = True |
| 5129 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5130 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5131 | self.assertFalse('test-semaphore-two' in |
| 5132 | tenant.semaphore_handler.semaphores) |
| 5133 | |
| 5134 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5135 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5136 | self.waitUntilSettled() |
| 5137 | |
| 5138 | self.assertEqual(len(self.builds), 4) |
| 5139 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5140 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5141 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5142 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5143 | self.assertTrue('test-semaphore-two' in |
| 5144 | tenant.semaphore_handler.semaphores) |
| 5145 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5146 | 'test-semaphore-two', [])), 2) |
| 5147 | |
| 5148 | self.executor_server.release('semaphore-two-test1') |
| 5149 | self.waitUntilSettled() |
| 5150 | |
| 5151 | self.assertEqual(len(self.builds), 4) |
| 5152 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5153 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5154 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5155 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5156 | self.assertTrue('test-semaphore-two' in |
| 5157 | tenant.semaphore_handler.semaphores) |
| 5158 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5159 | 'test-semaphore-two', [])), 2) |
| 5160 | |
| 5161 | self.executor_server.release('semaphore-two-test2') |
| 5162 | self.waitUntilSettled() |
| 5163 | |
| 5164 | self.assertEqual(len(self.builds), 4) |
| 5165 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5166 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5167 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5168 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5169 | self.assertTrue('test-semaphore-two' in |
| 5170 | tenant.semaphore_handler.semaphores) |
| 5171 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5172 | 'test-semaphore-two', [])), 2) |
| 5173 | |
| 5174 | self.executor_server.release('semaphore-two-test1') |
| 5175 | self.waitUntilSettled() |
| 5176 | |
| 5177 | self.assertEqual(len(self.builds), 3) |
| 5178 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5179 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5180 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5181 | self.assertTrue('test-semaphore-two' in |
| 5182 | tenant.semaphore_handler.semaphores) |
| 5183 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5184 | 'test-semaphore-two', [])), 1) |
| 5185 | |
| 5186 | self.executor_server.release('semaphore-two-test2') |
| 5187 | self.waitUntilSettled() |
| 5188 | |
| 5189 | self.assertEqual(len(self.builds), 2) |
| 5190 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5191 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5192 | self.assertFalse('test-semaphore-two' in |
| 5193 | tenant.semaphore_handler.semaphores) |
| 5194 | |
| 5195 | self.executor_server.hold_jobs_in_build = False |
| 5196 | self.executor_server.release() |
| 5197 | |
| 5198 | self.waitUntilSettled() |
| 5199 | self.assertEqual(len(self.builds), 0) |
| 5200 | |
| 5201 | self.assertEqual(A.reported, 1) |
| 5202 | self.assertEqual(B.reported, 1) |
| 5203 | |
| 5204 | def test_semaphore_abandon(self): |
| 5205 | "Test abandon with job semaphores" |
| 5206 | self.executor_server.hold_jobs_in_build = True |
| 5207 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5208 | check_pipeline = tenant.layout.pipelines['check'] |
| 5209 | |
| 5210 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5211 | self.assertFalse('test-semaphore' in |
| 5212 | tenant.semaphore_handler.semaphores) |
| 5213 | |
| 5214 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5215 | self.waitUntilSettled() |
| 5216 | |
| 5217 | self.assertTrue('test-semaphore' in |
| 5218 | tenant.semaphore_handler.semaphores) |
| 5219 | |
| 5220 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5221 | self.waitUntilSettled() |
| 5222 | |
| 5223 | # The check pipeline should be empty |
| 5224 | items = check_pipeline.getAllItems() |
| 5225 | self.assertEqual(len(items), 0) |
| 5226 | |
| 5227 | # The semaphore should be released |
| 5228 | self.assertFalse('test-semaphore' in |
| 5229 | tenant.semaphore_handler.semaphores) |
| 5230 | |
| 5231 | self.executor_server.hold_jobs_in_build = False |
| 5232 | self.executor_server.release() |
| 5233 | self.waitUntilSettled() |
| 5234 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5235 | def test_semaphore_new_patchset(self): |
| 5236 | "Test new patchset with job semaphores" |
| 5237 | self.executor_server.hold_jobs_in_build = True |
| 5238 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5239 | check_pipeline = tenant.layout.pipelines['check'] |
| 5240 | |
| 5241 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5242 | self.assertFalse('test-semaphore' in |
| 5243 | tenant.semaphore_handler.semaphores) |
| 5244 | |
| 5245 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5246 | self.waitUntilSettled() |
| 5247 | |
| 5248 | self.assertTrue('test-semaphore' in |
| 5249 | tenant.semaphore_handler.semaphores) |
| 5250 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5251 | self.assertEqual(len(semaphore), 1) |
| 5252 | |
| 5253 | A.addPatchset() |
| 5254 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5255 | self.waitUntilSettled() |
| 5256 | |
| 5257 | self.assertTrue('test-semaphore' in |
| 5258 | tenant.semaphore_handler.semaphores) |
| 5259 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5260 | self.assertEqual(len(semaphore), 1) |
| 5261 | |
| 5262 | items = check_pipeline.getAllItems() |
| 5263 | self.assertEqual(items[0].change.number, '1') |
| 5264 | self.assertEqual(items[0].change.patchset, '2') |
| 5265 | self.assertTrue(items[0].live) |
| 5266 | |
| 5267 | self.executor_server.hold_jobs_in_build = False |
| 5268 | self.executor_server.release() |
| 5269 | self.waitUntilSettled() |
| 5270 | |
| 5271 | # The semaphore should be released |
| 5272 | self.assertFalse('test-semaphore' in |
| 5273 | tenant.semaphore_handler.semaphores) |
| 5274 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5275 | def test_semaphore_reconfigure(self): |
| 5276 | "Test reconfigure with job semaphores" |
| 5277 | self.executor_server.hold_jobs_in_build = True |
| 5278 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5279 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5280 | self.assertFalse('test-semaphore' in |
| 5281 | tenant.semaphore_handler.semaphores) |
| 5282 | |
| 5283 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5284 | self.waitUntilSettled() |
| 5285 | |
| 5286 | self.assertTrue('test-semaphore' in |
| 5287 | tenant.semaphore_handler.semaphores) |
| 5288 | |
| 5289 | # reconfigure without layout change |
| 5290 | self.sched.reconfigure(self.config) |
| 5291 | self.waitUntilSettled() |
| 5292 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5293 | |
| 5294 | # semaphore still must be held |
| 5295 | self.assertTrue('test-semaphore' in |
| 5296 | tenant.semaphore_handler.semaphores) |
| 5297 | |
| 5298 | self.commitConfigUpdate( |
| 5299 | 'common-config', |
| 5300 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5301 | self.sched.reconfigure(self.config) |
| 5302 | self.waitUntilSettled() |
| 5303 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5304 | |
| 5305 | self.executor_server.release('project-test1') |
| 5306 | self.waitUntilSettled() |
| 5307 | |
| 5308 | # There should be no builds anymore |
| 5309 | self.assertEqual(len(self.builds), 0) |
| 5310 | |
| 5311 | # The semaphore should be released |
| 5312 | self.assertFalse('test-semaphore' in |
| 5313 | tenant.semaphore_handler.semaphores) |
| 5314 | |
| 5315 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5316 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5317 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5318 | |
| 5319 | def test_semaphore_tenant_isolation(self): |
| 5320 | "Test semaphores in multiple tenants" |
| 5321 | |
| 5322 | self.waitUntilSettled() |
| 5323 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5324 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5325 | |
| 5326 | self.executor_server.hold_jobs_in_build = True |
| 5327 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5328 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5329 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5330 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5331 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5332 | self.assertFalse('test-semaphore' in |
| 5333 | tenant_one.semaphore_handler.semaphores) |
| 5334 | self.assertFalse('test-semaphore' in |
| 5335 | tenant_two.semaphore_handler.semaphores) |
| 5336 | |
| 5337 | # add patches to project1 of tenant-one |
| 5338 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5339 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5340 | self.waitUntilSettled() |
| 5341 | |
| 5342 | # one build of project1-test1 must run |
| 5343 | # semaphore of tenant-one must be acquired once |
| 5344 | # semaphore of tenant-two must not be acquired |
| 5345 | self.assertEqual(len(self.builds), 1) |
| 5346 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5347 | self.assertTrue('test-semaphore' in |
| 5348 | tenant_one.semaphore_handler.semaphores) |
| 5349 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5350 | 'test-semaphore', [])), 1) |
| 5351 | self.assertFalse('test-semaphore' in |
| 5352 | tenant_two.semaphore_handler.semaphores) |
| 5353 | |
| 5354 | # add patches to project2 of tenant-two |
| 5355 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5356 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5357 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5358 | self.waitUntilSettled() |
| 5359 | |
| 5360 | # one build of project1-test1 must run |
| 5361 | # two builds of project2-test1 must run |
| 5362 | # semaphore of tenant-one must be acquired once |
| 5363 | # semaphore of tenant-two must be acquired twice |
| 5364 | self.assertEqual(len(self.builds), 3) |
| 5365 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5366 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5367 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5368 | self.assertTrue('test-semaphore' in |
| 5369 | tenant_one.semaphore_handler.semaphores) |
| 5370 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5371 | 'test-semaphore', [])), 1) |
| 5372 | self.assertTrue('test-semaphore' in |
| 5373 | tenant_two.semaphore_handler.semaphores) |
| 5374 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5375 | 'test-semaphore', [])), 2) |
| 5376 | |
| 5377 | self.executor_server.release('project1-test1') |
| 5378 | self.waitUntilSettled() |
| 5379 | |
| 5380 | # one build of project1-test1 must run |
| 5381 | # two builds of project2-test1 must run |
| 5382 | # semaphore of tenant-one must be acquired once |
| 5383 | # semaphore of tenant-two must be acquired twice |
| 5384 | self.assertEqual(len(self.builds), 3) |
| 5385 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5386 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5387 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5388 | self.assertTrue('test-semaphore' in |
| 5389 | tenant_one.semaphore_handler.semaphores) |
| 5390 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5391 | 'test-semaphore', [])), 1) |
| 5392 | self.assertTrue('test-semaphore' in |
| 5393 | tenant_two.semaphore_handler.semaphores) |
| 5394 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5395 | 'test-semaphore', [])), 2) |
| 5396 | |
| 5397 | self.executor_server.release('project2-test1') |
| 5398 | self.waitUntilSettled() |
| 5399 | |
| 5400 | # one build of project1-test1 must run |
| 5401 | # one build of project2-test1 must run |
| 5402 | # semaphore of tenant-one must be acquired once |
| 5403 | # semaphore of tenant-two must be acquired once |
| 5404 | self.assertEqual(len(self.builds), 2) |
| 5405 | self.assertTrue('test-semaphore' in |
| 5406 | tenant_one.semaphore_handler.semaphores) |
| 5407 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5408 | 'test-semaphore', [])), 1) |
| 5409 | self.assertTrue('test-semaphore' in |
| 5410 | tenant_two.semaphore_handler.semaphores) |
| 5411 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5412 | 'test-semaphore', [])), 1) |
| 5413 | |
| 5414 | self.executor_server.hold_jobs_in_build = False |
| 5415 | self.executor_server.release() |
| 5416 | |
| 5417 | self.waitUntilSettled() |
| 5418 | |
| 5419 | # no build must run |
| 5420 | # semaphore of tenant-one must not be acquired |
| 5421 | # semaphore of tenant-two must not be acquired |
| 5422 | self.assertEqual(len(self.builds), 0) |
| 5423 | self.assertFalse('test-semaphore' in |
| 5424 | tenant_one.semaphore_handler.semaphores) |
| 5425 | self.assertFalse('test-semaphore' in |
| 5426 | tenant_two.semaphore_handler.semaphores) |
| 5427 | |
| 5428 | self.assertEqual(A.reported, 1) |
| 5429 | self.assertEqual(B.reported, 1) |
| 5430 | |
| 5431 | |
Tobias Henkel | e9a2251 | 2017-12-22 08:36:12 +0100 | [diff] [blame] | 5432 | class TestImplicitProject(ZuulTestCase): |
| 5433 | tenant_config_file = 'config/implicit-project/main.yaml' |
| 5434 | |
| 5435 | def test_implicit_project(self): |
| 5436 | # config project should work with implicit project name |
| 5437 | A = self.fake_gerrit.addFakeChange('common-config', 'master', 'A') |
| 5438 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5439 | |
| 5440 | # untrusted project should work with implicit project name |
| 5441 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5442 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5443 | |
| 5444 | self.waitUntilSettled() |
| 5445 | |
| 5446 | self.assertEqual(A.data['status'], 'NEW') |
| 5447 | self.assertEqual(A.reported, 1) |
| 5448 | self.assertEqual(B.data['status'], 'NEW') |
| 5449 | self.assertEqual(B.reported, 1) |
| 5450 | self.assertHistory([ |
| 5451 | dict(name='test-common', result='SUCCESS', changes='1,1'), |
| 5452 | dict(name='test-common', result='SUCCESS', changes='2,1'), |
| 5453 | dict(name='test-project', result='SUCCESS', changes='2,1'), |
| 5454 | ], ordered=False) |
| 5455 | |
| 5456 | # now test adding a further project in repo |
| 5457 | in_repo_conf = textwrap.dedent( |
| 5458 | """ |
| 5459 | - job: |
| 5460 | name: test-project |
| 5461 | run: playbooks/test-project.yaml |
| 5462 | - job: |
| 5463 | name: test2-project |
| 5464 | run: playbooks/test-project.yaml |
| 5465 | |
| 5466 | - project: |
| 5467 | check: |
| 5468 | jobs: |
| 5469 | - test-project |
| 5470 | gate: |
| 5471 | jobs: |
| 5472 | - test-project |
| 5473 | |
| 5474 | - project: |
| 5475 | check: |
| 5476 | jobs: |
| 5477 | - test2-project |
| 5478 | gate: |
| 5479 | jobs: |
| 5480 | - test2-project |
| 5481 | |
| 5482 | """) |
| 5483 | file_dict = {'.zuul.yaml': in_repo_conf} |
| 5484 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5485 | files=file_dict) |
| 5486 | C.addApproval('Code-Review', 2) |
| 5487 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 5488 | self.waitUntilSettled() |
| 5489 | |
| 5490 | # change C must be merged |
| 5491 | self.assertEqual(C.data['status'], 'MERGED') |
| 5492 | self.assertEqual(C.reported, 2) |
| 5493 | self.assertHistory([ |
| 5494 | dict(name='test-common', result='SUCCESS', changes='1,1'), |
| 5495 | dict(name='test-common', result='SUCCESS', changes='2,1'), |
| 5496 | dict(name='test-project', result='SUCCESS', changes='2,1'), |
| 5497 | dict(name='test-common', result='SUCCESS', changes='3,1'), |
| 5498 | dict(name='test-project', result='SUCCESS', changes='3,1'), |
| 5499 | dict(name='test2-project', result='SUCCESS', changes='3,1'), |
| 5500 | ], ordered=False) |
| 5501 | |
| 5502 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5503 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5504 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5505 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5506 | |
| 5507 | def test_semaphore_in_repo(self): |
| 5508 | "Test semaphores in repo config" |
| 5509 | |
| 5510 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5511 | # max value should not be evaluated dynamically but must be updated |
| 5512 | # after the change lands. |
| 5513 | |
| 5514 | self.waitUntilSettled() |
| 5515 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5516 | |
| 5517 | in_repo_conf = textwrap.dedent( |
| 5518 | """ |
| 5519 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5520 | name: project-test1 |
| 5521 | |
| 5522 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5523 | name: project-test2 |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 5524 | run: playbooks/project-test2.yaml |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5525 | semaphore: test-semaphore |
| 5526 | |
| 5527 | - project: |
| 5528 | name: org/project |
| 5529 | tenant-one-gate: |
| 5530 | jobs: |
| 5531 | - project-test2 |
| 5532 | |
| 5533 | # the max value in dynamic layout must be ignored |
| 5534 | - semaphore: |
| 5535 | name: test-semaphore |
| 5536 | max: 2 |
| 5537 | """) |
| 5538 | |
| 5539 | in_repo_playbook = textwrap.dedent( |
| 5540 | """ |
| 5541 | - hosts: all |
| 5542 | tasks: [] |
| 5543 | """) |
| 5544 | |
| 5545 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5546 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5547 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5548 | files=file_dict) |
| 5549 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5550 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5551 | B.setDependsOn(A, 1) |
| 5552 | C.setDependsOn(A, 1) |
| 5553 | |
| 5554 | self.executor_server.hold_jobs_in_build = True |
| 5555 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5556 | A.addApproval('Code-Review', 2) |
| 5557 | B.addApproval('Code-Review', 2) |
| 5558 | C.addApproval('Code-Review', 2) |
| 5559 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5560 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5561 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5562 | self.waitUntilSettled() |
| 5563 | |
| 5564 | # check that the layout in a queue item still has max value of 1 |
| 5565 | # for test-semaphore |
| 5566 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5567 | queue = None |
| 5568 | for queue_candidate in pipeline.queues: |
| 5569 | if queue_candidate.name == 'org/project': |
| 5570 | queue = queue_candidate |
| 5571 | break |
| 5572 | queue_item = queue.queue[0] |
James E. Blair | 29a24fd | 2017-10-02 15:04:56 -0700 | [diff] [blame] | 5573 | item_dynamic_layout = queue_item.layout |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5574 | dynamic_test_semaphore = \ |
| 5575 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5576 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5577 | |
| 5578 | # one build must be in queue, one semaphores acquired |
| 5579 | self.assertEqual(len(self.builds), 1) |
| 5580 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5581 | self.assertTrue('test-semaphore' in |
| 5582 | tenant.semaphore_handler.semaphores) |
| 5583 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5584 | 'test-semaphore', [])), 1) |
| 5585 | |
| 5586 | self.executor_server.release('project-test2') |
| 5587 | self.waitUntilSettled() |
| 5588 | |
| 5589 | # change A must be merged |
| 5590 | self.assertEqual(A.data['status'], 'MERGED') |
| 5591 | self.assertEqual(A.reported, 2) |
| 5592 | |
| 5593 | # send change-merged event as the gerrit mock doesn't send it |
| 5594 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5595 | self.waitUntilSettled() |
| 5596 | |
| 5597 | # now that change A was merged, the new semaphore max must be effective |
| 5598 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5599 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5600 | |
| 5601 | # two builds must be in queue, two semaphores acquired |
| 5602 | self.assertEqual(len(self.builds), 2) |
| 5603 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5604 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5605 | self.assertTrue('test-semaphore' in |
| 5606 | tenant.semaphore_handler.semaphores) |
| 5607 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5608 | 'test-semaphore', [])), 2) |
| 5609 | |
| 5610 | self.executor_server.release('project-test2') |
| 5611 | self.waitUntilSettled() |
| 5612 | |
| 5613 | self.assertEqual(len(self.builds), 0) |
| 5614 | self.assertFalse('test-semaphore' in |
| 5615 | tenant.semaphore_handler.semaphores) |
| 5616 | |
| 5617 | self.executor_server.hold_jobs_in_build = False |
| 5618 | self.executor_server.release() |
| 5619 | |
| 5620 | self.waitUntilSettled() |
| 5621 | self.assertEqual(len(self.builds), 0) |
| 5622 | |
| 5623 | self.assertEqual(A.reported, 2) |
| 5624 | self.assertEqual(B.reported, 2) |
| 5625 | self.assertEqual(C.reported, 2) |
David Shrewsbury | f6dc176 | 2017-10-02 13:34:37 -0400 | [diff] [blame] | 5626 | |
| 5627 | |
| 5628 | class TestSchedulerBranchMatcher(ZuulTestCase): |
| 5629 | |
| 5630 | @simple_layout('layouts/matcher-test.yaml') |
| 5631 | def test_job_branch_ignored(self): |
| 5632 | ''' |
| 5633 | Test that branch matching logic works. |
| 5634 | |
| 5635 | The 'ignore-branch' job has a branch matcher that is supposed to |
| 5636 | match every branch except for the 'featureA' branch, so it should |
| 5637 | not be run on a change to that branch. |
| 5638 | ''' |
| 5639 | self.create_branch('org/project', 'featureA') |
| 5640 | A = self.fake_gerrit.addFakeChange('org/project', 'featureA', 'A') |
| 5641 | A.addApproval('Code-Review', 2) |
| 5642 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5643 | self.waitUntilSettled() |
| 5644 | self.printHistory() |
| 5645 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5646 | 'SUCCESS') |
| 5647 | self.assertJobNotInHistory('ignore-branch') |
| 5648 | self.assertEqual(A.data['status'], 'MERGED') |
| 5649 | self.assertEqual(A.reported, 2, |
| 5650 | "A should report start and success") |
| 5651 | self.assertIn('gate', A.messages[1], |
| 5652 | "A should transit gate") |