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 | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 22 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 23 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | import time |
Clint Byrum | 03454a5 | 2017-05-26 17:14:02 -0700 | [diff] [blame] | 25 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 27 | import git |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 28 | import testtools |
Monty Taylor | b934c1a | 2017-06-16 19:31:47 -0500 | [diff] [blame] | 29 | import urllib |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 31 | import zuul.change_matcher |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 32 | from zuul.driver.gerrit import gerritreporter |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 33 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 34 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 35 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 36 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | from tests.base import ( |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 38 | SSLZuulTestCase, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 39 | ZuulTestCase, |
| 40 | repack_repo, |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 41 | simple_layout, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 42 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 43 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 44 | |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 45 | class TestSchedulerSSL(SSLZuulTestCase): |
| 46 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 47 | |
| 48 | def test_jobs_executed(self): |
| 49 | "Test that jobs are executed and a change is merged" |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 50 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 51 | A.addApproval('Code-Review', 2) |
| 52 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 53 | self.waitUntilSettled() |
| 54 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 55 | 'SUCCESS') |
| 56 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 57 | 'SUCCESS') |
| 58 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 59 | 'SUCCESS') |
| 60 | self.assertEqual(A.data['status'], 'MERGED') |
| 61 | self.assertEqual(A.reported, 2) |
| 62 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 63 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 64 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 65 | 'label1') |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 66 | |
| 67 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 68 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 69 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 70 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 71 | def test_jobs_executed(self): |
| 72 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 73 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 74 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 75 | A.addApproval('Code-Review', 2) |
| 76 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 77 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 78 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 79 | 'SUCCESS') |
| 80 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 81 | 'SUCCESS') |
| 82 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 83 | 'SUCCESS') |
| 84 | self.assertEqual(A.data['status'], 'MERGED') |
| 85 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 86 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 87 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 88 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 89 | 'label1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 90 | |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 91 | for stat in self.statsd.stats: |
| 92 | k, v = stat.decode('utf-8').split(':') |
| 93 | self.log.debug('stat %s:%s', k, v) |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 94 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 95 | # Per-driver |
| 96 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 97 | # Per-driver per-connection |
| 98 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 99 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 100 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 101 | 'zuul.tenant.tenant-one.pipeline.gate.current_changes', |
| 102 | value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 103 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 104 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 105 | 'org_project.master.job.project-merge.SUCCESS', kind='ms') |
| 106 | self.assertReportedStat( |
| 107 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 108 | 'org_project.master.job.project-merge.SUCCESS', value='1|c') |
| 109 | self.assertReportedStat( |
| 110 | 'zuul.tenant.tenant-one.pipeline.gate.resident_time', kind='ms') |
| 111 | self.assertReportedStat( |
| 112 | 'zuul.tenant.tenant-one.pipeline.gate.total_changes', value='1|c') |
| 113 | self.assertReportedStat( |
| 114 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 115 | 'org_project.master.resident_time', kind='ms') |
| 116 | self.assertReportedStat( |
| 117 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 118 | 'org_project.master.total_changes', value='1|c') |
James E. Blair | faf8198 | 2017-10-10 15:42:26 -0700 | [diff] [blame] | 119 | exec_key = 'zuul.executor.%s' % self.executor_server.hostname |
| 120 | self.assertReportedStat(exec_key + '.builds', value='1|c') |
James E. Blair | 4f1731b | 2017-10-10 18:11:42 -0700 | [diff] [blame] | 121 | self.assertReportedStat('zuul.nodepool.requested', value='1|c') |
| 122 | self.assertReportedStat('zuul.nodepool.requested.label.label1', |
| 123 | value='1|c') |
| 124 | self.assertReportedStat('zuul.nodepool.fulfilled.label.label1', |
| 125 | value='1|c') |
| 126 | self.assertReportedStat('zuul.nodepool.requested.size.1', value='1|c') |
| 127 | self.assertReportedStat('zuul.nodepool.fulfilled.size.1', value='1|c') |
| 128 | self.assertReportedStat('zuul.nodepool.current_requests', value='1|g') |
James E. Blair | bdd50e6 | 2017-10-21 08:18:55 -0700 | [diff] [blame] | 129 | self.assertReportedStat('zuul.executors.online', value='1|g') |
| 130 | self.assertReportedStat('zuul.executors.accepting', value='1|g') |
| 131 | self.assertReportedStat('zuul.mergers.online', value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 132 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 133 | for build in self.history: |
| 134 | self.assertTrue(build.parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 135 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 136 | def test_initial_pipeline_gauges(self): |
| 137 | "Test that each pipeline reported its length on start" |
James E. Blair | 57bf14d | 2017-10-21 09:09:48 -0700 | [diff] [blame] | 138 | self.assertReportedStat('zuul.tenant.tenant-one.pipeline.gate.' |
| 139 | 'current_changes', |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 140 | value='0|g') |
James E. Blair | 57bf14d | 2017-10-21 09:09:48 -0700 | [diff] [blame] | 141 | self.assertReportedStat('zuul.tenant.tenant-one.pipeline.check.' |
| 142 | 'current_changes', |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 143 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 144 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 145 | def test_job_branch(self): |
| 146 | "Test the correct variant of a job runs on a branch" |
| 147 | self.create_branch('org/project', 'stable') |
| 148 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 149 | A.addApproval('Code-Review', 2) |
| 150 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 151 | self.waitUntilSettled() |
| 152 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 153 | 'SUCCESS') |
| 154 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 155 | 'SUCCESS') |
| 156 | self.assertEqual(A.data['status'], 'MERGED') |
| 157 | self.assertEqual(A.reported, 2, |
| 158 | "A should report start and success") |
| 159 | self.assertIn('gate', A.messages[1], |
| 160 | "A should transit gate") |
| 161 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 162 | 'label2') |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 163 | |
James E. Blair | da5bb7e | 2018-01-22 16:12:17 -0800 | [diff] [blame^] | 164 | @simple_layout('layouts/branch-deletion.yaml') |
| 165 | def test_branch_deletion(self): |
| 166 | "Test the correct variant of a job runs on a branch" |
| 167 | self._startMerger() |
| 168 | for f in list(self.executor_server.merger_worker.functions.keys()): |
| 169 | f = str(f) |
| 170 | if f.startswith('merger:'): |
| 171 | self.executor_server.merger_worker.unRegisterFunction(f) |
| 172 | |
| 173 | self.create_branch('org/project', 'stable') |
| 174 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 175 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 176 | self.waitUntilSettled() |
| 177 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 178 | 'SUCCESS') |
| 179 | |
| 180 | self.delete_branch('org/project', 'stable') |
| 181 | path = os.path.join(self.executor_src_root, 'review.example.com') |
| 182 | shutil.rmtree(path) |
| 183 | |
| 184 | self.executor_server.hold_jobs_in_build = True |
| 185 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 186 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 187 | self.waitUntilSettled() |
| 188 | build = self.builds[0] |
| 189 | |
| 190 | # Make sure there is no stable branch in the checked out git repo. |
| 191 | pname = 'review.example.com/org/project' |
| 192 | work = build.getWorkspaceRepos([pname]) |
| 193 | work = work[pname] |
| 194 | heads = set([str(x) for x in work.heads]) |
| 195 | self.assertEqual(heads, set(['master'])) |
| 196 | self.executor_server.hold_jobs_in_build = False |
| 197 | build.release() |
| 198 | self.waitUntilSettled() |
| 199 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 200 | 'SUCCESS') |
| 201 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 202 | def test_parallel_changes(self): |
| 203 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 204 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 205 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 206 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 207 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 208 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 209 | A.addApproval('Code-Review', 2) |
| 210 | B.addApproval('Code-Review', 2) |
| 211 | C.addApproval('Code-Review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 212 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 213 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 214 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 215 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 216 | |
| 217 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 218 | self.assertEqual(len(self.builds), 1) |
| 219 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 220 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 221 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 222 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 223 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 224 | self.assertEqual(len(self.builds), 3) |
| 225 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 226 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 227 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 228 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 229 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 230 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 231 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 232 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 233 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 234 | self.assertEqual(len(self.builds), 5) |
| 235 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 236 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 237 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 238 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 239 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 240 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 241 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 242 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 243 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 244 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 245 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 246 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 247 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 248 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 249 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 250 | self.assertEqual(len(self.builds), 6) |
| 251 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 252 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 253 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 254 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 255 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 256 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 257 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 258 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 259 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 260 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 261 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 262 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 263 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 264 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 265 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 266 | self.executor_server.hold_jobs_in_build = False |
| 267 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 268 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 269 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 270 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 271 | self.assertEqual(len(self.history), 9) |
| 272 | self.assertEqual(A.data['status'], 'MERGED') |
| 273 | self.assertEqual(B.data['status'], 'MERGED') |
| 274 | self.assertEqual(C.data['status'], 'MERGED') |
| 275 | self.assertEqual(A.reported, 2) |
| 276 | self.assertEqual(B.reported, 2) |
| 277 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 278 | |
| 279 | def test_failed_changes(self): |
| 280 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 281 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 282 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 283 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 284 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 285 | A.addApproval('Code-Review', 2) |
| 286 | B.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 287 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 288 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 289 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 290 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 291 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 292 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 293 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 294 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 295 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 296 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 297 | # A/project-merge is complete |
| 298 | self.assertBuilds([ |
| 299 | dict(name='project-test1', changes='1,1'), |
| 300 | dict(name='project-test2', changes='1,1'), |
| 301 | dict(name='project-merge', changes='1,1 2,1'), |
| 302 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 303 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 304 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 305 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 306 | # A/project-merge is complete |
| 307 | # B/project-merge is complete |
| 308 | self.assertBuilds([ |
| 309 | dict(name='project-test1', changes='1,1'), |
| 310 | dict(name='project-test2', changes='1,1'), |
| 311 | dict(name='project-test1', changes='1,1 2,1'), |
| 312 | dict(name='project-test2', changes='1,1 2,1'), |
| 313 | ]) |
| 314 | |
| 315 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 316 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 317 | self.builds[0].release() |
| 318 | self.waitUntilSettled() |
| 319 | |
| 320 | self.orderedRelease() |
| 321 | self.assertHistory([ |
| 322 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 323 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 324 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 325 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 326 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 327 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 328 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 329 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 330 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 331 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 332 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 333 | self.assertEqual(A.data['status'], 'NEW') |
| 334 | self.assertEqual(B.data['status'], 'MERGED') |
| 335 | self.assertEqual(A.reported, 2) |
| 336 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 337 | |
| 338 | def test_independent_queues(self): |
| 339 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 340 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 341 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 342 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 343 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 344 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 345 | A.addApproval('Code-Review', 2) |
| 346 | B.addApproval('Code-Review', 2) |
| 347 | C.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 348 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 349 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 350 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 351 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 352 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 353 | self.waitUntilSettled() |
| 354 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 355 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 356 | self.waitUntilSettled() |
| 357 | |
| 358 | # 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] | 359 | self.assertBuilds([ |
| 360 | dict(name='project-merge', changes='1,1'), |
| 361 | dict(name='project-merge', changes='2,1'), |
| 362 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 363 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 364 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 365 | self.builds[0].release() |
| 366 | self.waitUntilSettled() |
| 367 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 368 | self.waitUntilSettled() |
| 369 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 370 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 371 | self.waitUntilSettled() |
| 372 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 373 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 374 | self.assertBuilds([ |
| 375 | dict(name='project-test1', changes='1,1'), |
| 376 | dict(name='project-test2', changes='1,1'), |
| 377 | dict(name='project-test1', changes='2,1'), |
| 378 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 379 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 380 | dict(name='project-test1', changes='2,1 3,1'), |
| 381 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 382 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 383 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 384 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 385 | self.orderedRelease() |
| 386 | self.assertHistory([ |
| 387 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 388 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 389 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 390 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 391 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 392 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 393 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 394 | dict( |
| 395 | name='project1-project2-integration', |
| 396 | result='SUCCESS', |
| 397 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 398 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 399 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 400 | dict(name='project1-project2-integration', |
| 401 | result='SUCCESS', |
| 402 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 403 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 404 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 405 | self.assertEqual(A.data['status'], 'MERGED') |
| 406 | self.assertEqual(B.data['status'], 'MERGED') |
| 407 | self.assertEqual(C.data['status'], 'MERGED') |
| 408 | self.assertEqual(A.reported, 2) |
| 409 | self.assertEqual(B.reported, 2) |
| 410 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 411 | |
| 412 | def test_failed_change_at_head(self): |
| 413 | "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] | 414 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 415 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 416 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 417 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 418 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 419 | A.addApproval('Code-Review', 2) |
| 420 | B.addApproval('Code-Review', 2) |
| 421 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 422 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 423 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 424 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 425 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 426 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 427 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 428 | |
| 429 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 430 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 431 | self.assertBuilds([ |
| 432 | dict(name='project-merge', changes='1,1'), |
| 433 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 434 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 435 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 436 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 437 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 438 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 439 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 440 | self.waitUntilSettled() |
| 441 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 442 | self.assertBuilds([ |
| 443 | dict(name='project-test1', changes='1,1'), |
| 444 | dict(name='project-test2', changes='1,1'), |
| 445 | dict(name='project-test1', changes='1,1 2,1'), |
| 446 | dict(name='project-test2', changes='1,1 2,1'), |
| 447 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 448 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 449 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 450 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 451 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 452 | self.waitUntilSettled() |
| 453 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 454 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 455 | self.assertBuilds([ |
| 456 | dict(name='project-test2', changes='1,1'), |
| 457 | dict(name='project-merge', changes='2,1'), |
| 458 | ]) |
| 459 | # Unordered history comparison because the aborts can finish |
| 460 | # in any order. |
| 461 | self.assertHistory([ |
| 462 | dict(name='project-merge', result='SUCCESS', |
| 463 | changes='1,1'), |
| 464 | dict(name='project-merge', result='SUCCESS', |
| 465 | changes='1,1 2,1'), |
| 466 | dict(name='project-merge', result='SUCCESS', |
| 467 | changes='1,1 2,1 3,1'), |
| 468 | dict(name='project-test1', result='FAILURE', |
| 469 | changes='1,1'), |
| 470 | dict(name='project-test1', result='ABORTED', |
| 471 | changes='1,1 2,1'), |
| 472 | dict(name='project-test2', result='ABORTED', |
| 473 | changes='1,1 2,1'), |
| 474 | dict(name='project-test1', result='ABORTED', |
| 475 | changes='1,1 2,1 3,1'), |
| 476 | dict(name='project-test2', result='ABORTED', |
| 477 | changes='1,1 2,1 3,1'), |
| 478 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 479 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 480 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 481 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 482 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 483 | self.waitUntilSettled() |
| 484 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 485 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 486 | self.assertBuilds([]) |
| 487 | self.assertHistory([ |
| 488 | dict(name='project-merge', result='SUCCESS', |
| 489 | changes='1,1'), |
| 490 | dict(name='project-merge', result='SUCCESS', |
| 491 | changes='1,1 2,1'), |
| 492 | dict(name='project-merge', result='SUCCESS', |
| 493 | changes='1,1 2,1 3,1'), |
| 494 | dict(name='project-test1', result='FAILURE', |
| 495 | changes='1,1'), |
| 496 | dict(name='project-test1', result='ABORTED', |
| 497 | changes='1,1 2,1'), |
| 498 | dict(name='project-test2', result='ABORTED', |
| 499 | changes='1,1 2,1'), |
| 500 | dict(name='project-test1', result='ABORTED', |
| 501 | changes='1,1 2,1 3,1'), |
| 502 | dict(name='project-test2', result='ABORTED', |
| 503 | changes='1,1 2,1 3,1'), |
| 504 | dict(name='project-merge', result='SUCCESS', |
| 505 | changes='2,1'), |
| 506 | dict(name='project-merge', result='SUCCESS', |
| 507 | changes='2,1 3,1'), |
| 508 | dict(name='project-test2', result='SUCCESS', |
| 509 | changes='1,1'), |
| 510 | dict(name='project-test1', result='SUCCESS', |
| 511 | changes='2,1'), |
| 512 | dict(name='project-test2', result='SUCCESS', |
| 513 | changes='2,1'), |
| 514 | dict(name='project-test1', result='SUCCESS', |
| 515 | changes='2,1 3,1'), |
| 516 | dict(name='project-test2', result='SUCCESS', |
| 517 | changes='2,1 3,1'), |
| 518 | ], ordered=False) |
| 519 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 520 | self.assertEqual(A.data['status'], 'NEW') |
| 521 | self.assertEqual(B.data['status'], 'MERGED') |
| 522 | self.assertEqual(C.data['status'], 'MERGED') |
| 523 | self.assertEqual(A.reported, 2) |
| 524 | self.assertEqual(B.reported, 2) |
| 525 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 526 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 527 | def test_failed_change_in_middle(self): |
| 528 | "Test a failed change in the middle of the queue" |
| 529 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 530 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 531 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 532 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 533 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 534 | A.addApproval('Code-Review', 2) |
| 535 | B.addApproval('Code-Review', 2) |
| 536 | C.addApproval('Code-Review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 537 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 538 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 539 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 540 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 541 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 542 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 543 | |
| 544 | self.waitUntilSettled() |
| 545 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 546 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 547 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 548 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 549 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 550 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 551 | self.waitUntilSettled() |
| 552 | |
| 553 | self.assertEqual(len(self.builds), 6) |
| 554 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 555 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 556 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 557 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 558 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 559 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 560 | |
| 561 | self.release(self.builds[2]) |
| 562 | self.waitUntilSettled() |
| 563 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 564 | # project-test1 and project-test2 for A |
| 565 | # project-test2 for B |
| 566 | # project-merge for C (without B) |
| 567 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 568 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 569 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 570 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 571 | self.waitUntilSettled() |
| 572 | |
| 573 | # project-test1 and project-test2 for A |
| 574 | # project-test2 for B |
| 575 | # project-test1 and project-test2 for C |
| 576 | self.assertEqual(len(self.builds), 5) |
| 577 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 578 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 579 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 580 | builds = items[0].current_build_set.getBuilds() |
| 581 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 582 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 583 | builds = items[1].current_build_set.getBuilds() |
| 584 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 585 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 586 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 587 | builds = items[2].current_build_set.getBuilds() |
| 588 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 589 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 590 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 591 | self.executor_server.hold_jobs_in_build = False |
| 592 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 593 | self.waitUntilSettled() |
| 594 | |
| 595 | self.assertEqual(len(self.builds), 0) |
| 596 | self.assertEqual(len(self.history), 12) |
| 597 | self.assertEqual(A.data['status'], 'MERGED') |
| 598 | self.assertEqual(B.data['status'], 'NEW') |
| 599 | self.assertEqual(C.data['status'], 'MERGED') |
| 600 | self.assertEqual(A.reported, 2) |
| 601 | self.assertEqual(B.reported, 2) |
| 602 | self.assertEqual(C.reported, 2) |
| 603 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 604 | def test_failed_change_at_head_with_queue(self): |
| 605 | "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] | 606 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 607 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 608 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 609 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 610 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 611 | A.addApproval('Code-Review', 2) |
| 612 | B.addApproval('Code-Review', 2) |
| 613 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 614 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 615 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 616 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 617 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 618 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 619 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 620 | |
| 621 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 622 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 623 | self.assertEqual(len(self.builds), 0) |
| 624 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 625 | self.assertEqual(queue[0].name, b'executor:execute') |
| 626 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 627 | self.assertEqual(job_args['job'], 'project-merge') |
| 628 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 629 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 630 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 631 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 632 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 633 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 634 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 635 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 636 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 637 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 638 | self.assertEqual(len(self.builds), 0) |
| 639 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 640 | |
| 641 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 642 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 643 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 644 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 645 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 646 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 647 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 648 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 649 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 650 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 651 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 652 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 653 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 654 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 655 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 656 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 657 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 658 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 659 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 660 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 661 | self.waitUntilSettled() |
| 662 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 663 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 664 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 665 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 666 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 667 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 668 | self.gearman_server.hold_jobs_in_queue = False |
| 669 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 670 | self.waitUntilSettled() |
| 671 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 672 | self.assertEqual(len(self.builds), 0) |
| 673 | self.assertEqual(len(self.history), 11) |
| 674 | self.assertEqual(A.data['status'], 'NEW') |
| 675 | self.assertEqual(B.data['status'], 'MERGED') |
| 676 | self.assertEqual(C.data['status'], 'MERGED') |
| 677 | self.assertEqual(A.reported, 2) |
| 678 | self.assertEqual(B.reported, 2) |
| 679 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 680 | |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 681 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 682 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 683 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 684 | A.addApproval('Code-Review', 2) |
| 685 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 686 | self.waitUntilSettled() |
| 687 | time.sleep(2) |
| 688 | |
James E. Blair | ae0f23c | 2017-09-13 10:55:15 -0600 | [diff] [blame] | 689 | data = json.loads(self.sched.formatStatusJSON('tenant-one')) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 690 | found_job = None |
| 691 | for pipeline in data['pipelines']: |
| 692 | if pipeline['name'] != 'gate': |
| 693 | continue |
| 694 | for queue in pipeline['change_queues']: |
| 695 | for head in queue['heads']: |
| 696 | for item in head: |
| 697 | for job in item['jobs']: |
| 698 | if job['name'] == 'project-merge': |
| 699 | found_job = job |
| 700 | break |
| 701 | |
| 702 | self.assertIsNotNone(found_job) |
| 703 | if iteration == 1: |
| 704 | self.assertIsNotNone(found_job['estimated_time']) |
| 705 | self.assertIsNone(found_job['remaining_time']) |
| 706 | else: |
| 707 | self.assertIsNotNone(found_job['estimated_time']) |
| 708 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 709 | self.assertIsNotNone(found_job['remaining_time']) |
| 710 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 711 | self.executor_server.hold_jobs_in_build = False |
| 712 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 713 | self.waitUntilSettled() |
| 714 | |
| 715 | def test_time_database(self): |
| 716 | "Test the time database" |
| 717 | |
| 718 | self._test_time_database(1) |
| 719 | self._test_time_database(2) |
| 720 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 721 | def test_two_failed_changes_at_head(self): |
| 722 | "Test that changes are reparented correctly if 2 fail at head" |
| 723 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 724 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 725 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 726 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 727 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 728 | A.addApproval('Code-Review', 2) |
| 729 | B.addApproval('Code-Review', 2) |
| 730 | C.addApproval('Code-Review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 731 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 732 | self.executor_server.failJob('project-test1', A) |
| 733 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 734 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 735 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 736 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 737 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 738 | self.waitUntilSettled() |
| 739 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 740 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 741 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 742 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 743 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 744 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 745 | self.waitUntilSettled() |
| 746 | |
| 747 | self.assertEqual(len(self.builds), 6) |
| 748 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 749 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 750 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 751 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 752 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 753 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 754 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 755 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 756 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 757 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 758 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 759 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 760 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 761 | |
| 762 | # Fail change B first |
| 763 | self.release(self.builds[2]) |
| 764 | self.waitUntilSettled() |
| 765 | |
| 766 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 767 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 768 | self.waitUntilSettled() |
| 769 | |
| 770 | self.assertEqual(len(self.builds), 5) |
| 771 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 772 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 773 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 774 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 775 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 776 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 777 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 778 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 779 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 780 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 781 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 782 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 783 | |
| 784 | # Finish running all passing jobs for change A |
| 785 | self.release(self.builds[1]) |
| 786 | self.waitUntilSettled() |
| 787 | # Fail and report change A |
| 788 | self.release(self.builds[0]) |
| 789 | self.waitUntilSettled() |
| 790 | |
| 791 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 792 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 793 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 794 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 795 | self.waitUntilSettled() |
| 796 | |
| 797 | self.assertEqual(len(self.builds), 4) |
| 798 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 799 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 800 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 801 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 802 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 803 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 804 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 805 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 806 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 807 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 808 | # After A failed and B and C restarted, B should be back in |
| 809 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 810 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 811 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 812 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 813 | self.executor_server.hold_jobs_in_build = False |
| 814 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 815 | self.waitUntilSettled() |
| 816 | |
| 817 | self.assertEqual(len(self.builds), 0) |
| 818 | self.assertEqual(len(self.history), 21) |
| 819 | self.assertEqual(A.data['status'], 'NEW') |
| 820 | self.assertEqual(B.data['status'], 'NEW') |
| 821 | self.assertEqual(C.data['status'], 'MERGED') |
| 822 | self.assertEqual(A.reported, 2) |
| 823 | self.assertEqual(B.reported, 2) |
| 824 | self.assertEqual(C.reported, 2) |
| 825 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 826 | def test_patch_order(self): |
| 827 | "Test that dependent patches are tested in the right order" |
| 828 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 829 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 830 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 831 | A.addApproval('Code-Review', 2) |
| 832 | B.addApproval('Code-Review', 2) |
| 833 | C.addApproval('Code-Review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 834 | |
| 835 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 836 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 837 | M2.setMerged() |
| 838 | M1.setMerged() |
| 839 | |
| 840 | # C -> B -> A -> M1 -> M2 |
| 841 | # M2 is here to make sure it is never queried. If it is, it |
| 842 | # means zuul is walking down the entire history of merged |
| 843 | # changes. |
| 844 | |
| 845 | C.setDependsOn(B, 1) |
| 846 | B.setDependsOn(A, 1) |
| 847 | A.setDependsOn(M1, 1) |
| 848 | M1.setDependsOn(M2, 1) |
| 849 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 850 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 851 | |
| 852 | self.waitUntilSettled() |
| 853 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 854 | self.assertEqual(A.data['status'], 'NEW') |
| 855 | self.assertEqual(B.data['status'], 'NEW') |
| 856 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 857 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 858 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 859 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 860 | |
| 861 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 862 | self.assertEqual(M2.queried, 0) |
| 863 | self.assertEqual(A.data['status'], 'MERGED') |
| 864 | self.assertEqual(B.data['status'], 'MERGED') |
| 865 | self.assertEqual(C.data['status'], 'MERGED') |
| 866 | self.assertEqual(A.reported, 2) |
| 867 | self.assertEqual(B.reported, 2) |
| 868 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 869 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 870 | def test_needed_changes_enqueue(self): |
| 871 | "Test that a needed change is enqueued ahead" |
| 872 | # A Given a git tree like this, if we enqueue |
| 873 | # / \ change C, we should walk up and down the tree |
| 874 | # B G and enqueue changes in the order ABCDEFG. |
| 875 | # /|\ This is also the order that you would get if |
| 876 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 877 | # / the ordering is stable across re-enqueue events. |
| 878 | # D |
| 879 | |
| 880 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 881 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 882 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 883 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 884 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 885 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 886 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 887 | B.setDependsOn(A, 1) |
| 888 | C.setDependsOn(B, 1) |
| 889 | D.setDependsOn(C, 1) |
| 890 | E.setDependsOn(B, 1) |
| 891 | F.setDependsOn(B, 1) |
| 892 | G.setDependsOn(A, 1) |
| 893 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 894 | A.addApproval('Code-Review', 2) |
| 895 | B.addApproval('Code-Review', 2) |
| 896 | C.addApproval('Code-Review', 2) |
| 897 | D.addApproval('Code-Review', 2) |
| 898 | E.addApproval('Code-Review', 2) |
| 899 | F.addApproval('Code-Review', 2) |
| 900 | G.addApproval('Code-Review', 2) |
| 901 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 902 | |
| 903 | self.waitUntilSettled() |
| 904 | |
| 905 | self.assertEqual(A.data['status'], 'NEW') |
| 906 | self.assertEqual(B.data['status'], 'NEW') |
| 907 | self.assertEqual(C.data['status'], 'NEW') |
| 908 | self.assertEqual(D.data['status'], 'NEW') |
| 909 | self.assertEqual(E.data['status'], 'NEW') |
| 910 | self.assertEqual(F.data['status'], 'NEW') |
| 911 | self.assertEqual(G.data['status'], 'NEW') |
| 912 | |
| 913 | # We're about to add approvals to changes without adding the |
| 914 | # triggering events to Zuul, so that we can be sure that it is |
| 915 | # enqueing the changes based on dependencies, not because of |
| 916 | # triggering events. Since it will have the changes cached |
| 917 | # already (without approvals), we need to clear the cache |
| 918 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 919 | for connection in self.connections.connections.values(): |
James E. Blair | b0a95ab | 2017-10-18 09:39:18 -0700 | [diff] [blame] | 920 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 921 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 922 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 923 | A.addApproval('Approved', 1) |
| 924 | B.addApproval('Approved', 1) |
| 925 | D.addApproval('Approved', 1) |
| 926 | E.addApproval('Approved', 1) |
| 927 | F.addApproval('Approved', 1) |
| 928 | G.addApproval('Approved', 1) |
| 929 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 930 | |
| 931 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 932 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 933 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 934 | self.executor_server.hold_jobs_in_build = False |
| 935 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 936 | self.waitUntilSettled() |
| 937 | |
| 938 | self.assertEqual(A.data['status'], 'MERGED') |
| 939 | self.assertEqual(B.data['status'], 'MERGED') |
| 940 | self.assertEqual(C.data['status'], 'MERGED') |
| 941 | self.assertEqual(D.data['status'], 'MERGED') |
| 942 | self.assertEqual(E.data['status'], 'MERGED') |
| 943 | self.assertEqual(F.data['status'], 'MERGED') |
| 944 | self.assertEqual(G.data['status'], 'MERGED') |
| 945 | self.assertEqual(A.reported, 2) |
| 946 | self.assertEqual(B.reported, 2) |
| 947 | self.assertEqual(C.reported, 2) |
| 948 | self.assertEqual(D.reported, 2) |
| 949 | self.assertEqual(E.reported, 2) |
| 950 | self.assertEqual(F.reported, 2) |
| 951 | self.assertEqual(G.reported, 2) |
| 952 | self.assertEqual(self.history[6].changes, |
| 953 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 954 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 955 | def test_source_cache(self): |
| 956 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 957 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 958 | |
| 959 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 960 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 961 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 962 | A.addApproval('Code-Review', 2) |
| 963 | B.addApproval('Code-Review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 964 | |
| 965 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 966 | M1.setMerged() |
| 967 | |
| 968 | B.setDependsOn(A, 1) |
| 969 | A.setDependsOn(M1, 1) |
| 970 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 971 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 972 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 973 | |
| 974 | self.waitUntilSettled() |
| 975 | |
| 976 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 977 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 978 | build.release() |
| 979 | self.waitUntilSettled() |
| 980 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 981 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 982 | build.release() |
| 983 | self.waitUntilSettled() |
| 984 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 985 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 986 | self.waitUntilSettled() |
| 987 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 988 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 989 | # there should still be changes in the cache |
James E. Blair | b0a95ab | 2017-10-18 09:39:18 -0700 | [diff] [blame] | 990 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 991 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 992 | self.executor_server.hold_jobs_in_build = False |
| 993 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 994 | self.waitUntilSettled() |
| 995 | |
| 996 | self.assertEqual(A.data['status'], 'MERGED') |
| 997 | self.assertEqual(B.data['status'], 'MERGED') |
| 998 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 999 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 1000 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1001 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1002 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1003 | # TODO: move to test_gerrit (this is a unit test!) |
| 1004 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 1005 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 1006 | (trusted, project) = tenant.getProject('org/project') |
| 1007 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 1008 | |
| 1009 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 1010 | # it easier for users to create events for testing. |
| 1011 | event = zuul.model.TriggerEvent() |
| 1012 | event.trigger_name = 'gerrit' |
| 1013 | event.change_number = '1' |
| 1014 | event.patch_number = '2' |
| 1015 | |
| 1016 | a = source.getChange(event) |
| 1017 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1018 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1019 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1020 | A.addApproval('Code-Review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 1021 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1022 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1023 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1024 | A.addApproval('Approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 1025 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 1026 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1027 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1028 | def test_project_merge_conflict(self): |
| 1029 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1030 | |
| 1031 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1032 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1033 | 'master', 'A', |
| 1034 | files={'conflict': 'foo'}) |
| 1035 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1036 | 'master', 'B', |
| 1037 | files={'conflict': 'bar'}) |
| 1038 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1039 | 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1040 | A.addApproval('Code-Review', 2) |
| 1041 | B.addApproval('Code-Review', 2) |
| 1042 | C.addApproval('Code-Review', 2) |
| 1043 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1044 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1045 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1046 | self.waitUntilSettled() |
| 1047 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1048 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1049 | self.assertEqual(C.reported, 1) |
| 1050 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1051 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1052 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1053 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1054 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1055 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1056 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1057 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1058 | self.gearman_server.hold_jobs_in_queue = False |
| 1059 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1060 | self.waitUntilSettled() |
| 1061 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1062 | self.assertEqual(A.data['status'], 'MERGED') |
| 1063 | self.assertEqual(B.data['status'], 'NEW') |
| 1064 | self.assertEqual(C.data['status'], 'MERGED') |
| 1065 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1066 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1067 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1068 | |
| 1069 | self.assertHistory([ |
| 1070 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1071 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1072 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1073 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1074 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1075 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1076 | ], ordered=False) |
| 1077 | |
| 1078 | def test_delayed_merge_conflict(self): |
| 1079 | "Test that delayed check merge conflicts are handled properly" |
| 1080 | |
| 1081 | # 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] | 1082 | # the executor sucesfully merges a change based on an old |
| 1083 | # repo state (frozen by the scheduler) which would otherwise |
| 1084 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1085 | self.gearman_server.hold_jobs_in_queue = True |
| 1086 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1087 | 'master', 'A', |
| 1088 | files={'conflict': 'foo'}) |
| 1089 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1090 | 'master', 'B', |
| 1091 | files={'conflict': 'bar'}) |
| 1092 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1093 | 'master', 'C') |
| 1094 | C.setDependsOn(B, 1) |
| 1095 | |
| 1096 | # A enters the gate queue; B and C enter the check queue |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1097 | A.addApproval('Code-Review', 2) |
| 1098 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1099 | self.waitUntilSettled() |
| 1100 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1101 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1102 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1103 | self.waitUntilSettled() |
| 1104 | |
| 1105 | self.assertEqual(A.reported, 1) |
| 1106 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1107 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1108 | |
| 1109 | # A merges while B and C are queued in check |
| 1110 | # Release A project-merge |
| 1111 | queue = self.gearman_server.getQueue() |
| 1112 | self.release(queue[0]) |
| 1113 | self.waitUntilSettled() |
| 1114 | |
| 1115 | # Release A project-test* |
| 1116 | # gate has higher precedence, so A's test jobs are added in |
| 1117 | # front of the merge jobs for B and C |
| 1118 | queue = self.gearman_server.getQueue() |
| 1119 | self.release(queue[0]) |
| 1120 | self.release(queue[1]) |
| 1121 | self.waitUntilSettled() |
| 1122 | |
| 1123 | self.assertEqual(A.data['status'], 'MERGED') |
| 1124 | self.assertEqual(B.data['status'], 'NEW') |
| 1125 | self.assertEqual(C.data['status'], 'NEW') |
| 1126 | self.assertEqual(A.reported, 2) |
| 1127 | self.assertEqual(B.reported, 0) |
| 1128 | self.assertEqual(C.reported, 0) |
| 1129 | self.assertHistory([ |
| 1130 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1131 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1132 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1133 | ], ordered=False) |
| 1134 | |
| 1135 | # B and C report merge conflicts |
| 1136 | # Release B project-merge |
| 1137 | queue = self.gearman_server.getQueue() |
| 1138 | self.release(queue[0]) |
| 1139 | self.waitUntilSettled() |
| 1140 | |
| 1141 | # Release C |
| 1142 | self.gearman_server.hold_jobs_in_queue = False |
| 1143 | self.gearman_server.release() |
| 1144 | self.waitUntilSettled() |
| 1145 | |
| 1146 | self.assertEqual(A.data['status'], 'MERGED') |
| 1147 | self.assertEqual(B.data['status'], 'NEW') |
| 1148 | self.assertEqual(C.data['status'], 'NEW') |
| 1149 | self.assertEqual(A.reported, 2) |
| 1150 | self.assertEqual(B.reported, 1) |
| 1151 | self.assertEqual(C.reported, 1) |
| 1152 | |
| 1153 | self.assertHistory([ |
| 1154 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1155 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1156 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1157 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1158 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1159 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1160 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1161 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1162 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1163 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1164 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1165 | def test_post(self): |
| 1166 | "Test that post jobs run" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1167 | p = "review.example.com/org/project" |
| 1168 | upstream = self.getUpstreamRepos([p]) |
| 1169 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1170 | A.setMerged() |
| 1171 | A_commit = str(upstream[p].commit('master')) |
| 1172 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1173 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1174 | e = { |
| 1175 | "type": "ref-updated", |
| 1176 | "submitter": { |
| 1177 | "name": "User Name", |
| 1178 | }, |
| 1179 | "refUpdate": { |
| 1180 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1181 | "newRev": A_commit, |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1182 | "refName": "master", |
| 1183 | "project": "org/project", |
| 1184 | } |
| 1185 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1186 | self.fake_gerrit.addEvent(e) |
| 1187 | self.waitUntilSettled() |
| 1188 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1189 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1190 | self.assertEqual(len(self.history), 1) |
| 1191 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1192 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1193 | def test_post_ignore_deletes(self): |
| 1194 | "Test that deleting refs does not trigger post jobs" |
| 1195 | |
| 1196 | e = { |
| 1197 | "type": "ref-updated", |
| 1198 | "submitter": { |
| 1199 | "name": "User Name", |
| 1200 | }, |
| 1201 | "refUpdate": { |
| 1202 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1203 | "newRev": "0000000000000000000000000000000000000000", |
| 1204 | "refName": "master", |
| 1205 | "project": "org/project", |
| 1206 | } |
| 1207 | } |
| 1208 | self.fake_gerrit.addEvent(e) |
| 1209 | self.waitUntilSettled() |
| 1210 | |
| 1211 | job_names = [x.name for x in self.history] |
| 1212 | self.assertEqual(len(self.history), 0) |
| 1213 | self.assertNotIn('project-post', job_names) |
| 1214 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1215 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1216 | def test_post_ignore_deletes_negative(self): |
| 1217 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1218 | e = { |
| 1219 | "type": "ref-updated", |
| 1220 | "submitter": { |
| 1221 | "name": "User Name", |
| 1222 | }, |
| 1223 | "refUpdate": { |
| 1224 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1225 | "newRev": "0000000000000000000000000000000000000000", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1226 | "refName": "testbranch", |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1227 | "project": "org/project", |
| 1228 | } |
| 1229 | } |
| 1230 | self.fake_gerrit.addEvent(e) |
| 1231 | self.waitUntilSettled() |
| 1232 | |
| 1233 | job_names = [x.name for x in self.history] |
| 1234 | self.assertEqual(len(self.history), 1) |
| 1235 | self.assertIn('project-post', job_names) |
| 1236 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1237 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1238 | def test_build_configuration_branch_interaction(self): |
| 1239 | "Test that switching between branches works" |
| 1240 | self.test_build_configuration() |
| 1241 | self.test_build_configuration_branch() |
| 1242 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1243 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1244 | repo = git.Repo(path) |
| 1245 | repo.heads.master.commit = repo.commit('init') |
| 1246 | self.test_build_configuration() |
| 1247 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1248 | def test_dependent_changes_rebase(self): |
| 1249 | # Test that no errors occur when we walk a dependency tree |
| 1250 | # with an unused leaf node due to a rebase. |
| 1251 | # Start by constructing: C -> B -> A |
| 1252 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1253 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1254 | B.setDependsOn(A, 1) |
| 1255 | |
| 1256 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1257 | C.setDependsOn(B, 1) |
| 1258 | |
| 1259 | # Then rebase to form: D -> C -> A |
| 1260 | C.addPatchset() # C,2 |
| 1261 | C.setDependsOn(A, 1) |
| 1262 | |
| 1263 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1264 | D.setDependsOn(C, 2) |
| 1265 | |
| 1266 | # Walk the entire tree |
| 1267 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1268 | self.waitUntilSettled() |
| 1269 | self.assertEqual(len(self.history), 3) |
| 1270 | |
| 1271 | # Verify that walking just part of the tree still works |
| 1272 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1273 | self.waitUntilSettled() |
| 1274 | self.assertEqual(len(self.history), 6) |
| 1275 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1276 | def test_dependent_changes_dequeue(self): |
| 1277 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1278 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1279 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1280 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1281 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1282 | A.addApproval('Code-Review', 2) |
| 1283 | B.addApproval('Code-Review', 2) |
| 1284 | C.addApproval('Code-Review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1285 | |
| 1286 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1287 | M1.setMerged() |
| 1288 | |
| 1289 | # C -> B -> A -> M1 |
| 1290 | |
| 1291 | C.setDependsOn(B, 1) |
| 1292 | B.setDependsOn(A, 1) |
| 1293 | A.setDependsOn(M1, 1) |
| 1294 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1295 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1296 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1297 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1298 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1299 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1300 | |
| 1301 | self.waitUntilSettled() |
| 1302 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1303 | self.assertEqual(A.data['status'], 'NEW') |
| 1304 | self.assertEqual(A.reported, 2) |
| 1305 | self.assertEqual(B.data['status'], 'NEW') |
| 1306 | self.assertEqual(B.reported, 2) |
| 1307 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1308 | self.assertIn('This change depends on a change that failed to merge.', |
| 1309 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1310 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1311 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1312 | def test_failing_dependent_changes(self): |
| 1313 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1314 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1315 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1316 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1317 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1318 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1319 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1320 | A.addApproval('Code-Review', 2) |
| 1321 | B.addApproval('Code-Review', 2) |
| 1322 | C.addApproval('Code-Review', 2) |
| 1323 | D.addApproval('Code-Review', 2) |
| 1324 | E.addApproval('Code-Review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1325 | |
| 1326 | # E, D -> C -> B, A |
| 1327 | |
| 1328 | D.setDependsOn(C, 1) |
| 1329 | C.setDependsOn(B, 1) |
| 1330 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1331 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1332 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1333 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1334 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
| 1335 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1336 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1337 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1338 | |
| 1339 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1340 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1341 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1342 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1343 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1344 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1345 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1346 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1347 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1348 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1349 | self.waitUntilSettled() |
| 1350 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1351 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1352 | for build in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 1353 | if build.parameters['zuul']['change'] != '1': |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1354 | build.release() |
| 1355 | self.waitUntilSettled() |
| 1356 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1357 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1358 | self.waitUntilSettled() |
| 1359 | |
| 1360 | self.assertEqual(A.data['status'], 'MERGED') |
| 1361 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1362 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1363 | self.assertEqual(B.data['status'], 'NEW') |
| 1364 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1365 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1366 | self.assertEqual(C.data['status'], 'NEW') |
| 1367 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1368 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1369 | self.assertEqual(D.data['status'], 'NEW') |
| 1370 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1371 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1372 | self.assertEqual(E.data['status'], 'MERGED') |
| 1373 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1374 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1375 | self.assertEqual(len(self.history), 18) |
| 1376 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1377 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1378 | "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] | 1379 | # If it's dequeued more than once, we should see extra |
| 1380 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1381 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1382 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1383 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1384 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1385 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1386 | A.addApproval('Code-Review', 2) |
| 1387 | B.addApproval('Code-Review', 2) |
| 1388 | C.addApproval('Code-Review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1389 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1390 | self.executor_server.failJob('project-test1', A) |
| 1391 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1392 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1393 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1394 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1395 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1396 | |
| 1397 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1398 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1399 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1400 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1401 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1402 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1403 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1404 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1405 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1406 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1407 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1408 | self.waitUntilSettled() |
| 1409 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1410 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1411 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1412 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1413 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1414 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1415 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1416 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1417 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1418 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1419 | self.waitUntilSettled() |
| 1420 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1421 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1422 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1423 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1424 | self.executor_server.hold_jobs_in_build = False |
| 1425 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1426 | self.waitUntilSettled() |
| 1427 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1428 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1429 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1430 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1431 | self.assertEqual(A.data['status'], 'NEW') |
| 1432 | self.assertEqual(B.data['status'], 'MERGED') |
| 1433 | self.assertEqual(C.data['status'], 'MERGED') |
| 1434 | self.assertEqual(A.reported, 2) |
| 1435 | self.assertEqual(B.reported, 2) |
| 1436 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1437 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1438 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1439 | def test_nonvoting_job(self): |
| 1440 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1441 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1442 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1443 | 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1444 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1445 | self.executor_server.failJob('nonvoting-project-test2', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1446 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1447 | |
| 1448 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1449 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1450 | self.assertEqual(A.data['status'], 'MERGED') |
| 1451 | self.assertEqual(A.reported, 2) |
| 1452 | self.assertEqual( |
| 1453 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1454 | 'SUCCESS') |
| 1455 | self.assertEqual( |
| 1456 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1457 | 'SUCCESS') |
| 1458 | self.assertEqual( |
| 1459 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1460 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1461 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 1462 | self.assertTrue(self.getJobFromHistory('nonvoting-project-merge'). |
| 1463 | parameters['zuul']['voting']) |
| 1464 | self.assertTrue(self.getJobFromHistory('nonvoting-project-test1'). |
| 1465 | parameters['zuul']['voting']) |
| 1466 | self.assertFalse(self.getJobFromHistory('nonvoting-project-test2'). |
| 1467 | parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1468 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1469 | def test_check_queue_success(self): |
| 1470 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1471 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1472 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1473 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1474 | |
| 1475 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1476 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1477 | self.assertEqual(A.data['status'], 'NEW') |
| 1478 | self.assertEqual(A.reported, 1) |
| 1479 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1480 | 'SUCCESS') |
| 1481 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1482 | 'SUCCESS') |
| 1483 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1484 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1485 | |
| 1486 | def test_check_queue_failure(self): |
| 1487 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1488 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1489 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1490 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1491 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1492 | |
| 1493 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1494 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1495 | self.assertEqual(A.data['status'], 'NEW') |
| 1496 | self.assertEqual(A.reported, 1) |
| 1497 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1498 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1499 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1500 | 'SUCCESS') |
| 1501 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1502 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1503 | |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1504 | @simple_layout('layouts/autohold.yaml') |
| 1505 | def test_autohold(self): |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1506 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1507 | self.gearman_server.port) |
| 1508 | self.addCleanup(client.shutdown) |
David Shrewsbury | 36b2adf | 2017-07-31 15:40:13 -0400 | [diff] [blame] | 1509 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1510 | "reason text", 1) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1511 | self.assertTrue(r) |
| 1512 | |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1513 | # First check that successful jobs do not autohold |
| 1514 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1515 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1516 | |
| 1517 | self.waitUntilSettled() |
| 1518 | |
| 1519 | self.assertEqual(A.data['status'], 'NEW') |
| 1520 | self.assertEqual(A.reported, 1) |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1521 | # project-test2 |
| 1522 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 1523 | |
| 1524 | # Check nodepool for a held node |
| 1525 | held_node = None |
| 1526 | for node in self.fake_nodepool.getNodes(): |
| 1527 | if node['state'] == zuul.model.STATE_HOLD: |
| 1528 | held_node = node |
| 1529 | break |
| 1530 | self.assertIsNone(held_node) |
| 1531 | |
| 1532 | # Now test that failed jobs are autoheld |
| 1533 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1534 | self.executor_server.failJob('project-test2', B) |
| 1535 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1536 | |
| 1537 | self.waitUntilSettled() |
| 1538 | |
| 1539 | self.assertEqual(B.data['status'], 'NEW') |
| 1540 | self.assertEqual(B.reported, 1) |
| 1541 | # project-test2 |
| 1542 | self.assertEqual(self.history[1].result, 'FAILURE') |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1543 | |
| 1544 | # Check nodepool for a held node |
| 1545 | held_node = None |
| 1546 | for node in self.fake_nodepool.getNodes(): |
| 1547 | if node['state'] == zuul.model.STATE_HOLD: |
| 1548 | held_node = node |
| 1549 | break |
| 1550 | self.assertIsNotNone(held_node) |
| 1551 | |
| 1552 | # Validate node has recorded the failed job |
| 1553 | self.assertEqual( |
| 1554 | held_node['hold_job'], |
| 1555 | " ".join(['tenant-one', |
| 1556 | 'review.example.com/org/project', |
| 1557 | 'project-test2']) |
| 1558 | ) |
David Shrewsbury | f9af9df | 2017-08-01 15:19:26 -0400 | [diff] [blame] | 1559 | self.assertEqual(held_node['comment'], "reason text") |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1560 | |
| 1561 | # Another failed change should not hold any more nodes |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1562 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1563 | self.executor_server.failJob('project-test2', C) |
| 1564 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1565 | self.waitUntilSettled() |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1566 | self.assertEqual(C.data['status'], 'NEW') |
| 1567 | self.assertEqual(C.reported, 1) |
| 1568 | # project-test2 |
| 1569 | self.assertEqual(self.history[2].result, 'FAILURE') |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1570 | |
| 1571 | held_nodes = 0 |
| 1572 | for node in self.fake_nodepool.getNodes(): |
| 1573 | if node['state'] == zuul.model.STATE_HOLD: |
| 1574 | held_nodes += 1 |
| 1575 | self.assertEqual(held_nodes, 1) |
| 1576 | |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1577 | @simple_layout('layouts/autohold.yaml') |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1578 | def test_autohold_ignores_aborted_jobs(self): |
| 1579 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1580 | self.gearman_server.port) |
| 1581 | self.addCleanup(client.shutdown) |
| 1582 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1583 | "reason text", 1) |
| 1584 | self.assertTrue(r) |
| 1585 | |
| 1586 | self.executor_server.hold_jobs_in_build = True |
| 1587 | |
| 1588 | # Create a change that will have its job aborted |
| 1589 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1590 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1591 | self.waitUntilSettled() |
| 1592 | |
| 1593 | # Creating new patchset on change A will abort A,1's job because |
| 1594 | # a new patchset arrived replacing A,1 with A,2. |
| 1595 | A.addPatchset() |
| 1596 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1597 | |
| 1598 | self.waitUntilSettled() |
| 1599 | self.executor_server.hold_jobs_in_build = False |
| 1600 | self.executor_server.release() |
| 1601 | self.waitUntilSettled() |
| 1602 | |
| 1603 | self.assertEqual(A.data['status'], 'NEW') |
| 1604 | # Note only the successful job for A,2 will report as we don't |
| 1605 | # report aborted builds for old patchsets. |
| 1606 | self.assertEqual(A.reported, 1) |
| 1607 | # A,1 project-test2 |
| 1608 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1609 | # A,2 project-test2 |
| 1610 | self.assertEqual(self.history[1].result, 'SUCCESS') |
| 1611 | |
| 1612 | # Check nodepool for a held node |
| 1613 | held_node = None |
| 1614 | for node in self.fake_nodepool.getNodes(): |
| 1615 | if node['state'] == zuul.model.STATE_HOLD: |
| 1616 | held_node = node |
| 1617 | break |
| 1618 | self.assertIsNone(held_node) |
| 1619 | |
| 1620 | @simple_layout('layouts/autohold.yaml') |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1621 | def test_autohold_list(self): |
| 1622 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1623 | self.gearman_server.port) |
| 1624 | self.addCleanup(client.shutdown) |
| 1625 | |
| 1626 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1627 | "reason text", 1) |
| 1628 | self.assertTrue(r) |
| 1629 | |
| 1630 | autohold_requests = client.autohold_list() |
| 1631 | self.assertNotEqual({}, autohold_requests) |
| 1632 | self.assertEqual(1, len(autohold_requests.keys())) |
| 1633 | |
| 1634 | # The single dict key should be a CSV string value |
| 1635 | key = list(autohold_requests.keys())[0] |
| 1636 | tenant, project, job = key.split(',') |
| 1637 | |
| 1638 | self.assertEqual('tenant-one', tenant) |
| 1639 | self.assertIn('org/project', project) |
| 1640 | self.assertEqual('project-test2', job) |
| 1641 | |
| 1642 | # Note: the value is converted from set to list by json. |
| 1643 | self.assertEqual([1, "reason text"], autohold_requests[key]) |
| 1644 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1645 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1646 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1647 | # This particular test does a large amount of merges and needs a little |
| 1648 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1649 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1650 | "test that dependent changes behind dequeued changes work" |
| 1651 | # This complicated test is a reproduction of a real life bug |
| 1652 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1653 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1654 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1655 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1656 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1657 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1658 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1659 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1660 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1661 | D.setDependsOn(C, 1) |
| 1662 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1663 | A.addApproval('Code-Review', 2) |
| 1664 | B.addApproval('Code-Review', 2) |
| 1665 | C.addApproval('Code-Review', 2) |
| 1666 | D.addApproval('Code-Review', 2) |
| 1667 | E.addApproval('Code-Review', 2) |
| 1668 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1669 | |
| 1670 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1671 | |
| 1672 | # Change object re-use in the gerrit trigger is hidden if |
| 1673 | # changes are added in quick succession; waiting makes it more |
| 1674 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1675 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1676 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1677 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1678 | self.waitUntilSettled() |
| 1679 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1680 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1681 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1682 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1683 | self.waitUntilSettled() |
| 1684 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1685 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1686 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1687 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1688 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1689 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1690 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1691 | self.fake_gerrit.addEvent(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1692 | self.waitUntilSettled() |
| 1693 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1694 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1695 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1696 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1697 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1698 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1699 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1700 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1701 | self.waitUntilSettled() |
| 1702 | |
| 1703 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1704 | |
| 1705 | # Grab pointers to the jobs we want to release before |
| 1706 | # releasing any, because list indexes may change as |
| 1707 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1708 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1709 | a.release() |
| 1710 | b.release() |
| 1711 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1712 | self.waitUntilSettled() |
| 1713 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1714 | self.executor_server.hold_jobs_in_build = False |
| 1715 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1716 | self.waitUntilSettled() |
| 1717 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1718 | self.assertEqual(A.data['status'], 'NEW') |
| 1719 | self.assertEqual(B.data['status'], 'MERGED') |
| 1720 | self.assertEqual(C.data['status'], 'MERGED') |
| 1721 | self.assertEqual(D.data['status'], 'MERGED') |
| 1722 | self.assertEqual(E.data['status'], 'MERGED') |
| 1723 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1724 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1725 | self.assertEqual(A.reported, 2) |
| 1726 | self.assertEqual(B.reported, 2) |
| 1727 | self.assertEqual(C.reported, 2) |
| 1728 | self.assertEqual(D.reported, 2) |
| 1729 | self.assertEqual(E.reported, 2) |
| 1730 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1731 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1732 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1733 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1734 | |
| 1735 | def test_merger_repack(self): |
| 1736 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1737 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1738 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1739 | A.addApproval('Code-Review', 2) |
| 1740 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1741 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1742 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1743 | 'SUCCESS') |
| 1744 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1745 | 'SUCCESS') |
| 1746 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1747 | 'SUCCESS') |
| 1748 | self.assertEqual(A.data['status'], 'MERGED') |
| 1749 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1750 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1751 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1752 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1753 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1754 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1755 | if os.path.exists(path): |
| 1756 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1757 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1758 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1759 | if os.path.exists(path): |
| 1760 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1761 | |
| 1762 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1763 | A.addApproval('Code-Review', 2) |
| 1764 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1765 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1766 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1767 | 'SUCCESS') |
| 1768 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1769 | 'SUCCESS') |
| 1770 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1771 | 'SUCCESS') |
| 1772 | self.assertEqual(A.data['status'], 'MERGED') |
| 1773 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1774 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1775 | def test_merger_repack_large_change(self): |
| 1776 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1777 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1778 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1779 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1780 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1781 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1782 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1783 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1784 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1785 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1786 | # TODOv3(jeblair): add hostname to upstream root |
| 1787 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1788 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1789 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1790 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1791 | if os.path.exists(path): |
| 1792 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1793 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1794 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1795 | if os.path.exists(path): |
| 1796 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1797 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1798 | A.addApproval('Code-Review', 2) |
| 1799 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1800 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1801 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1802 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1803 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1804 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1805 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1806 | 'SUCCESS') |
| 1807 | self.assertEqual(A.data['status'], 'MERGED') |
| 1808 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1809 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1810 | def test_new_patchset_dequeues_old(self): |
| 1811 | "Test that a new patchset causes the old to be dequeued" |
| 1812 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1813 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1814 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1815 | M.setMerged() |
| 1816 | |
| 1817 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1818 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1819 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1820 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1821 | A.addApproval('Code-Review', 2) |
| 1822 | B.addApproval('Code-Review', 2) |
| 1823 | C.addApproval('Code-Review', 2) |
| 1824 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1825 | |
| 1826 | C.setDependsOn(B, 1) |
| 1827 | B.setDependsOn(A, 1) |
| 1828 | A.setDependsOn(M, 1) |
| 1829 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1830 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1831 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1832 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1833 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1834 | self.waitUntilSettled() |
| 1835 | |
| 1836 | B.addPatchset() |
| 1837 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1838 | self.waitUntilSettled() |
| 1839 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1840 | self.executor_server.hold_jobs_in_build = False |
| 1841 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1842 | self.waitUntilSettled() |
| 1843 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1844 | self.assertEqual(A.data['status'], 'MERGED') |
| 1845 | self.assertEqual(A.reported, 2) |
| 1846 | self.assertEqual(B.data['status'], 'NEW') |
| 1847 | self.assertEqual(B.reported, 2) |
| 1848 | self.assertEqual(C.data['status'], 'NEW') |
| 1849 | self.assertEqual(C.reported, 2) |
| 1850 | self.assertEqual(D.data['status'], 'MERGED') |
| 1851 | self.assertEqual(D.reported, 2) |
| 1852 | 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] | 1853 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1854 | def test_new_patchset_check(self): |
| 1855 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1856 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1857 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1858 | |
| 1859 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1860 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1861 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1862 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1863 | |
| 1864 | # Add two git-dependent changes |
| 1865 | B.setDependsOn(A, 1) |
| 1866 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1867 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1868 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1869 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1870 | |
| 1871 | # A live item, and a non-live/live pair |
| 1872 | items = check_pipeline.getAllItems() |
| 1873 | self.assertEqual(len(items), 3) |
| 1874 | |
| 1875 | self.assertEqual(items[0].change.number, '1') |
| 1876 | self.assertEqual(items[0].change.patchset, '1') |
| 1877 | self.assertFalse(items[0].live) |
| 1878 | |
| 1879 | self.assertEqual(items[1].change.number, '2') |
| 1880 | self.assertEqual(items[1].change.patchset, '1') |
| 1881 | self.assertTrue(items[1].live) |
| 1882 | |
| 1883 | self.assertEqual(items[2].change.number, '1') |
| 1884 | self.assertEqual(items[2].change.patchset, '1') |
| 1885 | self.assertTrue(items[2].live) |
| 1886 | |
| 1887 | # Add a new patchset to A |
| 1888 | A.addPatchset() |
| 1889 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1890 | self.waitUntilSettled() |
| 1891 | |
| 1892 | # The live copy of A,1 should be gone, but the non-live and B |
| 1893 | # should continue, and we should have a new A,2 |
| 1894 | items = check_pipeline.getAllItems() |
| 1895 | self.assertEqual(len(items), 3) |
| 1896 | |
| 1897 | self.assertEqual(items[0].change.number, '1') |
| 1898 | self.assertEqual(items[0].change.patchset, '1') |
| 1899 | self.assertFalse(items[0].live) |
| 1900 | |
| 1901 | self.assertEqual(items[1].change.number, '2') |
| 1902 | self.assertEqual(items[1].change.patchset, '1') |
| 1903 | self.assertTrue(items[1].live) |
| 1904 | |
| 1905 | self.assertEqual(items[2].change.number, '1') |
| 1906 | self.assertEqual(items[2].change.patchset, '2') |
| 1907 | self.assertTrue(items[2].live) |
| 1908 | |
| 1909 | # Add a new patchset to B |
| 1910 | B.addPatchset() |
| 1911 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1912 | self.waitUntilSettled() |
| 1913 | |
| 1914 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1915 | # but we should have a new B,2 (still based on A,1) |
| 1916 | items = check_pipeline.getAllItems() |
| 1917 | self.assertEqual(len(items), 3) |
| 1918 | |
| 1919 | self.assertEqual(items[0].change.number, '1') |
| 1920 | self.assertEqual(items[0].change.patchset, '2') |
| 1921 | self.assertTrue(items[0].live) |
| 1922 | |
| 1923 | self.assertEqual(items[1].change.number, '1') |
| 1924 | self.assertEqual(items[1].change.patchset, '1') |
| 1925 | self.assertFalse(items[1].live) |
| 1926 | |
| 1927 | self.assertEqual(items[2].change.number, '2') |
| 1928 | self.assertEqual(items[2].change.patchset, '2') |
| 1929 | self.assertTrue(items[2].live) |
| 1930 | |
| 1931 | self.builds[0].release() |
| 1932 | self.waitUntilSettled() |
| 1933 | self.builds[0].release() |
| 1934 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1935 | self.executor_server.hold_jobs_in_build = False |
| 1936 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1937 | self.waitUntilSettled() |
| 1938 | |
| 1939 | self.assertEqual(A.reported, 1) |
| 1940 | self.assertEqual(B.reported, 1) |
| 1941 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1942 | self.assertEqual(self.history[0].changes, '1,1') |
| 1943 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1944 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1945 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1946 | self.assertEqual(self.history[2].changes, '1,2') |
| 1947 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1948 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1949 | |
| 1950 | def test_abandoned_gate(self): |
| 1951 | "Test that an abandoned change is dequeued from gate" |
| 1952 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1953 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1954 | |
| 1955 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1956 | A.addApproval('Code-Review', 2) |
| 1957 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1958 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1959 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1960 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1961 | |
| 1962 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1963 | self.waitUntilSettled() |
| 1964 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1965 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1966 | self.waitUntilSettled() |
| 1967 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1968 | self.assertBuilds([]) |
| 1969 | self.assertHistory([ |
| 1970 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1971 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1972 | self.assertEqual(A.reported, 1, |
| 1973 | "Abandoned gate change should report only start") |
| 1974 | |
| 1975 | def test_abandoned_check(self): |
| 1976 | "Test that an abandoned change is dequeued from check" |
| 1977 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1978 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1979 | |
| 1980 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1981 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1982 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1983 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1984 | |
| 1985 | # Add two git-dependent changes |
| 1986 | B.setDependsOn(A, 1) |
| 1987 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1988 | self.waitUntilSettled() |
| 1989 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1990 | self.waitUntilSettled() |
| 1991 | # A live item, and a non-live/live pair |
| 1992 | items = check_pipeline.getAllItems() |
| 1993 | self.assertEqual(len(items), 3) |
| 1994 | |
| 1995 | self.assertEqual(items[0].change.number, '1') |
| 1996 | self.assertFalse(items[0].live) |
| 1997 | |
| 1998 | self.assertEqual(items[1].change.number, '2') |
| 1999 | self.assertTrue(items[1].live) |
| 2000 | |
| 2001 | self.assertEqual(items[2].change.number, '1') |
| 2002 | self.assertTrue(items[2].live) |
| 2003 | |
| 2004 | # Abandon A |
| 2005 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2006 | self.waitUntilSettled() |
| 2007 | |
| 2008 | # The live copy of A should be gone, but the non-live and B |
| 2009 | # should continue |
| 2010 | items = check_pipeline.getAllItems() |
| 2011 | self.assertEqual(len(items), 2) |
| 2012 | |
| 2013 | self.assertEqual(items[0].change.number, '1') |
| 2014 | self.assertFalse(items[0].live) |
| 2015 | |
| 2016 | self.assertEqual(items[1].change.number, '2') |
| 2017 | self.assertTrue(items[1].live) |
| 2018 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2019 | self.executor_server.hold_jobs_in_build = False |
| 2020 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2021 | self.waitUntilSettled() |
| 2022 | |
| 2023 | self.assertEqual(len(self.history), 4) |
| 2024 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 2025 | 'Build should have been aborted') |
| 2026 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 2027 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 2028 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2029 | def test_abandoned_not_timer(self): |
| 2030 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2031 | # This test can not use simple_layout because it must start |
| 2032 | # with a configuration which does not include a |
| 2033 | # timer-triggered job so that we have an opportunity to set |
| 2034 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2035 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2036 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2037 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2038 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2039 | # The pipeline triggers every second, so we should have seen |
| 2040 | # several by now. |
| 2041 | time.sleep(5) |
| 2042 | self.waitUntilSettled() |
| 2043 | # Stop queuing timer triggered jobs so that the assertions |
| 2044 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 2045 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2046 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2047 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 2048 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2049 | # If APScheduler is in mid-event when we remove the job, we |
| 2050 | # can end up with one more event firing, so give it an extra |
| 2051 | # second to settle. |
| 2052 | time.sleep(1) |
| 2053 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2054 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2055 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2056 | |
| 2057 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2058 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2059 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2060 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2061 | |
| 2062 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2063 | self.waitUntilSettled() |
| 2064 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2065 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2066 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2067 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2068 | self.waitUntilSettled() |
| 2069 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2070 | def test_new_patchset_dequeues_old_on_head(self): |
| 2071 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 2072 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2073 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2074 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 2075 | M.setMerged() |
| 2076 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2077 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2078 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2079 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2080 | A.addApproval('Code-Review', 2) |
| 2081 | B.addApproval('Code-Review', 2) |
| 2082 | C.addApproval('Code-Review', 2) |
| 2083 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2084 | |
| 2085 | C.setDependsOn(B, 1) |
| 2086 | B.setDependsOn(A, 1) |
| 2087 | A.setDependsOn(M, 1) |
| 2088 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2089 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2090 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2091 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2092 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2093 | self.waitUntilSettled() |
| 2094 | |
| 2095 | A.addPatchset() |
| 2096 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2097 | self.waitUntilSettled() |
| 2098 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2099 | self.executor_server.hold_jobs_in_build = False |
| 2100 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2101 | self.waitUntilSettled() |
| 2102 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2103 | self.assertEqual(A.data['status'], 'NEW') |
| 2104 | self.assertEqual(A.reported, 2) |
| 2105 | self.assertEqual(B.data['status'], 'NEW') |
| 2106 | self.assertEqual(B.reported, 2) |
| 2107 | self.assertEqual(C.data['status'], 'NEW') |
| 2108 | self.assertEqual(C.reported, 2) |
| 2109 | self.assertEqual(D.data['status'], 'MERGED') |
| 2110 | self.assertEqual(D.reported, 2) |
| 2111 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2112 | |
| 2113 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2114 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2115 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2116 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2117 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2118 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2119 | A.addApproval('Code-Review', 2) |
| 2120 | B.addApproval('Code-Review', 2) |
| 2121 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2122 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2123 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2124 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2125 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2126 | self.waitUntilSettled() |
| 2127 | |
| 2128 | B.addPatchset() |
| 2129 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2130 | self.waitUntilSettled() |
| 2131 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2132 | self.executor_server.hold_jobs_in_build = False |
| 2133 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2134 | self.waitUntilSettled() |
| 2135 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2136 | self.assertEqual(A.data['status'], 'MERGED') |
| 2137 | self.assertEqual(A.reported, 2) |
| 2138 | self.assertEqual(B.data['status'], 'NEW') |
| 2139 | self.assertEqual(B.reported, 2) |
| 2140 | self.assertEqual(C.data['status'], 'MERGED') |
| 2141 | self.assertEqual(C.reported, 2) |
| 2142 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2143 | |
| 2144 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2145 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2146 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2147 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2148 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2149 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2150 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2151 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2152 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2153 | self.waitUntilSettled() |
| 2154 | |
| 2155 | B.addPatchset() |
| 2156 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2157 | self.waitUntilSettled() |
| 2158 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2159 | self.executor_server.hold_jobs_in_build = False |
| 2160 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2161 | self.waitUntilSettled() |
| 2162 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2163 | self.assertEqual(A.data['status'], 'NEW') |
| 2164 | self.assertEqual(A.reported, 1) |
| 2165 | self.assertEqual(B.data['status'], 'NEW') |
| 2166 | self.assertEqual(B.reported, 1) |
| 2167 | self.assertEqual(C.data['status'], 'NEW') |
| 2168 | self.assertEqual(C.reported, 1) |
| 2169 | self.assertEqual(len(self.history), 10) |
| 2170 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2171 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2172 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2173 | def test_noop_job(self): |
| 2174 | "Test that the internal noop job works" |
| 2175 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2176 | A.addApproval('Code-Review', 2) |
| 2177 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2178 | self.waitUntilSettled() |
| 2179 | |
| 2180 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2181 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2182 | self.assertEqual(len(self.history), 0) |
| 2183 | self.assertEqual(A.data['status'], 'MERGED') |
| 2184 | self.assertEqual(A.reported, 2) |
| 2185 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2186 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2187 | def test_no_job_project(self): |
| 2188 | "Test that reports with no jobs don't get sent" |
| 2189 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2190 | 'master', 'A') |
| 2191 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2192 | self.waitUntilSettled() |
| 2193 | |
| 2194 | # Change wasn't reported to |
| 2195 | self.assertEqual(A.reported, False) |
| 2196 | |
| 2197 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2198 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2199 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2200 | items = check_pipeline.getAllItems() |
| 2201 | self.assertEqual(len(items), 0) |
| 2202 | |
| 2203 | self.assertEqual(len(self.history), 0) |
| 2204 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2205 | def test_zuul_refs(self): |
| 2206 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2207 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2208 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2209 | M1.setMerged() |
| 2210 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2211 | M2.setMerged() |
| 2212 | |
| 2213 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2214 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2215 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2216 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2217 | A.addApproval('Code-Review', 2) |
| 2218 | B.addApproval('Code-Review', 2) |
| 2219 | C.addApproval('Code-Review', 2) |
| 2220 | D.addApproval('Code-Review', 2) |
| 2221 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2222 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2223 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2224 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2225 | |
| 2226 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2227 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2228 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2229 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2230 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2231 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2232 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2233 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2234 | self.waitUntilSettled() |
| 2235 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2236 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2237 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2238 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2239 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2240 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2241 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2242 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2243 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2244 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2245 | d_build = x |
| 2246 | if a_build and b_build and c_build and d_build: |
| 2247 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2248 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2249 | # should have a, not b, and should not be in project2 |
| 2250 | self.assertTrue(a_build.hasChanges(A)) |
| 2251 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2252 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2253 | # should have a and b, and should not be in project2 |
| 2254 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2255 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2256 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2257 | # should have a and b in 1, c in 2 |
| 2258 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2259 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2260 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2261 | # should have a and b in 1, c and d in 2 |
| 2262 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2263 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2264 | self.executor_server.hold_jobs_in_build = False |
| 2265 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2266 | self.waitUntilSettled() |
| 2267 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2268 | self.assertEqual(A.data['status'], 'MERGED') |
| 2269 | self.assertEqual(A.reported, 2) |
| 2270 | self.assertEqual(B.data['status'], 'MERGED') |
| 2271 | self.assertEqual(B.reported, 2) |
| 2272 | self.assertEqual(C.data['status'], 'MERGED') |
| 2273 | self.assertEqual(C.reported, 2) |
| 2274 | self.assertEqual(D.data['status'], 'MERGED') |
| 2275 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2276 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2277 | def test_rerun_on_error(self): |
| 2278 | "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] | 2279 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2280 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2281 | A.addApproval('Code-Review', 2) |
| 2282 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2283 | self.waitUntilSettled() |
| 2284 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2285 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2286 | self.executor_server.hold_jobs_in_build = False |
| 2287 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2288 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2289 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2290 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2291 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2292 | def test_statsd(self): |
| 2293 | "Test each of the statsd methods used in the scheduler" |
James E. Blair | ded241e | 2017-10-10 13:22:40 -0700 | [diff] [blame] | 2294 | statsd = self.sched.statsd |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2295 | statsd.incr('test-incr') |
| 2296 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2297 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2298 | self.assertReportedStat('test-incr', '1|c') |
| 2299 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2300 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2301 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2302 | def test_stuck_job_cleanup(self): |
| 2303 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2304 | |
| 2305 | # 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] | 2306 | self.gearman_server.hold_jobs_in_queue = True |
| 2307 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2308 | A.addApproval('Code-Review', 2) |
| 2309 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2310 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2311 | # 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] | 2312 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2313 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2314 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2315 | self.sched.reconfigure(self.config) |
| 2316 | self.waitUntilSettled() |
| 2317 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2318 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2319 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2320 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2321 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2322 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2323 | |
| 2324 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2325 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2326 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2327 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2328 | def test_file_head(self): |
| 2329 | # This is a regression test for an observed bug. A change |
| 2330 | # with a file named "HEAD" in the root directory of the repo |
| 2331 | # was processed by a merger. It then was unable to reset the |
| 2332 | # repo because of: |
| 2333 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2334 | # with exit code 128 |
| 2335 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2336 | # and filename |
| 2337 | # Use '--' to separate filenames from revisions' |
| 2338 | |
| 2339 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2340 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2341 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2342 | |
| 2343 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2344 | self.waitUntilSettled() |
| 2345 | |
| 2346 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2347 | self.waitUntilSettled() |
| 2348 | |
| 2349 | self.assertIn('Build succeeded', A.messages[0]) |
| 2350 | self.assertIn('Build succeeded', B.messages[0]) |
| 2351 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2352 | def test_file_jobs(self): |
| 2353 | "Test that file jobs run only when appropriate" |
| 2354 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2355 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2356 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2357 | A.addApproval('Code-Review', 2) |
| 2358 | B.addApproval('Code-Review', 2) |
| 2359 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2360 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2361 | self.waitUntilSettled() |
| 2362 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2363 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2364 | if x.name == 'project-testfile'] |
| 2365 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2366 | self.assertEqual(len(testfile_jobs), 1) |
| 2367 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2368 | self.assertEqual(A.data['status'], 'MERGED') |
| 2369 | self.assertEqual(A.reported, 2) |
| 2370 | self.assertEqual(B.data['status'], 'MERGED') |
| 2371 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2372 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2373 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2374 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2375 | if should_skip: |
| 2376 | files = {'ignoreme': 'ignored\n'} |
| 2377 | else: |
| 2378 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2379 | |
| 2380 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2381 | 'master', |
| 2382 | 'test irrelevant-files', |
| 2383 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2384 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2385 | self.waitUntilSettled() |
| 2386 | |
| 2387 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2388 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2389 | |
| 2390 | if should_skip: |
| 2391 | self.assertEqual([], tested_change_ids) |
| 2392 | else: |
| 2393 | self.assertIn(change.data['number'], tested_change_ids) |
| 2394 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2395 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2396 | def test_irrelevant_files_match_skips_job(self): |
| 2397 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2398 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2399 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2400 | def test_irrelevant_files_no_match_runs_job(self): |
| 2401 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2402 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2403 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2404 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2405 | files = {'ignoreme': 'ignored\n'} |
| 2406 | |
| 2407 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2408 | 'master', |
| 2409 | 'test irrelevant-files', |
| 2410 | files=files) |
| 2411 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2412 | self.waitUntilSettled() |
| 2413 | |
| 2414 | run_jobs = set([build.name for build in self.history]) |
| 2415 | |
| 2416 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2417 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2418 | |
James E. Blair | af8b208 | 2017-10-03 15:38:27 -0700 | [diff] [blame] | 2419 | @simple_layout('layouts/job-vars.yaml') |
| 2420 | def test_inherited_job_variables(self): |
| 2421 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2422 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2423 | self.waitUntilSettled() |
| 2424 | self.assertHistory([ |
| 2425 | dict(name='parentjob', result='SUCCESS'), |
| 2426 | dict(name='child1', result='SUCCESS'), |
| 2427 | dict(name='child2', result='SUCCESS'), |
| 2428 | dict(name='child3', result='SUCCESS'), |
| 2429 | ], ordered=False) |
| 2430 | j = self.getJobFromHistory('parentjob') |
| 2431 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2432 | self.assertEqual(j.parameters['vars']['override'], 0) |
| 2433 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2434 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2435 | self.assertFalse('child1' in j.parameters['vars']) |
| 2436 | self.assertFalse('child2' in j.parameters['vars']) |
| 2437 | self.assertFalse('child3' in j.parameters['vars']) |
| 2438 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2439 | 'org/project0'])) |
| 2440 | j = self.getJobFromHistory('child1') |
| 2441 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2442 | self.assertEqual(j.parameters['vars']['override'], 1) |
| 2443 | self.assertEqual(j.parameters['vars']['child1override'], 1) |
| 2444 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2445 | self.assertEqual(j.parameters['vars']['child1'], 1) |
| 2446 | self.assertFalse('child2' in j.parameters['vars']) |
| 2447 | self.assertFalse('child3' in j.parameters['vars']) |
| 2448 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2449 | 'org/project1'])) |
| 2450 | j = self.getJobFromHistory('child2') |
| 2451 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2452 | self.assertEqual(j.parameters['vars']['override'], 2) |
| 2453 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2454 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2455 | self.assertFalse('child1' in j.parameters['vars']) |
| 2456 | self.assertEqual(j.parameters['vars']['child2'], 2) |
| 2457 | self.assertFalse('child3' in j.parameters['vars']) |
| 2458 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2459 | 'org/project2'])) |
| 2460 | j = self.getJobFromHistory('child3') |
| 2461 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2462 | self.assertEqual(j.parameters['vars']['override'], 3) |
| 2463 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2464 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2465 | self.assertFalse('child1' in j.parameters['vars']) |
| 2466 | self.assertFalse('child2' in j.parameters['vars']) |
| 2467 | self.assertEqual(j.parameters['vars']['child3'], 3) |
| 2468 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2469 | 'org/project3'])) |
| 2470 | |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2471 | @simple_layout('layouts/job-variants.yaml') |
| 2472 | def test_job_branch_variants(self): |
| 2473 | self.create_branch('org/project', 'stable/diablo') |
| 2474 | self.create_branch('org/project', 'stable/essex') |
| 2475 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2476 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2477 | self.waitUntilSettled() |
| 2478 | |
| 2479 | B = self.fake_gerrit.addFakeChange('org/project', 'stable/diablo', 'B') |
| 2480 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2481 | self.waitUntilSettled() |
| 2482 | |
| 2483 | C = self.fake_gerrit.addFakeChange('org/project', 'stable/essex', 'C') |
| 2484 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2485 | self.waitUntilSettled() |
| 2486 | self.assertHistory([ |
| 2487 | dict(name='python27', result='SUCCESS'), |
| 2488 | dict(name='python27', result='SUCCESS'), |
| 2489 | dict(name='python27', result='SUCCESS'), |
| 2490 | ]) |
| 2491 | |
| 2492 | p = self.history[0].parameters |
| 2493 | self.assertEqual(p['timeout'], 40) |
| 2494 | self.assertEqual(len(p['nodes']), 1) |
| 2495 | self.assertEqual(p['nodes'][0]['label'], 'new') |
| 2496 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2497 | ['base-pre', 'py27-pre']) |
| 2498 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2499 | ['py27-post-a', 'py27-post-b', 'base-post']) |
| 2500 | self.assertEqual([x['path'] for x in p['playbooks']], |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 2501 | ['playbooks/python27.yaml']) |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2502 | |
| 2503 | p = self.history[1].parameters |
| 2504 | self.assertEqual(p['timeout'], 50) |
| 2505 | self.assertEqual(len(p['nodes']), 1) |
| 2506 | self.assertEqual(p['nodes'][0]['label'], 'old') |
| 2507 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2508 | ['base-pre', 'py27-pre', 'py27-diablo-pre']) |
| 2509 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2510 | ['py27-diablo-post', 'py27-post-a', 'py27-post-b', |
| 2511 | 'base-post']) |
| 2512 | self.assertEqual([x['path'] for x in p['playbooks']], |
| 2513 | ['py27-diablo']) |
| 2514 | |
| 2515 | p = self.history[2].parameters |
| 2516 | self.assertEqual(p['timeout'], 40) |
| 2517 | self.assertEqual(len(p['nodes']), 1) |
| 2518 | self.assertEqual(p['nodes'][0]['label'], 'new') |
| 2519 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2520 | ['base-pre', 'py27-pre', 'py27-essex-pre']) |
| 2521 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2522 | ['py27-essex-post', 'py27-post-a', 'py27-post-b', |
| 2523 | 'base-post']) |
| 2524 | self.assertEqual([x['path'] for x in p['playbooks']], |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 2525 | ['playbooks/python27.yaml']) |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2526 | |
James E. Blair | 0029267 | 2017-10-26 15:29:39 -0700 | [diff] [blame] | 2527 | @simple_layout("layouts/no-run.yaml") |
| 2528 | def test_job_without_run(self): |
| 2529 | "Test that a job without a run playbook errors" |
| 2530 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2531 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2532 | self.waitUntilSettled() |
| 2533 | self.assertIn('Job base does not specify a run playbook', |
| 2534 | A.messages[-1]) |
| 2535 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2536 | def test_queue_names(self): |
| 2537 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2538 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2539 | (trusted, project1) = tenant.getProject('org/project1') |
| 2540 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2541 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2542 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2543 | self.assertEqual(q1.name, 'integrated') |
| 2544 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2545 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2546 | def test_queue_precedence(self): |
| 2547 | "Test that queue precedence works" |
| 2548 | |
| 2549 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2550 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2551 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2552 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2553 | A.addApproval('Code-Review', 2) |
| 2554 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2555 | |
| 2556 | self.waitUntilSettled() |
| 2557 | self.gearman_server.hold_jobs_in_queue = False |
| 2558 | self.gearman_server.release() |
| 2559 | self.waitUntilSettled() |
| 2560 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2561 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2562 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2563 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2564 | self.waitUntilSettled() |
| 2565 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2566 | self.log.debug(self.history) |
| 2567 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2568 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2569 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2570 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2571 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2572 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2573 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2574 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2575 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2576 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2577 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2578 | A.addApproval('Code-Review', 2) |
| 2579 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2580 | self.waitUntilSettled() |
| 2581 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2582 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2583 | self.waitUntilSettled() |
| 2584 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2585 | port = self.webapp.server.socket.getsockname()[1] |
| 2586 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2587 | req = urllib.request.Request( |
| 2588 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2589 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2590 | headers = f.info() |
| 2591 | self.assertIn('Content-Length', headers) |
| 2592 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2593 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2594 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2595 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2596 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2597 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2598 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2599 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2600 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2601 | self.executor_server.hold_jobs_in_build = False |
| 2602 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2603 | self.waitUntilSettled() |
| 2604 | |
| 2605 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2606 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2607 | for p in data['pipelines']: |
| 2608 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2609 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2610 | self.assertEqual(q['window'], 20) |
| 2611 | else: |
| 2612 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2613 | for head in q['heads']: |
| 2614 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2615 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2616 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2617 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2618 | status_jobs.append(job) |
| 2619 | self.assertEqual('project-merge', status_jobs[0]['name']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2620 | # TODO(mordred) pull uuids from self.builds |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2621 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 2622 | 'stream.html?uuid={uuid}&logfile=console.log'.format( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2623 | uuid=status_jobs[0]['uuid']), |
| 2624 | status_jobs[0]['url']) |
| 2625 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2626 | 'finger://{hostname}/{uuid}'.format( |
| 2627 | hostname=self.executor_server.hostname, |
| 2628 | uuid=status_jobs[0]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2629 | status_jobs[0]['finger_url']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2630 | # TOOD(mordred) configure a success-url on the base job |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2631 | self.assertEqual( |
| 2632 | 'finger://{hostname}/{uuid}'.format( |
| 2633 | hostname=self.executor_server.hostname, |
| 2634 | uuid=status_jobs[0]['uuid']), |
| 2635 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2636 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2637 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 2638 | 'stream.html?uuid={uuid}&logfile=console.log'.format( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2639 | uuid=status_jobs[1]['uuid']), |
| 2640 | status_jobs[1]['url']) |
| 2641 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2642 | 'finger://{hostname}/{uuid}'.format( |
| 2643 | hostname=self.executor_server.hostname, |
| 2644 | uuid=status_jobs[1]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2645 | status_jobs[1]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2646 | self.assertEqual( |
| 2647 | 'finger://{hostname}/{uuid}'.format( |
| 2648 | hostname=self.executor_server.hostname, |
| 2649 | uuid=status_jobs[1]['uuid']), |
| 2650 | status_jobs[1]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2651 | |
| 2652 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2653 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 2654 | 'stream.html?uuid={uuid}&logfile=console.log'.format( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2655 | uuid=status_jobs[2]['uuid']), |
| 2656 | status_jobs[2]['url']) |
| 2657 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2658 | 'finger://{hostname}/{uuid}'.format( |
| 2659 | hostname=self.executor_server.hostname, |
| 2660 | uuid=status_jobs[2]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2661 | status_jobs[2]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2662 | self.assertEqual( |
| 2663 | 'finger://{hostname}/{uuid}'.format( |
| 2664 | hostname=self.executor_server.hostname, |
| 2665 | uuid=status_jobs[2]['uuid']), |
| 2666 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2667 | |
Tobias Henkel | 65639f8 | 2017-07-10 10:25:42 +0200 | [diff] [blame] | 2668 | # check job dependencies |
| 2669 | self.assertIsNotNone(status_jobs[0]['dependencies']) |
| 2670 | self.assertIsNotNone(status_jobs[1]['dependencies']) |
| 2671 | self.assertIsNotNone(status_jobs[2]['dependencies']) |
| 2672 | self.assertEqual(len(status_jobs[0]['dependencies']), 0) |
| 2673 | self.assertEqual(len(status_jobs[1]['dependencies']), 1) |
| 2674 | self.assertEqual(len(status_jobs[2]['dependencies']), 1) |
| 2675 | self.assertIn('project-merge', status_jobs[1]['dependencies']) |
| 2676 | self.assertIn('project-merge', status_jobs[2]['dependencies']) |
| 2677 | |
James E. Blair | 419a867 | 2017-10-18 14:48:25 -0700 | [diff] [blame] | 2678 | def test_reconfigure_merge(self): |
| 2679 | """Test that two reconfigure events are merged""" |
| 2680 | |
| 2681 | tenant = self.sched.abide.tenants['tenant-one'] |
| 2682 | (trusted, project) = tenant.getProject('org/project') |
| 2683 | |
| 2684 | self.sched.run_handler_lock.acquire() |
| 2685 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2686 | |
| 2687 | self.sched.reconfigureTenant(tenant, project) |
| 2688 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2689 | |
| 2690 | self.sched.reconfigureTenant(tenant, project) |
| 2691 | # The second event should have been combined with the first |
| 2692 | # so we should still only have one entry. |
| 2693 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2694 | |
| 2695 | self.sched.run_handler_lock.release() |
| 2696 | self.waitUntilSettled() |
| 2697 | |
| 2698 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2699 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2700 | def test_live_reconfiguration(self): |
| 2701 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2702 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2703 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2704 | A.addApproval('Code-Review', 2) |
| 2705 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2706 | self.waitUntilSettled() |
| 2707 | |
| 2708 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2709 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2710 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2711 | self.executor_server.hold_jobs_in_build = False |
| 2712 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2713 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2714 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2715 | 'SUCCESS') |
| 2716 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2717 | 'SUCCESS') |
| 2718 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2719 | 'SUCCESS') |
| 2720 | self.assertEqual(A.data['status'], 'MERGED') |
| 2721 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2722 | |
James E. Blair | 027ba99 | 2017-09-20 13:48:32 -0700 | [diff] [blame] | 2723 | def test_live_reconfiguration_abort(self): |
| 2724 | # Raise an exception during reconfiguration and verify we |
| 2725 | # still function. |
| 2726 | self.executor_server.hold_jobs_in_build = True |
| 2727 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2728 | A.addApproval('Code-Review', 2) |
| 2729 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2730 | self.waitUntilSettled() |
| 2731 | |
| 2732 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2733 | pipeline = tenant.layout.pipelines['gate'] |
| 2734 | change = pipeline.getAllItems()[0].change |
| 2735 | # Set this to an invalid value to cause an exception during |
| 2736 | # reconfiguration. |
| 2737 | change.branch = None |
| 2738 | |
| 2739 | self.sched.reconfigure(self.config) |
| 2740 | self.waitUntilSettled() |
| 2741 | |
| 2742 | self.executor_server.hold_jobs_in_build = False |
| 2743 | self.executor_server.release() |
| 2744 | |
| 2745 | self.waitUntilSettled() |
| 2746 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2747 | 'ABORTED') |
| 2748 | self.assertEqual(A.data['status'], 'NEW') |
| 2749 | # The final report fails because of the invalid value set above. |
| 2750 | self.assertEqual(A.reported, 1) |
| 2751 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2752 | def test_live_reconfiguration_merge_conflict(self): |
| 2753 | # A real-world bug: a change in a gate queue has a merge |
| 2754 | # conflict and a job is added to its project while it's |
| 2755 | # sitting in the queue. The job gets added to the change and |
| 2756 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2757 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2758 | |
| 2759 | # This change is fine. It's here to stop the queue long |
| 2760 | # enough for the next change to be subject to the |
| 2761 | # reconfiguration, as well as to provide a conflict for the |
| 2762 | # next change. This change will succeed and merge. |
| 2763 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2764 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2765 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2766 | |
| 2767 | # This change will be in merge conflict. During the |
| 2768 | # reconfiguration, we will add a job. We want to make sure |
| 2769 | # that doesn't cause it to get stuck. |
| 2770 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2771 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2772 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2773 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2774 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2775 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2776 | |
| 2777 | self.waitUntilSettled() |
| 2778 | |
| 2779 | # No jobs have run yet |
| 2780 | self.assertEqual(A.data['status'], 'NEW') |
| 2781 | self.assertEqual(A.reported, 1) |
| 2782 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2783 | self.assertEqual(len(self.history), 0) |
| 2784 | |
| 2785 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2786 | self.commitConfigUpdate('common-config', |
| 2787 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2788 | self.sched.reconfigure(self.config) |
| 2789 | self.waitUntilSettled() |
| 2790 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2791 | self.executor_server.hold_jobs_in_build = False |
| 2792 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2793 | self.waitUntilSettled() |
| 2794 | |
| 2795 | self.assertEqual(A.data['status'], 'MERGED') |
| 2796 | self.assertEqual(A.reported, 2) |
| 2797 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2798 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2799 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2800 | 'SUCCESS') |
| 2801 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2802 | 'SUCCESS') |
| 2803 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2804 | 'SUCCESS') |
| 2805 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2806 | 'SUCCESS') |
| 2807 | self.assertEqual(len(self.history), 4) |
| 2808 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2809 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2810 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2811 | # that tests a job added to a job tree with a failed root does |
| 2812 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2813 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2814 | |
| 2815 | # This change is fine. It's here to stop the queue long |
| 2816 | # enough for the next change to be subject to the |
| 2817 | # reconfiguration. This change will succeed and merge. |
| 2818 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2819 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2820 | A.addApproval('Code-Review', 2) |
| 2821 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2822 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2823 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2824 | self.waitUntilSettled() |
| 2825 | |
| 2826 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2827 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2828 | B.addApproval('Code-Review', 2) |
| 2829 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2830 | self.waitUntilSettled() |
| 2831 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2832 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2833 | self.waitUntilSettled() |
| 2834 | |
| 2835 | # Both -merge jobs have run, but no others. |
| 2836 | self.assertEqual(A.data['status'], 'NEW') |
| 2837 | self.assertEqual(A.reported, 1) |
| 2838 | self.assertEqual(B.data['status'], 'NEW') |
| 2839 | self.assertEqual(B.reported, 1) |
| 2840 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2841 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2842 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2843 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2844 | self.assertEqual(len(self.history), 2) |
| 2845 | |
| 2846 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2847 | self.commitConfigUpdate('common-config', |
| 2848 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2849 | self.sched.reconfigure(self.config) |
| 2850 | self.waitUntilSettled() |
| 2851 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2852 | self.executor_server.hold_jobs_in_build = False |
| 2853 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2854 | self.waitUntilSettled() |
| 2855 | |
| 2856 | self.assertEqual(A.data['status'], 'MERGED') |
| 2857 | self.assertEqual(A.reported, 2) |
| 2858 | self.assertEqual(B.data['status'], 'NEW') |
| 2859 | self.assertEqual(B.reported, 2) |
| 2860 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2861 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2862 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2863 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2864 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2865 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2866 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2867 | self.assertEqual(len(self.history), 5) |
| 2868 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2869 | def test_live_reconfiguration_failed_job(self): |
| 2870 | # Test that a change with a removed failing job does not |
| 2871 | # disrupt reconfiguration. If a change has a failed job and |
| 2872 | # that job is removed during a reconfiguration, we observed a |
| 2873 | # bug where the code to re-set build statuses would run on |
| 2874 | # that build and raise an exception because the job no longer |
| 2875 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2876 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2877 | |
| 2878 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2879 | |
| 2880 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2881 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2882 | |
| 2883 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2884 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2885 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2886 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2887 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2888 | self.waitUntilSettled() |
| 2889 | |
| 2890 | self.assertEqual(A.data['status'], 'NEW') |
| 2891 | self.assertEqual(A.reported, 0) |
| 2892 | |
| 2893 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2894 | 'SUCCESS') |
| 2895 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2896 | 'FAILURE') |
| 2897 | self.assertEqual(len(self.history), 2) |
| 2898 | |
| 2899 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2900 | self.commitConfigUpdate('common-config', |
| 2901 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2902 | self.sched.reconfigure(self.config) |
| 2903 | self.waitUntilSettled() |
| 2904 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2905 | self.executor_server.hold_jobs_in_build = False |
| 2906 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2907 | self.waitUntilSettled() |
| 2908 | |
| 2909 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2910 | 'SUCCESS') |
| 2911 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2912 | 'SUCCESS') |
| 2913 | self.assertEqual(len(self.history), 4) |
| 2914 | |
| 2915 | self.assertEqual(A.data['status'], 'NEW') |
| 2916 | self.assertEqual(A.reported, 1) |
| 2917 | self.assertIn('Build succeeded', A.messages[0]) |
| 2918 | # Ensure the removed job was not included in the report. |
| 2919 | self.assertNotIn('project-test1', A.messages[0]) |
| 2920 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2921 | def test_live_reconfiguration_shared_queue(self): |
| 2922 | # Test that a change with a failing job which was removed from |
| 2923 | # this project but otherwise still exists in the system does |
| 2924 | # not disrupt reconfiguration. |
| 2925 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2926 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2927 | |
| 2928 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2929 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2930 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2931 | |
| 2932 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2933 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2934 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2935 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2936 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2937 | self.waitUntilSettled() |
| 2938 | |
| 2939 | self.assertEqual(A.data['status'], 'NEW') |
| 2940 | self.assertEqual(A.reported, 0) |
| 2941 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2942 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2943 | 'SUCCESS') |
| 2944 | self.assertEqual(self.getJobFromHistory( |
| 2945 | 'project1-project2-integration').result, 'FAILURE') |
| 2946 | self.assertEqual(len(self.history), 2) |
| 2947 | |
| 2948 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2949 | self.commitConfigUpdate( |
| 2950 | 'common-config', |
| 2951 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2952 | self.sched.reconfigure(self.config) |
| 2953 | self.waitUntilSettled() |
| 2954 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2955 | self.executor_server.hold_jobs_in_build = False |
| 2956 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2957 | self.waitUntilSettled() |
| 2958 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2959 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2960 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2961 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2962 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2963 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2964 | 'SUCCESS') |
| 2965 | self.assertEqual(self.getJobFromHistory( |
| 2966 | 'project1-project2-integration').result, 'FAILURE') |
| 2967 | self.assertEqual(len(self.history), 4) |
| 2968 | |
| 2969 | self.assertEqual(A.data['status'], 'NEW') |
| 2970 | self.assertEqual(A.reported, 1) |
| 2971 | self.assertIn('Build succeeded', A.messages[0]) |
| 2972 | # Ensure the removed job was not included in the report. |
| 2973 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2974 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2975 | def test_double_live_reconfiguration_shared_queue(self): |
| 2976 | # This was a real-world regression. A change is added to |
| 2977 | # gate; a reconfigure happens, a second change which depends |
| 2978 | # on the first is added, and a second reconfiguration happens. |
| 2979 | # Ensure that both changes merge. |
| 2980 | |
| 2981 | # A failure may indicate incorrect caching or cleaning up of |
| 2982 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2983 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2984 | |
| 2985 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2986 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2987 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2988 | A.addApproval('Code-Review', 2) |
| 2989 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2990 | |
| 2991 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2992 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2993 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2994 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2995 | self.waitUntilSettled() |
| 2996 | |
| 2997 | # Reconfigure (with only one change in the pipeline). |
| 2998 | self.sched.reconfigure(self.config) |
| 2999 | self.waitUntilSettled() |
| 3000 | |
| 3001 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3002 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3003 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3004 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3005 | self.waitUntilSettled() |
| 3006 | |
| 3007 | # Reconfigure (with both in the pipeline). |
| 3008 | self.sched.reconfigure(self.config) |
| 3009 | self.waitUntilSettled() |
| 3010 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3011 | self.executor_server.hold_jobs_in_build = False |
| 3012 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3013 | self.waitUntilSettled() |
| 3014 | |
| 3015 | self.assertEqual(len(self.history), 8) |
| 3016 | |
| 3017 | self.assertEqual(A.data['status'], 'MERGED') |
| 3018 | self.assertEqual(A.reported, 2) |
| 3019 | self.assertEqual(B.data['status'], 'MERGED') |
| 3020 | self.assertEqual(B.reported, 2) |
| 3021 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3022 | def test_live_reconfiguration_del_project(self): |
| 3023 | # Test project deletion from layout |
| 3024 | # while changes are enqueued |
| 3025 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3026 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3027 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3028 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3029 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 3030 | |
| 3031 | # A Depends-On: B |
| 3032 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3033 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3034 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3035 | |
| 3036 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3037 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 3038 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3039 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3040 | self.waitUntilSettled() |
| 3041 | self.assertEqual(len(self.builds), 5) |
| 3042 | |
| 3043 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 3044 | self.commitConfigUpdate( |
| 3045 | 'common-config', |
| 3046 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3047 | self.sched.reconfigure(self.config) |
| 3048 | self.waitUntilSettled() |
| 3049 | |
| 3050 | # Builds for C aborted, builds for A succeed, |
| 3051 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 3052 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3053 | self.assertEqual(job_c.changes, '3,1') |
| 3054 | self.assertEqual(job_c.result, 'ABORTED') |
| 3055 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3056 | self.executor_server.hold_jobs_in_build = False |
| 3057 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3058 | self.waitUntilSettled() |
| 3059 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 3060 | self.assertEqual( |
| 3061 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 3062 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3063 | |
| 3064 | self.assertEqual(A.data['status'], 'NEW') |
| 3065 | self.assertEqual(B.data['status'], 'NEW') |
| 3066 | self.assertEqual(C.data['status'], 'NEW') |
| 3067 | self.assertEqual(A.reported, 1) |
| 3068 | self.assertEqual(B.reported, 0) |
| 3069 | self.assertEqual(C.reported, 0) |
| 3070 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 3071 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3072 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3073 | self.assertIn('Build succeeded', A.messages[0]) |
| 3074 | |
James E. Blair | 872738f | 2017-10-31 16:40:36 -0700 | [diff] [blame] | 3075 | @simple_layout("layouts/reconfigure-failed-head.yaml") |
| 3076 | def test_live_reconfiguration_failed_change_at_head(self): |
| 3077 | # Test that if we reconfigure with a failed change at head, |
| 3078 | # that the change behind it isn't reparented onto it. |
| 3079 | |
| 3080 | self.executor_server.hold_jobs_in_build = True |
| 3081 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3082 | A.addApproval('Code-Review', 2) |
| 3083 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3084 | B.addApproval('Code-Review', 2) |
| 3085 | |
| 3086 | self.executor_server.failJob('job1', A) |
| 3087 | |
| 3088 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3089 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3090 | |
| 3091 | self.waitUntilSettled() |
| 3092 | |
| 3093 | self.assertBuilds([ |
| 3094 | dict(name='job1', changes='1,1'), |
| 3095 | dict(name='job2', changes='1,1'), |
| 3096 | dict(name='job1', changes='1,1 2,1'), |
| 3097 | dict(name='job2', changes='1,1 2,1'), |
| 3098 | ]) |
| 3099 | |
| 3100 | self.release(self.builds[0]) |
| 3101 | self.waitUntilSettled() |
| 3102 | |
| 3103 | self.assertBuilds([ |
| 3104 | dict(name='job2', changes='1,1'), |
| 3105 | dict(name='job1', changes='2,1'), |
| 3106 | dict(name='job2', changes='2,1'), |
| 3107 | ]) |
| 3108 | |
| 3109 | # Unordered history comparison because the aborts can finish |
| 3110 | # in any order. |
| 3111 | self.assertHistory([ |
| 3112 | dict(name='job1', result='FAILURE', changes='1,1'), |
| 3113 | dict(name='job1', result='ABORTED', changes='1,1 2,1'), |
| 3114 | dict(name='job2', result='ABORTED', changes='1,1 2,1'), |
| 3115 | ], ordered=False) |
| 3116 | |
| 3117 | self.sched.reconfigure(self.config) |
| 3118 | self.waitUntilSettled() |
| 3119 | |
| 3120 | self.executor_server.hold_jobs_in_build = False |
| 3121 | self.executor_server.release() |
| 3122 | self.waitUntilSettled() |
| 3123 | |
| 3124 | self.assertBuilds([]) |
| 3125 | |
| 3126 | self.assertHistory([ |
| 3127 | dict(name='job1', result='FAILURE', changes='1,1'), |
| 3128 | dict(name='job1', result='ABORTED', changes='1,1 2,1'), |
| 3129 | dict(name='job2', result='ABORTED', changes='1,1 2,1'), |
| 3130 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3131 | dict(name='job1', result='SUCCESS', changes='2,1'), |
| 3132 | dict(name='job2', result='SUCCESS', changes='2,1'), |
| 3133 | ], ordered=False) |
| 3134 | self.assertEqual(A.data['status'], 'NEW') |
| 3135 | self.assertEqual(B.data['status'], 'MERGED') |
| 3136 | self.assertEqual(A.reported, 2) |
| 3137 | self.assertEqual(B.reported, 2) |
| 3138 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3139 | def test_delayed_repo_init(self): |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3140 | self.init_repo("org/new-project") |
Clint Byrum | 627ba36 | 2017-08-14 13:20:40 -0700 | [diff] [blame] | 3141 | files = {'README': ''} |
| 3142 | self.addCommitToRepo("org/new-project", 'Initial commit', |
| 3143 | files=files, tag='init') |
| 3144 | self.newTenantConfig('tenants/delayed-repo-init.yaml') |
| 3145 | self.commitConfigUpdate( |
| 3146 | 'common-config', |
| 3147 | 'layouts/delayed-repo-init.yaml') |
| 3148 | self.sched.reconfigure(self.config) |
| 3149 | self.waitUntilSettled() |
| 3150 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3151 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 3152 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3153 | A.addApproval('Code-Review', 2) |
| 3154 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3155 | self.waitUntilSettled() |
| 3156 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3157 | 'SUCCESS') |
| 3158 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3159 | 'SUCCESS') |
| 3160 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3161 | 'SUCCESS') |
| 3162 | self.assertEqual(A.data['status'], 'MERGED') |
| 3163 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3164 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 3165 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3166 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3167 | self.init_repo("org/delete-project") |
| 3168 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 3169 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3170 | A.addApproval('Code-Review', 2) |
| 3171 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3172 | self.waitUntilSettled() |
| 3173 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3174 | 'SUCCESS') |
| 3175 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3176 | 'SUCCESS') |
| 3177 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3178 | 'SUCCESS') |
| 3179 | self.assertEqual(A.data['status'], 'MERGED') |
| 3180 | self.assertEqual(A.reported, 2) |
| 3181 | |
| 3182 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 3183 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 3184 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 3185 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3186 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 3187 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3188 | |
| 3189 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 3190 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3191 | B.addApproval('Code-Review', 2) |
| 3192 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3193 | self.waitUntilSettled() |
| 3194 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3195 | 'SUCCESS') |
| 3196 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3197 | 'SUCCESS') |
| 3198 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3199 | 'SUCCESS') |
| 3200 | self.assertEqual(B.data['status'], 'MERGED') |
| 3201 | self.assertEqual(B.reported, 2) |
| 3202 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 3203 | @simple_layout('layouts/untrusted-secrets.yaml') |
| 3204 | def test_untrusted_secrets(self): |
| 3205 | "Test untrusted secrets" |
| 3206 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3207 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3208 | self.waitUntilSettled() |
| 3209 | |
| 3210 | self.assertHistory([]) |
| 3211 | self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") |
James E. Blair | 8eb564a | 2017-08-10 09:21:41 -0700 | [diff] [blame] | 3212 | self.assertIn('does not allow post-review job', |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 3213 | A.messages[0]) |
| 3214 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 3215 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3216 | def test_tags(self): |
| 3217 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3218 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3219 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3220 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3221 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3222 | self.waitUntilSettled() |
| 3223 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 3224 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3225 | |
| 3226 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3227 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3228 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3229 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3230 | |
| 3231 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3232 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3233 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3234 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3235 | def test_timer(self): |
| 3236 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3237 | # This test can not use simple_layout because it must start |
| 3238 | # with a configuration which does not include a |
| 3239 | # timer-triggered job so that we have an opportunity to set |
| 3240 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3241 | self.create_branch('org/project', 'stable') |
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.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3244 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [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 | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3249 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3250 | |
| 3251 | self.assertEqual(len(self.builds), 2) |
| 3252 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3253 | port = self.webapp.server.socket.getsockname()[1] |
| 3254 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 3255 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3256 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 3257 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 3258 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3259 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3260 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3261 | # Stop queuing timer triggered jobs so that the assertions |
| 3262 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3263 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3264 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3265 | self.waitUntilSettled() |
| 3266 | # If APScheduler is in mid-event when we remove the job, we |
| 3267 | # can end up with one more event firing, so give it an extra |
| 3268 | # second to settle. |
| 3269 | time.sleep(1) |
| 3270 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3271 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3272 | self.waitUntilSettled() |
| 3273 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3274 | self.assertHistory([ |
| 3275 | dict(name='project-bitrot', result='SUCCESS', |
| 3276 | ref='refs/heads/master'), |
| 3277 | dict(name='project-bitrot', result='SUCCESS', |
| 3278 | ref='refs/heads/stable'), |
| 3279 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3280 | |
| 3281 | data = json.loads(data) |
| 3282 | status_jobs = set() |
| 3283 | for p in data['pipelines']: |
| 3284 | for q in p['change_queues']: |
| 3285 | for head in q['heads']: |
| 3286 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3287 | for job in change['jobs']: |
| 3288 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3289 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3290 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3291 | def test_idle(self): |
| 3292 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3293 | # This test can not use simple_layout because it must start |
| 3294 | # with a configuration which does not include a |
| 3295 | # timer-triggered job so that we have an opportunity to set |
| 3296 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3297 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3298 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3299 | for x in range(1, 3): |
| 3300 | # Test that timer triggers periodic jobs even across |
| 3301 | # layout config reloads. |
| 3302 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3303 | self.commitConfigUpdate('common-config', |
| 3304 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3305 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3306 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3307 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3308 | # The pipeline triggers every second, so we should have seen |
| 3309 | # several by now. |
| 3310 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3311 | |
| 3312 | # Stop queuing timer triggered jobs so that the assertions |
| 3313 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3314 | self.commitConfigUpdate('common-config', |
| 3315 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3316 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3317 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3318 | # If APScheduler is in mid-event when we remove the job, |
| 3319 | # we can end up with one more event firing, so give it an |
| 3320 | # extra second to settle. |
| 3321 | time.sleep(1) |
| 3322 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3323 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3324 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3325 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3326 | self.waitUntilSettled() |
| 3327 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3328 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3329 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3330 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3331 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3332 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3333 | self.waitUntilSettled() |
| 3334 | |
| 3335 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3336 | self.waitUntilSettled() |
| 3337 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3338 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3339 | |
| 3340 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3341 | # work on the knowledge of what the first message should be as |
| 3342 | # it is only configured to go to SMTP. |
| 3343 | |
| 3344 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3345 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3346 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3347 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3348 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3349 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3350 | |
| 3351 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3352 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3353 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3354 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3355 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3356 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3357 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3358 | def test_timer_smtp(self): |
| 3359 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3360 | # This test can not use simple_layout because it must start |
| 3361 | # with a configuration which does not include a |
| 3362 | # timer-triggered job so that we have an opportunity to set |
| 3363 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3364 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3365 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3366 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3367 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3368 | # The pipeline triggers every second, so we should have seen |
| 3369 | # several by now. |
| 3370 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3371 | self.waitUntilSettled() |
| 3372 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3373 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3374 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3375 | self.waitUntilSettled() |
| 3376 | self.assertEqual(len(self.history), 2) |
| 3377 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3378 | self.assertEqual(self.getJobFromHistory( |
| 3379 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3380 | self.assertEqual(self.getJobFromHistory( |
| 3381 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3382 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3383 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3384 | |
| 3385 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3386 | # work on the knowledge of what the first message should be as |
| 3387 | # it is only configured to go to SMTP. |
| 3388 | |
| 3389 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3390 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3391 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3392 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3393 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3394 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3395 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3396 | # Stop queuing timer triggered jobs and let any that may have |
| 3397 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3398 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3399 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3400 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3401 | # If APScheduler is in mid-event when we remove the job, we |
| 3402 | # can end up with one more event firing, so give it an extra |
| 3403 | # second to settle. |
| 3404 | time.sleep(1) |
| 3405 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3406 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3407 | self.waitUntilSettled() |
| 3408 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3409 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3410 | def test_timer_sshkey(self): |
| 3411 | "Test that a periodic job can setup SSH key authentication" |
| 3412 | self.worker.hold_jobs_in_build = True |
| 3413 | self.config.set('zuul', 'layout_config', |
| 3414 | 'tests/fixtures/layout-timer.yaml') |
| 3415 | self.sched.reconfigure(self.config) |
| 3416 | self.registerJobs() |
| 3417 | |
| 3418 | # The pipeline triggers every second, so we should have seen |
| 3419 | # several by now. |
| 3420 | time.sleep(5) |
| 3421 | self.waitUntilSettled() |
| 3422 | |
| 3423 | self.assertEqual(len(self.builds), 2) |
| 3424 | |
| 3425 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3426 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3427 | with open(ssh_wrapper) as f: |
| 3428 | ssh_wrapper_content = f.read() |
| 3429 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3430 | # In the unit tests Merger runs in the same process, |
| 3431 | # so we see its' environment variables |
| 3432 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3433 | |
| 3434 | self.worker.release('.*') |
| 3435 | self.waitUntilSettled() |
| 3436 | self.assertEqual(len(self.history), 2) |
| 3437 | |
| 3438 | self.assertEqual(self.getJobFromHistory( |
| 3439 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3440 | self.assertEqual(self.getJobFromHistory( |
| 3441 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3442 | |
| 3443 | # Stop queuing timer triggered jobs and let any that may have |
| 3444 | # queued through so that end of test assertions pass. |
| 3445 | self.config.set('zuul', 'layout_config', |
| 3446 | 'tests/fixtures/layout-no-timer.yaml') |
| 3447 | self.sched.reconfigure(self.config) |
| 3448 | self.registerJobs() |
| 3449 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3450 | # If APScheduler is in mid-event when we remove the job, we |
| 3451 | # can end up with one more event firing, so give it an extra |
| 3452 | # second to settle. |
| 3453 | time.sleep(1) |
| 3454 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3455 | self.worker.release('.*') |
| 3456 | self.waitUntilSettled() |
| 3457 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3458 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3459 | "Test that the RPC client can enqueue a change" |
| 3460 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3461 | A.addApproval('Code-Review', 2) |
| 3462 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3463 | |
| 3464 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3465 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3466 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3467 | r = client.enqueue(tenant='tenant-one', |
| 3468 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3469 | project='org/project', |
| 3470 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3471 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3472 | self.waitUntilSettled() |
| 3473 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3474 | 'SUCCESS') |
| 3475 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3476 | 'SUCCESS') |
| 3477 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3478 | 'SUCCESS') |
| 3479 | self.assertEqual(A.data['status'], 'MERGED') |
| 3480 | self.assertEqual(A.reported, 2) |
| 3481 | self.assertEqual(r, True) |
| 3482 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3483 | def test_client_enqueue_ref(self): |
| 3484 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3485 | p = "review.example.com/org/project" |
| 3486 | upstream = self.getUpstreamRepos([p]) |
| 3487 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3488 | A.setMerged() |
| 3489 | A_commit = str(upstream[p].commit('master')) |
| 3490 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3491 | |
| 3492 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3493 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3494 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3495 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3496 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3497 | pipeline='post', |
| 3498 | project='org/project', |
| 3499 | trigger='gerrit', |
| 3500 | ref='master', |
| 3501 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3502 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3503 | self.waitUntilSettled() |
| 3504 | job_names = [x.name for x in self.history] |
| 3505 | self.assertEqual(len(self.history), 1) |
| 3506 | self.assertIn('project-post', job_names) |
| 3507 | self.assertEqual(r, True) |
| 3508 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3509 | def test_client_enqueue_negative(self): |
| 3510 | "Test that the RPC client returns errors" |
| 3511 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3512 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3513 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3514 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3515 | "Invalid tenant"): |
| 3516 | r = client.enqueue(tenant='tenant-foo', |
| 3517 | pipeline='gate', |
| 3518 | project='org/project', |
| 3519 | trigger='gerrit', |
| 3520 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3521 | self.assertEqual(r, False) |
| 3522 | |
| 3523 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3524 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3525 | r = client.enqueue(tenant='tenant-one', |
| 3526 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3527 | project='project-does-not-exist', |
| 3528 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3529 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3530 | self.assertEqual(r, False) |
| 3531 | |
| 3532 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3533 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3534 | r = client.enqueue(tenant='tenant-one', |
| 3535 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3536 | project='org/project', |
| 3537 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3538 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3539 | self.assertEqual(r, False) |
| 3540 | |
| 3541 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3542 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3543 | r = client.enqueue(tenant='tenant-one', |
| 3544 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3545 | project='org/project', |
| 3546 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3547 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3548 | self.assertEqual(r, False) |
| 3549 | |
| 3550 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3551 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3552 | r = client.enqueue(tenant='tenant-one', |
| 3553 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3554 | project='org/project', |
| 3555 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3556 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3557 | self.assertEqual(r, False) |
| 3558 | |
| 3559 | self.waitUntilSettled() |
| 3560 | self.assertEqual(len(self.history), 0) |
| 3561 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3562 | |
| 3563 | def test_client_promote(self): |
| 3564 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3565 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3566 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3567 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3568 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3569 | A.addApproval('Code-Review', 2) |
| 3570 | B.addApproval('Code-Review', 2) |
| 3571 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3572 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3573 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3574 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3575 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3576 | |
| 3577 | self.waitUntilSettled() |
| 3578 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3579 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3580 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3581 | enqueue_times = {} |
| 3582 | for item in items: |
| 3583 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3584 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3585 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3586 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3587 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3588 | r = client.promote(tenant='tenant-one', |
| 3589 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3590 | change_ids=['2,1', '3,1']) |
| 3591 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3592 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3593 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3594 | for item in items: |
| 3595 | self.assertEqual( |
| 3596 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3597 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3598 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3599 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3600 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3601 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3602 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3603 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3604 | self.waitUntilSettled() |
| 3605 | |
| 3606 | self.assertEqual(len(self.builds), 6) |
| 3607 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3608 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3609 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3610 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3611 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3612 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3613 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3614 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3615 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3616 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3617 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3618 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3619 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3620 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3621 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3622 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3623 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3624 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3625 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3626 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3627 | self.waitUntilSettled() |
| 3628 | |
| 3629 | self.assertEqual(A.data['status'], 'MERGED') |
| 3630 | self.assertEqual(A.reported, 2) |
| 3631 | self.assertEqual(B.data['status'], 'MERGED') |
| 3632 | self.assertEqual(B.reported, 2) |
| 3633 | self.assertEqual(C.data['status'], 'MERGED') |
| 3634 | self.assertEqual(C.reported, 2) |
| 3635 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3636 | self.assertEqual(r, True) |
| 3637 | |
| 3638 | def test_client_promote_dependent(self): |
| 3639 | "Test that the RPC client can promote a dependent change" |
| 3640 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3641 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3642 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3643 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3644 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3645 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3646 | |
| 3647 | C.setDependsOn(B, 1) |
| 3648 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3649 | A.addApproval('Code-Review', 2) |
| 3650 | B.addApproval('Code-Review', 2) |
| 3651 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3652 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3653 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3654 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3655 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3656 | |
| 3657 | self.waitUntilSettled() |
| 3658 | |
| 3659 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3660 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3661 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3662 | r = client.promote(tenant='tenant-one', |
| 3663 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3664 | change_ids=['3,1']) |
| 3665 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3666 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3667 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3668 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3669 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3670 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3671 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3672 | self.waitUntilSettled() |
| 3673 | |
| 3674 | self.assertEqual(len(self.builds), 6) |
| 3675 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3676 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3677 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3678 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3679 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3680 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3681 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3682 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3683 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3684 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3685 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3686 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3687 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3688 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3689 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3690 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3691 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3692 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3693 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3694 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3695 | self.waitUntilSettled() |
| 3696 | |
| 3697 | self.assertEqual(A.data['status'], 'MERGED') |
| 3698 | self.assertEqual(A.reported, 2) |
| 3699 | self.assertEqual(B.data['status'], 'MERGED') |
| 3700 | self.assertEqual(B.reported, 2) |
| 3701 | self.assertEqual(C.data['status'], 'MERGED') |
| 3702 | self.assertEqual(C.reported, 2) |
| 3703 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3704 | self.assertEqual(r, True) |
| 3705 | |
| 3706 | def test_client_promote_negative(self): |
| 3707 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3708 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3709 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3710 | A.addApproval('Code-Review', 2) |
| 3711 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3712 | self.waitUntilSettled() |
| 3713 | |
| 3714 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3715 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3716 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3717 | |
| 3718 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3719 | r = client.promote(tenant='tenant-one', |
| 3720 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3721 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3722 | self.assertEqual(r, False) |
| 3723 | |
| 3724 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3725 | r = client.promote(tenant='tenant-one', |
| 3726 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3727 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3728 | self.assertEqual(r, False) |
| 3729 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3730 | self.executor_server.hold_jobs_in_build = False |
| 3731 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3732 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3733 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3734 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3735 | def test_queue_rate_limiting(self): |
| 3736 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3737 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3738 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3739 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3740 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3741 | |
| 3742 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3743 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3744 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3745 | A.addApproval('Code-Review', 2) |
| 3746 | B.addApproval('Code-Review', 2) |
| 3747 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3748 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3749 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3750 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3751 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3752 | self.waitUntilSettled() |
| 3753 | |
| 3754 | # Only A and B will have their merge jobs queued because |
| 3755 | # window is 2. |
| 3756 | self.assertEqual(len(self.builds), 2) |
| 3757 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3758 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3759 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3760 | # Release the merge jobs one at a time. |
| 3761 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3762 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3763 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3764 | self.waitUntilSettled() |
| 3765 | |
| 3766 | # Only A and B will have their test jobs queued because |
| 3767 | # window is 2. |
| 3768 | self.assertEqual(len(self.builds), 4) |
| 3769 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3770 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3771 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3772 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3773 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3774 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3775 | self.waitUntilSettled() |
| 3776 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3777 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3778 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3779 | # A failed so window is reduced by 1 to 1. |
| 3780 | self.assertEqual(queue.window, 1) |
| 3781 | self.assertEqual(queue.window_floor, 1) |
| 3782 | self.assertEqual(A.data['status'], 'NEW') |
| 3783 | |
| 3784 | # Gate is reset and only B's merge job is queued because |
| 3785 | # window shrunk to 1. |
| 3786 | self.assertEqual(len(self.builds), 1) |
| 3787 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3788 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3789 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3790 | self.waitUntilSettled() |
| 3791 | |
| 3792 | # Only B's test jobs are queued because window is still 1. |
| 3793 | self.assertEqual(len(self.builds), 2) |
| 3794 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3795 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3796 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3797 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3798 | self.waitUntilSettled() |
| 3799 | |
| 3800 | # B was successfully merged so window is increased to 2. |
| 3801 | self.assertEqual(queue.window, 2) |
| 3802 | self.assertEqual(queue.window_floor, 1) |
| 3803 | self.assertEqual(B.data['status'], 'MERGED') |
| 3804 | |
| 3805 | # Only C is left and its merge job is queued. |
| 3806 | self.assertEqual(len(self.builds), 1) |
| 3807 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3808 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3809 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3810 | self.waitUntilSettled() |
| 3811 | |
| 3812 | # After successful merge job the test jobs for C are queued. |
| 3813 | self.assertEqual(len(self.builds), 2) |
| 3814 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3815 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3816 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3817 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3818 | self.waitUntilSettled() |
| 3819 | |
| 3820 | # C successfully merged so window is bumped to 3. |
| 3821 | self.assertEqual(queue.window, 3) |
| 3822 | self.assertEqual(queue.window_floor, 1) |
| 3823 | self.assertEqual(C.data['status'], 'MERGED') |
| 3824 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3825 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3826 | def test_queue_rate_limiting_dependent(self): |
| 3827 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3828 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3829 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3830 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3831 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3832 | |
| 3833 | B.setDependsOn(A, 1) |
| 3834 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3835 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3836 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3837 | A.addApproval('Code-Review', 2) |
| 3838 | B.addApproval('Code-Review', 2) |
| 3839 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3840 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3841 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3842 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3843 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3844 | self.waitUntilSettled() |
| 3845 | |
| 3846 | # Only A and B will have their merge jobs queued because |
| 3847 | # window is 2. |
| 3848 | self.assertEqual(len(self.builds), 2) |
| 3849 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3850 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3851 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3852 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3853 | |
| 3854 | # Only A and B will have their test jobs queued because |
| 3855 | # window is 2. |
| 3856 | self.assertEqual(len(self.builds), 4) |
| 3857 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3858 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3859 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3860 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3861 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3862 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3863 | self.waitUntilSettled() |
| 3864 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3865 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3866 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3867 | # A failed so window is reduced by 1 to 1. |
| 3868 | self.assertEqual(queue.window, 1) |
| 3869 | self.assertEqual(queue.window_floor, 1) |
| 3870 | self.assertEqual(A.data['status'], 'NEW') |
| 3871 | self.assertEqual(B.data['status'], 'NEW') |
| 3872 | |
| 3873 | # Gate is reset and only C's merge job is queued because |
| 3874 | # window shrunk to 1 and A and B were dequeued. |
| 3875 | self.assertEqual(len(self.builds), 1) |
| 3876 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3877 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3878 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3879 | |
| 3880 | # Only C's test jobs are queued because window is still 1. |
| 3881 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3882 | builds = self.getSortedBuilds() |
| 3883 | self.assertEqual(builds[0].name, 'project-test1') |
| 3884 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3885 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3886 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3887 | self.waitUntilSettled() |
| 3888 | |
| 3889 | # C was successfully merged so window is increased to 2. |
| 3890 | self.assertEqual(queue.window, 2) |
| 3891 | self.assertEqual(queue.window_floor, 1) |
| 3892 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3893 | |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3894 | @simple_layout('layouts/reconfigure-window.yaml') |
| 3895 | def test_reconfigure_window_shrink(self): |
| 3896 | # Test the active window shrinking during reconfiguration |
| 3897 | self.executor_server.hold_jobs_in_build = True |
| 3898 | |
| 3899 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3900 | A.addApproval('Code-Review', 2) |
| 3901 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3902 | self.waitUntilSettled() |
| 3903 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3904 | B.addApproval('Code-Review', 2) |
| 3905 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3906 | self.waitUntilSettled() |
| 3907 | |
| 3908 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3909 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3910 | self.assertEqual(queue.window, 20) |
| 3911 | self.assertTrue(len(self.builds), 4) |
| 3912 | |
| 3913 | self.executor_server.release('job1') |
| 3914 | self.waitUntilSettled() |
| 3915 | self.commitConfigUpdate('org/common-config', |
| 3916 | 'layouts/reconfigure-window2.yaml') |
| 3917 | self.sched.reconfigure(self.config) |
| 3918 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3919 | queue = tenant.layout.pipelines['gate'].queues[0] |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3920 | # Even though we have configured a smaller window, the value |
| 3921 | # on the existing shared queue should be used. |
| 3922 | self.assertEqual(queue.window, 20) |
| 3923 | self.assertTrue(len(self.builds), 4) |
| 3924 | |
| 3925 | self.sched.reconfigure(self.config) |
| 3926 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3927 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3928 | self.assertEqual(queue.window, 20) |
| 3929 | self.assertTrue(len(self.builds), 4) |
| 3930 | |
| 3931 | self.executor_server.hold_jobs_in_build = False |
| 3932 | self.executor_server.release() |
| 3933 | |
| 3934 | self.waitUntilSettled() |
| 3935 | self.assertHistory([ |
| 3936 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 3937 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 3938 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3939 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 3940 | ], ordered=False) |
| 3941 | |
| 3942 | @simple_layout('layouts/reconfigure-window-fixed.yaml') |
| 3943 | def test_reconfigure_window_fixed(self): |
| 3944 | # Test the active window shrinking during reconfiguration |
| 3945 | self.executor_server.hold_jobs_in_build = True |
| 3946 | |
| 3947 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3948 | A.addApproval('Code-Review', 2) |
| 3949 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3950 | self.waitUntilSettled() |
| 3951 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3952 | B.addApproval('Code-Review', 2) |
| 3953 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3954 | self.waitUntilSettled() |
| 3955 | |
| 3956 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3957 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3958 | self.assertEqual(queue.window, 2) |
| 3959 | self.assertTrue(len(self.builds), 4) |
| 3960 | |
| 3961 | self.executor_server.release('job1') |
| 3962 | self.waitUntilSettled() |
| 3963 | self.commitConfigUpdate('org/common-config', |
| 3964 | 'layouts/reconfigure-window-fixed2.yaml') |
| 3965 | self.sched.reconfigure(self.config) |
| 3966 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3967 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3968 | # Because we have configured a static window, it should |
| 3969 | # be allowed to shrink on reconfiguration. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3970 | self.assertEqual(queue.window, 1) |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3971 | # B is outside the window, but still marked active until the |
| 3972 | # next pass through the queue processor, so its builds haven't |
| 3973 | # been canceled. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3974 | self.assertTrue(len(self.builds), 4) |
| 3975 | |
| 3976 | self.sched.reconfigure(self.config) |
| 3977 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3978 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3979 | self.assertEqual(queue.window, 1) |
| 3980 | # B's builds have been canceled now |
| 3981 | self.assertTrue(len(self.builds), 2) |
| 3982 | |
| 3983 | self.executor_server.hold_jobs_in_build = False |
| 3984 | self.executor_server.release() |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3985 | |
| 3986 | # B's builds will be restarted and will show up in our history |
| 3987 | # twice. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3988 | self.waitUntilSettled() |
| 3989 | self.assertHistory([ |
| 3990 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 3991 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 3992 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3993 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 3994 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 3995 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 3996 | ], ordered=False) |
| 3997 | |
| 3998 | @simple_layout('layouts/reconfigure-remove-add.yaml') |
| 3999 | def test_reconfigure_remove_add(self): |
| 4000 | # Test removing, then adding a job while in queue |
| 4001 | self.executor_server.hold_jobs_in_build = True |
| 4002 | |
| 4003 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4004 | A.addApproval('Code-Review', 2) |
| 4005 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4006 | self.waitUntilSettled() |
| 4007 | self.assertTrue(len(self.builds), 2) |
| 4008 | self.executor_server.release('job2') |
| 4009 | self.assertTrue(len(self.builds), 1) |
| 4010 | |
| 4011 | # Remove job2 |
| 4012 | self.commitConfigUpdate('org/common-config', |
| 4013 | 'layouts/reconfigure-remove-add2.yaml') |
| 4014 | self.sched.reconfigure(self.config) |
| 4015 | self.assertTrue(len(self.builds), 1) |
| 4016 | |
| 4017 | # Add job2 back |
| 4018 | self.commitConfigUpdate('org/common-config', |
| 4019 | 'layouts/reconfigure-remove-add.yaml') |
| 4020 | self.sched.reconfigure(self.config) |
| 4021 | self.assertTrue(len(self.builds), 2) |
| 4022 | |
| 4023 | self.executor_server.hold_jobs_in_build = False |
| 4024 | self.executor_server.release() |
| 4025 | # This will run new builds for B |
| 4026 | self.waitUntilSettled() |
| 4027 | self.assertHistory([ |
| 4028 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 4029 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 4030 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 4031 | ], ordered=False) |
| 4032 | |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4033 | def test_worker_update_metadata(self): |
| 4034 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4035 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4036 | |
| 4037 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4038 | A.addApproval('Code-Review', 2) |
| 4039 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4040 | self.waitUntilSettled() |
| 4041 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4042 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4043 | |
| 4044 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4045 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4046 | |
| 4047 | start = time.time() |
| 4048 | while True: |
| 4049 | if time.time() - start > 10: |
| 4050 | raise Exception("Timeout waiting for gearman server to report " |
| 4051 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4052 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4053 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4054 | break |
| 4055 | else: |
| 4056 | time.sleep(0) |
| 4057 | |
| 4058 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4059 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4060 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4061 | self.executor_server.hold_jobs_in_build = False |
| 4062 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4063 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4064 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 4065 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4066 | def test_footer_message(self): |
| 4067 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4068 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4069 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4070 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4071 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4072 | self.waitUntilSettled() |
| 4073 | |
| 4074 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4075 | B.addApproval('Code-Review', 2) |
| 4076 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4077 | self.waitUntilSettled() |
| 4078 | |
| 4079 | self.assertEqual(2, len(self.smtp_messages)) |
| 4080 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4081 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4082 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4083 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4084 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4085 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4086 | For CI problems and help debugging, contact ci@example.org""" |
| 4087 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4088 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 4089 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 4090 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 4091 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4092 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 4093 | @simple_layout('layouts/unmanaged-project.yaml') |
| 4094 | def test_unmanaged_project_start_message(self): |
| 4095 | "Test start reporting is not done for unmanaged projects." |
| 4096 | self.init_repo("org/project", tag='init') |
| 4097 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4098 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4099 | self.waitUntilSettled() |
| 4100 | |
| 4101 | self.assertEqual(0, len(A.messages)) |
| 4102 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4103 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4104 | def test_merge_failure_reporters(self): |
| 4105 | """Check that the config is set up correctly""" |
| 4106 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4107 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4108 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 4109 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 4110 | "dependencies was unable to be automatically merged with the " |
| 4111 | "current state of its repository. Please rebase the change and " |
| 4112 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4113 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4114 | self.assertEqual( |
| 4115 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4116 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4117 | |
| 4118 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4119 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4120 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4121 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4122 | |
| 4123 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4124 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 4125 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4126 | |
| 4127 | self.assertTrue( |
| 4128 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4129 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4130 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4131 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 4132 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4133 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4134 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4135 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4136 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4137 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4138 | gerritreporter.GerritReporter) and |
| 4139 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4140 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4141 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4142 | ) |
| 4143 | ) |
| 4144 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4145 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4146 | def test_merge_failure_reports(self): |
| 4147 | """Check that when a change fails to merge the correct message is sent |
| 4148 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4149 | self.updateConfigLayout( |
| 4150 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4151 | self.sched.reconfigure(self.config) |
| 4152 | self.registerJobs() |
| 4153 | |
| 4154 | # Check a test failure isn't reported to SMTP |
| 4155 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4156 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4157 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4158 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4159 | self.waitUntilSettled() |
| 4160 | |
| 4161 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 4162 | self.assertEqual(0, len(self.smtp_messages)) |
| 4163 | |
| 4164 | # Check a merge failure is reported to SMTP |
| 4165 | # B should be merged, but C will conflict with B |
| 4166 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4167 | B.addPatchset(['conflict']) |
| 4168 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4169 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4170 | B.addApproval('Code-Review', 2) |
| 4171 | C.addApproval('Code-Review', 2) |
| 4172 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4173 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4174 | self.waitUntilSettled() |
| 4175 | |
| 4176 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 4177 | self.assertEqual(1, len(self.smtp_messages)) |
| 4178 | self.assertEqual('The merge failed! For more information...', |
| 4179 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 4180 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4181 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 4182 | def test_default_merge_failure_reports(self): |
| 4183 | """Check that the default merge failure reports are correct.""" |
| 4184 | |
| 4185 | # A should report success, B should report merge failure. |
| 4186 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4187 | A.addPatchset(['conflict']) |
| 4188 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4189 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4190 | A.addApproval('Code-Review', 2) |
| 4191 | B.addApproval('Code-Review', 2) |
| 4192 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4193 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 4194 | self.waitUntilSettled() |
| 4195 | |
| 4196 | self.assertEqual(3, len(self.history)) # A jobs |
| 4197 | self.assertEqual(A.reported, 2) |
| 4198 | self.assertEqual(B.reported, 2) |
| 4199 | self.assertEqual(A.data['status'], 'MERGED') |
| 4200 | self.assertEqual(B.data['status'], 'NEW') |
| 4201 | self.assertIn('Build succeeded', A.messages[1]) |
| 4202 | self.assertIn('Merge Failed', B.messages[1]) |
| 4203 | self.assertIn('automatically merged', B.messages[1]) |
| 4204 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 4205 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 4206 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4207 | def test_client_get_running_jobs(self): |
| 4208 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4209 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4210 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4211 | A.addApproval('Code-Review', 2) |
| 4212 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4213 | self.waitUntilSettled() |
| 4214 | |
| 4215 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 4216 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 4217 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4218 | |
| 4219 | # Wait for gearman server to send the initial workData back to zuul |
| 4220 | start = time.time() |
| 4221 | while True: |
| 4222 | if time.time() - start > 10: |
| 4223 | raise Exception("Timeout waiting for gearman server to report " |
| 4224 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 4225 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4226 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4227 | break |
| 4228 | else: |
| 4229 | time.sleep(0) |
| 4230 | |
| 4231 | running_items = client.get_running_jobs() |
| 4232 | |
| 4233 | self.assertEqual(1, len(running_items)) |
| 4234 | running_item = running_items[0] |
| 4235 | self.assertEqual([], running_item['failing_reasons']) |
| 4236 | self.assertEqual([], running_item['items_behind']) |
James E. Blair | 0e4c791 | 2018-01-02 14:20:17 -0800 | [diff] [blame] | 4237 | self.assertEqual('https://review.example.com/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4238 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4239 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4240 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4241 | self.assertEqual(True, running_item['active']) |
| 4242 | self.assertEqual('1,1', running_item['id']) |
| 4243 | |
| 4244 | self.assertEqual(3, len(running_item['jobs'])) |
| 4245 | for job in running_item['jobs']: |
| 4246 | if job['name'] == 'project-merge': |
| 4247 | self.assertEqual('project-merge', job['name']) |
| 4248 | self.assertEqual('gate', job['pipeline']) |
| 4249 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4250 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 4251 | 'stream.html?uuid={uuid}&logfile=console.log' |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 4252 | .format(uuid=job['uuid']), job['url']) |
| 4253 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4254 | 'finger://{hostname}/{uuid}'.format( |
| 4255 | hostname=self.executor_server.hostname, |
| 4256 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 4257 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4258 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4259 | self.assertEqual(False, job['canceled']) |
| 4260 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4261 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4262 | self.assertEqual('gate', job['pipeline']) |
| 4263 | break |
| 4264 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4265 | self.executor_server.hold_jobs_in_build = False |
| 4266 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4267 | self.waitUntilSettled() |
| 4268 | |
| 4269 | running_items = client.get_running_jobs() |
| 4270 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4271 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 4272 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4273 | def test_nonvoting_pipeline(self): |
| 4274 | "Test that a nonvoting pipeline (experimental) can still report" |
| 4275 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 4276 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 4277 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4278 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4279 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 4280 | |
| 4281 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 4282 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 4283 | self.assertEqual( |
| 4284 | self.getJobFromHistory('experimental-project-test').result, |
| 4285 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4286 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4287 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4288 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4289 | def test_disable_at(self): |
| 4290 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4291 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4292 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4293 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4294 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4295 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4296 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4297 | |
| 4298 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4299 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4300 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4301 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4302 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4303 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4304 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4305 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4306 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4307 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4308 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4309 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4310 | self.executor_server.failJob('project-test1', A) |
| 4311 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4312 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4313 | self.executor_server.failJob('project-test1', D) |
| 4314 | self.executor_server.failJob('project-test1', E) |
| 4315 | self.executor_server.failJob('project-test1', F) |
| 4316 | self.executor_server.failJob('project-test1', G) |
| 4317 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4318 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4319 | self.executor_server.failJob('project-test1', J) |
| 4320 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4321 | |
| 4322 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4323 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4324 | self.waitUntilSettled() |
| 4325 | |
| 4326 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4327 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4328 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4329 | |
| 4330 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4331 | self.waitUntilSettled() |
| 4332 | |
| 4333 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4334 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4335 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4336 | |
| 4337 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4338 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4339 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4340 | self.waitUntilSettled() |
| 4341 | |
| 4342 | # We should be disabled now |
| 4343 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4344 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4345 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4346 | |
| 4347 | # We need to wait between each of these patches to make sure the |
| 4348 | # smtp messages come back in an expected order |
| 4349 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4350 | self.waitUntilSettled() |
| 4351 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4352 | self.waitUntilSettled() |
| 4353 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4354 | self.waitUntilSettled() |
| 4355 | |
| 4356 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4357 | # leaving a message on each change |
| 4358 | self.assertEqual(1, len(A.messages)) |
| 4359 | self.assertIn('Build failed.', A.messages[0]) |
| 4360 | self.assertEqual(1, len(B.messages)) |
| 4361 | self.assertIn('Build failed.', B.messages[0]) |
| 4362 | self.assertEqual(1, len(C.messages)) |
| 4363 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4364 | self.assertEqual(1, len(D.messages)) |
| 4365 | self.assertIn('Build failed.', D.messages[0]) |
| 4366 | self.assertEqual(1, len(E.messages)) |
| 4367 | self.assertIn('Build failed.', E.messages[0]) |
| 4368 | self.assertEqual(1, len(F.messages)) |
| 4369 | self.assertIn('Build failed.', F.messages[0]) |
| 4370 | |
| 4371 | # The last 3 (GHI) would have only reported via smtp. |
| 4372 | self.assertEqual(3, len(self.smtp_messages)) |
| 4373 | self.assertEqual(0, len(G.messages)) |
| 4374 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4375 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4376 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4377 | self.assertEqual(0, len(H.messages)) |
| 4378 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4379 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4380 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4381 | self.assertEqual(0, len(I.messages)) |
| 4382 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4383 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4384 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4385 | |
| 4386 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4387 | # comes out of disabled |
| 4388 | self.sched.reconfigure(self.config) |
| 4389 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4390 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4391 | |
| 4392 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4393 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4394 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4395 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4396 | |
| 4397 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4398 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4399 | self.waitUntilSettled() |
| 4400 | |
| 4401 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4402 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4403 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4404 | |
| 4405 | # J and K went back to gerrit |
| 4406 | self.assertEqual(1, len(J.messages)) |
| 4407 | self.assertIn('Build failed.', J.messages[0]) |
| 4408 | self.assertEqual(1, len(K.messages)) |
| 4409 | self.assertIn('Build failed.', K.messages[0]) |
| 4410 | # No more messages reported via smtp |
| 4411 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4412 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4413 | @simple_layout('layouts/one-job-project.yaml') |
| 4414 | def test_one_job_project(self): |
| 4415 | "Test that queueing works with one job" |
| 4416 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4417 | 'master', 'A') |
| 4418 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4419 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4420 | A.addApproval('Code-Review', 2) |
| 4421 | B.addApproval('Code-Review', 2) |
| 4422 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4423 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4424 | self.waitUntilSettled() |
| 4425 | |
| 4426 | self.assertEqual(A.data['status'], 'MERGED') |
| 4427 | self.assertEqual(A.reported, 2) |
| 4428 | self.assertEqual(B.data['status'], 'MERGED') |
| 4429 | self.assertEqual(B.reported, 2) |
| 4430 | |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4431 | def test_job_aborted(self): |
| 4432 | "Test that if a execute server aborts a job, it is run again" |
| 4433 | self.executor_server.hold_jobs_in_build = True |
| 4434 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4435 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4436 | self.waitUntilSettled() |
| 4437 | |
| 4438 | self.executor_server.release('.*-merge') |
| 4439 | self.waitUntilSettled() |
| 4440 | |
| 4441 | self.assertEqual(len(self.builds), 2) |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4442 | |
| 4443 | # first abort |
| 4444 | self.builds[0].aborted = True |
| 4445 | self.executor_server.release('.*-test*') |
| 4446 | self.waitUntilSettled() |
| 4447 | self.assertEqual(len(self.builds), 1) |
| 4448 | |
| 4449 | # second abort |
| 4450 | self.builds[0].aborted = True |
| 4451 | self.executor_server.release('.*-test*') |
| 4452 | self.waitUntilSettled() |
| 4453 | self.assertEqual(len(self.builds), 1) |
| 4454 | |
| 4455 | # third abort |
| 4456 | self.builds[0].aborted = True |
| 4457 | self.executor_server.release('.*-test*') |
| 4458 | self.waitUntilSettled() |
| 4459 | self.assertEqual(len(self.builds), 1) |
| 4460 | |
| 4461 | # fourth abort |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4462 | self.builds[0].aborted = True |
| 4463 | self.executor_server.release('.*-test*') |
| 4464 | self.waitUntilSettled() |
| 4465 | self.assertEqual(len(self.builds), 1) |
| 4466 | |
| 4467 | self.executor_server.hold_jobs_in_build = False |
| 4468 | self.executor_server.release() |
| 4469 | self.waitUntilSettled() |
| 4470 | |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4471 | self.assertEqual(len(self.history), 7) |
| 4472 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4473 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 4474 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4475 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4476 | "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] | 4477 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4478 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4479 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4480 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4481 | self.waitUntilSettled() |
| 4482 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4483 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4484 | self.waitUntilSettled() |
| 4485 | |
| 4486 | self.assertEqual(len(self.builds), 2) |
| 4487 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4488 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4489 | self.waitUntilSettled() |
| 4490 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4491 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4492 | self.assertEqual(len(self.builds), 1, |
| 4493 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4494 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4495 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4496 | self.waitUntilSettled() |
| 4497 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4498 | self.executor_server.hold_jobs_in_build = False |
| 4499 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4500 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4501 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4502 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4503 | self.assertEqual(A.reported, 1) |
| 4504 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4505 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4506 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4507 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4508 | |
| 4509 | self.fake_nodepool.paused = True |
| 4510 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4511 | A.addApproval('Code-Review', 2) |
| 4512 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4513 | self.waitUntilSettled() |
| 4514 | |
| 4515 | self.zk.client.stop() |
| 4516 | self.zk.client.start() |
| 4517 | self.fake_nodepool.paused = False |
| 4518 | self.waitUntilSettled() |
| 4519 | |
| 4520 | self.assertEqual(A.data['status'], 'MERGED') |
| 4521 | self.assertEqual(A.reported, 2) |
| 4522 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4523 | def test_nodepool_failure(self): |
| 4524 | "Test that jobs are reported after a nodepool failure" |
| 4525 | |
| 4526 | self.fake_nodepool.paused = True |
| 4527 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4528 | A.addApproval('Code-Review', 2) |
| 4529 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4530 | self.waitUntilSettled() |
| 4531 | |
| 4532 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4533 | self.fake_nodepool.addFailRequest(req) |
| 4534 | |
| 4535 | self.fake_nodepool.paused = False |
| 4536 | self.waitUntilSettled() |
| 4537 | |
| 4538 | self.assertEqual(A.data['status'], 'NEW') |
| 4539 | self.assertEqual(A.reported, 2) |
| 4540 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4541 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4542 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4543 | |
Monty Taylor | 6dc5bc1 | 2017-09-29 15:47:31 -0500 | [diff] [blame] | 4544 | def test_nodepool_priority(self): |
| 4545 | "Test that nodes are requested at the correct priority" |
| 4546 | |
| 4547 | self.fake_nodepool.paused = True |
| 4548 | |
| 4549 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4550 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4551 | |
| 4552 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4553 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4554 | |
| 4555 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4556 | C.addApproval('Code-Review', 2) |
| 4557 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 4558 | |
| 4559 | self.waitUntilSettled() |
| 4560 | |
| 4561 | reqs = self.fake_nodepool.getNodeRequests() |
| 4562 | |
| 4563 | # The requests come back sorted by oid. Since we have three requests |
| 4564 | # for the three changes each with a different priority. |
| 4565 | # Also they get a serial number based on order they were received |
| 4566 | # so the number on the endof the oid should map to order submitted. |
| 4567 | |
| 4568 | # * gate first - high priority - change C |
| 4569 | self.assertEqual(reqs[0]['_oid'], '100-0000000002') |
| 4570 | self.assertEqual(reqs[0]['node_types'], ['label1']) |
| 4571 | # * check second - normal priority - change B |
| 4572 | self.assertEqual(reqs[1]['_oid'], '200-0000000001') |
| 4573 | self.assertEqual(reqs[1]['node_types'], ['label1']) |
| 4574 | # * post third - low priority - change A |
| 4575 | # additionally, the post job defined uses an ubuntu-xenial node, |
| 4576 | # so we include that check just as an extra verification |
| 4577 | self.assertEqual(reqs[2]['_oid'], '300-0000000000') |
| 4578 | self.assertEqual(reqs[2]['node_types'], ['ubuntu-xenial']) |
| 4579 | |
| 4580 | self.fake_nodepool.paused = False |
| 4581 | self.waitUntilSettled() |
| 4582 | |
James E. Blair | fceaf41 | 2017-09-29 13:44:57 -0700 | [diff] [blame] | 4583 | @simple_layout('layouts/multiple-templates.yaml') |
| 4584 | def test_multiple_project_templates(self): |
| 4585 | # Test that applying multiple project templates to a project |
| 4586 | # doesn't alter them when used for a second project. |
| 4587 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4588 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4589 | self.waitUntilSettled() |
| 4590 | |
| 4591 | build = self.getJobFromHistory('py27') |
| 4592 | self.assertEqual(build.parameters['zuul']['jobtags'], []) |
| 4593 | |
James E. Blair | 29c7700 | 2017-10-05 14:56:35 -0700 | [diff] [blame] | 4594 | def test_pending_merge_in_reconfig(self): |
| 4595 | # Test that if we are waiting for an outstanding merge on |
| 4596 | # reconfiguration that we continue to do so. |
| 4597 | self.gearman_server.hold_merge_jobs_in_queue = True |
| 4598 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4599 | A.setMerged() |
| 4600 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4601 | self.waitUntilSettled() |
| 4602 | # Reconfigure while we still have an outstanding merge job |
| 4603 | self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'], |
| 4604 | None) |
| 4605 | self.waitUntilSettled() |
| 4606 | # Verify the merge job is still running and that the item is |
| 4607 | # in the pipeline |
| 4608 | self.assertEqual(len(self.sched.merger.jobs), 1) |
| 4609 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4610 | pipeline = tenant.layout.pipelines['post'] |
| 4611 | self.assertEqual(len(pipeline.getAllItems()), 1) |
| 4612 | self.gearman_server.hold_merge_jobs_in_queue = False |
| 4613 | self.gearman_server.release() |
| 4614 | self.waitUntilSettled() |
| 4615 | |
James E. Blair | c32a835 | 2017-10-11 16:27:50 -0700 | [diff] [blame] | 4616 | @simple_layout('layouts/parent-matchers.yaml') |
| 4617 | def test_parent_matchers(self): |
| 4618 | "Test that if a job's parent does not match, the job does not run" |
| 4619 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4620 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4621 | self.waitUntilSettled() |
| 4622 | |
| 4623 | self.assertHistory([]) |
| 4624 | |
| 4625 | files = {'foo.txt': ''} |
| 4626 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B', |
| 4627 | files=files) |
| 4628 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4629 | self.waitUntilSettled() |
| 4630 | |
| 4631 | files = {'bar.txt': ''} |
| 4632 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C', |
| 4633 | files=files) |
| 4634 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4635 | self.waitUntilSettled() |
| 4636 | |
| 4637 | files = {'foo.txt': '', 'bar.txt': ''} |
| 4638 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D', |
| 4639 | files=files) |
| 4640 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4641 | self.waitUntilSettled() |
| 4642 | |
| 4643 | self.assertHistory([ |
| 4644 | dict(name='child-job', result='SUCCESS', changes='2,1'), |
| 4645 | dict(name='child-job', result='SUCCESS', changes='3,1'), |
| 4646 | dict(name='child-job', result='SUCCESS', changes='4,1'), |
| 4647 | ]) |
| 4648 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4649 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4650 | class TestExecutor(ZuulTestCase): |
| 4651 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4652 | |
| 4653 | def assertFinalState(self): |
| 4654 | # In this test, we expect to shut down in a non-final state, |
| 4655 | # so skip these checks. |
| 4656 | pass |
| 4657 | |
| 4658 | def assertCleanShutdown(self): |
| 4659 | self.log.debug("Assert clean shutdown") |
| 4660 | |
| 4661 | # After shutdown, make sure no jobs are running |
| 4662 | self.assertEqual({}, self.executor_server.job_workers) |
| 4663 | |
| 4664 | # Make sure that git.Repo objects have been garbage collected. |
| 4665 | repos = [] |
| 4666 | gc.collect() |
| 4667 | for obj in gc.get_objects(): |
| 4668 | if isinstance(obj, git.Repo): |
| 4669 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4670 | repos.append(obj) |
| 4671 | self.assertEqual(len(repos), 0) |
| 4672 | |
| 4673 | def test_executor_shutdown(self): |
| 4674 | "Test that the executor can shut down with jobs running" |
| 4675 | |
| 4676 | self.executor_server.hold_jobs_in_build = True |
| 4677 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4678 | A.addApproval('Code-Review', 2) |
| 4679 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4680 | self.waitUntilSettled() |
| 4681 | |
| 4682 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4683 | class TestDependencyGraph(ZuulTestCase): |
| 4684 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4685 | |
| 4686 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4687 | "Test a job in a dependency graph is queued only once" |
| 4688 | # Job dependencies, starting with A |
| 4689 | # A |
| 4690 | # / \ |
| 4691 | # B C |
| 4692 | # / \ / \ |
| 4693 | # D F E |
| 4694 | # | |
| 4695 | # G |
| 4696 | |
| 4697 | self.executor_server.hold_jobs_in_build = True |
| 4698 | change = self.fake_gerrit.addFakeChange( |
| 4699 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4700 | change.addApproval('Code-Review', 2) |
| 4701 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4702 | |
| 4703 | self.waitUntilSettled() |
| 4704 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4705 | |
| 4706 | self.executor_server.release('A') |
| 4707 | self.waitUntilSettled() |
| 4708 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4709 | |
| 4710 | self.executor_server.release('B') |
| 4711 | self.waitUntilSettled() |
| 4712 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4713 | |
| 4714 | self.executor_server.release('D') |
| 4715 | self.waitUntilSettled() |
| 4716 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4717 | |
| 4718 | self.executor_server.release('C') |
| 4719 | self.waitUntilSettled() |
| 4720 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4721 | |
| 4722 | self.executor_server.release('F') |
| 4723 | self.waitUntilSettled() |
| 4724 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4725 | |
| 4726 | self.executor_server.release('G') |
| 4727 | self.waitUntilSettled() |
| 4728 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4729 | |
| 4730 | self.executor_server.release('E') |
| 4731 | self.waitUntilSettled() |
| 4732 | self.assertEqual(len(self.builds), 0) |
| 4733 | |
| 4734 | self.executor_server.hold_jobs_in_build = False |
| 4735 | self.executor_server.release() |
| 4736 | self.waitUntilSettled() |
| 4737 | |
| 4738 | self.assertEqual(len(self.builds), 0) |
| 4739 | self.assertEqual(len(self.history), 7) |
| 4740 | |
| 4741 | self.assertEqual(change.data['status'], 'MERGED') |
| 4742 | self.assertEqual(change.reported, 2) |
| 4743 | |
| 4744 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4745 | "Test that a job waits till all dependencies are successful" |
| 4746 | # Job dependencies, starting with A |
| 4747 | # A |
| 4748 | # / \ |
| 4749 | # B C* |
| 4750 | # / \ / \ |
| 4751 | # D F E |
| 4752 | # | |
| 4753 | # G |
| 4754 | |
| 4755 | self.executor_server.hold_jobs_in_build = True |
| 4756 | change = self.fake_gerrit.addFakeChange( |
| 4757 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4758 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4759 | |
| 4760 | self.executor_server.failJob('C', change) |
| 4761 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4762 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4763 | |
| 4764 | self.waitUntilSettled() |
| 4765 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4766 | |
| 4767 | self.executor_server.release('A') |
| 4768 | self.waitUntilSettled() |
| 4769 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4770 | |
| 4771 | self.executor_server.release('B') |
| 4772 | self.waitUntilSettled() |
| 4773 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4774 | |
| 4775 | self.executor_server.release('D') |
| 4776 | self.waitUntilSettled() |
| 4777 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4778 | |
| 4779 | self.executor_server.release('C') |
| 4780 | self.waitUntilSettled() |
| 4781 | self.assertEqual(len(self.builds), 0) |
| 4782 | |
| 4783 | self.executor_server.hold_jobs_in_build = False |
| 4784 | self.executor_server.release() |
| 4785 | self.waitUntilSettled() |
| 4786 | |
| 4787 | self.assertEqual(len(self.builds), 0) |
| 4788 | self.assertEqual(len(self.history), 4) |
| 4789 | |
| 4790 | self.assertEqual(change.data['status'], 'NEW') |
| 4791 | self.assertEqual(change.reported, 2) |
| 4792 | |
| 4793 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4794 | class TestDuplicatePipeline(ZuulTestCase): |
| 4795 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4796 | |
| 4797 | def test_duplicate_pipelines(self): |
| 4798 | "Test that a change matching multiple pipelines works" |
| 4799 | |
| 4800 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4801 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4802 | self.waitUntilSettled() |
| 4803 | |
| 4804 | self.assertHistory([ |
| 4805 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4806 | pipeline='dup1'), |
| 4807 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4808 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4809 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4810 | |
| 4811 | self.assertEqual(len(A.messages), 2) |
| 4812 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4813 | if 'dup1' in A.messages[0]: |
| 4814 | self.assertIn('dup1', A.messages[0]) |
| 4815 | self.assertNotIn('dup2', A.messages[0]) |
| 4816 | self.assertIn('project-test1', A.messages[0]) |
| 4817 | self.assertIn('dup2', A.messages[1]) |
| 4818 | self.assertNotIn('dup1', A.messages[1]) |
| 4819 | self.assertIn('project-test1', A.messages[1]) |
| 4820 | else: |
| 4821 | self.assertIn('dup1', A.messages[1]) |
| 4822 | self.assertNotIn('dup2', A.messages[1]) |
| 4823 | self.assertIn('project-test1', A.messages[1]) |
| 4824 | self.assertIn('dup2', A.messages[0]) |
| 4825 | self.assertNotIn('dup1', A.messages[0]) |
| 4826 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4827 | |
| 4828 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4829 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4830 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4831 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4832 | def test_job_from_templates_executed(self): |
| 4833 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4834 | |
| 4835 | A = self.fake_gerrit.addFakeChange( |
| 4836 | 'org/templated-project', 'master', 'A') |
| 4837 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4838 | self.waitUntilSettled() |
| 4839 | |
| 4840 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4841 | 'SUCCESS') |
| 4842 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4843 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4844 | |
| 4845 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4846 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4847 | |
| 4848 | A = self.fake_gerrit.addFakeChange( |
| 4849 | 'org/layered-project', 'master', 'A') |
| 4850 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4851 | self.waitUntilSettled() |
| 4852 | |
| 4853 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4854 | 'SUCCESS') |
| 4855 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4856 | 'SUCCESS') |
| 4857 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4858 | ).result, 'SUCCESS') |
| 4859 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4860 | ).result, 'SUCCESS') |
| 4861 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4862 | ).result, 'SUCCESS') |
| 4863 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4864 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4865 | |
James E. Blair | e74f571 | 2017-09-29 15:14:31 -0700 | [diff] [blame] | 4866 | def test_unimplied_branch_matchers(self): |
| 4867 | # This tests that there are no implied branch matchers added |
| 4868 | # by project templates. |
| 4869 | self.create_branch('org/layered-project', 'stable') |
| 4870 | |
| 4871 | A = self.fake_gerrit.addFakeChange( |
| 4872 | 'org/layered-project', 'stable', 'A') |
| 4873 | |
| 4874 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4875 | self.waitUntilSettled() |
| 4876 | |
| 4877 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4878 | 'SUCCESS') |
| 4879 | print(self.getJobFromHistory('project-test1'). |
| 4880 | parameters['zuul']['_inheritance_path']) |
| 4881 | |
| 4882 | def test_implied_branch_matchers(self): |
| 4883 | # This tests that there is an implied branch matcher when a |
| 4884 | # template is used on an in-repo project pipeline definition. |
| 4885 | self.create_branch('untrusted-config', 'stable') |
| 4886 | self.fake_gerrit.addEvent( |
| 4887 | self.fake_gerrit.getFakeBranchCreatedEvent( |
| 4888 | 'untrusted-config', 'stable')) |
| 4889 | self.waitUntilSettled() |
| 4890 | |
| 4891 | A = self.fake_gerrit.addFakeChange( |
| 4892 | 'untrusted-config', 'stable', 'A') |
| 4893 | |
| 4894 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4895 | self.waitUntilSettled() |
| 4896 | |
| 4897 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4898 | 'SUCCESS') |
| 4899 | print(self.getJobFromHistory('project-test1'). |
| 4900 | parameters['zuul']['_inheritance_path']) |
| 4901 | |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4902 | |
| 4903 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4904 | tenant_config_file = 'config/success-url/main.yaml' |
| 4905 | |
| 4906 | def test_success_url(self): |
| 4907 | "Ensure bad build params are ignored" |
| 4908 | self.sched.reconfigure(self.config) |
| 4909 | self.init_repo('org/docs') |
| 4910 | |
| 4911 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4912 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4913 | self.waitUntilSettled() |
| 4914 | |
| 4915 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4916 | self.assertEqual(len(self.history), 2) |
| 4917 | |
| 4918 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4919 | for build in self.history: |
| 4920 | if build.name == 'docs-draft-test': |
| 4921 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4922 | elif build.name == 'docs-draft-test2': |
| 4923 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4924 | |
| 4925 | # Two msgs: 'Starting...' + results |
| 4926 | self.assertEqual(len(self.smtp_messages), 2) |
| 4927 | body = self.smtp_messages[1]['body'].splitlines() |
| 4928 | self.assertEqual('Build succeeded.', body[0]) |
| 4929 | |
| 4930 | self.assertIn( |
| 4931 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4932 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4933 | body[2]) |
| 4934 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4935 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4936 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4937 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 4938 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4939 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4940 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4941 | |
| 4942 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4943 | class TestSchedulerMerges(ZuulTestCase): |
| 4944 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4945 | |
| 4946 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4947 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4948 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4949 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4950 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4951 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4952 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4953 | A.addApproval('Code-Review', 2) |
| 4954 | B.addApproval('Code-Review', 2) |
| 4955 | C.addApproval('Code-Review', 2) |
| 4956 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4957 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4958 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4959 | self.waitUntilSettled() |
| 4960 | |
| 4961 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4962 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4963 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4964 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4965 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4966 | repo_messages.reverse() |
| 4967 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4968 | self.executor_server.hold_jobs_in_build = False |
| 4969 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4970 | self.waitUntilSettled() |
| 4971 | |
| 4972 | return repo_messages |
| 4973 | |
| 4974 | def _test_merge(self, mode): |
James E. Blair | da5bb7e | 2018-01-22 16:12:17 -0800 | [diff] [blame^] | 4975 | us_path = 'file://' + os.path.join( |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4976 | self.upstream_root, 'org/project-%s' % mode) |
| 4977 | expected_messages = [ |
| 4978 | 'initial commit', |
| 4979 | 'add content from fixture', |
| 4980 | # the intermediate commits order is nondeterministic |
| 4981 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4982 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4983 | ] |
| 4984 | result = self._test_project_merge_mode(mode) |
| 4985 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4986 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4987 | |
| 4988 | def test_project_merge_mode_merge(self): |
| 4989 | self._test_merge('merge') |
| 4990 | |
| 4991 | def test_project_merge_mode_merge_resolve(self): |
| 4992 | self._test_merge('merge-resolve') |
| 4993 | |
| 4994 | def test_project_merge_mode_cherrypick(self): |
| 4995 | expected_messages = [ |
| 4996 | 'initial commit', |
| 4997 | 'add content from fixture', |
| 4998 | 'A-1', |
| 4999 | 'B-1', |
| 5000 | 'C-1'] |
| 5001 | result = self._test_project_merge_mode('cherry-pick') |
| 5002 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5003 | |
| 5004 | def test_merge_branch(self): |
| 5005 | "Test that the right commits are on alternate branches" |
| 5006 | self.create_branch('org/project-merge-branches', 'mp') |
| 5007 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5008 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5009 | A = self.fake_gerrit.addFakeChange( |
| 5010 | 'org/project-merge-branches', 'mp', 'A') |
| 5011 | B = self.fake_gerrit.addFakeChange( |
| 5012 | 'org/project-merge-branches', 'mp', 'B') |
| 5013 | C = self.fake_gerrit.addFakeChange( |
| 5014 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5015 | A.addApproval('Code-Review', 2) |
| 5016 | B.addApproval('Code-Review', 2) |
| 5017 | C.addApproval('Code-Review', 2) |
| 5018 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5019 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5020 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5021 | self.waitUntilSettled() |
| 5022 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5023 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5024 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5025 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5026 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5027 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5028 | self.waitUntilSettled() |
| 5029 | |
| 5030 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 5031 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5032 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5033 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5034 | repo = git.Repo(path) |
| 5035 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5036 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5037 | repo_messages.reverse() |
| 5038 | correct_messages = [ |
| 5039 | 'initial commit', |
| 5040 | 'add content from fixture', |
| 5041 | 'mp commit', |
| 5042 | 'A-1', 'B-1', 'C-1'] |
| 5043 | self.assertEqual(repo_messages, correct_messages) |
| 5044 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5045 | self.executor_server.hold_jobs_in_build = False |
| 5046 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5047 | self.waitUntilSettled() |
| 5048 | |
| 5049 | def test_merge_multi_branch(self): |
| 5050 | "Test that dependent changes on multiple branches are merged" |
| 5051 | self.create_branch('org/project-merge-branches', 'mp') |
| 5052 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5053 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5054 | A = self.fake_gerrit.addFakeChange( |
| 5055 | 'org/project-merge-branches', 'master', 'A') |
| 5056 | B = self.fake_gerrit.addFakeChange( |
| 5057 | 'org/project-merge-branches', 'mp', 'B') |
| 5058 | C = self.fake_gerrit.addFakeChange( |
| 5059 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5060 | A.addApproval('Code-Review', 2) |
| 5061 | B.addApproval('Code-Review', 2) |
| 5062 | C.addApproval('Code-Review', 2) |
| 5063 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5064 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5065 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5066 | self.waitUntilSettled() |
| 5067 | |
| 5068 | job_A = None |
| 5069 | for job in self.builds: |
| 5070 | if 'project-merge' in job.name: |
| 5071 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5072 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5073 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 5074 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5075 | repo = git.Repo(path) |
| 5076 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5077 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5078 | repo_messages.reverse() |
| 5079 | correct_messages = [ |
| 5080 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5081 | self.assertEqual(repo_messages, correct_messages) |
| 5082 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5083 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5084 | self.waitUntilSettled() |
| 5085 | |
| 5086 | job_B = None |
| 5087 | for job in self.builds: |
| 5088 | if 'project-merge' in job.name: |
| 5089 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5090 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5091 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 5092 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5093 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5094 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5095 | repo_messages.reverse() |
| 5096 | correct_messages = [ |
| 5097 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5098 | self.assertEqual(repo_messages, correct_messages) |
| 5099 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5100 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5101 | self.waitUntilSettled() |
| 5102 | |
| 5103 | job_C = None |
| 5104 | for job in self.builds: |
| 5105 | if 'project-merge' in job.name: |
| 5106 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 5107 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5108 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 5109 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5110 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5111 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5112 | |
| 5113 | repo_messages.reverse() |
| 5114 | correct_messages = [ |
| 5115 | 'initial commit', 'add content from fixture', |
| 5116 | 'A-1', 'C-1'] |
| 5117 | # Ensure the right commits are in the history for this ref |
| 5118 | self.assertEqual(repo_messages, correct_messages) |
| 5119 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5120 | self.executor_server.hold_jobs_in_build = False |
| 5121 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5122 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5123 | |
| 5124 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5125 | class TestSemaphore(ZuulTestCase): |
| 5126 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5127 | |
| 5128 | def test_semaphore_one(self): |
| 5129 | "Test semaphores with max=1 (mutex)" |
| 5130 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5131 | |
| 5132 | self.executor_server.hold_jobs_in_build = True |
| 5133 | |
| 5134 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5135 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5136 | self.assertFalse('test-semaphore' in |
| 5137 | tenant.semaphore_handler.semaphores) |
| 5138 | |
| 5139 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5140 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5141 | self.waitUntilSettled() |
| 5142 | |
| 5143 | self.assertEqual(len(self.builds), 3) |
| 5144 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5145 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5146 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5147 | |
| 5148 | self.executor_server.release('semaphore-one-test1') |
| 5149 | self.waitUntilSettled() |
| 5150 | |
| 5151 | self.assertEqual(len(self.builds), 3) |
| 5152 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5153 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5154 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5155 | self.assertTrue('test-semaphore' in |
| 5156 | tenant.semaphore_handler.semaphores) |
| 5157 | |
| 5158 | self.executor_server.release('semaphore-one-test2') |
| 5159 | self.waitUntilSettled() |
| 5160 | |
| 5161 | self.assertEqual(len(self.builds), 3) |
| 5162 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5163 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5164 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5165 | self.assertTrue('test-semaphore' in |
| 5166 | tenant.semaphore_handler.semaphores) |
| 5167 | |
| 5168 | self.executor_server.release('semaphore-one-test1') |
| 5169 | self.waitUntilSettled() |
| 5170 | |
| 5171 | self.assertEqual(len(self.builds), 3) |
| 5172 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5173 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5174 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5175 | self.assertTrue('test-semaphore' in |
| 5176 | tenant.semaphore_handler.semaphores) |
| 5177 | |
| 5178 | self.executor_server.release('semaphore-one-test2') |
| 5179 | self.waitUntilSettled() |
| 5180 | |
| 5181 | self.assertEqual(len(self.builds), 2) |
| 5182 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5183 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5184 | self.assertFalse('test-semaphore' in |
| 5185 | tenant.semaphore_handler.semaphores) |
| 5186 | |
| 5187 | self.executor_server.hold_jobs_in_build = False |
| 5188 | self.executor_server.release() |
| 5189 | |
| 5190 | self.waitUntilSettled() |
| 5191 | self.assertEqual(len(self.builds), 0) |
| 5192 | |
| 5193 | self.assertEqual(A.reported, 1) |
| 5194 | self.assertEqual(B.reported, 1) |
| 5195 | self.assertFalse('test-semaphore' in |
| 5196 | tenant.semaphore_handler.semaphores) |
| 5197 | |
| 5198 | def test_semaphore_two(self): |
| 5199 | "Test semaphores with max>1" |
| 5200 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5201 | |
| 5202 | self.executor_server.hold_jobs_in_build = True |
| 5203 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5204 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5205 | self.assertFalse('test-semaphore-two' in |
| 5206 | tenant.semaphore_handler.semaphores) |
| 5207 | |
| 5208 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5209 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5210 | self.waitUntilSettled() |
| 5211 | |
| 5212 | self.assertEqual(len(self.builds), 4) |
| 5213 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5214 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5215 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5216 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5217 | self.assertTrue('test-semaphore-two' in |
| 5218 | tenant.semaphore_handler.semaphores) |
| 5219 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5220 | 'test-semaphore-two', [])), 2) |
| 5221 | |
| 5222 | self.executor_server.release('semaphore-two-test1') |
| 5223 | self.waitUntilSettled() |
| 5224 | |
| 5225 | self.assertEqual(len(self.builds), 4) |
| 5226 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5227 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5228 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5229 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5230 | self.assertTrue('test-semaphore-two' in |
| 5231 | tenant.semaphore_handler.semaphores) |
| 5232 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5233 | 'test-semaphore-two', [])), 2) |
| 5234 | |
| 5235 | self.executor_server.release('semaphore-two-test2') |
| 5236 | self.waitUntilSettled() |
| 5237 | |
| 5238 | self.assertEqual(len(self.builds), 4) |
| 5239 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5240 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5241 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5242 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5243 | self.assertTrue('test-semaphore-two' in |
| 5244 | tenant.semaphore_handler.semaphores) |
| 5245 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5246 | 'test-semaphore-two', [])), 2) |
| 5247 | |
| 5248 | self.executor_server.release('semaphore-two-test1') |
| 5249 | self.waitUntilSettled() |
| 5250 | |
| 5251 | self.assertEqual(len(self.builds), 3) |
| 5252 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5253 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5254 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5255 | self.assertTrue('test-semaphore-two' in |
| 5256 | tenant.semaphore_handler.semaphores) |
| 5257 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5258 | 'test-semaphore-two', [])), 1) |
| 5259 | |
| 5260 | self.executor_server.release('semaphore-two-test2') |
| 5261 | self.waitUntilSettled() |
| 5262 | |
| 5263 | self.assertEqual(len(self.builds), 2) |
| 5264 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5265 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5266 | self.assertFalse('test-semaphore-two' in |
| 5267 | tenant.semaphore_handler.semaphores) |
| 5268 | |
| 5269 | self.executor_server.hold_jobs_in_build = False |
| 5270 | self.executor_server.release() |
| 5271 | |
| 5272 | self.waitUntilSettled() |
| 5273 | self.assertEqual(len(self.builds), 0) |
| 5274 | |
| 5275 | self.assertEqual(A.reported, 1) |
| 5276 | self.assertEqual(B.reported, 1) |
| 5277 | |
| 5278 | def test_semaphore_abandon(self): |
| 5279 | "Test abandon with job semaphores" |
| 5280 | self.executor_server.hold_jobs_in_build = True |
| 5281 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5282 | check_pipeline = tenant.layout.pipelines['check'] |
| 5283 | |
| 5284 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5285 | self.assertFalse('test-semaphore' in |
| 5286 | tenant.semaphore_handler.semaphores) |
| 5287 | |
| 5288 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5289 | self.waitUntilSettled() |
| 5290 | |
| 5291 | self.assertTrue('test-semaphore' in |
| 5292 | tenant.semaphore_handler.semaphores) |
| 5293 | |
| 5294 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5295 | self.waitUntilSettled() |
| 5296 | |
| 5297 | # The check pipeline should be empty |
| 5298 | items = check_pipeline.getAllItems() |
| 5299 | self.assertEqual(len(items), 0) |
| 5300 | |
| 5301 | # The semaphore should be released |
| 5302 | self.assertFalse('test-semaphore' in |
| 5303 | tenant.semaphore_handler.semaphores) |
| 5304 | |
| 5305 | self.executor_server.hold_jobs_in_build = False |
| 5306 | self.executor_server.release() |
| 5307 | self.waitUntilSettled() |
| 5308 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5309 | def test_semaphore_new_patchset(self): |
| 5310 | "Test new patchset with job semaphores" |
| 5311 | self.executor_server.hold_jobs_in_build = True |
| 5312 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5313 | check_pipeline = tenant.layout.pipelines['check'] |
| 5314 | |
| 5315 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5316 | self.assertFalse('test-semaphore' in |
| 5317 | tenant.semaphore_handler.semaphores) |
| 5318 | |
| 5319 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5320 | self.waitUntilSettled() |
| 5321 | |
| 5322 | self.assertTrue('test-semaphore' in |
| 5323 | tenant.semaphore_handler.semaphores) |
| 5324 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5325 | self.assertEqual(len(semaphore), 1) |
| 5326 | |
| 5327 | A.addPatchset() |
| 5328 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5329 | self.waitUntilSettled() |
| 5330 | |
| 5331 | self.assertTrue('test-semaphore' in |
| 5332 | tenant.semaphore_handler.semaphores) |
| 5333 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5334 | self.assertEqual(len(semaphore), 1) |
| 5335 | |
| 5336 | items = check_pipeline.getAllItems() |
| 5337 | self.assertEqual(items[0].change.number, '1') |
| 5338 | self.assertEqual(items[0].change.patchset, '2') |
| 5339 | self.assertTrue(items[0].live) |
| 5340 | |
| 5341 | self.executor_server.hold_jobs_in_build = False |
| 5342 | self.executor_server.release() |
| 5343 | self.waitUntilSettled() |
| 5344 | |
| 5345 | # The semaphore should be released |
| 5346 | self.assertFalse('test-semaphore' in |
| 5347 | tenant.semaphore_handler.semaphores) |
| 5348 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5349 | def test_semaphore_reconfigure(self): |
| 5350 | "Test reconfigure with job semaphores" |
| 5351 | self.executor_server.hold_jobs_in_build = True |
| 5352 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5353 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5354 | self.assertFalse('test-semaphore' in |
| 5355 | tenant.semaphore_handler.semaphores) |
| 5356 | |
| 5357 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5358 | self.waitUntilSettled() |
| 5359 | |
| 5360 | self.assertTrue('test-semaphore' in |
| 5361 | tenant.semaphore_handler.semaphores) |
| 5362 | |
| 5363 | # reconfigure without layout change |
| 5364 | self.sched.reconfigure(self.config) |
| 5365 | self.waitUntilSettled() |
| 5366 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5367 | |
| 5368 | # semaphore still must be held |
| 5369 | self.assertTrue('test-semaphore' in |
| 5370 | tenant.semaphore_handler.semaphores) |
| 5371 | |
| 5372 | self.commitConfigUpdate( |
| 5373 | 'common-config', |
| 5374 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5375 | self.sched.reconfigure(self.config) |
| 5376 | self.waitUntilSettled() |
| 5377 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5378 | |
| 5379 | self.executor_server.release('project-test1') |
| 5380 | self.waitUntilSettled() |
| 5381 | |
| 5382 | # There should be no builds anymore |
| 5383 | self.assertEqual(len(self.builds), 0) |
| 5384 | |
| 5385 | # The semaphore should be released |
| 5386 | self.assertFalse('test-semaphore' in |
| 5387 | tenant.semaphore_handler.semaphores) |
| 5388 | |
| 5389 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5390 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5391 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5392 | |
| 5393 | def test_semaphore_tenant_isolation(self): |
| 5394 | "Test semaphores in multiple tenants" |
| 5395 | |
| 5396 | self.waitUntilSettled() |
| 5397 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5398 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5399 | |
| 5400 | self.executor_server.hold_jobs_in_build = True |
| 5401 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5402 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5403 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5404 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5405 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5406 | self.assertFalse('test-semaphore' in |
| 5407 | tenant_one.semaphore_handler.semaphores) |
| 5408 | self.assertFalse('test-semaphore' in |
| 5409 | tenant_two.semaphore_handler.semaphores) |
| 5410 | |
| 5411 | # add patches to project1 of tenant-one |
| 5412 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5413 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5414 | self.waitUntilSettled() |
| 5415 | |
| 5416 | # one build of project1-test1 must run |
| 5417 | # semaphore of tenant-one must be acquired once |
| 5418 | # semaphore of tenant-two must not be acquired |
| 5419 | self.assertEqual(len(self.builds), 1) |
| 5420 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5421 | self.assertTrue('test-semaphore' in |
| 5422 | tenant_one.semaphore_handler.semaphores) |
| 5423 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5424 | 'test-semaphore', [])), 1) |
| 5425 | self.assertFalse('test-semaphore' in |
| 5426 | tenant_two.semaphore_handler.semaphores) |
| 5427 | |
| 5428 | # add patches to project2 of tenant-two |
| 5429 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5430 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5431 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5432 | self.waitUntilSettled() |
| 5433 | |
| 5434 | # one build of project1-test1 must run |
| 5435 | # two builds of project2-test1 must run |
| 5436 | # semaphore of tenant-one must be acquired once |
| 5437 | # semaphore of tenant-two must be acquired twice |
| 5438 | self.assertEqual(len(self.builds), 3) |
| 5439 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5440 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5441 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5442 | self.assertTrue('test-semaphore' in |
| 5443 | tenant_one.semaphore_handler.semaphores) |
| 5444 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5445 | 'test-semaphore', [])), 1) |
| 5446 | self.assertTrue('test-semaphore' in |
| 5447 | tenant_two.semaphore_handler.semaphores) |
| 5448 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5449 | 'test-semaphore', [])), 2) |
| 5450 | |
| 5451 | self.executor_server.release('project1-test1') |
| 5452 | self.waitUntilSettled() |
| 5453 | |
| 5454 | # one build of project1-test1 must run |
| 5455 | # two builds of project2-test1 must run |
| 5456 | # semaphore of tenant-one must be acquired once |
| 5457 | # semaphore of tenant-two must be acquired twice |
| 5458 | self.assertEqual(len(self.builds), 3) |
| 5459 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5460 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5461 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5462 | self.assertTrue('test-semaphore' in |
| 5463 | tenant_one.semaphore_handler.semaphores) |
| 5464 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5465 | 'test-semaphore', [])), 1) |
| 5466 | self.assertTrue('test-semaphore' in |
| 5467 | tenant_two.semaphore_handler.semaphores) |
| 5468 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5469 | 'test-semaphore', [])), 2) |
| 5470 | |
| 5471 | self.executor_server.release('project2-test1') |
| 5472 | self.waitUntilSettled() |
| 5473 | |
| 5474 | # one build of project1-test1 must run |
| 5475 | # one build of project2-test1 must run |
| 5476 | # semaphore of tenant-one must be acquired once |
| 5477 | # semaphore of tenant-two must be acquired once |
| 5478 | self.assertEqual(len(self.builds), 2) |
| 5479 | self.assertTrue('test-semaphore' in |
| 5480 | tenant_one.semaphore_handler.semaphores) |
| 5481 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5482 | 'test-semaphore', [])), 1) |
| 5483 | self.assertTrue('test-semaphore' in |
| 5484 | tenant_two.semaphore_handler.semaphores) |
| 5485 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5486 | 'test-semaphore', [])), 1) |
| 5487 | |
| 5488 | self.executor_server.hold_jobs_in_build = False |
| 5489 | self.executor_server.release() |
| 5490 | |
| 5491 | self.waitUntilSettled() |
| 5492 | |
| 5493 | # no build must run |
| 5494 | # semaphore of tenant-one must not be acquired |
| 5495 | # semaphore of tenant-two must not be acquired |
| 5496 | self.assertEqual(len(self.builds), 0) |
| 5497 | self.assertFalse('test-semaphore' in |
| 5498 | tenant_one.semaphore_handler.semaphores) |
| 5499 | self.assertFalse('test-semaphore' in |
| 5500 | tenant_two.semaphore_handler.semaphores) |
| 5501 | |
| 5502 | self.assertEqual(A.reported, 1) |
| 5503 | self.assertEqual(B.reported, 1) |
| 5504 | |
| 5505 | |
Tobias Henkel | e9a2251 | 2017-12-22 08:36:12 +0100 | [diff] [blame] | 5506 | class TestImplicitProject(ZuulTestCase): |
| 5507 | tenant_config_file = 'config/implicit-project/main.yaml' |
| 5508 | |
| 5509 | def test_implicit_project(self): |
| 5510 | # config project should work with implicit project name |
| 5511 | A = self.fake_gerrit.addFakeChange('common-config', 'master', 'A') |
| 5512 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5513 | |
| 5514 | # untrusted project should work with implicit project name |
| 5515 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5516 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5517 | |
| 5518 | self.waitUntilSettled() |
| 5519 | |
| 5520 | self.assertEqual(A.data['status'], 'NEW') |
| 5521 | self.assertEqual(A.reported, 1) |
| 5522 | self.assertEqual(B.data['status'], 'NEW') |
| 5523 | self.assertEqual(B.reported, 1) |
| 5524 | self.assertHistory([ |
| 5525 | dict(name='test-common', result='SUCCESS', changes='1,1'), |
| 5526 | dict(name='test-common', result='SUCCESS', changes='2,1'), |
| 5527 | dict(name='test-project', result='SUCCESS', changes='2,1'), |
| 5528 | ], ordered=False) |
| 5529 | |
| 5530 | # now test adding a further project in repo |
| 5531 | in_repo_conf = textwrap.dedent( |
| 5532 | """ |
| 5533 | - job: |
| 5534 | name: test-project |
| 5535 | run: playbooks/test-project.yaml |
| 5536 | - job: |
| 5537 | name: test2-project |
| 5538 | run: playbooks/test-project.yaml |
| 5539 | |
| 5540 | - project: |
| 5541 | check: |
| 5542 | jobs: |
| 5543 | - test-project |
| 5544 | gate: |
| 5545 | jobs: |
| 5546 | - test-project |
| 5547 | |
| 5548 | - project: |
| 5549 | check: |
| 5550 | jobs: |
| 5551 | - test2-project |
| 5552 | gate: |
| 5553 | jobs: |
| 5554 | - test2-project |
| 5555 | |
| 5556 | """) |
| 5557 | file_dict = {'.zuul.yaml': in_repo_conf} |
| 5558 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5559 | files=file_dict) |
| 5560 | C.addApproval('Code-Review', 2) |
| 5561 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 5562 | self.waitUntilSettled() |
| 5563 | |
| 5564 | # change C must be merged |
| 5565 | self.assertEqual(C.data['status'], 'MERGED') |
| 5566 | self.assertEqual(C.reported, 2) |
| 5567 | self.assertHistory([ |
| 5568 | dict(name='test-common', result='SUCCESS', changes='1,1'), |
| 5569 | dict(name='test-common', result='SUCCESS', changes='2,1'), |
| 5570 | dict(name='test-project', result='SUCCESS', changes='2,1'), |
| 5571 | dict(name='test-common', result='SUCCESS', changes='3,1'), |
| 5572 | dict(name='test-project', result='SUCCESS', changes='3,1'), |
| 5573 | dict(name='test2-project', result='SUCCESS', changes='3,1'), |
| 5574 | ], ordered=False) |
| 5575 | |
| 5576 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5577 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5578 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5579 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5580 | |
| 5581 | def test_semaphore_in_repo(self): |
| 5582 | "Test semaphores in repo config" |
| 5583 | |
| 5584 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5585 | # max value should not be evaluated dynamically but must be updated |
| 5586 | # after the change lands. |
| 5587 | |
| 5588 | self.waitUntilSettled() |
| 5589 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5590 | |
| 5591 | in_repo_conf = textwrap.dedent( |
| 5592 | """ |
| 5593 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5594 | name: project-test1 |
| 5595 | |
| 5596 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5597 | name: project-test2 |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 5598 | run: playbooks/project-test2.yaml |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5599 | semaphore: test-semaphore |
| 5600 | |
| 5601 | - project: |
| 5602 | name: org/project |
| 5603 | tenant-one-gate: |
| 5604 | jobs: |
| 5605 | - project-test2 |
| 5606 | |
| 5607 | # the max value in dynamic layout must be ignored |
| 5608 | - semaphore: |
| 5609 | name: test-semaphore |
| 5610 | max: 2 |
| 5611 | """) |
| 5612 | |
| 5613 | in_repo_playbook = textwrap.dedent( |
| 5614 | """ |
| 5615 | - hosts: all |
| 5616 | tasks: [] |
| 5617 | """) |
| 5618 | |
| 5619 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5620 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5621 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5622 | files=file_dict) |
| 5623 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5624 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5625 | B.setDependsOn(A, 1) |
| 5626 | C.setDependsOn(A, 1) |
| 5627 | |
| 5628 | self.executor_server.hold_jobs_in_build = True |
| 5629 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5630 | A.addApproval('Code-Review', 2) |
| 5631 | B.addApproval('Code-Review', 2) |
| 5632 | C.addApproval('Code-Review', 2) |
| 5633 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5634 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5635 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5636 | self.waitUntilSettled() |
| 5637 | |
| 5638 | # check that the layout in a queue item still has max value of 1 |
| 5639 | # for test-semaphore |
| 5640 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5641 | queue = None |
| 5642 | for queue_candidate in pipeline.queues: |
| 5643 | if queue_candidate.name == 'org/project': |
| 5644 | queue = queue_candidate |
| 5645 | break |
| 5646 | queue_item = queue.queue[0] |
James E. Blair | 29a24fd | 2017-10-02 15:04:56 -0700 | [diff] [blame] | 5647 | item_dynamic_layout = queue_item.layout |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5648 | dynamic_test_semaphore = \ |
| 5649 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5650 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5651 | |
| 5652 | # one build must be in queue, one semaphores acquired |
| 5653 | self.assertEqual(len(self.builds), 1) |
| 5654 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5655 | self.assertTrue('test-semaphore' in |
| 5656 | tenant.semaphore_handler.semaphores) |
| 5657 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5658 | 'test-semaphore', [])), 1) |
| 5659 | |
| 5660 | self.executor_server.release('project-test2') |
| 5661 | self.waitUntilSettled() |
| 5662 | |
| 5663 | # change A must be merged |
| 5664 | self.assertEqual(A.data['status'], 'MERGED') |
| 5665 | self.assertEqual(A.reported, 2) |
| 5666 | |
| 5667 | # send change-merged event as the gerrit mock doesn't send it |
| 5668 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5669 | self.waitUntilSettled() |
| 5670 | |
| 5671 | # now that change A was merged, the new semaphore max must be effective |
| 5672 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5673 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5674 | |
| 5675 | # two builds must be in queue, two semaphores acquired |
| 5676 | self.assertEqual(len(self.builds), 2) |
| 5677 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5678 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5679 | self.assertTrue('test-semaphore' in |
| 5680 | tenant.semaphore_handler.semaphores) |
| 5681 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5682 | 'test-semaphore', [])), 2) |
| 5683 | |
| 5684 | self.executor_server.release('project-test2') |
| 5685 | self.waitUntilSettled() |
| 5686 | |
| 5687 | self.assertEqual(len(self.builds), 0) |
| 5688 | self.assertFalse('test-semaphore' in |
| 5689 | tenant.semaphore_handler.semaphores) |
| 5690 | |
| 5691 | self.executor_server.hold_jobs_in_build = False |
| 5692 | self.executor_server.release() |
| 5693 | |
| 5694 | self.waitUntilSettled() |
| 5695 | self.assertEqual(len(self.builds), 0) |
| 5696 | |
| 5697 | self.assertEqual(A.reported, 2) |
| 5698 | self.assertEqual(B.reported, 2) |
| 5699 | self.assertEqual(C.reported, 2) |
David Shrewsbury | f6dc176 | 2017-10-02 13:34:37 -0400 | [diff] [blame] | 5700 | |
| 5701 | |
| 5702 | class TestSchedulerBranchMatcher(ZuulTestCase): |
| 5703 | |
| 5704 | @simple_layout('layouts/matcher-test.yaml') |
| 5705 | def test_job_branch_ignored(self): |
| 5706 | ''' |
| 5707 | Test that branch matching logic works. |
| 5708 | |
| 5709 | The 'ignore-branch' job has a branch matcher that is supposed to |
| 5710 | match every branch except for the 'featureA' branch, so it should |
| 5711 | not be run on a change to that branch. |
| 5712 | ''' |
| 5713 | self.create_branch('org/project', 'featureA') |
| 5714 | A = self.fake_gerrit.addFakeChange('org/project', 'featureA', 'A') |
| 5715 | A.addApproval('Code-Review', 2) |
| 5716 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5717 | self.waitUntilSettled() |
| 5718 | self.printHistory() |
| 5719 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5720 | 'SUCCESS') |
| 5721 | self.assertJobNotInHistory('ignore-branch') |
| 5722 | self.assertEqual(A.data['status'], 'MERGED') |
| 5723 | self.assertEqual(A.reported, 2, |
| 5724 | "A should report start and success") |
| 5725 | self.assertIn('gate', A.messages[1], |
| 5726 | "A should transit gate") |