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" |
| 50 | |
| 51 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 52 | A.addApproval('Code-Review', 2) |
| 53 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 54 | self.waitUntilSettled() |
| 55 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 56 | 'SUCCESS') |
| 57 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 58 | 'SUCCESS') |
| 59 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 60 | 'SUCCESS') |
| 61 | self.assertEqual(A.data['status'], 'MERGED') |
| 62 | self.assertEqual(A.reported, 2) |
| 63 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 64 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 65 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 66 | 'label1') |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 67 | |
| 68 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 69 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 70 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 71 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 72 | def test_jobs_executed(self): |
| 73 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 74 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 75 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 76 | A.addApproval('Code-Review', 2) |
| 77 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 78 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 79 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 80 | 'SUCCESS') |
| 81 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 82 | 'SUCCESS') |
| 83 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 84 | 'SUCCESS') |
| 85 | self.assertEqual(A.data['status'], 'MERGED') |
| 86 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 87 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 88 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 89 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 90 | 'label1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 91 | |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 92 | for stat in self.statsd.stats: |
| 93 | k, v = stat.decode('utf-8').split(':') |
| 94 | self.log.debug('stat %s:%s', k, v) |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 95 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 96 | # Per-driver |
| 97 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 98 | # Per-driver per-connection |
| 99 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 100 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 101 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 102 | 'zuul.tenant.tenant-one.pipeline.gate.current_changes', |
| 103 | value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 104 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 105 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 106 | 'org_project.master.job.project-merge.SUCCESS', kind='ms') |
| 107 | self.assertReportedStat( |
| 108 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 109 | 'org_project.master.job.project-merge.SUCCESS', value='1|c') |
| 110 | self.assertReportedStat( |
| 111 | 'zuul.tenant.tenant-one.pipeline.gate.resident_time', kind='ms') |
| 112 | self.assertReportedStat( |
| 113 | 'zuul.tenant.tenant-one.pipeline.gate.total_changes', value='1|c') |
| 114 | self.assertReportedStat( |
| 115 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 116 | 'org_project.master.resident_time', kind='ms') |
| 117 | self.assertReportedStat( |
| 118 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 119 | 'org_project.master.total_changes', value='1|c') |
James E. Blair | faf8198 | 2017-10-10 15:42:26 -0700 | [diff] [blame] | 120 | exec_key = 'zuul.executor.%s' % self.executor_server.hostname |
| 121 | self.assertReportedStat(exec_key + '.builds', value='1|c') |
James E. Blair | 4f1731b | 2017-10-10 18:11:42 -0700 | [diff] [blame] | 122 | self.assertReportedStat('zuul.nodepool.requested', value='1|c') |
| 123 | self.assertReportedStat('zuul.nodepool.requested.label.label1', |
| 124 | value='1|c') |
| 125 | self.assertReportedStat('zuul.nodepool.fulfilled.label.label1', |
| 126 | value='1|c') |
| 127 | self.assertReportedStat('zuul.nodepool.requested.size.1', value='1|c') |
| 128 | self.assertReportedStat('zuul.nodepool.fulfilled.size.1', value='1|c') |
| 129 | self.assertReportedStat('zuul.nodepool.current_requests', value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 130 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 131 | for build in self.history: |
| 132 | self.assertTrue(build.parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 133 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 134 | def test_initial_pipeline_gauges(self): |
| 135 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 136 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 137 | value='0|g') |
| 138 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 139 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 140 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 141 | def test_job_branch(self): |
| 142 | "Test the correct variant of a job runs on a branch" |
| 143 | self.create_branch('org/project', 'stable') |
| 144 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 145 | A.addApproval('Code-Review', 2) |
| 146 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 147 | self.waitUntilSettled() |
| 148 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 149 | 'SUCCESS') |
| 150 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 151 | 'SUCCESS') |
| 152 | self.assertEqual(A.data['status'], 'MERGED') |
| 153 | self.assertEqual(A.reported, 2, |
| 154 | "A should report start and success") |
| 155 | self.assertIn('gate', A.messages[1], |
| 156 | "A should transit gate") |
| 157 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 158 | 'label2') |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 159 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 160 | def test_parallel_changes(self): |
| 161 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 162 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 163 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 164 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 165 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 166 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 167 | A.addApproval('Code-Review', 2) |
| 168 | B.addApproval('Code-Review', 2) |
| 169 | C.addApproval('Code-Review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 170 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 171 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 172 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 173 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 174 | |
| 175 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 176 | self.assertEqual(len(self.builds), 1) |
| 177 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 178 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 179 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 180 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 181 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 182 | self.assertEqual(len(self.builds), 3) |
| 183 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 184 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 185 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 186 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 187 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 188 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 189 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 190 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 191 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 192 | self.assertEqual(len(self.builds), 5) |
| 193 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 194 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 195 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 196 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 197 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 198 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 199 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 200 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 201 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 202 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 203 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 204 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 205 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 206 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 207 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 208 | self.assertEqual(len(self.builds), 6) |
| 209 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 210 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 211 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 212 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 213 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 214 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 215 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 216 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 217 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 218 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 219 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 220 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 221 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 222 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 223 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 224 | self.executor_server.hold_jobs_in_build = False |
| 225 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 226 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 227 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 228 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 229 | self.assertEqual(len(self.history), 9) |
| 230 | self.assertEqual(A.data['status'], 'MERGED') |
| 231 | self.assertEqual(B.data['status'], 'MERGED') |
| 232 | self.assertEqual(C.data['status'], 'MERGED') |
| 233 | self.assertEqual(A.reported, 2) |
| 234 | self.assertEqual(B.reported, 2) |
| 235 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 236 | |
| 237 | def test_failed_changes(self): |
| 238 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 239 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 240 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 241 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 242 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 243 | A.addApproval('Code-Review', 2) |
| 244 | B.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 245 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 246 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 247 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 248 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 249 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 250 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 251 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 252 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 253 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 254 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 255 | # A/project-merge is complete |
| 256 | self.assertBuilds([ |
| 257 | dict(name='project-test1', changes='1,1'), |
| 258 | dict(name='project-test2', changes='1,1'), |
| 259 | dict(name='project-merge', changes='1,1 2,1'), |
| 260 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 261 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 262 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 263 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 264 | # A/project-merge is complete |
| 265 | # B/project-merge is complete |
| 266 | self.assertBuilds([ |
| 267 | dict(name='project-test1', changes='1,1'), |
| 268 | dict(name='project-test2', changes='1,1'), |
| 269 | dict(name='project-test1', changes='1,1 2,1'), |
| 270 | dict(name='project-test2', changes='1,1 2,1'), |
| 271 | ]) |
| 272 | |
| 273 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 274 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 275 | self.builds[0].release() |
| 276 | self.waitUntilSettled() |
| 277 | |
| 278 | self.orderedRelease() |
| 279 | self.assertHistory([ |
| 280 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 281 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 282 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 283 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 284 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 285 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 286 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 287 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 288 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 289 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 290 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 291 | self.assertEqual(A.data['status'], 'NEW') |
| 292 | self.assertEqual(B.data['status'], 'MERGED') |
| 293 | self.assertEqual(A.reported, 2) |
| 294 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 295 | |
| 296 | def test_independent_queues(self): |
| 297 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 298 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 299 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 300 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 301 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 302 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 303 | A.addApproval('Code-Review', 2) |
| 304 | B.addApproval('Code-Review', 2) |
| 305 | C.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 306 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 307 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 308 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 309 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 310 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 311 | self.waitUntilSettled() |
| 312 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 313 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 314 | self.waitUntilSettled() |
| 315 | |
| 316 | # 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] | 317 | self.assertBuilds([ |
| 318 | dict(name='project-merge', changes='1,1'), |
| 319 | dict(name='project-merge', changes='2,1'), |
| 320 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 321 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 322 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 323 | self.builds[0].release() |
| 324 | self.waitUntilSettled() |
| 325 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 326 | self.waitUntilSettled() |
| 327 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 328 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 329 | self.waitUntilSettled() |
| 330 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 331 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 332 | self.assertBuilds([ |
| 333 | dict(name='project-test1', changes='1,1'), |
| 334 | dict(name='project-test2', changes='1,1'), |
| 335 | dict(name='project-test1', changes='2,1'), |
| 336 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 337 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 338 | dict(name='project-test1', changes='2,1 3,1'), |
| 339 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 340 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 341 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 342 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 343 | self.orderedRelease() |
| 344 | self.assertHistory([ |
| 345 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 346 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 347 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 348 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 349 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 350 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 351 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 352 | dict( |
| 353 | name='project1-project2-integration', |
| 354 | result='SUCCESS', |
| 355 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 356 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 357 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 358 | dict(name='project1-project2-integration', |
| 359 | result='SUCCESS', |
| 360 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 361 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 362 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 363 | self.assertEqual(A.data['status'], 'MERGED') |
| 364 | self.assertEqual(B.data['status'], 'MERGED') |
| 365 | self.assertEqual(C.data['status'], 'MERGED') |
| 366 | self.assertEqual(A.reported, 2) |
| 367 | self.assertEqual(B.reported, 2) |
| 368 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 369 | |
| 370 | def test_failed_change_at_head(self): |
| 371 | "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] | 372 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 373 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 374 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 375 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 376 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 377 | A.addApproval('Code-Review', 2) |
| 378 | B.addApproval('Code-Review', 2) |
| 379 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 380 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 381 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 382 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 383 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 384 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 385 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 386 | |
| 387 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 388 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 389 | self.assertBuilds([ |
| 390 | dict(name='project-merge', changes='1,1'), |
| 391 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 392 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 393 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 394 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 395 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 396 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 397 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 398 | self.waitUntilSettled() |
| 399 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 400 | self.assertBuilds([ |
| 401 | dict(name='project-test1', changes='1,1'), |
| 402 | dict(name='project-test2', changes='1,1'), |
| 403 | dict(name='project-test1', changes='1,1 2,1'), |
| 404 | dict(name='project-test2', changes='1,1 2,1'), |
| 405 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 406 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 407 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 408 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 409 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 410 | self.waitUntilSettled() |
| 411 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 412 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 413 | self.assertBuilds([ |
| 414 | dict(name='project-test2', changes='1,1'), |
| 415 | dict(name='project-merge', changes='2,1'), |
| 416 | ]) |
| 417 | # Unordered history comparison because the aborts can finish |
| 418 | # in any order. |
| 419 | self.assertHistory([ |
| 420 | dict(name='project-merge', result='SUCCESS', |
| 421 | changes='1,1'), |
| 422 | dict(name='project-merge', result='SUCCESS', |
| 423 | changes='1,1 2,1'), |
| 424 | dict(name='project-merge', result='SUCCESS', |
| 425 | changes='1,1 2,1 3,1'), |
| 426 | dict(name='project-test1', result='FAILURE', |
| 427 | changes='1,1'), |
| 428 | dict(name='project-test1', result='ABORTED', |
| 429 | changes='1,1 2,1'), |
| 430 | dict(name='project-test2', result='ABORTED', |
| 431 | changes='1,1 2,1'), |
| 432 | dict(name='project-test1', result='ABORTED', |
| 433 | changes='1,1 2,1 3,1'), |
| 434 | dict(name='project-test2', result='ABORTED', |
| 435 | changes='1,1 2,1 3,1'), |
| 436 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 437 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 438 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 439 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 440 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 441 | self.waitUntilSettled() |
| 442 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 443 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 444 | self.assertBuilds([]) |
| 445 | self.assertHistory([ |
| 446 | dict(name='project-merge', result='SUCCESS', |
| 447 | changes='1,1'), |
| 448 | dict(name='project-merge', result='SUCCESS', |
| 449 | changes='1,1 2,1'), |
| 450 | dict(name='project-merge', result='SUCCESS', |
| 451 | changes='1,1 2,1 3,1'), |
| 452 | dict(name='project-test1', result='FAILURE', |
| 453 | changes='1,1'), |
| 454 | dict(name='project-test1', result='ABORTED', |
| 455 | changes='1,1 2,1'), |
| 456 | dict(name='project-test2', result='ABORTED', |
| 457 | changes='1,1 2,1'), |
| 458 | dict(name='project-test1', result='ABORTED', |
| 459 | changes='1,1 2,1 3,1'), |
| 460 | dict(name='project-test2', result='ABORTED', |
| 461 | changes='1,1 2,1 3,1'), |
| 462 | dict(name='project-merge', result='SUCCESS', |
| 463 | changes='2,1'), |
| 464 | dict(name='project-merge', result='SUCCESS', |
| 465 | changes='2,1 3,1'), |
| 466 | dict(name='project-test2', result='SUCCESS', |
| 467 | changes='1,1'), |
| 468 | dict(name='project-test1', result='SUCCESS', |
| 469 | changes='2,1'), |
| 470 | dict(name='project-test2', result='SUCCESS', |
| 471 | changes='2,1'), |
| 472 | dict(name='project-test1', result='SUCCESS', |
| 473 | changes='2,1 3,1'), |
| 474 | dict(name='project-test2', result='SUCCESS', |
| 475 | changes='2,1 3,1'), |
| 476 | ], ordered=False) |
| 477 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 478 | self.assertEqual(A.data['status'], 'NEW') |
| 479 | self.assertEqual(B.data['status'], 'MERGED') |
| 480 | self.assertEqual(C.data['status'], 'MERGED') |
| 481 | self.assertEqual(A.reported, 2) |
| 482 | self.assertEqual(B.reported, 2) |
| 483 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 484 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 485 | def test_failed_change_in_middle(self): |
| 486 | "Test a failed change in the middle of the queue" |
| 487 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 488 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 489 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 490 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 491 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 492 | A.addApproval('Code-Review', 2) |
| 493 | B.addApproval('Code-Review', 2) |
| 494 | C.addApproval('Code-Review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 495 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 496 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 497 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 498 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 499 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 500 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 501 | |
| 502 | self.waitUntilSettled() |
| 503 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 504 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 505 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 506 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 507 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 508 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 509 | self.waitUntilSettled() |
| 510 | |
| 511 | self.assertEqual(len(self.builds), 6) |
| 512 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 513 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 514 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 515 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 516 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 517 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 518 | |
| 519 | self.release(self.builds[2]) |
| 520 | self.waitUntilSettled() |
| 521 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 522 | # project-test1 and project-test2 for A |
| 523 | # project-test2 for B |
| 524 | # project-merge for C (without B) |
| 525 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 526 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 527 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 528 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 529 | self.waitUntilSettled() |
| 530 | |
| 531 | # project-test1 and project-test2 for A |
| 532 | # project-test2 for B |
| 533 | # project-test1 and project-test2 for C |
| 534 | self.assertEqual(len(self.builds), 5) |
| 535 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 536 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 537 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 538 | builds = items[0].current_build_set.getBuilds() |
| 539 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 540 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 541 | builds = items[1].current_build_set.getBuilds() |
| 542 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 543 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 544 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 545 | builds = items[2].current_build_set.getBuilds() |
| 546 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 547 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 548 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 549 | self.executor_server.hold_jobs_in_build = False |
| 550 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 551 | self.waitUntilSettled() |
| 552 | |
| 553 | self.assertEqual(len(self.builds), 0) |
| 554 | self.assertEqual(len(self.history), 12) |
| 555 | self.assertEqual(A.data['status'], 'MERGED') |
| 556 | self.assertEqual(B.data['status'], 'NEW') |
| 557 | self.assertEqual(C.data['status'], 'MERGED') |
| 558 | self.assertEqual(A.reported, 2) |
| 559 | self.assertEqual(B.reported, 2) |
| 560 | self.assertEqual(C.reported, 2) |
| 561 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 562 | def test_failed_change_at_head_with_queue(self): |
| 563 | "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] | 564 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 565 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 566 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 567 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 568 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 569 | A.addApproval('Code-Review', 2) |
| 570 | B.addApproval('Code-Review', 2) |
| 571 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 572 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 573 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 574 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 575 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 576 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 577 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 578 | |
| 579 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 580 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 581 | self.assertEqual(len(self.builds), 0) |
| 582 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 583 | self.assertEqual(queue[0].name, b'executor:execute') |
| 584 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 585 | self.assertEqual(job_args['job'], 'project-merge') |
| 586 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 587 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 588 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 589 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 590 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 591 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 592 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 593 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 594 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 595 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 596 | self.assertEqual(len(self.builds), 0) |
| 597 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 598 | |
| 599 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 600 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 601 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 602 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 603 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 604 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 605 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 606 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 607 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 608 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 609 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 610 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 611 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 612 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 613 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 614 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 615 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 616 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 617 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 618 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 619 | self.waitUntilSettled() |
| 620 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 621 | self.assertEqual(len(self.builds), 0) |
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(queue), 2) # project-test2, project-merge for B |
| 624 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 625 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 626 | self.gearman_server.hold_jobs_in_queue = False |
| 627 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 628 | self.waitUntilSettled() |
| 629 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 630 | self.assertEqual(len(self.builds), 0) |
| 631 | self.assertEqual(len(self.history), 11) |
| 632 | self.assertEqual(A.data['status'], 'NEW') |
| 633 | self.assertEqual(B.data['status'], 'MERGED') |
| 634 | self.assertEqual(C.data['status'], 'MERGED') |
| 635 | self.assertEqual(A.reported, 2) |
| 636 | self.assertEqual(B.reported, 2) |
| 637 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 638 | |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 639 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 640 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 641 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 642 | A.addApproval('Code-Review', 2) |
| 643 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 644 | self.waitUntilSettled() |
| 645 | time.sleep(2) |
| 646 | |
James E. Blair | ae0f23c | 2017-09-13 10:55:15 -0600 | [diff] [blame] | 647 | data = json.loads(self.sched.formatStatusJSON('tenant-one')) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 648 | found_job = None |
| 649 | for pipeline in data['pipelines']: |
| 650 | if pipeline['name'] != 'gate': |
| 651 | continue |
| 652 | for queue in pipeline['change_queues']: |
| 653 | for head in queue['heads']: |
| 654 | for item in head: |
| 655 | for job in item['jobs']: |
| 656 | if job['name'] == 'project-merge': |
| 657 | found_job = job |
| 658 | break |
| 659 | |
| 660 | self.assertIsNotNone(found_job) |
| 661 | if iteration == 1: |
| 662 | self.assertIsNotNone(found_job['estimated_time']) |
| 663 | self.assertIsNone(found_job['remaining_time']) |
| 664 | else: |
| 665 | self.assertIsNotNone(found_job['estimated_time']) |
| 666 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 667 | self.assertIsNotNone(found_job['remaining_time']) |
| 668 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 669 | self.executor_server.hold_jobs_in_build = False |
| 670 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 671 | self.waitUntilSettled() |
| 672 | |
| 673 | def test_time_database(self): |
| 674 | "Test the time database" |
| 675 | |
| 676 | self._test_time_database(1) |
| 677 | self._test_time_database(2) |
| 678 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 679 | def test_two_failed_changes_at_head(self): |
| 680 | "Test that changes are reparented correctly if 2 fail at head" |
| 681 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 682 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 683 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 684 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 685 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 686 | A.addApproval('Code-Review', 2) |
| 687 | B.addApproval('Code-Review', 2) |
| 688 | C.addApproval('Code-Review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 689 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 690 | self.executor_server.failJob('project-test1', A) |
| 691 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 692 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 693 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 694 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 695 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 696 | self.waitUntilSettled() |
| 697 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 698 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 699 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 700 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 701 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 702 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 703 | self.waitUntilSettled() |
| 704 | |
| 705 | self.assertEqual(len(self.builds), 6) |
| 706 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 707 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 708 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 709 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 710 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 711 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 712 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 713 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 714 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 715 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 716 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 717 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 718 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 719 | |
| 720 | # Fail change B first |
| 721 | self.release(self.builds[2]) |
| 722 | self.waitUntilSettled() |
| 723 | |
| 724 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 725 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 726 | self.waitUntilSettled() |
| 727 | |
| 728 | self.assertEqual(len(self.builds), 5) |
| 729 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 730 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 731 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 732 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 733 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 734 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 735 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 736 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 737 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 738 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 739 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 740 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 741 | |
| 742 | # Finish running all passing jobs for change A |
| 743 | self.release(self.builds[1]) |
| 744 | self.waitUntilSettled() |
| 745 | # Fail and report change A |
| 746 | self.release(self.builds[0]) |
| 747 | self.waitUntilSettled() |
| 748 | |
| 749 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 750 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 751 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 752 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 753 | self.waitUntilSettled() |
| 754 | |
| 755 | self.assertEqual(len(self.builds), 4) |
| 756 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 757 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 758 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 759 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 760 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 761 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 762 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 763 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 764 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 765 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 766 | # After A failed and B and C restarted, B should be back in |
| 767 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 768 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 769 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 770 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 771 | self.executor_server.hold_jobs_in_build = False |
| 772 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 773 | self.waitUntilSettled() |
| 774 | |
| 775 | self.assertEqual(len(self.builds), 0) |
| 776 | self.assertEqual(len(self.history), 21) |
| 777 | self.assertEqual(A.data['status'], 'NEW') |
| 778 | self.assertEqual(B.data['status'], 'NEW') |
| 779 | self.assertEqual(C.data['status'], 'MERGED') |
| 780 | self.assertEqual(A.reported, 2) |
| 781 | self.assertEqual(B.reported, 2) |
| 782 | self.assertEqual(C.reported, 2) |
| 783 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 784 | def test_patch_order(self): |
| 785 | "Test that dependent patches are tested in the right order" |
| 786 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 787 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 788 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 789 | A.addApproval('Code-Review', 2) |
| 790 | B.addApproval('Code-Review', 2) |
| 791 | C.addApproval('Code-Review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 792 | |
| 793 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 794 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 795 | M2.setMerged() |
| 796 | M1.setMerged() |
| 797 | |
| 798 | # C -> B -> A -> M1 -> M2 |
| 799 | # M2 is here to make sure it is never queried. If it is, it |
| 800 | # means zuul is walking down the entire history of merged |
| 801 | # changes. |
| 802 | |
| 803 | C.setDependsOn(B, 1) |
| 804 | B.setDependsOn(A, 1) |
| 805 | A.setDependsOn(M1, 1) |
| 806 | M1.setDependsOn(M2, 1) |
| 807 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 808 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 809 | |
| 810 | self.waitUntilSettled() |
| 811 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 812 | self.assertEqual(A.data['status'], 'NEW') |
| 813 | self.assertEqual(B.data['status'], 'NEW') |
| 814 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 815 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 816 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 817 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 818 | |
| 819 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 820 | self.assertEqual(M2.queried, 0) |
| 821 | self.assertEqual(A.data['status'], 'MERGED') |
| 822 | self.assertEqual(B.data['status'], 'MERGED') |
| 823 | self.assertEqual(C.data['status'], 'MERGED') |
| 824 | self.assertEqual(A.reported, 2) |
| 825 | self.assertEqual(B.reported, 2) |
| 826 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 827 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 828 | def test_needed_changes_enqueue(self): |
| 829 | "Test that a needed change is enqueued ahead" |
| 830 | # A Given a git tree like this, if we enqueue |
| 831 | # / \ change C, we should walk up and down the tree |
| 832 | # B G and enqueue changes in the order ABCDEFG. |
| 833 | # /|\ This is also the order that you would get if |
| 834 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 835 | # / the ordering is stable across re-enqueue events. |
| 836 | # D |
| 837 | |
| 838 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 839 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 840 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 841 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 842 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 843 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 844 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 845 | B.setDependsOn(A, 1) |
| 846 | C.setDependsOn(B, 1) |
| 847 | D.setDependsOn(C, 1) |
| 848 | E.setDependsOn(B, 1) |
| 849 | F.setDependsOn(B, 1) |
| 850 | G.setDependsOn(A, 1) |
| 851 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 852 | A.addApproval('Code-Review', 2) |
| 853 | B.addApproval('Code-Review', 2) |
| 854 | C.addApproval('Code-Review', 2) |
| 855 | D.addApproval('Code-Review', 2) |
| 856 | E.addApproval('Code-Review', 2) |
| 857 | F.addApproval('Code-Review', 2) |
| 858 | G.addApproval('Code-Review', 2) |
| 859 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 860 | |
| 861 | self.waitUntilSettled() |
| 862 | |
| 863 | self.assertEqual(A.data['status'], 'NEW') |
| 864 | self.assertEqual(B.data['status'], 'NEW') |
| 865 | self.assertEqual(C.data['status'], 'NEW') |
| 866 | self.assertEqual(D.data['status'], 'NEW') |
| 867 | self.assertEqual(E.data['status'], 'NEW') |
| 868 | self.assertEqual(F.data['status'], 'NEW') |
| 869 | self.assertEqual(G.data['status'], 'NEW') |
| 870 | |
| 871 | # We're about to add approvals to changes without adding the |
| 872 | # triggering events to Zuul, so that we can be sure that it is |
| 873 | # enqueing the changes based on dependencies, not because of |
| 874 | # triggering events. Since it will have the changes cached |
| 875 | # already (without approvals), we need to clear the cache |
| 876 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 877 | for connection in self.connections.connections.values(): |
James E. Blair | b970430 | 2017-10-11 16:42:18 -0700 | [diff] [blame] | 878 | if hasattr(connection, '_change_cache'): |
| 879 | connection._change_cache.clear() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 880 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 881 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 882 | A.addApproval('Approved', 1) |
| 883 | B.addApproval('Approved', 1) |
| 884 | D.addApproval('Approved', 1) |
| 885 | E.addApproval('Approved', 1) |
| 886 | F.addApproval('Approved', 1) |
| 887 | G.addApproval('Approved', 1) |
| 888 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 889 | |
| 890 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 891 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 892 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 893 | self.executor_server.hold_jobs_in_build = False |
| 894 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 895 | self.waitUntilSettled() |
| 896 | |
| 897 | self.assertEqual(A.data['status'], 'MERGED') |
| 898 | self.assertEqual(B.data['status'], 'MERGED') |
| 899 | self.assertEqual(C.data['status'], 'MERGED') |
| 900 | self.assertEqual(D.data['status'], 'MERGED') |
| 901 | self.assertEqual(E.data['status'], 'MERGED') |
| 902 | self.assertEqual(F.data['status'], 'MERGED') |
| 903 | self.assertEqual(G.data['status'], 'MERGED') |
| 904 | self.assertEqual(A.reported, 2) |
| 905 | self.assertEqual(B.reported, 2) |
| 906 | self.assertEqual(C.reported, 2) |
| 907 | self.assertEqual(D.reported, 2) |
| 908 | self.assertEqual(E.reported, 2) |
| 909 | self.assertEqual(F.reported, 2) |
| 910 | self.assertEqual(G.reported, 2) |
| 911 | self.assertEqual(self.history[6].changes, |
| 912 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 913 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 914 | def test_source_cache(self): |
| 915 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 916 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 917 | |
| 918 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 919 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 920 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 921 | A.addApproval('Code-Review', 2) |
| 922 | B.addApproval('Code-Review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 923 | |
| 924 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 925 | M1.setMerged() |
| 926 | |
| 927 | B.setDependsOn(A, 1) |
| 928 | A.setDependsOn(M1, 1) |
| 929 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 930 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 931 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 932 | |
| 933 | self.waitUntilSettled() |
| 934 | |
| 935 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 936 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 937 | build.release() |
| 938 | self.waitUntilSettled() |
| 939 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 940 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 941 | build.release() |
| 942 | self.waitUntilSettled() |
| 943 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 944 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 945 | self.waitUntilSettled() |
| 946 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 947 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 948 | # there should still be changes in the cache |
James E. Blair | b970430 | 2017-10-11 16:42:18 -0700 | [diff] [blame] | 949 | self.assertNotEqual(len(list(self.fake_gerrit._change_cache.keys())), |
| 950 | 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 951 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 952 | self.executor_server.hold_jobs_in_build = False |
| 953 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 954 | self.waitUntilSettled() |
| 955 | |
| 956 | self.assertEqual(A.data['status'], 'MERGED') |
| 957 | self.assertEqual(B.data['status'], 'MERGED') |
| 958 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 959 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 960 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 961 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 962 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 963 | # TODO: move to test_gerrit (this is a unit test!) |
| 964 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 965 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 966 | (trusted, project) = tenant.getProject('org/project') |
| 967 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 968 | |
| 969 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 970 | # it easier for users to create events for testing. |
| 971 | event = zuul.model.TriggerEvent() |
| 972 | event.trigger_name = 'gerrit' |
| 973 | event.change_number = '1' |
| 974 | event.patch_number = '2' |
| 975 | |
| 976 | a = source.getChange(event) |
| 977 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 978 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 979 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 980 | A.addApproval('Code-Review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 981 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 982 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 983 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 984 | A.addApproval('Approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 985 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 986 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 987 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 988 | def test_project_merge_conflict(self): |
| 989 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 990 | |
| 991 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 992 | A = self.fake_gerrit.addFakeChange('org/project', |
| 993 | 'master', 'A', |
| 994 | files={'conflict': 'foo'}) |
| 995 | B = self.fake_gerrit.addFakeChange('org/project', |
| 996 | 'master', 'B', |
| 997 | files={'conflict': 'bar'}) |
| 998 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 999 | 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1000 | A.addApproval('Code-Review', 2) |
| 1001 | B.addApproval('Code-Review', 2) |
| 1002 | C.addApproval('Code-Review', 2) |
| 1003 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1004 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1005 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1006 | self.waitUntilSettled() |
| 1007 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1008 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1009 | self.assertEqual(C.reported, 1) |
| 1010 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1011 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1012 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1013 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1014 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1015 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1016 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1017 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1018 | self.gearman_server.hold_jobs_in_queue = False |
| 1019 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1020 | self.waitUntilSettled() |
| 1021 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1022 | self.assertEqual(A.data['status'], 'MERGED') |
| 1023 | self.assertEqual(B.data['status'], 'NEW') |
| 1024 | self.assertEqual(C.data['status'], 'MERGED') |
| 1025 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1026 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1027 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1028 | |
| 1029 | self.assertHistory([ |
| 1030 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1031 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1032 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1033 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1034 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1035 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1036 | ], ordered=False) |
| 1037 | |
| 1038 | def test_delayed_merge_conflict(self): |
| 1039 | "Test that delayed check merge conflicts are handled properly" |
| 1040 | |
| 1041 | # 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] | 1042 | # the executor sucesfully merges a change based on an old |
| 1043 | # repo state (frozen by the scheduler) which would otherwise |
| 1044 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1045 | self.gearman_server.hold_jobs_in_queue = True |
| 1046 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1047 | 'master', 'A', |
| 1048 | files={'conflict': 'foo'}) |
| 1049 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1050 | 'master', 'B', |
| 1051 | files={'conflict': 'bar'}) |
| 1052 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1053 | 'master', 'C') |
| 1054 | C.setDependsOn(B, 1) |
| 1055 | |
| 1056 | # A enters the gate queue; B and C enter the check queue |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1057 | A.addApproval('Code-Review', 2) |
| 1058 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1059 | self.waitUntilSettled() |
| 1060 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1061 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1062 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1063 | self.waitUntilSettled() |
| 1064 | |
| 1065 | self.assertEqual(A.reported, 1) |
| 1066 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1067 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1068 | |
| 1069 | # A merges while B and C are queued in check |
| 1070 | # Release A project-merge |
| 1071 | queue = self.gearman_server.getQueue() |
| 1072 | self.release(queue[0]) |
| 1073 | self.waitUntilSettled() |
| 1074 | |
| 1075 | # Release A project-test* |
| 1076 | # gate has higher precedence, so A's test jobs are added in |
| 1077 | # front of the merge jobs for B and C |
| 1078 | queue = self.gearman_server.getQueue() |
| 1079 | self.release(queue[0]) |
| 1080 | self.release(queue[1]) |
| 1081 | self.waitUntilSettled() |
| 1082 | |
| 1083 | self.assertEqual(A.data['status'], 'MERGED') |
| 1084 | self.assertEqual(B.data['status'], 'NEW') |
| 1085 | self.assertEqual(C.data['status'], 'NEW') |
| 1086 | self.assertEqual(A.reported, 2) |
| 1087 | self.assertEqual(B.reported, 0) |
| 1088 | self.assertEqual(C.reported, 0) |
| 1089 | self.assertHistory([ |
| 1090 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1091 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1092 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1093 | ], ordered=False) |
| 1094 | |
| 1095 | # B and C report merge conflicts |
| 1096 | # Release B project-merge |
| 1097 | queue = self.gearman_server.getQueue() |
| 1098 | self.release(queue[0]) |
| 1099 | self.waitUntilSettled() |
| 1100 | |
| 1101 | # Release C |
| 1102 | self.gearman_server.hold_jobs_in_queue = False |
| 1103 | self.gearman_server.release() |
| 1104 | self.waitUntilSettled() |
| 1105 | |
| 1106 | self.assertEqual(A.data['status'], 'MERGED') |
| 1107 | self.assertEqual(B.data['status'], 'NEW') |
| 1108 | self.assertEqual(C.data['status'], 'NEW') |
| 1109 | self.assertEqual(A.reported, 2) |
| 1110 | self.assertEqual(B.reported, 1) |
| 1111 | self.assertEqual(C.reported, 1) |
| 1112 | |
| 1113 | self.assertHistory([ |
| 1114 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1115 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1116 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1117 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1118 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1119 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1120 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1121 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1122 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1123 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1124 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1125 | def test_post(self): |
| 1126 | "Test that post jobs run" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1127 | p = "review.example.com/org/project" |
| 1128 | upstream = self.getUpstreamRepos([p]) |
| 1129 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1130 | A.setMerged() |
| 1131 | A_commit = str(upstream[p].commit('master')) |
| 1132 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1133 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1134 | e = { |
| 1135 | "type": "ref-updated", |
| 1136 | "submitter": { |
| 1137 | "name": "User Name", |
| 1138 | }, |
| 1139 | "refUpdate": { |
| 1140 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1141 | "newRev": A_commit, |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1142 | "refName": "master", |
| 1143 | "project": "org/project", |
| 1144 | } |
| 1145 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1146 | self.fake_gerrit.addEvent(e) |
| 1147 | self.waitUntilSettled() |
| 1148 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1149 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1150 | self.assertEqual(len(self.history), 1) |
| 1151 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1152 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1153 | def test_post_ignore_deletes(self): |
| 1154 | "Test that deleting refs does not trigger post jobs" |
| 1155 | |
| 1156 | e = { |
| 1157 | "type": "ref-updated", |
| 1158 | "submitter": { |
| 1159 | "name": "User Name", |
| 1160 | }, |
| 1161 | "refUpdate": { |
| 1162 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1163 | "newRev": "0000000000000000000000000000000000000000", |
| 1164 | "refName": "master", |
| 1165 | "project": "org/project", |
| 1166 | } |
| 1167 | } |
| 1168 | self.fake_gerrit.addEvent(e) |
| 1169 | self.waitUntilSettled() |
| 1170 | |
| 1171 | job_names = [x.name for x in self.history] |
| 1172 | self.assertEqual(len(self.history), 0) |
| 1173 | self.assertNotIn('project-post', job_names) |
| 1174 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1175 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1176 | def test_post_ignore_deletes_negative(self): |
| 1177 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1178 | e = { |
| 1179 | "type": "ref-updated", |
| 1180 | "submitter": { |
| 1181 | "name": "User Name", |
| 1182 | }, |
| 1183 | "refUpdate": { |
| 1184 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1185 | "newRev": "0000000000000000000000000000000000000000", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1186 | "refName": "testbranch", |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1187 | "project": "org/project", |
| 1188 | } |
| 1189 | } |
| 1190 | self.fake_gerrit.addEvent(e) |
| 1191 | self.waitUntilSettled() |
| 1192 | |
| 1193 | job_names = [x.name for x in self.history] |
| 1194 | self.assertEqual(len(self.history), 1) |
| 1195 | self.assertIn('project-post', job_names) |
| 1196 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1197 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1198 | def test_build_configuration_branch_interaction(self): |
| 1199 | "Test that switching between branches works" |
| 1200 | self.test_build_configuration() |
| 1201 | self.test_build_configuration_branch() |
| 1202 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1203 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1204 | repo = git.Repo(path) |
| 1205 | repo.heads.master.commit = repo.commit('init') |
| 1206 | self.test_build_configuration() |
| 1207 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1208 | def test_dependent_changes_rebase(self): |
| 1209 | # Test that no errors occur when we walk a dependency tree |
| 1210 | # with an unused leaf node due to a rebase. |
| 1211 | # Start by constructing: C -> B -> A |
| 1212 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1213 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1214 | B.setDependsOn(A, 1) |
| 1215 | |
| 1216 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1217 | C.setDependsOn(B, 1) |
| 1218 | |
| 1219 | # Then rebase to form: D -> C -> A |
| 1220 | C.addPatchset() # C,2 |
| 1221 | C.setDependsOn(A, 1) |
| 1222 | |
| 1223 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1224 | D.setDependsOn(C, 2) |
| 1225 | |
| 1226 | # Walk the entire tree |
| 1227 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1228 | self.waitUntilSettled() |
| 1229 | self.assertEqual(len(self.history), 3) |
| 1230 | |
| 1231 | # Verify that walking just part of the tree still works |
| 1232 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1233 | self.waitUntilSettled() |
| 1234 | self.assertEqual(len(self.history), 6) |
| 1235 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1236 | def test_dependent_changes_dequeue(self): |
| 1237 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1238 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1239 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1240 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1241 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1242 | A.addApproval('Code-Review', 2) |
| 1243 | B.addApproval('Code-Review', 2) |
| 1244 | C.addApproval('Code-Review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1245 | |
| 1246 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1247 | M1.setMerged() |
| 1248 | |
| 1249 | # C -> B -> A -> M1 |
| 1250 | |
| 1251 | C.setDependsOn(B, 1) |
| 1252 | B.setDependsOn(A, 1) |
| 1253 | A.setDependsOn(M1, 1) |
| 1254 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1255 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1256 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1257 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1258 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1259 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1260 | |
| 1261 | self.waitUntilSettled() |
| 1262 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1263 | self.assertEqual(A.data['status'], 'NEW') |
| 1264 | self.assertEqual(A.reported, 2) |
| 1265 | self.assertEqual(B.data['status'], 'NEW') |
| 1266 | self.assertEqual(B.reported, 2) |
| 1267 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1268 | self.assertIn('This change depends on a change that failed to merge.', |
| 1269 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1270 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1271 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1272 | def test_failing_dependent_changes(self): |
| 1273 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1274 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1275 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1276 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1277 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1278 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1279 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1280 | A.addApproval('Code-Review', 2) |
| 1281 | B.addApproval('Code-Review', 2) |
| 1282 | C.addApproval('Code-Review', 2) |
| 1283 | D.addApproval('Code-Review', 2) |
| 1284 | E.addApproval('Code-Review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1285 | |
| 1286 | # E, D -> C -> B, A |
| 1287 | |
| 1288 | D.setDependsOn(C, 1) |
| 1289 | C.setDependsOn(B, 1) |
| 1290 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1291 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1292 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1293 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1294 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
| 1295 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1296 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1297 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1298 | |
| 1299 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1300 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1301 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1302 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1303 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1304 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1305 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1306 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1307 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1308 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1309 | self.waitUntilSettled() |
| 1310 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1311 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1312 | for build in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 1313 | if build.parameters['zuul']['change'] != '1': |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1314 | build.release() |
| 1315 | self.waitUntilSettled() |
| 1316 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1317 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1318 | self.waitUntilSettled() |
| 1319 | |
| 1320 | self.assertEqual(A.data['status'], 'MERGED') |
| 1321 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1322 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1323 | self.assertEqual(B.data['status'], 'NEW') |
| 1324 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1325 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1326 | self.assertEqual(C.data['status'], 'NEW') |
| 1327 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1328 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1329 | self.assertEqual(D.data['status'], 'NEW') |
| 1330 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1331 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1332 | self.assertEqual(E.data['status'], 'MERGED') |
| 1333 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1334 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1335 | self.assertEqual(len(self.history), 18) |
| 1336 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1337 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1338 | "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] | 1339 | # If it's dequeued more than once, we should see extra |
| 1340 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1341 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1342 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1343 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1344 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1345 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1346 | A.addApproval('Code-Review', 2) |
| 1347 | B.addApproval('Code-Review', 2) |
| 1348 | C.addApproval('Code-Review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1349 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1350 | self.executor_server.failJob('project-test1', A) |
| 1351 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1352 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1353 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1354 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1355 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1356 | |
| 1357 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1358 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1359 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1360 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1361 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1362 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1363 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1364 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1365 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1366 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1367 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1368 | self.waitUntilSettled() |
| 1369 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1370 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1371 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1372 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1373 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1374 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1375 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1376 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1377 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1378 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1379 | self.waitUntilSettled() |
| 1380 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1381 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1382 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1383 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1384 | self.executor_server.hold_jobs_in_build = False |
| 1385 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1386 | self.waitUntilSettled() |
| 1387 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1388 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1389 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1390 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1391 | self.assertEqual(A.data['status'], 'NEW') |
| 1392 | self.assertEqual(B.data['status'], 'MERGED') |
| 1393 | self.assertEqual(C.data['status'], 'MERGED') |
| 1394 | self.assertEqual(A.reported, 2) |
| 1395 | self.assertEqual(B.reported, 2) |
| 1396 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1397 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1398 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1399 | def test_nonvoting_job(self): |
| 1400 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1401 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1402 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1403 | 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1404 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1405 | self.executor_server.failJob('nonvoting-project-test2', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1406 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1407 | |
| 1408 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1409 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1410 | self.assertEqual(A.data['status'], 'MERGED') |
| 1411 | self.assertEqual(A.reported, 2) |
| 1412 | self.assertEqual( |
| 1413 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1414 | 'SUCCESS') |
| 1415 | self.assertEqual( |
| 1416 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1417 | 'SUCCESS') |
| 1418 | self.assertEqual( |
| 1419 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1420 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1421 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 1422 | self.assertTrue(self.getJobFromHistory('nonvoting-project-merge'). |
| 1423 | parameters['zuul']['voting']) |
| 1424 | self.assertTrue(self.getJobFromHistory('nonvoting-project-test1'). |
| 1425 | parameters['zuul']['voting']) |
| 1426 | self.assertFalse(self.getJobFromHistory('nonvoting-project-test2'). |
| 1427 | parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1428 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1429 | def test_check_queue_success(self): |
| 1430 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1431 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1432 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1433 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1434 | |
| 1435 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1436 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1437 | self.assertEqual(A.data['status'], 'NEW') |
| 1438 | self.assertEqual(A.reported, 1) |
| 1439 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1440 | 'SUCCESS') |
| 1441 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1442 | 'SUCCESS') |
| 1443 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1444 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1445 | |
| 1446 | def test_check_queue_failure(self): |
| 1447 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1448 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1449 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1450 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1451 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1452 | |
| 1453 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1454 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1455 | self.assertEqual(A.data['status'], 'NEW') |
| 1456 | self.assertEqual(A.reported, 1) |
| 1457 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1458 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1459 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1460 | 'SUCCESS') |
| 1461 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1462 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1463 | |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1464 | @simple_layout('layouts/autohold.yaml') |
| 1465 | def test_autohold(self): |
| 1466 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1467 | |
| 1468 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1469 | self.gearman_server.port) |
| 1470 | self.addCleanup(client.shutdown) |
David Shrewsbury | 36b2adf | 2017-07-31 15:40:13 -0400 | [diff] [blame] | 1471 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1472 | "reason text", 1) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1473 | self.assertTrue(r) |
| 1474 | |
| 1475 | self.executor_server.failJob('project-test2', A) |
| 1476 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1477 | |
| 1478 | self.waitUntilSettled() |
| 1479 | |
| 1480 | self.assertEqual(A.data['status'], 'NEW') |
| 1481 | self.assertEqual(A.reported, 1) |
| 1482 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1483 | 'FAILURE') |
| 1484 | |
| 1485 | # Check nodepool for a held node |
| 1486 | held_node = None |
| 1487 | for node in self.fake_nodepool.getNodes(): |
| 1488 | if node['state'] == zuul.model.STATE_HOLD: |
| 1489 | held_node = node |
| 1490 | break |
| 1491 | self.assertIsNotNone(held_node) |
| 1492 | |
| 1493 | # Validate node has recorded the failed job |
| 1494 | self.assertEqual( |
| 1495 | held_node['hold_job'], |
| 1496 | " ".join(['tenant-one', |
| 1497 | 'review.example.com/org/project', |
| 1498 | 'project-test2']) |
| 1499 | ) |
David Shrewsbury | f9af9df | 2017-08-01 15:19:26 -0400 | [diff] [blame] | 1500 | self.assertEqual(held_node['comment'], "reason text") |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1501 | |
| 1502 | # Another failed change should not hold any more nodes |
| 1503 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1504 | self.executor_server.failJob('project-test2', B) |
| 1505 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1506 | self.waitUntilSettled() |
| 1507 | self.assertEqual(B.data['status'], 'NEW') |
| 1508 | self.assertEqual(B.reported, 1) |
| 1509 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1510 | 'FAILURE') |
| 1511 | |
| 1512 | held_nodes = 0 |
| 1513 | for node in self.fake_nodepool.getNodes(): |
| 1514 | if node['state'] == zuul.model.STATE_HOLD: |
| 1515 | held_nodes += 1 |
| 1516 | self.assertEqual(held_nodes, 1) |
| 1517 | |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1518 | @simple_layout('layouts/autohold.yaml') |
| 1519 | def test_autohold_list(self): |
| 1520 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1521 | self.gearman_server.port) |
| 1522 | self.addCleanup(client.shutdown) |
| 1523 | |
| 1524 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1525 | "reason text", 1) |
| 1526 | self.assertTrue(r) |
| 1527 | |
| 1528 | autohold_requests = client.autohold_list() |
| 1529 | self.assertNotEqual({}, autohold_requests) |
| 1530 | self.assertEqual(1, len(autohold_requests.keys())) |
| 1531 | |
| 1532 | # The single dict key should be a CSV string value |
| 1533 | key = list(autohold_requests.keys())[0] |
| 1534 | tenant, project, job = key.split(',') |
| 1535 | |
| 1536 | self.assertEqual('tenant-one', tenant) |
| 1537 | self.assertIn('org/project', project) |
| 1538 | self.assertEqual('project-test2', job) |
| 1539 | |
| 1540 | # Note: the value is converted from set to list by json. |
| 1541 | self.assertEqual([1, "reason text"], autohold_requests[key]) |
| 1542 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1543 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1544 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1545 | # This particular test does a large amount of merges and needs a little |
| 1546 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1547 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1548 | "test that dependent changes behind dequeued changes work" |
| 1549 | # This complicated test is a reproduction of a real life bug |
| 1550 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1551 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1552 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1553 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1554 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1555 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1556 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1557 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1558 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1559 | D.setDependsOn(C, 1) |
| 1560 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1561 | A.addApproval('Code-Review', 2) |
| 1562 | B.addApproval('Code-Review', 2) |
| 1563 | C.addApproval('Code-Review', 2) |
| 1564 | D.addApproval('Code-Review', 2) |
| 1565 | E.addApproval('Code-Review', 2) |
| 1566 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1567 | |
| 1568 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1569 | |
| 1570 | # Change object re-use in the gerrit trigger is hidden if |
| 1571 | # changes are added in quick succession; waiting makes it more |
| 1572 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1573 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1574 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1575 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1576 | self.waitUntilSettled() |
| 1577 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1578 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1579 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1580 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1581 | self.waitUntilSettled() |
| 1582 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1583 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1584 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1585 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1586 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1587 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1588 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1589 | self.fake_gerrit.addEvent(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1590 | self.waitUntilSettled() |
| 1591 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1592 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1593 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1594 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1595 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1596 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1597 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1598 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1599 | self.waitUntilSettled() |
| 1600 | |
| 1601 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1602 | |
| 1603 | # Grab pointers to the jobs we want to release before |
| 1604 | # releasing any, because list indexes may change as |
| 1605 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1606 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1607 | a.release() |
| 1608 | b.release() |
| 1609 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1610 | self.waitUntilSettled() |
| 1611 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1612 | self.executor_server.hold_jobs_in_build = False |
| 1613 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1614 | self.waitUntilSettled() |
| 1615 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1616 | self.assertEqual(A.data['status'], 'NEW') |
| 1617 | self.assertEqual(B.data['status'], 'MERGED') |
| 1618 | self.assertEqual(C.data['status'], 'MERGED') |
| 1619 | self.assertEqual(D.data['status'], 'MERGED') |
| 1620 | self.assertEqual(E.data['status'], 'MERGED') |
| 1621 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1622 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1623 | self.assertEqual(A.reported, 2) |
| 1624 | self.assertEqual(B.reported, 2) |
| 1625 | self.assertEqual(C.reported, 2) |
| 1626 | self.assertEqual(D.reported, 2) |
| 1627 | self.assertEqual(E.reported, 2) |
| 1628 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1629 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1630 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1631 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1632 | |
| 1633 | def test_merger_repack(self): |
| 1634 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1635 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1636 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1637 | A.addApproval('Code-Review', 2) |
| 1638 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1639 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1640 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1641 | 'SUCCESS') |
| 1642 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1643 | 'SUCCESS') |
| 1644 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1645 | 'SUCCESS') |
| 1646 | self.assertEqual(A.data['status'], 'MERGED') |
| 1647 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1648 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1649 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1650 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1651 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1652 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1653 | if os.path.exists(path): |
| 1654 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1655 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1656 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1657 | if os.path.exists(path): |
| 1658 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1659 | |
| 1660 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1661 | A.addApproval('Code-Review', 2) |
| 1662 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1663 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1664 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1665 | 'SUCCESS') |
| 1666 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1667 | 'SUCCESS') |
| 1668 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1669 | 'SUCCESS') |
| 1670 | self.assertEqual(A.data['status'], 'MERGED') |
| 1671 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1672 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1673 | def test_merger_repack_large_change(self): |
| 1674 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1675 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1676 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1677 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1678 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1679 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1680 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1681 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1682 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1683 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1684 | # TODOv3(jeblair): add hostname to upstream root |
| 1685 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1686 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1687 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1688 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1689 | if os.path.exists(path): |
| 1690 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1691 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1692 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1693 | if os.path.exists(path): |
| 1694 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1695 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1696 | A.addApproval('Code-Review', 2) |
| 1697 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1698 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1699 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1700 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1701 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1702 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1703 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1704 | 'SUCCESS') |
| 1705 | self.assertEqual(A.data['status'], 'MERGED') |
| 1706 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1707 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1708 | def test_new_patchset_dequeues_old(self): |
| 1709 | "Test that a new patchset causes the old to be dequeued" |
| 1710 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1711 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1712 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1713 | M.setMerged() |
| 1714 | |
| 1715 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1716 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1717 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1718 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1719 | A.addApproval('Code-Review', 2) |
| 1720 | B.addApproval('Code-Review', 2) |
| 1721 | C.addApproval('Code-Review', 2) |
| 1722 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1723 | |
| 1724 | C.setDependsOn(B, 1) |
| 1725 | B.setDependsOn(A, 1) |
| 1726 | A.setDependsOn(M, 1) |
| 1727 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1728 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1729 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1730 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1731 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1732 | self.waitUntilSettled() |
| 1733 | |
| 1734 | B.addPatchset() |
| 1735 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1736 | self.waitUntilSettled() |
| 1737 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1738 | self.executor_server.hold_jobs_in_build = False |
| 1739 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1740 | self.waitUntilSettled() |
| 1741 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1742 | self.assertEqual(A.data['status'], 'MERGED') |
| 1743 | self.assertEqual(A.reported, 2) |
| 1744 | self.assertEqual(B.data['status'], 'NEW') |
| 1745 | self.assertEqual(B.reported, 2) |
| 1746 | self.assertEqual(C.data['status'], 'NEW') |
| 1747 | self.assertEqual(C.reported, 2) |
| 1748 | self.assertEqual(D.data['status'], 'MERGED') |
| 1749 | self.assertEqual(D.reported, 2) |
| 1750 | 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] | 1751 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1752 | def test_new_patchset_check(self): |
| 1753 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1754 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1755 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1756 | |
| 1757 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1758 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1759 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1760 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1761 | |
| 1762 | # Add two git-dependent changes |
| 1763 | B.setDependsOn(A, 1) |
| 1764 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1765 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1766 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1767 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1768 | |
| 1769 | # A live item, and a non-live/live pair |
| 1770 | items = check_pipeline.getAllItems() |
| 1771 | self.assertEqual(len(items), 3) |
| 1772 | |
| 1773 | self.assertEqual(items[0].change.number, '1') |
| 1774 | self.assertEqual(items[0].change.patchset, '1') |
| 1775 | self.assertFalse(items[0].live) |
| 1776 | |
| 1777 | self.assertEqual(items[1].change.number, '2') |
| 1778 | self.assertEqual(items[1].change.patchset, '1') |
| 1779 | self.assertTrue(items[1].live) |
| 1780 | |
| 1781 | self.assertEqual(items[2].change.number, '1') |
| 1782 | self.assertEqual(items[2].change.patchset, '1') |
| 1783 | self.assertTrue(items[2].live) |
| 1784 | |
| 1785 | # Add a new patchset to A |
| 1786 | A.addPatchset() |
| 1787 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1788 | self.waitUntilSettled() |
| 1789 | |
| 1790 | # The live copy of A,1 should be gone, but the non-live and B |
| 1791 | # should continue, and we should have a new A,2 |
| 1792 | items = check_pipeline.getAllItems() |
| 1793 | self.assertEqual(len(items), 3) |
| 1794 | |
| 1795 | self.assertEqual(items[0].change.number, '1') |
| 1796 | self.assertEqual(items[0].change.patchset, '1') |
| 1797 | self.assertFalse(items[0].live) |
| 1798 | |
| 1799 | self.assertEqual(items[1].change.number, '2') |
| 1800 | self.assertEqual(items[1].change.patchset, '1') |
| 1801 | self.assertTrue(items[1].live) |
| 1802 | |
| 1803 | self.assertEqual(items[2].change.number, '1') |
| 1804 | self.assertEqual(items[2].change.patchset, '2') |
| 1805 | self.assertTrue(items[2].live) |
| 1806 | |
| 1807 | # Add a new patchset to B |
| 1808 | B.addPatchset() |
| 1809 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1810 | self.waitUntilSettled() |
| 1811 | |
| 1812 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1813 | # but we should have a new B,2 (still based on A,1) |
| 1814 | items = check_pipeline.getAllItems() |
| 1815 | self.assertEqual(len(items), 3) |
| 1816 | |
| 1817 | self.assertEqual(items[0].change.number, '1') |
| 1818 | self.assertEqual(items[0].change.patchset, '2') |
| 1819 | self.assertTrue(items[0].live) |
| 1820 | |
| 1821 | self.assertEqual(items[1].change.number, '1') |
| 1822 | self.assertEqual(items[1].change.patchset, '1') |
| 1823 | self.assertFalse(items[1].live) |
| 1824 | |
| 1825 | self.assertEqual(items[2].change.number, '2') |
| 1826 | self.assertEqual(items[2].change.patchset, '2') |
| 1827 | self.assertTrue(items[2].live) |
| 1828 | |
| 1829 | self.builds[0].release() |
| 1830 | self.waitUntilSettled() |
| 1831 | self.builds[0].release() |
| 1832 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1833 | self.executor_server.hold_jobs_in_build = False |
| 1834 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1835 | self.waitUntilSettled() |
| 1836 | |
| 1837 | self.assertEqual(A.reported, 1) |
| 1838 | self.assertEqual(B.reported, 1) |
| 1839 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1840 | self.assertEqual(self.history[0].changes, '1,1') |
| 1841 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1842 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1843 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1844 | self.assertEqual(self.history[2].changes, '1,2') |
| 1845 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1846 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1847 | |
| 1848 | def test_abandoned_gate(self): |
| 1849 | "Test that an abandoned change is dequeued from gate" |
| 1850 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1851 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1852 | |
| 1853 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1854 | A.addApproval('Code-Review', 2) |
| 1855 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1856 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1857 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1858 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1859 | |
| 1860 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1861 | self.waitUntilSettled() |
| 1862 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1863 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1864 | self.waitUntilSettled() |
| 1865 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1866 | self.assertBuilds([]) |
| 1867 | self.assertHistory([ |
| 1868 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1869 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1870 | self.assertEqual(A.reported, 1, |
| 1871 | "Abandoned gate change should report only start") |
| 1872 | |
| 1873 | def test_abandoned_check(self): |
| 1874 | "Test that an abandoned change is dequeued from check" |
| 1875 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1876 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1877 | |
| 1878 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1879 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1880 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1881 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1882 | |
| 1883 | # Add two git-dependent changes |
| 1884 | B.setDependsOn(A, 1) |
| 1885 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1886 | self.waitUntilSettled() |
| 1887 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1888 | self.waitUntilSettled() |
| 1889 | # A live item, and a non-live/live pair |
| 1890 | items = check_pipeline.getAllItems() |
| 1891 | self.assertEqual(len(items), 3) |
| 1892 | |
| 1893 | self.assertEqual(items[0].change.number, '1') |
| 1894 | self.assertFalse(items[0].live) |
| 1895 | |
| 1896 | self.assertEqual(items[1].change.number, '2') |
| 1897 | self.assertTrue(items[1].live) |
| 1898 | |
| 1899 | self.assertEqual(items[2].change.number, '1') |
| 1900 | self.assertTrue(items[2].live) |
| 1901 | |
| 1902 | # Abandon A |
| 1903 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1904 | self.waitUntilSettled() |
| 1905 | |
| 1906 | # The live copy of A should be gone, but the non-live and B |
| 1907 | # should continue |
| 1908 | items = check_pipeline.getAllItems() |
| 1909 | self.assertEqual(len(items), 2) |
| 1910 | |
| 1911 | self.assertEqual(items[0].change.number, '1') |
| 1912 | self.assertFalse(items[0].live) |
| 1913 | |
| 1914 | self.assertEqual(items[1].change.number, '2') |
| 1915 | self.assertTrue(items[1].live) |
| 1916 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1917 | self.executor_server.hold_jobs_in_build = False |
| 1918 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1919 | self.waitUntilSettled() |
| 1920 | |
| 1921 | self.assertEqual(len(self.history), 4) |
| 1922 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1923 | 'Build should have been aborted') |
| 1924 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1925 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1926 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1927 | def test_abandoned_not_timer(self): |
| 1928 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1929 | # This test can not use simple_layout because it must start |
| 1930 | # with a configuration which does not include a |
| 1931 | # timer-triggered job so that we have an opportunity to set |
| 1932 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1933 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1934 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1935 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1936 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1937 | # The pipeline triggers every second, so we should have seen |
| 1938 | # several by now. |
| 1939 | time.sleep(5) |
| 1940 | self.waitUntilSettled() |
| 1941 | # Stop queuing timer triggered jobs so that the assertions |
| 1942 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1943 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1944 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1945 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 1946 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 1947 | # If APScheduler is in mid-event when we remove the job, we |
| 1948 | # can end up with one more event firing, so give it an extra |
| 1949 | # second to settle. |
| 1950 | time.sleep(1) |
| 1951 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1952 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1953 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1954 | |
| 1955 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1956 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1957 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1958 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1959 | |
| 1960 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1961 | self.waitUntilSettled() |
| 1962 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1963 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1964 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1965 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1966 | self.waitUntilSettled() |
| 1967 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1968 | def test_new_patchset_dequeues_old_on_head(self): |
| 1969 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1970 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1971 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1972 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1973 | M.setMerged() |
| 1974 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1975 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1976 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1977 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1978 | A.addApproval('Code-Review', 2) |
| 1979 | B.addApproval('Code-Review', 2) |
| 1980 | C.addApproval('Code-Review', 2) |
| 1981 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1982 | |
| 1983 | C.setDependsOn(B, 1) |
| 1984 | B.setDependsOn(A, 1) |
| 1985 | A.setDependsOn(M, 1) |
| 1986 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1987 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1988 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1989 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1990 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1991 | self.waitUntilSettled() |
| 1992 | |
| 1993 | A.addPatchset() |
| 1994 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1995 | self.waitUntilSettled() |
| 1996 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1997 | self.executor_server.hold_jobs_in_build = False |
| 1998 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1999 | self.waitUntilSettled() |
| 2000 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2001 | self.assertEqual(A.data['status'], 'NEW') |
| 2002 | self.assertEqual(A.reported, 2) |
| 2003 | self.assertEqual(B.data['status'], 'NEW') |
| 2004 | self.assertEqual(B.reported, 2) |
| 2005 | self.assertEqual(C.data['status'], 'NEW') |
| 2006 | self.assertEqual(C.reported, 2) |
| 2007 | self.assertEqual(D.data['status'], 'MERGED') |
| 2008 | self.assertEqual(D.reported, 2) |
| 2009 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2010 | |
| 2011 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2012 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2013 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2014 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2015 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2016 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2017 | A.addApproval('Code-Review', 2) |
| 2018 | B.addApproval('Code-Review', 2) |
| 2019 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2020 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2021 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2022 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2023 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2024 | self.waitUntilSettled() |
| 2025 | |
| 2026 | B.addPatchset() |
| 2027 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2028 | self.waitUntilSettled() |
| 2029 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2030 | self.executor_server.hold_jobs_in_build = False |
| 2031 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2032 | self.waitUntilSettled() |
| 2033 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2034 | self.assertEqual(A.data['status'], 'MERGED') |
| 2035 | self.assertEqual(A.reported, 2) |
| 2036 | self.assertEqual(B.data['status'], 'NEW') |
| 2037 | self.assertEqual(B.reported, 2) |
| 2038 | self.assertEqual(C.data['status'], 'MERGED') |
| 2039 | self.assertEqual(C.reported, 2) |
| 2040 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2041 | |
| 2042 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2043 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2044 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2045 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2046 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2047 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2048 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2049 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2050 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2051 | self.waitUntilSettled() |
| 2052 | |
| 2053 | B.addPatchset() |
| 2054 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2055 | self.waitUntilSettled() |
| 2056 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2057 | self.executor_server.hold_jobs_in_build = False |
| 2058 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2059 | self.waitUntilSettled() |
| 2060 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2061 | self.assertEqual(A.data['status'], 'NEW') |
| 2062 | self.assertEqual(A.reported, 1) |
| 2063 | self.assertEqual(B.data['status'], 'NEW') |
| 2064 | self.assertEqual(B.reported, 1) |
| 2065 | self.assertEqual(C.data['status'], 'NEW') |
| 2066 | self.assertEqual(C.reported, 1) |
| 2067 | self.assertEqual(len(self.history), 10) |
| 2068 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2069 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2070 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2071 | def test_noop_job(self): |
| 2072 | "Test that the internal noop job works" |
| 2073 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2074 | A.addApproval('Code-Review', 2) |
| 2075 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2076 | self.waitUntilSettled() |
| 2077 | |
| 2078 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2079 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2080 | self.assertEqual(len(self.history), 0) |
| 2081 | self.assertEqual(A.data['status'], 'MERGED') |
| 2082 | self.assertEqual(A.reported, 2) |
| 2083 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2084 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2085 | def test_no_job_project(self): |
| 2086 | "Test that reports with no jobs don't get sent" |
| 2087 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2088 | 'master', 'A') |
| 2089 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2090 | self.waitUntilSettled() |
| 2091 | |
| 2092 | # Change wasn't reported to |
| 2093 | self.assertEqual(A.reported, False) |
| 2094 | |
| 2095 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2096 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2097 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2098 | items = check_pipeline.getAllItems() |
| 2099 | self.assertEqual(len(items), 0) |
| 2100 | |
| 2101 | self.assertEqual(len(self.history), 0) |
| 2102 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2103 | def test_zuul_refs(self): |
| 2104 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2105 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2106 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2107 | M1.setMerged() |
| 2108 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2109 | M2.setMerged() |
| 2110 | |
| 2111 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2112 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2113 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2114 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2115 | A.addApproval('Code-Review', 2) |
| 2116 | B.addApproval('Code-Review', 2) |
| 2117 | C.addApproval('Code-Review', 2) |
| 2118 | D.addApproval('Code-Review', 2) |
| 2119 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2120 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2121 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2122 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2123 | |
| 2124 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2125 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2126 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2127 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2128 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2129 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2130 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2131 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2132 | self.waitUntilSettled() |
| 2133 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2134 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2135 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2136 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2137 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2138 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2139 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2140 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2141 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2142 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2143 | d_build = x |
| 2144 | if a_build and b_build and c_build and d_build: |
| 2145 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2146 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2147 | # should have a, not b, and should not be in project2 |
| 2148 | self.assertTrue(a_build.hasChanges(A)) |
| 2149 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2150 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2151 | # should have a and b, and should not be in project2 |
| 2152 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2153 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2154 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2155 | # should have a and b in 1, c in 2 |
| 2156 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2157 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2158 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2159 | # should have a and b in 1, c and d in 2 |
| 2160 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2161 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2162 | self.executor_server.hold_jobs_in_build = False |
| 2163 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2164 | self.waitUntilSettled() |
| 2165 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2166 | self.assertEqual(A.data['status'], 'MERGED') |
| 2167 | self.assertEqual(A.reported, 2) |
| 2168 | self.assertEqual(B.data['status'], 'MERGED') |
| 2169 | self.assertEqual(B.reported, 2) |
| 2170 | self.assertEqual(C.data['status'], 'MERGED') |
| 2171 | self.assertEqual(C.reported, 2) |
| 2172 | self.assertEqual(D.data['status'], 'MERGED') |
| 2173 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2174 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2175 | def test_rerun_on_error(self): |
| 2176 | "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] | 2177 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2178 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2179 | A.addApproval('Code-Review', 2) |
| 2180 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2181 | self.waitUntilSettled() |
| 2182 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2183 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2184 | self.executor_server.hold_jobs_in_build = False |
| 2185 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2186 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2187 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2188 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2189 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2190 | def test_statsd(self): |
| 2191 | "Test each of the statsd methods used in the scheduler" |
James E. Blair | ded241e | 2017-10-10 13:22:40 -0700 | [diff] [blame] | 2192 | statsd = self.sched.statsd |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2193 | statsd.incr('test-incr') |
| 2194 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2195 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2196 | self.assertReportedStat('test-incr', '1|c') |
| 2197 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2198 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2199 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2200 | def test_stuck_job_cleanup(self): |
| 2201 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2202 | |
| 2203 | # 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] | 2204 | self.gearman_server.hold_jobs_in_queue = True |
| 2205 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2206 | A.addApproval('Code-Review', 2) |
| 2207 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2208 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2209 | # 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] | 2210 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2211 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2212 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2213 | self.sched.reconfigure(self.config) |
| 2214 | self.waitUntilSettled() |
| 2215 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2216 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2217 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2218 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2219 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2220 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2221 | |
| 2222 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2223 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2224 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2225 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2226 | def test_file_head(self): |
| 2227 | # This is a regression test for an observed bug. A change |
| 2228 | # with a file named "HEAD" in the root directory of the repo |
| 2229 | # was processed by a merger. It then was unable to reset the |
| 2230 | # repo because of: |
| 2231 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2232 | # with exit code 128 |
| 2233 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2234 | # and filename |
| 2235 | # Use '--' to separate filenames from revisions' |
| 2236 | |
| 2237 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2238 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2239 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2240 | |
| 2241 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2242 | self.waitUntilSettled() |
| 2243 | |
| 2244 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2245 | self.waitUntilSettled() |
| 2246 | |
| 2247 | self.assertIn('Build succeeded', A.messages[0]) |
| 2248 | self.assertIn('Build succeeded', B.messages[0]) |
| 2249 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2250 | def test_file_jobs(self): |
| 2251 | "Test that file jobs run only when appropriate" |
| 2252 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2253 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2254 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2255 | A.addApproval('Code-Review', 2) |
| 2256 | B.addApproval('Code-Review', 2) |
| 2257 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2258 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2259 | self.waitUntilSettled() |
| 2260 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2261 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2262 | if x.name == 'project-testfile'] |
| 2263 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2264 | self.assertEqual(len(testfile_jobs), 1) |
| 2265 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2266 | self.assertEqual(A.data['status'], 'MERGED') |
| 2267 | self.assertEqual(A.reported, 2) |
| 2268 | self.assertEqual(B.data['status'], 'MERGED') |
| 2269 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2270 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2271 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2272 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2273 | if should_skip: |
| 2274 | files = {'ignoreme': 'ignored\n'} |
| 2275 | else: |
| 2276 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2277 | |
| 2278 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2279 | 'master', |
| 2280 | 'test irrelevant-files', |
| 2281 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2282 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2283 | self.waitUntilSettled() |
| 2284 | |
| 2285 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2286 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2287 | |
| 2288 | if should_skip: |
| 2289 | self.assertEqual([], tested_change_ids) |
| 2290 | else: |
| 2291 | self.assertIn(change.data['number'], tested_change_ids) |
| 2292 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2293 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2294 | def test_irrelevant_files_match_skips_job(self): |
| 2295 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2296 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2297 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2298 | def test_irrelevant_files_no_match_runs_job(self): |
| 2299 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2300 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2301 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2302 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2303 | files = {'ignoreme': 'ignored\n'} |
| 2304 | |
| 2305 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2306 | 'master', |
| 2307 | 'test irrelevant-files', |
| 2308 | files=files) |
| 2309 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2310 | self.waitUntilSettled() |
| 2311 | |
| 2312 | run_jobs = set([build.name for build in self.history]) |
| 2313 | |
| 2314 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2315 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2316 | |
James E. Blair | af8b208 | 2017-10-03 15:38:27 -0700 | [diff] [blame] | 2317 | @simple_layout('layouts/job-vars.yaml') |
| 2318 | def test_inherited_job_variables(self): |
| 2319 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2320 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2321 | self.waitUntilSettled() |
| 2322 | self.assertHistory([ |
| 2323 | dict(name='parentjob', result='SUCCESS'), |
| 2324 | dict(name='child1', result='SUCCESS'), |
| 2325 | dict(name='child2', result='SUCCESS'), |
| 2326 | dict(name='child3', result='SUCCESS'), |
| 2327 | ], ordered=False) |
| 2328 | j = self.getJobFromHistory('parentjob') |
| 2329 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2330 | self.assertEqual(j.parameters['vars']['override'], 0) |
| 2331 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2332 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2333 | self.assertFalse('child1' in j.parameters['vars']) |
| 2334 | self.assertFalse('child2' in j.parameters['vars']) |
| 2335 | self.assertFalse('child3' in j.parameters['vars']) |
| 2336 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2337 | 'org/project0'])) |
| 2338 | j = self.getJobFromHistory('child1') |
| 2339 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2340 | self.assertEqual(j.parameters['vars']['override'], 1) |
| 2341 | self.assertEqual(j.parameters['vars']['child1override'], 1) |
| 2342 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2343 | self.assertEqual(j.parameters['vars']['child1'], 1) |
| 2344 | self.assertFalse('child2' in j.parameters['vars']) |
| 2345 | self.assertFalse('child3' in j.parameters['vars']) |
| 2346 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2347 | 'org/project1'])) |
| 2348 | j = self.getJobFromHistory('child2') |
| 2349 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2350 | self.assertEqual(j.parameters['vars']['override'], 2) |
| 2351 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2352 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2353 | self.assertFalse('child1' in j.parameters['vars']) |
| 2354 | self.assertEqual(j.parameters['vars']['child2'], 2) |
| 2355 | self.assertFalse('child3' in j.parameters['vars']) |
| 2356 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2357 | 'org/project2'])) |
| 2358 | j = self.getJobFromHistory('child3') |
| 2359 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2360 | self.assertEqual(j.parameters['vars']['override'], 3) |
| 2361 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2362 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2363 | self.assertFalse('child1' in j.parameters['vars']) |
| 2364 | self.assertFalse('child2' in j.parameters['vars']) |
| 2365 | self.assertEqual(j.parameters['vars']['child3'], 3) |
| 2366 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2367 | 'org/project3'])) |
| 2368 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2369 | def test_queue_names(self): |
| 2370 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2371 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2372 | (trusted, project1) = tenant.getProject('org/project1') |
| 2373 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2374 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2375 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2376 | self.assertEqual(q1.name, 'integrated') |
| 2377 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2378 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2379 | def test_queue_precedence(self): |
| 2380 | "Test that queue precedence works" |
| 2381 | |
| 2382 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2383 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2384 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2385 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2386 | A.addApproval('Code-Review', 2) |
| 2387 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2388 | |
| 2389 | self.waitUntilSettled() |
| 2390 | self.gearman_server.hold_jobs_in_queue = False |
| 2391 | self.gearman_server.release() |
| 2392 | self.waitUntilSettled() |
| 2393 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2394 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2395 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2396 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2397 | self.waitUntilSettled() |
| 2398 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2399 | self.log.debug(self.history) |
| 2400 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2401 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2402 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2403 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2404 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2405 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2406 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2407 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2408 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2409 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2410 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2411 | A.addApproval('Code-Review', 2) |
| 2412 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2413 | self.waitUntilSettled() |
| 2414 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2415 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2416 | self.waitUntilSettled() |
| 2417 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2418 | port = self.webapp.server.socket.getsockname()[1] |
| 2419 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2420 | req = urllib.request.Request( |
| 2421 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2422 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2423 | headers = f.info() |
| 2424 | self.assertIn('Content-Length', headers) |
| 2425 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2426 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2427 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2428 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2429 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2430 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2431 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2432 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2433 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2434 | self.executor_server.hold_jobs_in_build = False |
| 2435 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2436 | self.waitUntilSettled() |
| 2437 | |
| 2438 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2439 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2440 | for p in data['pipelines']: |
| 2441 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2442 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2443 | self.assertEqual(q['window'], 20) |
| 2444 | else: |
| 2445 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2446 | for head in q['heads']: |
| 2447 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2448 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2449 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2450 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2451 | status_jobs.append(job) |
| 2452 | self.assertEqual('project-merge', status_jobs[0]['name']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2453 | # TODO(mordred) pull uuids from self.builds |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2454 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2455 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2456 | uuid=status_jobs[0]['uuid']), |
| 2457 | status_jobs[0]['url']) |
| 2458 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2459 | 'finger://{hostname}/{uuid}'.format( |
| 2460 | hostname=self.executor_server.hostname, |
| 2461 | uuid=status_jobs[0]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2462 | status_jobs[0]['finger_url']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2463 | # TOOD(mordred) configure a success-url on the base job |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2464 | self.assertEqual( |
| 2465 | 'finger://{hostname}/{uuid}'.format( |
| 2466 | hostname=self.executor_server.hostname, |
| 2467 | uuid=status_jobs[0]['uuid']), |
| 2468 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2469 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2470 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2471 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2472 | uuid=status_jobs[1]['uuid']), |
| 2473 | status_jobs[1]['url']) |
| 2474 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2475 | 'finger://{hostname}/{uuid}'.format( |
| 2476 | hostname=self.executor_server.hostname, |
| 2477 | uuid=status_jobs[1]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2478 | status_jobs[1]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2479 | self.assertEqual( |
| 2480 | 'finger://{hostname}/{uuid}'.format( |
| 2481 | hostname=self.executor_server.hostname, |
| 2482 | uuid=status_jobs[1]['uuid']), |
| 2483 | status_jobs[1]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2484 | |
| 2485 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2486 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2487 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2488 | uuid=status_jobs[2]['uuid']), |
| 2489 | status_jobs[2]['url']) |
| 2490 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2491 | 'finger://{hostname}/{uuid}'.format( |
| 2492 | hostname=self.executor_server.hostname, |
| 2493 | uuid=status_jobs[2]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2494 | status_jobs[2]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2495 | self.assertEqual( |
| 2496 | 'finger://{hostname}/{uuid}'.format( |
| 2497 | hostname=self.executor_server.hostname, |
| 2498 | uuid=status_jobs[2]['uuid']), |
| 2499 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2500 | |
Tobias Henkel | 65639f8 | 2017-07-10 10:25:42 +0200 | [diff] [blame] | 2501 | # check job dependencies |
| 2502 | self.assertIsNotNone(status_jobs[0]['dependencies']) |
| 2503 | self.assertIsNotNone(status_jobs[1]['dependencies']) |
| 2504 | self.assertIsNotNone(status_jobs[2]['dependencies']) |
| 2505 | self.assertEqual(len(status_jobs[0]['dependencies']), 0) |
| 2506 | self.assertEqual(len(status_jobs[1]['dependencies']), 1) |
| 2507 | self.assertEqual(len(status_jobs[2]['dependencies']), 1) |
| 2508 | self.assertIn('project-merge', status_jobs[1]['dependencies']) |
| 2509 | self.assertIn('project-merge', status_jobs[2]['dependencies']) |
| 2510 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2511 | def test_live_reconfiguration(self): |
| 2512 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2513 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2514 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2515 | A.addApproval('Code-Review', 2) |
| 2516 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2517 | self.waitUntilSettled() |
| 2518 | |
| 2519 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2520 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2521 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2522 | self.executor_server.hold_jobs_in_build = False |
| 2523 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2524 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2525 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2526 | 'SUCCESS') |
| 2527 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2528 | 'SUCCESS') |
| 2529 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2530 | 'SUCCESS') |
| 2531 | self.assertEqual(A.data['status'], 'MERGED') |
| 2532 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2533 | |
James E. Blair | 027ba99 | 2017-09-20 13:48:32 -0700 | [diff] [blame] | 2534 | def test_live_reconfiguration_abort(self): |
| 2535 | # Raise an exception during reconfiguration and verify we |
| 2536 | # still function. |
| 2537 | self.executor_server.hold_jobs_in_build = True |
| 2538 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2539 | A.addApproval('Code-Review', 2) |
| 2540 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2541 | self.waitUntilSettled() |
| 2542 | |
| 2543 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2544 | pipeline = tenant.layout.pipelines['gate'] |
| 2545 | change = pipeline.getAllItems()[0].change |
| 2546 | # Set this to an invalid value to cause an exception during |
| 2547 | # reconfiguration. |
| 2548 | change.branch = None |
| 2549 | |
| 2550 | self.sched.reconfigure(self.config) |
| 2551 | self.waitUntilSettled() |
| 2552 | |
| 2553 | self.executor_server.hold_jobs_in_build = False |
| 2554 | self.executor_server.release() |
| 2555 | |
| 2556 | self.waitUntilSettled() |
| 2557 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2558 | 'ABORTED') |
| 2559 | self.assertEqual(A.data['status'], 'NEW') |
| 2560 | # The final report fails because of the invalid value set above. |
| 2561 | self.assertEqual(A.reported, 1) |
| 2562 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2563 | def test_live_reconfiguration_merge_conflict(self): |
| 2564 | # A real-world bug: a change in a gate queue has a merge |
| 2565 | # conflict and a job is added to its project while it's |
| 2566 | # sitting in the queue. The job gets added to the change and |
| 2567 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2568 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2569 | |
| 2570 | # This change is fine. It's here to stop the queue long |
| 2571 | # enough for the next change to be subject to the |
| 2572 | # reconfiguration, as well as to provide a conflict for the |
| 2573 | # next change. This change will succeed and merge. |
| 2574 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2575 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2576 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2577 | |
| 2578 | # This change will be in merge conflict. During the |
| 2579 | # reconfiguration, we will add a job. We want to make sure |
| 2580 | # that doesn't cause it to get stuck. |
| 2581 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2582 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2583 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2584 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2585 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2586 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2587 | |
| 2588 | self.waitUntilSettled() |
| 2589 | |
| 2590 | # No jobs have run yet |
| 2591 | self.assertEqual(A.data['status'], 'NEW') |
| 2592 | self.assertEqual(A.reported, 1) |
| 2593 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2594 | self.assertEqual(len(self.history), 0) |
| 2595 | |
| 2596 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2597 | self.commitConfigUpdate('common-config', |
| 2598 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2599 | self.sched.reconfigure(self.config) |
| 2600 | self.waitUntilSettled() |
| 2601 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2602 | self.executor_server.hold_jobs_in_build = False |
| 2603 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2604 | self.waitUntilSettled() |
| 2605 | |
| 2606 | self.assertEqual(A.data['status'], 'MERGED') |
| 2607 | self.assertEqual(A.reported, 2) |
| 2608 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2609 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2610 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2611 | 'SUCCESS') |
| 2612 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2613 | 'SUCCESS') |
| 2614 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2615 | 'SUCCESS') |
| 2616 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2617 | 'SUCCESS') |
| 2618 | self.assertEqual(len(self.history), 4) |
| 2619 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2620 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2621 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2622 | # that tests a job added to a job tree with a failed root does |
| 2623 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2624 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2625 | |
| 2626 | # This change is fine. It's here to stop the queue long |
| 2627 | # enough for the next change to be subject to the |
| 2628 | # reconfiguration. This change will succeed and merge. |
| 2629 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2630 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2631 | A.addApproval('Code-Review', 2) |
| 2632 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2633 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2634 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2635 | self.waitUntilSettled() |
| 2636 | |
| 2637 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2638 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2639 | B.addApproval('Code-Review', 2) |
| 2640 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2641 | self.waitUntilSettled() |
| 2642 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2643 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2644 | self.waitUntilSettled() |
| 2645 | |
| 2646 | # Both -merge jobs have run, but no others. |
| 2647 | self.assertEqual(A.data['status'], 'NEW') |
| 2648 | self.assertEqual(A.reported, 1) |
| 2649 | self.assertEqual(B.data['status'], 'NEW') |
| 2650 | self.assertEqual(B.reported, 1) |
| 2651 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2652 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2653 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2654 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2655 | self.assertEqual(len(self.history), 2) |
| 2656 | |
| 2657 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2658 | self.commitConfigUpdate('common-config', |
| 2659 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2660 | self.sched.reconfigure(self.config) |
| 2661 | self.waitUntilSettled() |
| 2662 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2663 | self.executor_server.hold_jobs_in_build = False |
| 2664 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2665 | self.waitUntilSettled() |
| 2666 | |
| 2667 | self.assertEqual(A.data['status'], 'MERGED') |
| 2668 | self.assertEqual(A.reported, 2) |
| 2669 | self.assertEqual(B.data['status'], 'NEW') |
| 2670 | self.assertEqual(B.reported, 2) |
| 2671 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2672 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2673 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2674 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2675 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2676 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2677 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2678 | self.assertEqual(len(self.history), 5) |
| 2679 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2680 | def test_live_reconfiguration_failed_job(self): |
| 2681 | # Test that a change with a removed failing job does not |
| 2682 | # disrupt reconfiguration. If a change has a failed job and |
| 2683 | # that job is removed during a reconfiguration, we observed a |
| 2684 | # bug where the code to re-set build statuses would run on |
| 2685 | # that build and raise an exception because the job no longer |
| 2686 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2687 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2688 | |
| 2689 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2690 | |
| 2691 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2692 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2693 | |
| 2694 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2695 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2696 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2697 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2698 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2699 | self.waitUntilSettled() |
| 2700 | |
| 2701 | self.assertEqual(A.data['status'], 'NEW') |
| 2702 | self.assertEqual(A.reported, 0) |
| 2703 | |
| 2704 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2705 | 'SUCCESS') |
| 2706 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2707 | 'FAILURE') |
| 2708 | self.assertEqual(len(self.history), 2) |
| 2709 | |
| 2710 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2711 | self.commitConfigUpdate('common-config', |
| 2712 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2713 | self.sched.reconfigure(self.config) |
| 2714 | self.waitUntilSettled() |
| 2715 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2716 | self.executor_server.hold_jobs_in_build = False |
| 2717 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2718 | self.waitUntilSettled() |
| 2719 | |
| 2720 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2721 | 'SUCCESS') |
| 2722 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2723 | 'SUCCESS') |
| 2724 | self.assertEqual(len(self.history), 4) |
| 2725 | |
| 2726 | self.assertEqual(A.data['status'], 'NEW') |
| 2727 | self.assertEqual(A.reported, 1) |
| 2728 | self.assertIn('Build succeeded', A.messages[0]) |
| 2729 | # Ensure the removed job was not included in the report. |
| 2730 | self.assertNotIn('project-test1', A.messages[0]) |
| 2731 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2732 | def test_live_reconfiguration_shared_queue(self): |
| 2733 | # Test that a change with a failing job which was removed from |
| 2734 | # this project but otherwise still exists in the system does |
| 2735 | # not disrupt reconfiguration. |
| 2736 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2737 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2738 | |
| 2739 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2740 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2741 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2742 | |
| 2743 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2744 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2745 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2746 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2747 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2748 | self.waitUntilSettled() |
| 2749 | |
| 2750 | self.assertEqual(A.data['status'], 'NEW') |
| 2751 | self.assertEqual(A.reported, 0) |
| 2752 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2753 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2754 | 'SUCCESS') |
| 2755 | self.assertEqual(self.getJobFromHistory( |
| 2756 | 'project1-project2-integration').result, 'FAILURE') |
| 2757 | self.assertEqual(len(self.history), 2) |
| 2758 | |
| 2759 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2760 | self.commitConfigUpdate( |
| 2761 | 'common-config', |
| 2762 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2763 | self.sched.reconfigure(self.config) |
| 2764 | self.waitUntilSettled() |
| 2765 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2766 | self.executor_server.hold_jobs_in_build = False |
| 2767 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2768 | self.waitUntilSettled() |
| 2769 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2770 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2771 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2772 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2773 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2774 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2775 | 'SUCCESS') |
| 2776 | self.assertEqual(self.getJobFromHistory( |
| 2777 | 'project1-project2-integration').result, 'FAILURE') |
| 2778 | self.assertEqual(len(self.history), 4) |
| 2779 | |
| 2780 | self.assertEqual(A.data['status'], 'NEW') |
| 2781 | self.assertEqual(A.reported, 1) |
| 2782 | self.assertIn('Build succeeded', A.messages[0]) |
| 2783 | # Ensure the removed job was not included in the report. |
| 2784 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2785 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2786 | def test_double_live_reconfiguration_shared_queue(self): |
| 2787 | # This was a real-world regression. A change is added to |
| 2788 | # gate; a reconfigure happens, a second change which depends |
| 2789 | # on the first is added, and a second reconfiguration happens. |
| 2790 | # Ensure that both changes merge. |
| 2791 | |
| 2792 | # A failure may indicate incorrect caching or cleaning up of |
| 2793 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2794 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2795 | |
| 2796 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2797 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2798 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2799 | A.addApproval('Code-Review', 2) |
| 2800 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2801 | |
| 2802 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2803 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2804 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2805 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2806 | self.waitUntilSettled() |
| 2807 | |
| 2808 | # Reconfigure (with only one change in the pipeline). |
| 2809 | self.sched.reconfigure(self.config) |
| 2810 | self.waitUntilSettled() |
| 2811 | |
| 2812 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2813 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2814 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2815 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2816 | self.waitUntilSettled() |
| 2817 | |
| 2818 | # Reconfigure (with both in the pipeline). |
| 2819 | self.sched.reconfigure(self.config) |
| 2820 | self.waitUntilSettled() |
| 2821 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2822 | self.executor_server.hold_jobs_in_build = False |
| 2823 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2824 | self.waitUntilSettled() |
| 2825 | |
| 2826 | self.assertEqual(len(self.history), 8) |
| 2827 | |
| 2828 | self.assertEqual(A.data['status'], 'MERGED') |
| 2829 | self.assertEqual(A.reported, 2) |
| 2830 | self.assertEqual(B.data['status'], 'MERGED') |
| 2831 | self.assertEqual(B.reported, 2) |
| 2832 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2833 | def test_live_reconfiguration_del_project(self): |
| 2834 | # Test project deletion from layout |
| 2835 | # while changes are enqueued |
| 2836 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2837 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2838 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2839 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2840 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2841 | |
| 2842 | # A Depends-On: B |
| 2843 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2844 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2845 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2846 | |
| 2847 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2848 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2849 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2850 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2851 | self.waitUntilSettled() |
| 2852 | self.assertEqual(len(self.builds), 5) |
| 2853 | |
| 2854 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2855 | self.commitConfigUpdate( |
| 2856 | 'common-config', |
| 2857 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2858 | self.sched.reconfigure(self.config) |
| 2859 | self.waitUntilSettled() |
| 2860 | |
| 2861 | # Builds for C aborted, builds for A succeed, |
| 2862 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2863 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2864 | self.assertEqual(job_c.changes, '3,1') |
| 2865 | self.assertEqual(job_c.result, 'ABORTED') |
| 2866 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2867 | self.executor_server.hold_jobs_in_build = False |
| 2868 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2869 | self.waitUntilSettled() |
| 2870 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2871 | self.assertEqual( |
| 2872 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2873 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2874 | |
| 2875 | self.assertEqual(A.data['status'], 'NEW') |
| 2876 | self.assertEqual(B.data['status'], 'NEW') |
| 2877 | self.assertEqual(C.data['status'], 'NEW') |
| 2878 | self.assertEqual(A.reported, 1) |
| 2879 | self.assertEqual(B.reported, 0) |
| 2880 | self.assertEqual(C.reported, 0) |
| 2881 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2882 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2883 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2884 | self.assertIn('Build succeeded', A.messages[0]) |
| 2885 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2886 | def test_delayed_repo_init(self): |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2887 | self.init_repo("org/new-project") |
Clint Byrum | 627ba36 | 2017-08-14 13:20:40 -0700 | [diff] [blame] | 2888 | files = {'README': ''} |
| 2889 | self.addCommitToRepo("org/new-project", 'Initial commit', |
| 2890 | files=files, tag='init') |
| 2891 | self.newTenantConfig('tenants/delayed-repo-init.yaml') |
| 2892 | self.commitConfigUpdate( |
| 2893 | 'common-config', |
| 2894 | 'layouts/delayed-repo-init.yaml') |
| 2895 | self.sched.reconfigure(self.config) |
| 2896 | self.waitUntilSettled() |
| 2897 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2898 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2899 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2900 | A.addApproval('Code-Review', 2) |
| 2901 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2902 | self.waitUntilSettled() |
| 2903 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2904 | 'SUCCESS') |
| 2905 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2906 | 'SUCCESS') |
| 2907 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2908 | 'SUCCESS') |
| 2909 | self.assertEqual(A.data['status'], 'MERGED') |
| 2910 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2911 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2912 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2913 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2914 | self.init_repo("org/delete-project") |
| 2915 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2916 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2917 | A.addApproval('Code-Review', 2) |
| 2918 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2919 | self.waitUntilSettled() |
| 2920 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2921 | 'SUCCESS') |
| 2922 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2923 | 'SUCCESS') |
| 2924 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2925 | 'SUCCESS') |
| 2926 | self.assertEqual(A.data['status'], 'MERGED') |
| 2927 | self.assertEqual(A.reported, 2) |
| 2928 | |
| 2929 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2930 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2931 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2932 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2933 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2934 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2935 | |
| 2936 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2937 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2938 | B.addApproval('Code-Review', 2) |
| 2939 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2940 | self.waitUntilSettled() |
| 2941 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2942 | 'SUCCESS') |
| 2943 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2944 | 'SUCCESS') |
| 2945 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2946 | 'SUCCESS') |
| 2947 | self.assertEqual(B.data['status'], 'MERGED') |
| 2948 | self.assertEqual(B.reported, 2) |
| 2949 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 2950 | @simple_layout('layouts/untrusted-secrets.yaml') |
| 2951 | def test_untrusted_secrets(self): |
| 2952 | "Test untrusted secrets" |
| 2953 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2954 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2955 | self.waitUntilSettled() |
| 2956 | |
| 2957 | self.assertHistory([]) |
| 2958 | self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") |
James E. Blair | 8eb564a | 2017-08-10 09:21:41 -0700 | [diff] [blame] | 2959 | self.assertIn('does not allow post-review job', |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 2960 | A.messages[0]) |
| 2961 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2962 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2963 | def test_tags(self): |
| 2964 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2965 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2966 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2967 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2968 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2969 | self.waitUntilSettled() |
| 2970 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2971 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2972 | |
| 2973 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2974 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2975 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2976 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2977 | |
| 2978 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2979 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2980 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2981 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2982 | def test_timer(self): |
| 2983 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2984 | # This test can not use simple_layout because it must start |
| 2985 | # with a configuration which does not include a |
| 2986 | # timer-triggered job so that we have an opportunity to set |
| 2987 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2988 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2989 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2990 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2991 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2992 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2993 | # The pipeline triggers every second, so we should have seen |
| 2994 | # several by now. |
| 2995 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2996 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2997 | |
| 2998 | self.assertEqual(len(self.builds), 2) |
| 2999 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3000 | port = self.webapp.server.socket.getsockname()[1] |
| 3001 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 3002 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3003 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 3004 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 3005 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3006 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3007 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3008 | # Stop queuing timer triggered jobs so that the assertions |
| 3009 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3010 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3011 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3012 | self.waitUntilSettled() |
| 3013 | # If APScheduler is in mid-event when we remove the job, we |
| 3014 | # can end up with one more event firing, so give it an extra |
| 3015 | # second to settle. |
| 3016 | time.sleep(1) |
| 3017 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3018 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3019 | self.waitUntilSettled() |
| 3020 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3021 | self.assertHistory([ |
| 3022 | dict(name='project-bitrot', result='SUCCESS', |
| 3023 | ref='refs/heads/master'), |
| 3024 | dict(name='project-bitrot', result='SUCCESS', |
| 3025 | ref='refs/heads/stable'), |
| 3026 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3027 | |
| 3028 | data = json.loads(data) |
| 3029 | status_jobs = set() |
| 3030 | for p in data['pipelines']: |
| 3031 | for q in p['change_queues']: |
| 3032 | for head in q['heads']: |
| 3033 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3034 | for job in change['jobs']: |
| 3035 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3036 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3037 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3038 | def test_idle(self): |
| 3039 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3040 | # This test can not use simple_layout because it must start |
| 3041 | # with a configuration which does not include a |
| 3042 | # timer-triggered job so that we have an opportunity to set |
| 3043 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3044 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3045 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3046 | for x in range(1, 3): |
| 3047 | # Test that timer triggers periodic jobs even across |
| 3048 | # layout config reloads. |
| 3049 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3050 | self.commitConfigUpdate('common-config', |
| 3051 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3052 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3053 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3054 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3055 | # The pipeline triggers every second, so we should have seen |
| 3056 | # several by now. |
| 3057 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3058 | |
| 3059 | # Stop queuing timer triggered jobs so that the assertions |
| 3060 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3061 | self.commitConfigUpdate('common-config', |
| 3062 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3063 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3064 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3065 | # If APScheduler is in mid-event when we remove the job, |
| 3066 | # we can end up with one more event firing, so give it an |
| 3067 | # extra second to settle. |
| 3068 | time.sleep(1) |
| 3069 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3070 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3071 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3072 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3073 | self.waitUntilSettled() |
| 3074 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3075 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3076 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3077 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3078 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3079 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3080 | self.waitUntilSettled() |
| 3081 | |
| 3082 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3083 | self.waitUntilSettled() |
| 3084 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3085 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3086 | |
| 3087 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3088 | # work on the knowledge of what the first message should be as |
| 3089 | # it is only configured to go to SMTP. |
| 3090 | |
| 3091 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3092 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3093 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3094 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3095 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3096 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3097 | |
| 3098 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3099 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3100 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3101 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3102 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3103 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3104 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3105 | def test_timer_smtp(self): |
| 3106 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3107 | # This test can not use simple_layout because it must start |
| 3108 | # with a configuration which does not include a |
| 3109 | # timer-triggered job so that we have an opportunity to set |
| 3110 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3111 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3112 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3113 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3114 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3115 | # The pipeline triggers every second, so we should have seen |
| 3116 | # several by now. |
| 3117 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3118 | self.waitUntilSettled() |
| 3119 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3120 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3121 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3122 | self.waitUntilSettled() |
| 3123 | self.assertEqual(len(self.history), 2) |
| 3124 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3125 | self.assertEqual(self.getJobFromHistory( |
| 3126 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3127 | self.assertEqual(self.getJobFromHistory( |
| 3128 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3129 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3130 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3131 | |
| 3132 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3133 | # work on the knowledge of what the first message should be as |
| 3134 | # it is only configured to go to SMTP. |
| 3135 | |
| 3136 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3137 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3138 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3139 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3140 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3141 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3142 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3143 | # Stop queuing timer triggered jobs and let any that may have |
| 3144 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3145 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3146 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3147 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3148 | # If APScheduler is in mid-event when we remove the job, we |
| 3149 | # can end up with one more event firing, so give it an extra |
| 3150 | # second to settle. |
| 3151 | time.sleep(1) |
| 3152 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3153 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3154 | self.waitUntilSettled() |
| 3155 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3156 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3157 | def test_timer_sshkey(self): |
| 3158 | "Test that a periodic job can setup SSH key authentication" |
| 3159 | self.worker.hold_jobs_in_build = True |
| 3160 | self.config.set('zuul', 'layout_config', |
| 3161 | 'tests/fixtures/layout-timer.yaml') |
| 3162 | self.sched.reconfigure(self.config) |
| 3163 | self.registerJobs() |
| 3164 | |
| 3165 | # The pipeline triggers every second, so we should have seen |
| 3166 | # several by now. |
| 3167 | time.sleep(5) |
| 3168 | self.waitUntilSettled() |
| 3169 | |
| 3170 | self.assertEqual(len(self.builds), 2) |
| 3171 | |
| 3172 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3173 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3174 | with open(ssh_wrapper) as f: |
| 3175 | ssh_wrapper_content = f.read() |
| 3176 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3177 | # In the unit tests Merger runs in the same process, |
| 3178 | # so we see its' environment variables |
| 3179 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3180 | |
| 3181 | self.worker.release('.*') |
| 3182 | self.waitUntilSettled() |
| 3183 | self.assertEqual(len(self.history), 2) |
| 3184 | |
| 3185 | self.assertEqual(self.getJobFromHistory( |
| 3186 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3187 | self.assertEqual(self.getJobFromHistory( |
| 3188 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3189 | |
| 3190 | # Stop queuing timer triggered jobs and let any that may have |
| 3191 | # queued through so that end of test assertions pass. |
| 3192 | self.config.set('zuul', 'layout_config', |
| 3193 | 'tests/fixtures/layout-no-timer.yaml') |
| 3194 | self.sched.reconfigure(self.config) |
| 3195 | self.registerJobs() |
| 3196 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3197 | # If APScheduler is in mid-event when we remove the job, we |
| 3198 | # can end up with one more event firing, so give it an extra |
| 3199 | # second to settle. |
| 3200 | time.sleep(1) |
| 3201 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3202 | self.worker.release('.*') |
| 3203 | self.waitUntilSettled() |
| 3204 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3205 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3206 | "Test that the RPC client can enqueue a change" |
| 3207 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3208 | A.addApproval('Code-Review', 2) |
| 3209 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3210 | |
| 3211 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3212 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3213 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3214 | r = client.enqueue(tenant='tenant-one', |
| 3215 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3216 | project='org/project', |
| 3217 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3218 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3219 | self.waitUntilSettled() |
| 3220 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3221 | 'SUCCESS') |
| 3222 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3223 | 'SUCCESS') |
| 3224 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3225 | 'SUCCESS') |
| 3226 | self.assertEqual(A.data['status'], 'MERGED') |
| 3227 | self.assertEqual(A.reported, 2) |
| 3228 | self.assertEqual(r, True) |
| 3229 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3230 | def test_client_enqueue_ref(self): |
| 3231 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3232 | p = "review.example.com/org/project" |
| 3233 | upstream = self.getUpstreamRepos([p]) |
| 3234 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3235 | A.setMerged() |
| 3236 | A_commit = str(upstream[p].commit('master')) |
| 3237 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3238 | |
| 3239 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3240 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3241 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3242 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3243 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3244 | pipeline='post', |
| 3245 | project='org/project', |
| 3246 | trigger='gerrit', |
| 3247 | ref='master', |
| 3248 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3249 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3250 | self.waitUntilSettled() |
| 3251 | job_names = [x.name for x in self.history] |
| 3252 | self.assertEqual(len(self.history), 1) |
| 3253 | self.assertIn('project-post', job_names) |
| 3254 | self.assertEqual(r, True) |
| 3255 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3256 | def test_client_enqueue_negative(self): |
| 3257 | "Test that the RPC client returns errors" |
| 3258 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3259 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3260 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3261 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3262 | "Invalid tenant"): |
| 3263 | r = client.enqueue(tenant='tenant-foo', |
| 3264 | pipeline='gate', |
| 3265 | project='org/project', |
| 3266 | trigger='gerrit', |
| 3267 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3268 | self.assertEqual(r, False) |
| 3269 | |
| 3270 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3271 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3272 | r = client.enqueue(tenant='tenant-one', |
| 3273 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3274 | project='project-does-not-exist', |
| 3275 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3276 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3277 | self.assertEqual(r, False) |
| 3278 | |
| 3279 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3280 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3281 | r = client.enqueue(tenant='tenant-one', |
| 3282 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3283 | project='org/project', |
| 3284 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3285 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3286 | self.assertEqual(r, False) |
| 3287 | |
| 3288 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3289 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3290 | r = client.enqueue(tenant='tenant-one', |
| 3291 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3292 | project='org/project', |
| 3293 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3294 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3295 | self.assertEqual(r, False) |
| 3296 | |
| 3297 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3298 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3299 | r = client.enqueue(tenant='tenant-one', |
| 3300 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3301 | project='org/project', |
| 3302 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3303 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3304 | self.assertEqual(r, False) |
| 3305 | |
| 3306 | self.waitUntilSettled() |
| 3307 | self.assertEqual(len(self.history), 0) |
| 3308 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3309 | |
| 3310 | def test_client_promote(self): |
| 3311 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3312 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3313 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3314 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3315 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3316 | A.addApproval('Code-Review', 2) |
| 3317 | B.addApproval('Code-Review', 2) |
| 3318 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3319 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3320 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3321 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3322 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3323 | |
| 3324 | self.waitUntilSettled() |
| 3325 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3326 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3327 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3328 | enqueue_times = {} |
| 3329 | for item in items: |
| 3330 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3331 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3332 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3333 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3334 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3335 | r = client.promote(tenant='tenant-one', |
| 3336 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3337 | change_ids=['2,1', '3,1']) |
| 3338 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3339 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3340 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3341 | for item in items: |
| 3342 | self.assertEqual( |
| 3343 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3344 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3345 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3346 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3347 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3348 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3349 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3350 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3351 | self.waitUntilSettled() |
| 3352 | |
| 3353 | self.assertEqual(len(self.builds), 6) |
| 3354 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3355 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3356 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3357 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3358 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3359 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3360 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3361 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3362 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3363 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3364 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3365 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3366 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3367 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3368 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3369 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3370 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3371 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3372 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3373 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3374 | self.waitUntilSettled() |
| 3375 | |
| 3376 | self.assertEqual(A.data['status'], 'MERGED') |
| 3377 | self.assertEqual(A.reported, 2) |
| 3378 | self.assertEqual(B.data['status'], 'MERGED') |
| 3379 | self.assertEqual(B.reported, 2) |
| 3380 | self.assertEqual(C.data['status'], 'MERGED') |
| 3381 | self.assertEqual(C.reported, 2) |
| 3382 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3383 | self.assertEqual(r, True) |
| 3384 | |
| 3385 | def test_client_promote_dependent(self): |
| 3386 | "Test that the RPC client can promote a dependent change" |
| 3387 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3388 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3389 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3390 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3391 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3392 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3393 | |
| 3394 | C.setDependsOn(B, 1) |
| 3395 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3396 | A.addApproval('Code-Review', 2) |
| 3397 | B.addApproval('Code-Review', 2) |
| 3398 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3399 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3400 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3401 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3402 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3403 | |
| 3404 | self.waitUntilSettled() |
| 3405 | |
| 3406 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3407 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3408 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3409 | r = client.promote(tenant='tenant-one', |
| 3410 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3411 | change_ids=['3,1']) |
| 3412 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3413 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3414 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3415 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3416 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3417 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3418 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3419 | self.waitUntilSettled() |
| 3420 | |
| 3421 | self.assertEqual(len(self.builds), 6) |
| 3422 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3423 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3424 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3425 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3426 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3427 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3428 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3429 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3430 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3431 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3432 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3433 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3434 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3435 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3436 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3437 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3438 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3439 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3440 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3441 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3442 | self.waitUntilSettled() |
| 3443 | |
| 3444 | self.assertEqual(A.data['status'], 'MERGED') |
| 3445 | self.assertEqual(A.reported, 2) |
| 3446 | self.assertEqual(B.data['status'], 'MERGED') |
| 3447 | self.assertEqual(B.reported, 2) |
| 3448 | self.assertEqual(C.data['status'], 'MERGED') |
| 3449 | self.assertEqual(C.reported, 2) |
| 3450 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3451 | self.assertEqual(r, True) |
| 3452 | |
| 3453 | def test_client_promote_negative(self): |
| 3454 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3455 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3456 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3457 | A.addApproval('Code-Review', 2) |
| 3458 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3459 | self.waitUntilSettled() |
| 3460 | |
| 3461 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3462 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3463 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3464 | |
| 3465 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3466 | r = client.promote(tenant='tenant-one', |
| 3467 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3468 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3469 | self.assertEqual(r, False) |
| 3470 | |
| 3471 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3472 | r = client.promote(tenant='tenant-one', |
| 3473 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3474 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3475 | self.assertEqual(r, False) |
| 3476 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3477 | self.executor_server.hold_jobs_in_build = False |
| 3478 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3479 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3480 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3481 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3482 | def test_queue_rate_limiting(self): |
| 3483 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3484 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3485 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3486 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3487 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3488 | |
| 3489 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3490 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3491 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3492 | A.addApproval('Code-Review', 2) |
| 3493 | B.addApproval('Code-Review', 2) |
| 3494 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3495 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3496 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3497 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3498 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3499 | self.waitUntilSettled() |
| 3500 | |
| 3501 | # Only A and B will have their merge jobs queued because |
| 3502 | # window is 2. |
| 3503 | self.assertEqual(len(self.builds), 2) |
| 3504 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3505 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3506 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3507 | # Release the merge jobs one at a time. |
| 3508 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3509 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3510 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3511 | self.waitUntilSettled() |
| 3512 | |
| 3513 | # Only A and B will have their test jobs queued because |
| 3514 | # window is 2. |
| 3515 | self.assertEqual(len(self.builds), 4) |
| 3516 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3517 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3518 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3519 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3520 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3521 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3522 | self.waitUntilSettled() |
| 3523 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3524 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3525 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3526 | # A failed so window is reduced by 1 to 1. |
| 3527 | self.assertEqual(queue.window, 1) |
| 3528 | self.assertEqual(queue.window_floor, 1) |
| 3529 | self.assertEqual(A.data['status'], 'NEW') |
| 3530 | |
| 3531 | # Gate is reset and only B's merge job is queued because |
| 3532 | # window shrunk to 1. |
| 3533 | self.assertEqual(len(self.builds), 1) |
| 3534 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3535 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3536 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3537 | self.waitUntilSettled() |
| 3538 | |
| 3539 | # Only B's test jobs are queued because window is still 1. |
| 3540 | self.assertEqual(len(self.builds), 2) |
| 3541 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3542 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3543 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3544 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3545 | self.waitUntilSettled() |
| 3546 | |
| 3547 | # B was successfully merged so window is increased to 2. |
| 3548 | self.assertEqual(queue.window, 2) |
| 3549 | self.assertEqual(queue.window_floor, 1) |
| 3550 | self.assertEqual(B.data['status'], 'MERGED') |
| 3551 | |
| 3552 | # Only C is left and its merge job is queued. |
| 3553 | self.assertEqual(len(self.builds), 1) |
| 3554 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3555 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3556 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3557 | self.waitUntilSettled() |
| 3558 | |
| 3559 | # After successful merge job the test jobs for C are queued. |
| 3560 | self.assertEqual(len(self.builds), 2) |
| 3561 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3562 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3563 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3564 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3565 | self.waitUntilSettled() |
| 3566 | |
| 3567 | # C successfully merged so window is bumped to 3. |
| 3568 | self.assertEqual(queue.window, 3) |
| 3569 | self.assertEqual(queue.window_floor, 1) |
| 3570 | self.assertEqual(C.data['status'], 'MERGED') |
| 3571 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3572 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3573 | def test_queue_rate_limiting_dependent(self): |
| 3574 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3575 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3576 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3577 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3578 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3579 | |
| 3580 | B.setDependsOn(A, 1) |
| 3581 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3582 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3583 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3584 | A.addApproval('Code-Review', 2) |
| 3585 | B.addApproval('Code-Review', 2) |
| 3586 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3587 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3588 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3589 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3590 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3591 | self.waitUntilSettled() |
| 3592 | |
| 3593 | # Only A and B will have their merge jobs queued because |
| 3594 | # window is 2. |
| 3595 | self.assertEqual(len(self.builds), 2) |
| 3596 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3597 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3598 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3599 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3600 | |
| 3601 | # Only A and B will have their test jobs queued because |
| 3602 | # window is 2. |
| 3603 | self.assertEqual(len(self.builds), 4) |
| 3604 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3605 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3606 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3607 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3608 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3609 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3610 | self.waitUntilSettled() |
| 3611 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3612 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3613 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3614 | # A failed so window is reduced by 1 to 1. |
| 3615 | self.assertEqual(queue.window, 1) |
| 3616 | self.assertEqual(queue.window_floor, 1) |
| 3617 | self.assertEqual(A.data['status'], 'NEW') |
| 3618 | self.assertEqual(B.data['status'], 'NEW') |
| 3619 | |
| 3620 | # Gate is reset and only C's merge job is queued because |
| 3621 | # window shrunk to 1 and A and B were dequeued. |
| 3622 | self.assertEqual(len(self.builds), 1) |
| 3623 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3624 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3625 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3626 | |
| 3627 | # Only C's test jobs are queued because window is still 1. |
| 3628 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3629 | builds = self.getSortedBuilds() |
| 3630 | self.assertEqual(builds[0].name, 'project-test1') |
| 3631 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3632 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3633 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3634 | self.waitUntilSettled() |
| 3635 | |
| 3636 | # C was successfully merged so window is increased to 2. |
| 3637 | self.assertEqual(queue.window, 2) |
| 3638 | self.assertEqual(queue.window_floor, 1) |
| 3639 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3640 | |
| 3641 | def test_worker_update_metadata(self): |
| 3642 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3643 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3644 | |
| 3645 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3646 | A.addApproval('Code-Review', 2) |
| 3647 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3648 | self.waitUntilSettled() |
| 3649 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3650 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3651 | |
| 3652 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3653 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3654 | |
| 3655 | start = time.time() |
| 3656 | while True: |
| 3657 | if time.time() - start > 10: |
| 3658 | raise Exception("Timeout waiting for gearman server to report " |
| 3659 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3660 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3661 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3662 | break |
| 3663 | else: |
| 3664 | time.sleep(0) |
| 3665 | |
| 3666 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3667 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3668 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3669 | self.executor_server.hold_jobs_in_build = False |
| 3670 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3671 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3672 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3673 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3674 | def test_footer_message(self): |
| 3675 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3676 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3677 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3678 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3679 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3680 | self.waitUntilSettled() |
| 3681 | |
| 3682 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3683 | B.addApproval('Code-Review', 2) |
| 3684 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3685 | self.waitUntilSettled() |
| 3686 | |
| 3687 | self.assertEqual(2, len(self.smtp_messages)) |
| 3688 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3689 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3690 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3691 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3692 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3693 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3694 | For CI problems and help debugging, contact ci@example.org""" |
| 3695 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3696 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3697 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3698 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3699 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3700 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3701 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3702 | def test_unmanaged_project_start_message(self): |
| 3703 | "Test start reporting is not done for unmanaged projects." |
| 3704 | self.init_repo("org/project", tag='init') |
| 3705 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3706 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3707 | self.waitUntilSettled() |
| 3708 | |
| 3709 | self.assertEqual(0, len(A.messages)) |
| 3710 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3711 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3712 | def test_merge_failure_reporters(self): |
| 3713 | """Check that the config is set up correctly""" |
| 3714 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3715 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3716 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3717 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3718 | "dependencies was unable to be automatically merged with the " |
| 3719 | "current state of its repository. Please rebase the change and " |
| 3720 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3721 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3722 | self.assertEqual( |
| 3723 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3724 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3725 | |
| 3726 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3727 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3728 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3729 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3730 | |
| 3731 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3732 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 3733 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3734 | |
| 3735 | self.assertTrue( |
| 3736 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3737 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3738 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3739 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 3740 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3741 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3742 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3743 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3744 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3745 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3746 | gerritreporter.GerritReporter) and |
| 3747 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3748 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3749 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3750 | ) |
| 3751 | ) |
| 3752 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3753 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3754 | def test_merge_failure_reports(self): |
| 3755 | """Check that when a change fails to merge the correct message is sent |
| 3756 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3757 | self.updateConfigLayout( |
| 3758 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3759 | self.sched.reconfigure(self.config) |
| 3760 | self.registerJobs() |
| 3761 | |
| 3762 | # Check a test failure isn't reported to SMTP |
| 3763 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3764 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3765 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3766 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3767 | self.waitUntilSettled() |
| 3768 | |
| 3769 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3770 | self.assertEqual(0, len(self.smtp_messages)) |
| 3771 | |
| 3772 | # Check a merge failure is reported to SMTP |
| 3773 | # B should be merged, but C will conflict with B |
| 3774 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3775 | B.addPatchset(['conflict']) |
| 3776 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3777 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3778 | B.addApproval('Code-Review', 2) |
| 3779 | C.addApproval('Code-Review', 2) |
| 3780 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3781 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3782 | self.waitUntilSettled() |
| 3783 | |
| 3784 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3785 | self.assertEqual(1, len(self.smtp_messages)) |
| 3786 | self.assertEqual('The merge failed! For more information...', |
| 3787 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3788 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3789 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3790 | def test_default_merge_failure_reports(self): |
| 3791 | """Check that the default merge failure reports are correct.""" |
| 3792 | |
| 3793 | # A should report success, B should report merge failure. |
| 3794 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3795 | A.addPatchset(['conflict']) |
| 3796 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3797 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3798 | A.addApproval('Code-Review', 2) |
| 3799 | B.addApproval('Code-Review', 2) |
| 3800 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3801 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3802 | self.waitUntilSettled() |
| 3803 | |
| 3804 | self.assertEqual(3, len(self.history)) # A jobs |
| 3805 | self.assertEqual(A.reported, 2) |
| 3806 | self.assertEqual(B.reported, 2) |
| 3807 | self.assertEqual(A.data['status'], 'MERGED') |
| 3808 | self.assertEqual(B.data['status'], 'NEW') |
| 3809 | self.assertIn('Build succeeded', A.messages[1]) |
| 3810 | self.assertIn('Merge Failed', B.messages[1]) |
| 3811 | self.assertIn('automatically merged', B.messages[1]) |
| 3812 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3813 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3814 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3815 | def test_client_get_running_jobs(self): |
| 3816 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3817 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3818 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3819 | A.addApproval('Code-Review', 2) |
| 3820 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3821 | self.waitUntilSettled() |
| 3822 | |
| 3823 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3824 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3825 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3826 | |
| 3827 | # Wait for gearman server to send the initial workData back to zuul |
| 3828 | start = time.time() |
| 3829 | while True: |
| 3830 | if time.time() - start > 10: |
| 3831 | raise Exception("Timeout waiting for gearman server to report " |
| 3832 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3833 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3834 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3835 | break |
| 3836 | else: |
| 3837 | time.sleep(0) |
| 3838 | |
| 3839 | running_items = client.get_running_jobs() |
| 3840 | |
| 3841 | self.assertEqual(1, len(running_items)) |
| 3842 | running_item = running_items[0] |
| 3843 | self.assertEqual([], running_item['failing_reasons']) |
| 3844 | self.assertEqual([], running_item['items_behind']) |
| 3845 | self.assertEqual('https://hostname/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3846 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3847 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3848 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3849 | self.assertEqual(True, running_item['active']) |
| 3850 | self.assertEqual('1,1', running_item['id']) |
| 3851 | |
| 3852 | self.assertEqual(3, len(running_item['jobs'])) |
| 3853 | for job in running_item['jobs']: |
| 3854 | if job['name'] == 'project-merge': |
| 3855 | self.assertEqual('project-merge', job['name']) |
| 3856 | self.assertEqual('gate', job['pipeline']) |
| 3857 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3858 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3859 | 'static/stream.html?uuid={uuid}&logfile=console.log' |
| 3860 | .format(uuid=job['uuid']), job['url']) |
| 3861 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3862 | 'finger://{hostname}/{uuid}'.format( |
| 3863 | hostname=self.executor_server.hostname, |
| 3864 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3865 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3866 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3867 | self.assertEqual(False, job['canceled']) |
| 3868 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3869 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3870 | self.assertEqual('gate', job['pipeline']) |
| 3871 | break |
| 3872 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3873 | self.executor_server.hold_jobs_in_build = False |
| 3874 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3875 | self.waitUntilSettled() |
| 3876 | |
| 3877 | running_items = client.get_running_jobs() |
| 3878 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3879 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3880 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3881 | def test_nonvoting_pipeline(self): |
| 3882 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3883 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3884 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3885 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3886 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3887 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3888 | |
| 3889 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3890 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3891 | self.assertEqual( |
| 3892 | self.getJobFromHistory('experimental-project-test').result, |
| 3893 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3894 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3895 | |
| 3896 | def test_crd_gate(self): |
| 3897 | "Test cross-repo dependencies" |
| 3898 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3899 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3900 | A.addApproval('Code-Review', 2) |
| 3901 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3902 | |
| 3903 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3904 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3905 | AM2.setMerged() |
| 3906 | AM1.setMerged() |
| 3907 | |
| 3908 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3909 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3910 | BM2.setMerged() |
| 3911 | BM1.setMerged() |
| 3912 | |
| 3913 | # A -> AM1 -> AM2 |
| 3914 | # B -> BM1 -> BM2 |
| 3915 | # A Depends-On: B |
| 3916 | # M2 is here to make sure it is never queried. If it is, it |
| 3917 | # means zuul is walking down the entire history of merged |
| 3918 | # changes. |
| 3919 | |
| 3920 | B.setDependsOn(BM1, 1) |
| 3921 | BM1.setDependsOn(BM2, 1) |
| 3922 | |
| 3923 | A.setDependsOn(AM1, 1) |
| 3924 | AM1.setDependsOn(AM2, 1) |
| 3925 | |
| 3926 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3927 | A.subject, B.data['id']) |
| 3928 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3929 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3930 | self.waitUntilSettled() |
| 3931 | |
| 3932 | self.assertEqual(A.data['status'], 'NEW') |
| 3933 | self.assertEqual(B.data['status'], 'NEW') |
| 3934 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3935 | for connection in self.connections.connections.values(): |
James E. Blair | b970430 | 2017-10-11 16:42:18 -0700 | [diff] [blame] | 3936 | if hasattr(connection, '_change_cache'): |
| 3937 | connection._change_cache.clear() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3938 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3939 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3940 | B.addApproval('Approved', 1) |
| 3941 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3942 | self.waitUntilSettled() |
| 3943 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3944 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3945 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3946 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3947 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3948 | self.executor_server.hold_jobs_in_build = False |
| 3949 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3950 | self.waitUntilSettled() |
| 3951 | |
| 3952 | self.assertEqual(AM2.queried, 0) |
| 3953 | self.assertEqual(BM2.queried, 0) |
| 3954 | self.assertEqual(A.data['status'], 'MERGED') |
| 3955 | self.assertEqual(B.data['status'], 'MERGED') |
| 3956 | self.assertEqual(A.reported, 2) |
| 3957 | self.assertEqual(B.reported, 2) |
| 3958 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3959 | changes = self.getJobFromHistory( |
| 3960 | 'project-merge', 'org/project1').changes |
| 3961 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3962 | |
| 3963 | def test_crd_branch(self): |
| 3964 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3965 | |
| 3966 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3967 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3968 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3969 | C1 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C1') |
| 3970 | C2 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C2', |
| 3971 | status='ABANDONED') |
| 3972 | C1.data['id'] = B.data['id'] |
| 3973 | C2.data['id'] = B.data['id'] |
| 3974 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3975 | A.addApproval('Code-Review', 2) |
| 3976 | B.addApproval('Code-Review', 2) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3977 | C1.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3978 | |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3979 | # A Depends-On: B+C1 |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3980 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3981 | A.subject, B.data['id']) |
| 3982 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3983 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3984 | B.addApproval('Approved', 1) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3985 | C1.addApproval('Approved', 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3986 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3987 | self.waitUntilSettled() |
| 3988 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3989 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3990 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3991 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3992 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3993 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3994 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3995 | self.executor_server.hold_jobs_in_build = False |
| 3996 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3997 | self.waitUntilSettled() |
| 3998 | |
| 3999 | self.assertEqual(A.data['status'], 'MERGED') |
| 4000 | self.assertEqual(B.data['status'], 'MERGED') |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 4001 | self.assertEqual(C1.data['status'], 'MERGED') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4002 | self.assertEqual(A.reported, 2) |
| 4003 | self.assertEqual(B.reported, 2) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 4004 | self.assertEqual(C1.reported, 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4005 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 4006 | changes = self.getJobFromHistory( |
| 4007 | 'project-merge', 'org/project1').changes |
| 4008 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4009 | |
| 4010 | def test_crd_multiline(self): |
| 4011 | "Test multiple depends-on lines in commit" |
| 4012 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4013 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4014 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4015 | A.addApproval('Code-Review', 2) |
| 4016 | B.addApproval('Code-Review', 2) |
| 4017 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4018 | |
| 4019 | # A Depends-On: B+C |
| 4020 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 4021 | A.subject, B.data['id'], C.data['id']) |
| 4022 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4023 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4024 | B.addApproval('Approved', 1) |
| 4025 | C.addApproval('Approved', 1) |
| 4026 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4027 | self.waitUntilSettled() |
| 4028 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4029 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4030 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4031 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4032 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4033 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4034 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4035 | self.executor_server.hold_jobs_in_build = False |
| 4036 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4037 | self.waitUntilSettled() |
| 4038 | |
| 4039 | self.assertEqual(A.data['status'], 'MERGED') |
| 4040 | self.assertEqual(B.data['status'], 'MERGED') |
| 4041 | self.assertEqual(C.data['status'], 'MERGED') |
| 4042 | self.assertEqual(A.reported, 2) |
| 4043 | self.assertEqual(B.reported, 2) |
| 4044 | self.assertEqual(C.reported, 2) |
| 4045 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4046 | changes = self.getJobFromHistory( |
| 4047 | 'project-merge', 'org/project1').changes |
| 4048 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4049 | |
| 4050 | def test_crd_unshared_gate(self): |
| 4051 | "Test cross-repo dependencies in unshared gate queues" |
| 4052 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4053 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4054 | A.addApproval('Code-Review', 2) |
| 4055 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4056 | |
| 4057 | # A Depends-On: B |
| 4058 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4059 | A.subject, B.data['id']) |
| 4060 | |
| 4061 | # A and B do not share a queue, make sure that A is unable to |
| 4062 | # enqueue B (and therefore, A is unable to be enqueued). |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4063 | B.addApproval('Approved', 1) |
| 4064 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4065 | self.waitUntilSettled() |
| 4066 | |
| 4067 | self.assertEqual(A.data['status'], 'NEW') |
| 4068 | self.assertEqual(B.data['status'], 'NEW') |
| 4069 | self.assertEqual(A.reported, 0) |
| 4070 | self.assertEqual(B.reported, 0) |
| 4071 | self.assertEqual(len(self.history), 0) |
| 4072 | |
| 4073 | # Enqueue and merge B alone. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4074 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4075 | self.waitUntilSettled() |
| 4076 | |
| 4077 | self.assertEqual(B.data['status'], 'MERGED') |
| 4078 | self.assertEqual(B.reported, 2) |
| 4079 | |
| 4080 | # Now that B is merged, A should be able to be enqueued and |
| 4081 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4082 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4083 | self.waitUntilSettled() |
| 4084 | |
| 4085 | self.assertEqual(A.data['status'], 'MERGED') |
| 4086 | self.assertEqual(A.reported, 2) |
| 4087 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4088 | def test_crd_gate_reverse(self): |
| 4089 | "Test reverse cross-repo dependencies" |
| 4090 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4091 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4092 | A.addApproval('Code-Review', 2) |
| 4093 | B.addApproval('Code-Review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4094 | |
| 4095 | # A Depends-On: B |
| 4096 | |
| 4097 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4098 | A.subject, B.data['id']) |
| 4099 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4100 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4101 | self.waitUntilSettled() |
| 4102 | |
| 4103 | self.assertEqual(A.data['status'], 'NEW') |
| 4104 | self.assertEqual(B.data['status'], 'NEW') |
| 4105 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4106 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4107 | A.addApproval('Approved', 1) |
| 4108 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4109 | self.waitUntilSettled() |
| 4110 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4111 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4112 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4113 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4114 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4115 | self.executor_server.hold_jobs_in_build = False |
| 4116 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4117 | self.waitUntilSettled() |
| 4118 | |
| 4119 | self.assertEqual(A.data['status'], 'MERGED') |
| 4120 | self.assertEqual(B.data['status'], 'MERGED') |
| 4121 | self.assertEqual(A.reported, 2) |
| 4122 | self.assertEqual(B.reported, 2) |
| 4123 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4124 | changes = self.getJobFromHistory( |
| 4125 | 'project-merge', 'org/project1').changes |
| 4126 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4127 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4128 | def test_crd_cycle(self): |
| 4129 | "Test cross-repo dependency cycles" |
| 4130 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4131 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4132 | A.addApproval('Code-Review', 2) |
| 4133 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4134 | |
| 4135 | # A -> B -> A (via commit-depends) |
| 4136 | |
| 4137 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4138 | A.subject, B.data['id']) |
| 4139 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4140 | B.subject, A.data['id']) |
| 4141 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4142 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4143 | self.waitUntilSettled() |
| 4144 | |
| 4145 | self.assertEqual(A.reported, 0) |
| 4146 | self.assertEqual(B.reported, 0) |
| 4147 | self.assertEqual(A.data['status'], 'NEW') |
| 4148 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4149 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4150 | def test_crd_gate_unknown(self): |
| 4151 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4152 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4153 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4154 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4155 | A.addApproval('Code-Review', 2) |
| 4156 | B.addApproval('Code-Review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4157 | |
| 4158 | # A Depends-On: B |
| 4159 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4160 | A.subject, B.data['id']) |
| 4161 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4162 | B.addApproval('Approved', 1) |
| 4163 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4164 | self.waitUntilSettled() |
| 4165 | |
| 4166 | # Unknown projects cannot share a queue with any other |
| 4167 | # since they don't have common jobs with any other (they have no jobs). |
| 4168 | # Changes which depend on unknown project changes |
| 4169 | # should not be processed in dependent pipeline |
| 4170 | self.assertEqual(A.data['status'], 'NEW') |
| 4171 | self.assertEqual(B.data['status'], 'NEW') |
| 4172 | self.assertEqual(A.reported, 0) |
| 4173 | self.assertEqual(B.reported, 0) |
| 4174 | self.assertEqual(len(self.history), 0) |
| 4175 | |
James E. Blair | 7720b40 | 2017-06-07 08:51:49 -0700 | [diff] [blame] | 4176 | # Simulate change B being gated outside this layout Set the |
| 4177 | # change merged before submitting the event so that when the |
| 4178 | # event triggers a gerrit query to update the change, we get |
| 4179 | # the information that it was merged. |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4180 | B.setMerged() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4181 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4182 | self.waitUntilSettled() |
| 4183 | self.assertEqual(len(self.history), 0) |
| 4184 | |
| 4185 | # Now that B is merged, A should be able to be enqueued and |
| 4186 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4187 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4188 | self.waitUntilSettled() |
| 4189 | |
| 4190 | self.assertEqual(A.data['status'], 'MERGED') |
| 4191 | self.assertEqual(A.reported, 2) |
| 4192 | self.assertEqual(B.data['status'], 'MERGED') |
| 4193 | self.assertEqual(B.reported, 0) |
| 4194 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4195 | def test_crd_check(self): |
| 4196 | "Test cross-repo dependencies in independent pipelines" |
| 4197 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4198 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4199 | self.gearman_server.hold_jobs_in_queue = True |
| 4200 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4201 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4202 | |
| 4203 | # A Depends-On: B |
| 4204 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4205 | A.subject, B.data['id']) |
| 4206 | |
| 4207 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4208 | self.waitUntilSettled() |
| 4209 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4210 | self.gearman_server.hold_jobs_in_queue = False |
| 4211 | self.gearman_server.release() |
| 4212 | self.waitUntilSettled() |
| 4213 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4214 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4215 | self.waitUntilSettled() |
| 4216 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4217 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4218 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4219 | self.executor_server.hold_jobs_in_build = False |
| 4220 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4221 | self.waitUntilSettled() |
| 4222 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4223 | self.assertEqual(A.data['status'], 'NEW') |
| 4224 | self.assertEqual(B.data['status'], 'NEW') |
| 4225 | self.assertEqual(A.reported, 1) |
| 4226 | self.assertEqual(B.reported, 0) |
| 4227 | |
| 4228 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4229 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4230 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4231 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4232 | def test_crd_check_git_depends(self): |
| 4233 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4234 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4235 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4236 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4237 | |
| 4238 | # Add two git-dependent changes and make sure they both report |
| 4239 | # success. |
| 4240 | B.setDependsOn(A, 1) |
| 4241 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4242 | self.waitUntilSettled() |
| 4243 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4244 | self.waitUntilSettled() |
| 4245 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4246 | self.orderedRelease() |
| 4247 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4248 | self.waitUntilSettled() |
| 4249 | |
| 4250 | self.assertEqual(A.data['status'], 'NEW') |
| 4251 | self.assertEqual(B.data['status'], 'NEW') |
| 4252 | self.assertEqual(A.reported, 1) |
| 4253 | self.assertEqual(B.reported, 1) |
| 4254 | |
| 4255 | self.assertEqual(self.history[0].changes, '1,1') |
| 4256 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4257 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4258 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4259 | |
| 4260 | self.assertIn('Build succeeded', A.messages[0]) |
| 4261 | self.assertIn('Build succeeded', B.messages[0]) |
| 4262 | |
| 4263 | def test_crd_check_duplicate(self): |
| 4264 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4265 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4266 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4267 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4268 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4269 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4270 | |
| 4271 | # Add two git-dependent changes... |
| 4272 | B.setDependsOn(A, 1) |
| 4273 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4274 | self.waitUntilSettled() |
| 4275 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4276 | |
| 4277 | # ...make sure the live one is not duplicated... |
| 4278 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4279 | self.waitUntilSettled() |
| 4280 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4281 | |
| 4282 | # ...but the non-live one is able to be. |
| 4283 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4284 | self.waitUntilSettled() |
| 4285 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4286 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4287 | # Release jobs in order to avoid races with change A jobs |
| 4288 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4289 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4290 | self.executor_server.hold_jobs_in_build = False |
| 4291 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4292 | self.waitUntilSettled() |
| 4293 | |
| 4294 | self.assertEqual(A.data['status'], 'NEW') |
| 4295 | self.assertEqual(B.data['status'], 'NEW') |
| 4296 | self.assertEqual(A.reported, 1) |
| 4297 | self.assertEqual(B.reported, 1) |
| 4298 | |
| 4299 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4300 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4301 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4302 | |
| 4303 | self.assertIn('Build succeeded', A.messages[0]) |
| 4304 | self.assertIn('Build succeeded', B.messages[0]) |
| 4305 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4306 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4307 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4308 | |
| 4309 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4310 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4311 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4312 | |
| 4313 | # A Depends-On: B |
| 4314 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4315 | A.subject, B.data['id']) |
| 4316 | |
| 4317 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4318 | self.waitUntilSettled() |
| 4319 | |
| 4320 | self.sched.reconfigure(self.config) |
| 4321 | |
| 4322 | # Make sure the items still share a change queue, and the |
| 4323 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4324 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4325 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4326 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4327 | first_item = queue.queue[0] |
| 4328 | for item in queue.queue: |
| 4329 | self.assertEqual(item.queue, first_item.queue) |
| 4330 | self.assertFalse(first_item.live) |
| 4331 | self.assertTrue(queue.queue[1].live) |
| 4332 | |
| 4333 | self.gearman_server.hold_jobs_in_queue = False |
| 4334 | self.gearman_server.release() |
| 4335 | self.waitUntilSettled() |
| 4336 | |
| 4337 | self.assertEqual(A.data['status'], 'NEW') |
| 4338 | self.assertEqual(B.data['status'], 'NEW') |
| 4339 | self.assertEqual(A.reported, 1) |
| 4340 | self.assertEqual(B.reported, 0) |
| 4341 | |
| 4342 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4343 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4344 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4345 | def test_crd_check_reconfiguration(self): |
| 4346 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4347 | |
| 4348 | def test_crd_undefined_project(self): |
| 4349 | """Test that undefined projects in dependencies are handled for |
| 4350 | independent pipelines""" |
| 4351 | # It's a hack for fake gerrit, |
| 4352 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4353 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4354 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4355 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4356 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4357 | def test_crd_check_ignore_dependencies(self): |
| 4358 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4359 | |
| 4360 | self.gearman_server.hold_jobs_in_queue = True |
| 4361 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4362 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4363 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4364 | |
| 4365 | # A Depends-On: B |
| 4366 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4367 | A.subject, B.data['id']) |
| 4368 | # C git-depends on B |
| 4369 | C.setDependsOn(B, 1) |
| 4370 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4371 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4372 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4373 | self.waitUntilSettled() |
| 4374 | |
| 4375 | # Make sure none of the items share a change queue, and all |
| 4376 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4377 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4378 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4379 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4380 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4381 | for item in check_pipeline.getAllItems(): |
| 4382 | self.assertTrue(item.live) |
| 4383 | |
| 4384 | self.gearman_server.hold_jobs_in_queue = False |
| 4385 | self.gearman_server.release() |
| 4386 | self.waitUntilSettled() |
| 4387 | |
| 4388 | self.assertEqual(A.data['status'], 'NEW') |
| 4389 | self.assertEqual(B.data['status'], 'NEW') |
| 4390 | self.assertEqual(C.data['status'], 'NEW') |
| 4391 | self.assertEqual(A.reported, 1) |
| 4392 | self.assertEqual(B.reported, 1) |
| 4393 | self.assertEqual(C.reported, 1) |
| 4394 | |
| 4395 | # Each job should have tested exactly one change |
| 4396 | for job in self.history: |
| 4397 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4398 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4399 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4400 | def test_crd_check_transitive(self): |
| 4401 | "Test transitive cross-repo dependencies" |
| 4402 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4403 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4404 | # and C,2 (not C,1 which would indicate stale data in the |
| 4405 | # cache for B). |
| 4406 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4407 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4408 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4409 | |
| 4410 | # A Depends-On: B |
| 4411 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4412 | A.subject, B.data['id']) |
| 4413 | |
| 4414 | # B Depends-On: C |
| 4415 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4416 | B.subject, C.data['id']) |
| 4417 | |
| 4418 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4419 | self.waitUntilSettled() |
| 4420 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4421 | |
| 4422 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4423 | self.waitUntilSettled() |
| 4424 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4425 | |
| 4426 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4427 | self.waitUntilSettled() |
| 4428 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4429 | |
| 4430 | C.addPatchset() |
| 4431 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4432 | self.waitUntilSettled() |
| 4433 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4434 | |
| 4435 | A.addPatchset() |
| 4436 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4437 | self.waitUntilSettled() |
| 4438 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4439 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4440 | def test_crd_check_unknown(self): |
| 4441 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4442 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4443 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4444 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4445 | # A Depends-On: B |
| 4446 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4447 | A.subject, B.data['id']) |
| 4448 | |
| 4449 | # Make sure zuul has seen an event on B. |
| 4450 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4451 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4452 | self.waitUntilSettled() |
| 4453 | |
| 4454 | self.assertEqual(A.data['status'], 'NEW') |
| 4455 | self.assertEqual(A.reported, 1) |
| 4456 | self.assertEqual(B.data['status'], 'NEW') |
| 4457 | self.assertEqual(B.reported, 0) |
| 4458 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4459 | def test_crd_cycle_join(self): |
| 4460 | "Test an updated change creates a cycle" |
| 4461 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4462 | |
| 4463 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4464 | self.waitUntilSettled() |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4465 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4466 | |
| 4467 | # Create B->A |
| 4468 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4469 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4470 | B.subject, A.data['id']) |
| 4471 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4472 | self.waitUntilSettled() |
| 4473 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4474 | # Dep is there so zuul should have reported on B |
| 4475 | self.assertEqual(B.reported, 1) |
| 4476 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4477 | # Update A to add A->B (a cycle). |
| 4478 | A.addPatchset() |
| 4479 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4480 | A.subject, B.data['id']) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4481 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4482 | self.waitUntilSettled() |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4483 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4484 | # Dependency cycle injected so zuul should not have reported again on A |
| 4485 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4486 | |
| 4487 | # Now if we update B to remove the depends-on, everything |
| 4488 | # should be okay. B; A->B |
| 4489 | |
| 4490 | B.addPatchset() |
| 4491 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4492 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4493 | self.waitUntilSettled() |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4494 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4495 | # Cycle was removed so now zuul should have reported again on A |
| 4496 | self.assertEqual(A.reported, 2) |
| 4497 | |
| 4498 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 4499 | self.waitUntilSettled() |
| 4500 | self.assertEqual(B.reported, 2) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4501 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4502 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4503 | def test_disable_at(self): |
| 4504 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4505 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4506 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4507 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4508 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4509 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4510 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4511 | |
| 4512 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4513 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4514 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4515 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4516 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4517 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4518 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4519 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4520 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4521 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4522 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4523 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4524 | self.executor_server.failJob('project-test1', A) |
| 4525 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4526 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4527 | self.executor_server.failJob('project-test1', D) |
| 4528 | self.executor_server.failJob('project-test1', E) |
| 4529 | self.executor_server.failJob('project-test1', F) |
| 4530 | self.executor_server.failJob('project-test1', G) |
| 4531 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4532 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4533 | self.executor_server.failJob('project-test1', J) |
| 4534 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4535 | |
| 4536 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4537 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4538 | self.waitUntilSettled() |
| 4539 | |
| 4540 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4541 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4542 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4543 | |
| 4544 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4545 | self.waitUntilSettled() |
| 4546 | |
| 4547 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4548 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4549 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4550 | |
| 4551 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4552 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4553 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4554 | self.waitUntilSettled() |
| 4555 | |
| 4556 | # We should be disabled now |
| 4557 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4558 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4559 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4560 | |
| 4561 | # We need to wait between each of these patches to make sure the |
| 4562 | # smtp messages come back in an expected order |
| 4563 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4564 | self.waitUntilSettled() |
| 4565 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4566 | self.waitUntilSettled() |
| 4567 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4568 | self.waitUntilSettled() |
| 4569 | |
| 4570 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4571 | # leaving a message on each change |
| 4572 | self.assertEqual(1, len(A.messages)) |
| 4573 | self.assertIn('Build failed.', A.messages[0]) |
| 4574 | self.assertEqual(1, len(B.messages)) |
| 4575 | self.assertIn('Build failed.', B.messages[0]) |
| 4576 | self.assertEqual(1, len(C.messages)) |
| 4577 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4578 | self.assertEqual(1, len(D.messages)) |
| 4579 | self.assertIn('Build failed.', D.messages[0]) |
| 4580 | self.assertEqual(1, len(E.messages)) |
| 4581 | self.assertIn('Build failed.', E.messages[0]) |
| 4582 | self.assertEqual(1, len(F.messages)) |
| 4583 | self.assertIn('Build failed.', F.messages[0]) |
| 4584 | |
| 4585 | # The last 3 (GHI) would have only reported via smtp. |
| 4586 | self.assertEqual(3, len(self.smtp_messages)) |
| 4587 | self.assertEqual(0, len(G.messages)) |
| 4588 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4589 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4590 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4591 | self.assertEqual(0, len(H.messages)) |
| 4592 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4593 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4594 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4595 | self.assertEqual(0, len(I.messages)) |
| 4596 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4597 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4598 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4599 | |
| 4600 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4601 | # comes out of disabled |
| 4602 | self.sched.reconfigure(self.config) |
| 4603 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4604 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4605 | |
| 4606 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4607 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4608 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4609 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4610 | |
| 4611 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4612 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4613 | self.waitUntilSettled() |
| 4614 | |
| 4615 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4616 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4617 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4618 | |
| 4619 | # J and K went back to gerrit |
| 4620 | self.assertEqual(1, len(J.messages)) |
| 4621 | self.assertIn('Build failed.', J.messages[0]) |
| 4622 | self.assertEqual(1, len(K.messages)) |
| 4623 | self.assertIn('Build failed.', K.messages[0]) |
| 4624 | # No more messages reported via smtp |
| 4625 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4626 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4627 | @simple_layout('layouts/one-job-project.yaml') |
| 4628 | def test_one_job_project(self): |
| 4629 | "Test that queueing works with one job" |
| 4630 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4631 | 'master', 'A') |
| 4632 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4633 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4634 | A.addApproval('Code-Review', 2) |
| 4635 | B.addApproval('Code-Review', 2) |
| 4636 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4637 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4638 | self.waitUntilSettled() |
| 4639 | |
| 4640 | self.assertEqual(A.data['status'], 'MERGED') |
| 4641 | self.assertEqual(A.reported, 2) |
| 4642 | self.assertEqual(B.data['status'], 'MERGED') |
| 4643 | self.assertEqual(B.reported, 2) |
| 4644 | |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4645 | def test_job_aborted(self): |
| 4646 | "Test that if a execute server aborts a job, it is run again" |
| 4647 | self.executor_server.hold_jobs_in_build = True |
| 4648 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4649 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4650 | self.waitUntilSettled() |
| 4651 | |
| 4652 | self.executor_server.release('.*-merge') |
| 4653 | self.waitUntilSettled() |
| 4654 | |
| 4655 | self.assertEqual(len(self.builds), 2) |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4656 | |
| 4657 | # first abort |
| 4658 | self.builds[0].aborted = True |
| 4659 | self.executor_server.release('.*-test*') |
| 4660 | self.waitUntilSettled() |
| 4661 | self.assertEqual(len(self.builds), 1) |
| 4662 | |
| 4663 | # second abort |
| 4664 | self.builds[0].aborted = True |
| 4665 | self.executor_server.release('.*-test*') |
| 4666 | self.waitUntilSettled() |
| 4667 | self.assertEqual(len(self.builds), 1) |
| 4668 | |
| 4669 | # third abort |
| 4670 | self.builds[0].aborted = True |
| 4671 | self.executor_server.release('.*-test*') |
| 4672 | self.waitUntilSettled() |
| 4673 | self.assertEqual(len(self.builds), 1) |
| 4674 | |
| 4675 | # fourth abort |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4676 | self.builds[0].aborted = True |
| 4677 | self.executor_server.release('.*-test*') |
| 4678 | self.waitUntilSettled() |
| 4679 | self.assertEqual(len(self.builds), 1) |
| 4680 | |
| 4681 | self.executor_server.hold_jobs_in_build = False |
| 4682 | self.executor_server.release() |
| 4683 | self.waitUntilSettled() |
| 4684 | |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4685 | self.assertEqual(len(self.history), 7) |
| 4686 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4687 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 4688 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4689 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4690 | "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] | 4691 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4692 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4693 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4694 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4695 | self.waitUntilSettled() |
| 4696 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4697 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4698 | self.waitUntilSettled() |
| 4699 | |
| 4700 | self.assertEqual(len(self.builds), 2) |
| 4701 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4702 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4703 | self.waitUntilSettled() |
| 4704 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4705 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4706 | self.assertEqual(len(self.builds), 1, |
| 4707 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4708 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4709 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4710 | self.waitUntilSettled() |
| 4711 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4712 | self.executor_server.hold_jobs_in_build = False |
| 4713 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4714 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4715 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4716 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4717 | self.assertEqual(A.reported, 1) |
| 4718 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4719 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4720 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4721 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4722 | |
| 4723 | self.fake_nodepool.paused = True |
| 4724 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4725 | A.addApproval('Code-Review', 2) |
| 4726 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4727 | self.waitUntilSettled() |
| 4728 | |
| 4729 | self.zk.client.stop() |
| 4730 | self.zk.client.start() |
| 4731 | self.fake_nodepool.paused = False |
| 4732 | self.waitUntilSettled() |
| 4733 | |
| 4734 | self.assertEqual(A.data['status'], 'MERGED') |
| 4735 | self.assertEqual(A.reported, 2) |
| 4736 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4737 | def test_nodepool_failure(self): |
| 4738 | "Test that jobs are reported after a nodepool failure" |
| 4739 | |
| 4740 | self.fake_nodepool.paused = True |
| 4741 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4742 | A.addApproval('Code-Review', 2) |
| 4743 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4744 | self.waitUntilSettled() |
| 4745 | |
| 4746 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4747 | self.fake_nodepool.addFailRequest(req) |
| 4748 | |
| 4749 | self.fake_nodepool.paused = False |
| 4750 | self.waitUntilSettled() |
| 4751 | |
| 4752 | self.assertEqual(A.data['status'], 'NEW') |
| 4753 | self.assertEqual(A.reported, 2) |
| 4754 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4755 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4756 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4757 | |
Monty Taylor | 6dc5bc1 | 2017-09-29 15:47:31 -0500 | [diff] [blame] | 4758 | def test_nodepool_priority(self): |
| 4759 | "Test that nodes are requested at the correct priority" |
| 4760 | |
| 4761 | self.fake_nodepool.paused = True |
| 4762 | |
| 4763 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4764 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4765 | |
| 4766 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4767 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4768 | |
| 4769 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4770 | C.addApproval('Code-Review', 2) |
| 4771 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 4772 | |
| 4773 | self.waitUntilSettled() |
| 4774 | |
| 4775 | reqs = self.fake_nodepool.getNodeRequests() |
| 4776 | |
| 4777 | # The requests come back sorted by oid. Since we have three requests |
| 4778 | # for the three changes each with a different priority. |
| 4779 | # Also they get a serial number based on order they were received |
| 4780 | # so the number on the endof the oid should map to order submitted. |
| 4781 | |
| 4782 | # * gate first - high priority - change C |
| 4783 | self.assertEqual(reqs[0]['_oid'], '100-0000000002') |
| 4784 | self.assertEqual(reqs[0]['node_types'], ['label1']) |
| 4785 | # * check second - normal priority - change B |
| 4786 | self.assertEqual(reqs[1]['_oid'], '200-0000000001') |
| 4787 | self.assertEqual(reqs[1]['node_types'], ['label1']) |
| 4788 | # * post third - low priority - change A |
| 4789 | # additionally, the post job defined uses an ubuntu-xenial node, |
| 4790 | # so we include that check just as an extra verification |
| 4791 | self.assertEqual(reqs[2]['_oid'], '300-0000000000') |
| 4792 | self.assertEqual(reqs[2]['node_types'], ['ubuntu-xenial']) |
| 4793 | |
| 4794 | self.fake_nodepool.paused = False |
| 4795 | self.waitUntilSettled() |
| 4796 | |
James E. Blair | fceaf41 | 2017-09-29 13:44:57 -0700 | [diff] [blame] | 4797 | @simple_layout('layouts/multiple-templates.yaml') |
| 4798 | def test_multiple_project_templates(self): |
| 4799 | # Test that applying multiple project templates to a project |
| 4800 | # doesn't alter them when used for a second project. |
| 4801 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4802 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4803 | self.waitUntilSettled() |
| 4804 | |
| 4805 | build = self.getJobFromHistory('py27') |
| 4806 | self.assertEqual(build.parameters['zuul']['jobtags'], []) |
| 4807 | |
James E. Blair | 29c7700 | 2017-10-05 14:56:35 -0700 | [diff] [blame] | 4808 | def test_pending_merge_in_reconfig(self): |
| 4809 | # Test that if we are waiting for an outstanding merge on |
| 4810 | # reconfiguration that we continue to do so. |
| 4811 | self.gearman_server.hold_merge_jobs_in_queue = True |
| 4812 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4813 | A.setMerged() |
| 4814 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4815 | self.waitUntilSettled() |
| 4816 | # Reconfigure while we still have an outstanding merge job |
| 4817 | self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'], |
| 4818 | None) |
| 4819 | self.waitUntilSettled() |
| 4820 | # Verify the merge job is still running and that the item is |
| 4821 | # in the pipeline |
| 4822 | self.assertEqual(len(self.sched.merger.jobs), 1) |
| 4823 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4824 | pipeline = tenant.layout.pipelines['post'] |
| 4825 | self.assertEqual(len(pipeline.getAllItems()), 1) |
| 4826 | self.gearman_server.hold_merge_jobs_in_queue = False |
| 4827 | self.gearman_server.release() |
| 4828 | self.waitUntilSettled() |
| 4829 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4830 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4831 | class TestExecutor(ZuulTestCase): |
| 4832 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4833 | |
| 4834 | def assertFinalState(self): |
| 4835 | # In this test, we expect to shut down in a non-final state, |
| 4836 | # so skip these checks. |
| 4837 | pass |
| 4838 | |
| 4839 | def assertCleanShutdown(self): |
| 4840 | self.log.debug("Assert clean shutdown") |
| 4841 | |
| 4842 | # After shutdown, make sure no jobs are running |
| 4843 | self.assertEqual({}, self.executor_server.job_workers) |
| 4844 | |
| 4845 | # Make sure that git.Repo objects have been garbage collected. |
| 4846 | repos = [] |
| 4847 | gc.collect() |
| 4848 | for obj in gc.get_objects(): |
| 4849 | if isinstance(obj, git.Repo): |
| 4850 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4851 | repos.append(obj) |
| 4852 | self.assertEqual(len(repos), 0) |
| 4853 | |
| 4854 | def test_executor_shutdown(self): |
| 4855 | "Test that the executor can shut down with jobs running" |
| 4856 | |
| 4857 | self.executor_server.hold_jobs_in_build = True |
| 4858 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4859 | A.addApproval('Code-Review', 2) |
| 4860 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4861 | self.waitUntilSettled() |
| 4862 | |
| 4863 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4864 | class TestDependencyGraph(ZuulTestCase): |
| 4865 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4866 | |
| 4867 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4868 | "Test a job in a dependency graph is queued only once" |
| 4869 | # Job dependencies, starting with A |
| 4870 | # A |
| 4871 | # / \ |
| 4872 | # B C |
| 4873 | # / \ / \ |
| 4874 | # D F E |
| 4875 | # | |
| 4876 | # G |
| 4877 | |
| 4878 | self.executor_server.hold_jobs_in_build = True |
| 4879 | change = self.fake_gerrit.addFakeChange( |
| 4880 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4881 | change.addApproval('Code-Review', 2) |
| 4882 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4883 | |
| 4884 | self.waitUntilSettled() |
| 4885 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4886 | |
| 4887 | self.executor_server.release('A') |
| 4888 | self.waitUntilSettled() |
| 4889 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4890 | |
| 4891 | self.executor_server.release('B') |
| 4892 | self.waitUntilSettled() |
| 4893 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4894 | |
| 4895 | self.executor_server.release('D') |
| 4896 | self.waitUntilSettled() |
| 4897 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4898 | |
| 4899 | self.executor_server.release('C') |
| 4900 | self.waitUntilSettled() |
| 4901 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4902 | |
| 4903 | self.executor_server.release('F') |
| 4904 | self.waitUntilSettled() |
| 4905 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4906 | |
| 4907 | self.executor_server.release('G') |
| 4908 | self.waitUntilSettled() |
| 4909 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4910 | |
| 4911 | self.executor_server.release('E') |
| 4912 | self.waitUntilSettled() |
| 4913 | self.assertEqual(len(self.builds), 0) |
| 4914 | |
| 4915 | self.executor_server.hold_jobs_in_build = False |
| 4916 | self.executor_server.release() |
| 4917 | self.waitUntilSettled() |
| 4918 | |
| 4919 | self.assertEqual(len(self.builds), 0) |
| 4920 | self.assertEqual(len(self.history), 7) |
| 4921 | |
| 4922 | self.assertEqual(change.data['status'], 'MERGED') |
| 4923 | self.assertEqual(change.reported, 2) |
| 4924 | |
| 4925 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4926 | "Test that a job waits till all dependencies are successful" |
| 4927 | # Job dependencies, starting with A |
| 4928 | # A |
| 4929 | # / \ |
| 4930 | # B C* |
| 4931 | # / \ / \ |
| 4932 | # D F E |
| 4933 | # | |
| 4934 | # G |
| 4935 | |
| 4936 | self.executor_server.hold_jobs_in_build = True |
| 4937 | change = self.fake_gerrit.addFakeChange( |
| 4938 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4939 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4940 | |
| 4941 | self.executor_server.failJob('C', change) |
| 4942 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4943 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4944 | |
| 4945 | self.waitUntilSettled() |
| 4946 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4947 | |
| 4948 | self.executor_server.release('A') |
| 4949 | self.waitUntilSettled() |
| 4950 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4951 | |
| 4952 | self.executor_server.release('B') |
| 4953 | self.waitUntilSettled() |
| 4954 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4955 | |
| 4956 | self.executor_server.release('D') |
| 4957 | self.waitUntilSettled() |
| 4958 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4959 | |
| 4960 | self.executor_server.release('C') |
| 4961 | self.waitUntilSettled() |
| 4962 | self.assertEqual(len(self.builds), 0) |
| 4963 | |
| 4964 | self.executor_server.hold_jobs_in_build = False |
| 4965 | self.executor_server.release() |
| 4966 | self.waitUntilSettled() |
| 4967 | |
| 4968 | self.assertEqual(len(self.builds), 0) |
| 4969 | self.assertEqual(len(self.history), 4) |
| 4970 | |
| 4971 | self.assertEqual(change.data['status'], 'NEW') |
| 4972 | self.assertEqual(change.reported, 2) |
| 4973 | |
| 4974 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4975 | class TestDuplicatePipeline(ZuulTestCase): |
| 4976 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4977 | |
| 4978 | def test_duplicate_pipelines(self): |
| 4979 | "Test that a change matching multiple pipelines works" |
| 4980 | |
| 4981 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4982 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4983 | self.waitUntilSettled() |
| 4984 | |
| 4985 | self.assertHistory([ |
| 4986 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4987 | pipeline='dup1'), |
| 4988 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4989 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4990 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4991 | |
| 4992 | self.assertEqual(len(A.messages), 2) |
| 4993 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4994 | if 'dup1' in A.messages[0]: |
| 4995 | self.assertIn('dup1', A.messages[0]) |
| 4996 | self.assertNotIn('dup2', A.messages[0]) |
| 4997 | self.assertIn('project-test1', A.messages[0]) |
| 4998 | self.assertIn('dup2', A.messages[1]) |
| 4999 | self.assertNotIn('dup1', A.messages[1]) |
| 5000 | self.assertIn('project-test1', A.messages[1]) |
| 5001 | else: |
| 5002 | self.assertIn('dup1', A.messages[1]) |
| 5003 | self.assertNotIn('dup2', A.messages[1]) |
| 5004 | self.assertIn('project-test1', A.messages[1]) |
| 5005 | self.assertIn('dup2', A.messages[0]) |
| 5006 | self.assertNotIn('dup1', A.messages[0]) |
| 5007 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 5008 | |
| 5009 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 5010 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 5011 | tenant_config_file = 'config/templated-project/main.yaml' |
| 5012 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5013 | def test_job_from_templates_executed(self): |
| 5014 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 5015 | |
| 5016 | A = self.fake_gerrit.addFakeChange( |
| 5017 | 'org/templated-project', 'master', 'A') |
| 5018 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5019 | self.waitUntilSettled() |
| 5020 | |
| 5021 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5022 | 'SUCCESS') |
| 5023 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 5024 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 5025 | |
| 5026 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5027 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 5028 | |
| 5029 | A = self.fake_gerrit.addFakeChange( |
| 5030 | 'org/layered-project', 'master', 'A') |
| 5031 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5032 | self.waitUntilSettled() |
| 5033 | |
| 5034 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5035 | 'SUCCESS') |
| 5036 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 5037 | 'SUCCESS') |
| 5038 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 5039 | ).result, 'SUCCESS') |
| 5040 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 5041 | ).result, 'SUCCESS') |
| 5042 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 5043 | ).result, 'SUCCESS') |
| 5044 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 5045 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5046 | |
James E. Blair | e74f571 | 2017-09-29 15:14:31 -0700 | [diff] [blame] | 5047 | def test_unimplied_branch_matchers(self): |
| 5048 | # This tests that there are no implied branch matchers added |
| 5049 | # by project templates. |
| 5050 | self.create_branch('org/layered-project', 'stable') |
| 5051 | |
| 5052 | A = self.fake_gerrit.addFakeChange( |
| 5053 | 'org/layered-project', 'stable', 'A') |
| 5054 | |
| 5055 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5056 | self.waitUntilSettled() |
| 5057 | |
| 5058 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5059 | 'SUCCESS') |
| 5060 | print(self.getJobFromHistory('project-test1'). |
| 5061 | parameters['zuul']['_inheritance_path']) |
| 5062 | |
| 5063 | def test_implied_branch_matchers(self): |
| 5064 | # This tests that there is an implied branch matcher when a |
| 5065 | # template is used on an in-repo project pipeline definition. |
| 5066 | self.create_branch('untrusted-config', 'stable') |
| 5067 | self.fake_gerrit.addEvent( |
| 5068 | self.fake_gerrit.getFakeBranchCreatedEvent( |
| 5069 | 'untrusted-config', 'stable')) |
| 5070 | self.waitUntilSettled() |
| 5071 | |
| 5072 | A = self.fake_gerrit.addFakeChange( |
| 5073 | 'untrusted-config', 'stable', 'A') |
| 5074 | |
| 5075 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5076 | self.waitUntilSettled() |
| 5077 | |
| 5078 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5079 | 'SUCCESS') |
| 5080 | print(self.getJobFromHistory('project-test1'). |
| 5081 | parameters['zuul']['_inheritance_path']) |
| 5082 | |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5083 | |
| 5084 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 5085 | tenant_config_file = 'config/success-url/main.yaml' |
| 5086 | |
| 5087 | def test_success_url(self): |
| 5088 | "Ensure bad build params are ignored" |
| 5089 | self.sched.reconfigure(self.config) |
| 5090 | self.init_repo('org/docs') |
| 5091 | |
| 5092 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 5093 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5094 | self.waitUntilSettled() |
| 5095 | |
| 5096 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 5097 | self.assertEqual(len(self.history), 2) |
| 5098 | |
| 5099 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 5100 | for build in self.history: |
| 5101 | if build.name == 'docs-draft-test': |
| 5102 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5103 | elif build.name == 'docs-draft-test2': |
| 5104 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5105 | |
| 5106 | # Two msgs: 'Starting...' + results |
| 5107 | self.assertEqual(len(self.smtp_messages), 2) |
| 5108 | body = self.smtp_messages[1]['body'].splitlines() |
| 5109 | self.assertEqual('Build succeeded.', body[0]) |
| 5110 | |
| 5111 | self.assertIn( |
| 5112 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 5113 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 5114 | body[2]) |
| 5115 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5116 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5117 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 5118 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 5119 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5120 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5121 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5122 | |
| 5123 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5124 | class TestSchedulerMerges(ZuulTestCase): |
| 5125 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5126 | |
| 5127 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5128 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5129 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5130 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5131 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 5132 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 5133 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5134 | A.addApproval('Code-Review', 2) |
| 5135 | B.addApproval('Code-Review', 2) |
| 5136 | C.addApproval('Code-Review', 2) |
| 5137 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5138 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5139 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5140 | self.waitUntilSettled() |
| 5141 | |
| 5142 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5143 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5144 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5145 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5146 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5147 | repo_messages.reverse() |
| 5148 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5149 | self.executor_server.hold_jobs_in_build = False |
| 5150 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5151 | self.waitUntilSettled() |
| 5152 | |
| 5153 | return repo_messages |
| 5154 | |
| 5155 | def _test_merge(self, mode): |
| 5156 | us_path = os.path.join( |
| 5157 | self.upstream_root, 'org/project-%s' % mode) |
| 5158 | expected_messages = [ |
| 5159 | 'initial commit', |
| 5160 | 'add content from fixture', |
| 5161 | # the intermediate commits order is nondeterministic |
| 5162 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 5163 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 5164 | ] |
| 5165 | result = self._test_project_merge_mode(mode) |
| 5166 | self.assertEqual(result[:2], expected_messages[:2]) |
| 5167 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 5168 | |
| 5169 | def test_project_merge_mode_merge(self): |
| 5170 | self._test_merge('merge') |
| 5171 | |
| 5172 | def test_project_merge_mode_merge_resolve(self): |
| 5173 | self._test_merge('merge-resolve') |
| 5174 | |
| 5175 | def test_project_merge_mode_cherrypick(self): |
| 5176 | expected_messages = [ |
| 5177 | 'initial commit', |
| 5178 | 'add content from fixture', |
| 5179 | 'A-1', |
| 5180 | 'B-1', |
| 5181 | 'C-1'] |
| 5182 | result = self._test_project_merge_mode('cherry-pick') |
| 5183 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5184 | |
| 5185 | def test_merge_branch(self): |
| 5186 | "Test that the right commits are on alternate branches" |
| 5187 | self.create_branch('org/project-merge-branches', 'mp') |
| 5188 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5189 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5190 | A = self.fake_gerrit.addFakeChange( |
| 5191 | 'org/project-merge-branches', 'mp', 'A') |
| 5192 | B = self.fake_gerrit.addFakeChange( |
| 5193 | 'org/project-merge-branches', 'mp', 'B') |
| 5194 | C = self.fake_gerrit.addFakeChange( |
| 5195 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5196 | A.addApproval('Code-Review', 2) |
| 5197 | B.addApproval('Code-Review', 2) |
| 5198 | C.addApproval('Code-Review', 2) |
| 5199 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5200 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5201 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5202 | self.waitUntilSettled() |
| 5203 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5204 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5205 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5206 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5207 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5208 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5209 | self.waitUntilSettled() |
| 5210 | |
| 5211 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 5212 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5213 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5214 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5215 | repo = git.Repo(path) |
| 5216 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5217 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5218 | repo_messages.reverse() |
| 5219 | correct_messages = [ |
| 5220 | 'initial commit', |
| 5221 | 'add content from fixture', |
| 5222 | 'mp commit', |
| 5223 | 'A-1', 'B-1', 'C-1'] |
| 5224 | self.assertEqual(repo_messages, correct_messages) |
| 5225 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5226 | self.executor_server.hold_jobs_in_build = False |
| 5227 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5228 | self.waitUntilSettled() |
| 5229 | |
| 5230 | def test_merge_multi_branch(self): |
| 5231 | "Test that dependent changes on multiple branches are merged" |
| 5232 | self.create_branch('org/project-merge-branches', 'mp') |
| 5233 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5234 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5235 | A = self.fake_gerrit.addFakeChange( |
| 5236 | 'org/project-merge-branches', 'master', 'A') |
| 5237 | B = self.fake_gerrit.addFakeChange( |
| 5238 | 'org/project-merge-branches', 'mp', 'B') |
| 5239 | C = self.fake_gerrit.addFakeChange( |
| 5240 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5241 | A.addApproval('Code-Review', 2) |
| 5242 | B.addApproval('Code-Review', 2) |
| 5243 | C.addApproval('Code-Review', 2) |
| 5244 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5245 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5246 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5247 | self.waitUntilSettled() |
| 5248 | |
| 5249 | job_A = None |
| 5250 | for job in self.builds: |
| 5251 | if 'project-merge' in job.name: |
| 5252 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5253 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5254 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 5255 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5256 | repo = git.Repo(path) |
| 5257 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5258 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5259 | repo_messages.reverse() |
| 5260 | correct_messages = [ |
| 5261 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5262 | self.assertEqual(repo_messages, correct_messages) |
| 5263 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5264 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5265 | self.waitUntilSettled() |
| 5266 | |
| 5267 | job_B = None |
| 5268 | for job in self.builds: |
| 5269 | if 'project-merge' in job.name: |
| 5270 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5271 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5272 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 5273 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5274 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5275 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5276 | repo_messages.reverse() |
| 5277 | correct_messages = [ |
| 5278 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5279 | self.assertEqual(repo_messages, correct_messages) |
| 5280 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5281 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5282 | self.waitUntilSettled() |
| 5283 | |
| 5284 | job_C = None |
| 5285 | for job in self.builds: |
| 5286 | if 'project-merge' in job.name: |
| 5287 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 5288 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5289 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 5290 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5291 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5292 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5293 | |
| 5294 | repo_messages.reverse() |
| 5295 | correct_messages = [ |
| 5296 | 'initial commit', 'add content from fixture', |
| 5297 | 'A-1', 'C-1'] |
| 5298 | # Ensure the right commits are in the history for this ref |
| 5299 | self.assertEqual(repo_messages, correct_messages) |
| 5300 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5301 | self.executor_server.hold_jobs_in_build = False |
| 5302 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5303 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5304 | |
| 5305 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5306 | class TestSemaphore(ZuulTestCase): |
| 5307 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5308 | |
| 5309 | def test_semaphore_one(self): |
| 5310 | "Test semaphores with max=1 (mutex)" |
| 5311 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5312 | |
| 5313 | self.executor_server.hold_jobs_in_build = True |
| 5314 | |
| 5315 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5316 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5317 | self.assertFalse('test-semaphore' in |
| 5318 | tenant.semaphore_handler.semaphores) |
| 5319 | |
| 5320 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5321 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5322 | self.waitUntilSettled() |
| 5323 | |
| 5324 | self.assertEqual(len(self.builds), 3) |
| 5325 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5326 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5327 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5328 | |
| 5329 | self.executor_server.release('semaphore-one-test1') |
| 5330 | self.waitUntilSettled() |
| 5331 | |
| 5332 | self.assertEqual(len(self.builds), 3) |
| 5333 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5334 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5335 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5336 | self.assertTrue('test-semaphore' in |
| 5337 | tenant.semaphore_handler.semaphores) |
| 5338 | |
| 5339 | self.executor_server.release('semaphore-one-test2') |
| 5340 | self.waitUntilSettled() |
| 5341 | |
| 5342 | self.assertEqual(len(self.builds), 3) |
| 5343 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5344 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5345 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5346 | self.assertTrue('test-semaphore' in |
| 5347 | tenant.semaphore_handler.semaphores) |
| 5348 | |
| 5349 | self.executor_server.release('semaphore-one-test1') |
| 5350 | self.waitUntilSettled() |
| 5351 | |
| 5352 | self.assertEqual(len(self.builds), 3) |
| 5353 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5354 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5355 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5356 | self.assertTrue('test-semaphore' in |
| 5357 | tenant.semaphore_handler.semaphores) |
| 5358 | |
| 5359 | self.executor_server.release('semaphore-one-test2') |
| 5360 | self.waitUntilSettled() |
| 5361 | |
| 5362 | self.assertEqual(len(self.builds), 2) |
| 5363 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5364 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5365 | self.assertFalse('test-semaphore' in |
| 5366 | tenant.semaphore_handler.semaphores) |
| 5367 | |
| 5368 | self.executor_server.hold_jobs_in_build = False |
| 5369 | self.executor_server.release() |
| 5370 | |
| 5371 | self.waitUntilSettled() |
| 5372 | self.assertEqual(len(self.builds), 0) |
| 5373 | |
| 5374 | self.assertEqual(A.reported, 1) |
| 5375 | self.assertEqual(B.reported, 1) |
| 5376 | self.assertFalse('test-semaphore' in |
| 5377 | tenant.semaphore_handler.semaphores) |
| 5378 | |
| 5379 | def test_semaphore_two(self): |
| 5380 | "Test semaphores with max>1" |
| 5381 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5382 | |
| 5383 | self.executor_server.hold_jobs_in_build = True |
| 5384 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5385 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5386 | self.assertFalse('test-semaphore-two' in |
| 5387 | tenant.semaphore_handler.semaphores) |
| 5388 | |
| 5389 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5390 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5391 | self.waitUntilSettled() |
| 5392 | |
| 5393 | self.assertEqual(len(self.builds), 4) |
| 5394 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5395 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5396 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5397 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5398 | self.assertTrue('test-semaphore-two' in |
| 5399 | tenant.semaphore_handler.semaphores) |
| 5400 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5401 | 'test-semaphore-two', [])), 2) |
| 5402 | |
| 5403 | self.executor_server.release('semaphore-two-test1') |
| 5404 | self.waitUntilSettled() |
| 5405 | |
| 5406 | self.assertEqual(len(self.builds), 4) |
| 5407 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5408 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5409 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5410 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5411 | self.assertTrue('test-semaphore-two' in |
| 5412 | tenant.semaphore_handler.semaphores) |
| 5413 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5414 | 'test-semaphore-two', [])), 2) |
| 5415 | |
| 5416 | self.executor_server.release('semaphore-two-test2') |
| 5417 | self.waitUntilSettled() |
| 5418 | |
| 5419 | self.assertEqual(len(self.builds), 4) |
| 5420 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5421 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5422 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5423 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5424 | self.assertTrue('test-semaphore-two' in |
| 5425 | tenant.semaphore_handler.semaphores) |
| 5426 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5427 | 'test-semaphore-two', [])), 2) |
| 5428 | |
| 5429 | self.executor_server.release('semaphore-two-test1') |
| 5430 | self.waitUntilSettled() |
| 5431 | |
| 5432 | self.assertEqual(len(self.builds), 3) |
| 5433 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5434 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5435 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5436 | self.assertTrue('test-semaphore-two' in |
| 5437 | tenant.semaphore_handler.semaphores) |
| 5438 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5439 | 'test-semaphore-two', [])), 1) |
| 5440 | |
| 5441 | self.executor_server.release('semaphore-two-test2') |
| 5442 | self.waitUntilSettled() |
| 5443 | |
| 5444 | self.assertEqual(len(self.builds), 2) |
| 5445 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5446 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5447 | self.assertFalse('test-semaphore-two' in |
| 5448 | tenant.semaphore_handler.semaphores) |
| 5449 | |
| 5450 | self.executor_server.hold_jobs_in_build = False |
| 5451 | self.executor_server.release() |
| 5452 | |
| 5453 | self.waitUntilSettled() |
| 5454 | self.assertEqual(len(self.builds), 0) |
| 5455 | |
| 5456 | self.assertEqual(A.reported, 1) |
| 5457 | self.assertEqual(B.reported, 1) |
| 5458 | |
| 5459 | def test_semaphore_abandon(self): |
| 5460 | "Test abandon with job semaphores" |
| 5461 | self.executor_server.hold_jobs_in_build = True |
| 5462 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5463 | check_pipeline = tenant.layout.pipelines['check'] |
| 5464 | |
| 5465 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5466 | self.assertFalse('test-semaphore' in |
| 5467 | tenant.semaphore_handler.semaphores) |
| 5468 | |
| 5469 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5470 | self.waitUntilSettled() |
| 5471 | |
| 5472 | self.assertTrue('test-semaphore' in |
| 5473 | tenant.semaphore_handler.semaphores) |
| 5474 | |
| 5475 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5476 | self.waitUntilSettled() |
| 5477 | |
| 5478 | # The check pipeline should be empty |
| 5479 | items = check_pipeline.getAllItems() |
| 5480 | self.assertEqual(len(items), 0) |
| 5481 | |
| 5482 | # The semaphore should be released |
| 5483 | self.assertFalse('test-semaphore' in |
| 5484 | tenant.semaphore_handler.semaphores) |
| 5485 | |
| 5486 | self.executor_server.hold_jobs_in_build = False |
| 5487 | self.executor_server.release() |
| 5488 | self.waitUntilSettled() |
| 5489 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5490 | def test_semaphore_new_patchset(self): |
| 5491 | "Test new patchset with job semaphores" |
| 5492 | self.executor_server.hold_jobs_in_build = True |
| 5493 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5494 | check_pipeline = tenant.layout.pipelines['check'] |
| 5495 | |
| 5496 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5497 | self.assertFalse('test-semaphore' in |
| 5498 | tenant.semaphore_handler.semaphores) |
| 5499 | |
| 5500 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5501 | self.waitUntilSettled() |
| 5502 | |
| 5503 | self.assertTrue('test-semaphore' in |
| 5504 | tenant.semaphore_handler.semaphores) |
| 5505 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5506 | self.assertEqual(len(semaphore), 1) |
| 5507 | |
| 5508 | A.addPatchset() |
| 5509 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5510 | self.waitUntilSettled() |
| 5511 | |
| 5512 | self.assertTrue('test-semaphore' in |
| 5513 | tenant.semaphore_handler.semaphores) |
| 5514 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5515 | self.assertEqual(len(semaphore), 1) |
| 5516 | |
| 5517 | items = check_pipeline.getAllItems() |
| 5518 | self.assertEqual(items[0].change.number, '1') |
| 5519 | self.assertEqual(items[0].change.patchset, '2') |
| 5520 | self.assertTrue(items[0].live) |
| 5521 | |
| 5522 | self.executor_server.hold_jobs_in_build = False |
| 5523 | self.executor_server.release() |
| 5524 | self.waitUntilSettled() |
| 5525 | |
| 5526 | # The semaphore should be released |
| 5527 | self.assertFalse('test-semaphore' in |
| 5528 | tenant.semaphore_handler.semaphores) |
| 5529 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5530 | def test_semaphore_reconfigure(self): |
| 5531 | "Test reconfigure with job semaphores" |
| 5532 | self.executor_server.hold_jobs_in_build = True |
| 5533 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5534 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5535 | self.assertFalse('test-semaphore' in |
| 5536 | tenant.semaphore_handler.semaphores) |
| 5537 | |
| 5538 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5539 | self.waitUntilSettled() |
| 5540 | |
| 5541 | self.assertTrue('test-semaphore' in |
| 5542 | tenant.semaphore_handler.semaphores) |
| 5543 | |
| 5544 | # reconfigure without layout change |
| 5545 | self.sched.reconfigure(self.config) |
| 5546 | self.waitUntilSettled() |
| 5547 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5548 | |
| 5549 | # semaphore still must be held |
| 5550 | self.assertTrue('test-semaphore' in |
| 5551 | tenant.semaphore_handler.semaphores) |
| 5552 | |
| 5553 | self.commitConfigUpdate( |
| 5554 | 'common-config', |
| 5555 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5556 | self.sched.reconfigure(self.config) |
| 5557 | self.waitUntilSettled() |
| 5558 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5559 | |
| 5560 | self.executor_server.release('project-test1') |
| 5561 | self.waitUntilSettled() |
| 5562 | |
| 5563 | # There should be no builds anymore |
| 5564 | self.assertEqual(len(self.builds), 0) |
| 5565 | |
| 5566 | # The semaphore should be released |
| 5567 | self.assertFalse('test-semaphore' in |
| 5568 | tenant.semaphore_handler.semaphores) |
| 5569 | |
| 5570 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5571 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5572 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5573 | |
| 5574 | def test_semaphore_tenant_isolation(self): |
| 5575 | "Test semaphores in multiple tenants" |
| 5576 | |
| 5577 | self.waitUntilSettled() |
| 5578 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5579 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5580 | |
| 5581 | self.executor_server.hold_jobs_in_build = True |
| 5582 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5583 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5584 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5585 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5586 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5587 | self.assertFalse('test-semaphore' in |
| 5588 | tenant_one.semaphore_handler.semaphores) |
| 5589 | self.assertFalse('test-semaphore' in |
| 5590 | tenant_two.semaphore_handler.semaphores) |
| 5591 | |
| 5592 | # add patches to project1 of tenant-one |
| 5593 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5594 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5595 | self.waitUntilSettled() |
| 5596 | |
| 5597 | # one build of project1-test1 must run |
| 5598 | # semaphore of tenant-one must be acquired once |
| 5599 | # semaphore of tenant-two must not be acquired |
| 5600 | self.assertEqual(len(self.builds), 1) |
| 5601 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5602 | self.assertTrue('test-semaphore' in |
| 5603 | tenant_one.semaphore_handler.semaphores) |
| 5604 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5605 | 'test-semaphore', [])), 1) |
| 5606 | self.assertFalse('test-semaphore' in |
| 5607 | tenant_two.semaphore_handler.semaphores) |
| 5608 | |
| 5609 | # add patches to project2 of tenant-two |
| 5610 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5611 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5612 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5613 | self.waitUntilSettled() |
| 5614 | |
| 5615 | # one build of project1-test1 must run |
| 5616 | # two builds of project2-test1 must run |
| 5617 | # semaphore of tenant-one must be acquired once |
| 5618 | # semaphore of tenant-two must be acquired twice |
| 5619 | self.assertEqual(len(self.builds), 3) |
| 5620 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5621 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5622 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5623 | self.assertTrue('test-semaphore' in |
| 5624 | tenant_one.semaphore_handler.semaphores) |
| 5625 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5626 | 'test-semaphore', [])), 1) |
| 5627 | self.assertTrue('test-semaphore' in |
| 5628 | tenant_two.semaphore_handler.semaphores) |
| 5629 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5630 | 'test-semaphore', [])), 2) |
| 5631 | |
| 5632 | self.executor_server.release('project1-test1') |
| 5633 | self.waitUntilSettled() |
| 5634 | |
| 5635 | # one build of project1-test1 must run |
| 5636 | # two builds of project2-test1 must run |
| 5637 | # semaphore of tenant-one must be acquired once |
| 5638 | # semaphore of tenant-two must be acquired twice |
| 5639 | self.assertEqual(len(self.builds), 3) |
| 5640 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5641 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5642 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5643 | self.assertTrue('test-semaphore' in |
| 5644 | tenant_one.semaphore_handler.semaphores) |
| 5645 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5646 | 'test-semaphore', [])), 1) |
| 5647 | self.assertTrue('test-semaphore' in |
| 5648 | tenant_two.semaphore_handler.semaphores) |
| 5649 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5650 | 'test-semaphore', [])), 2) |
| 5651 | |
| 5652 | self.executor_server.release('project2-test1') |
| 5653 | self.waitUntilSettled() |
| 5654 | |
| 5655 | # one build of project1-test1 must run |
| 5656 | # one build of project2-test1 must run |
| 5657 | # semaphore of tenant-one must be acquired once |
| 5658 | # semaphore of tenant-two must be acquired once |
| 5659 | self.assertEqual(len(self.builds), 2) |
| 5660 | self.assertTrue('test-semaphore' in |
| 5661 | tenant_one.semaphore_handler.semaphores) |
| 5662 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5663 | 'test-semaphore', [])), 1) |
| 5664 | self.assertTrue('test-semaphore' in |
| 5665 | tenant_two.semaphore_handler.semaphores) |
| 5666 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5667 | 'test-semaphore', [])), 1) |
| 5668 | |
| 5669 | self.executor_server.hold_jobs_in_build = False |
| 5670 | self.executor_server.release() |
| 5671 | |
| 5672 | self.waitUntilSettled() |
| 5673 | |
| 5674 | # no build must run |
| 5675 | # semaphore of tenant-one must not be acquired |
| 5676 | # semaphore of tenant-two must not be acquired |
| 5677 | self.assertEqual(len(self.builds), 0) |
| 5678 | self.assertFalse('test-semaphore' in |
| 5679 | tenant_one.semaphore_handler.semaphores) |
| 5680 | self.assertFalse('test-semaphore' in |
| 5681 | tenant_two.semaphore_handler.semaphores) |
| 5682 | |
| 5683 | self.assertEqual(A.reported, 1) |
| 5684 | self.assertEqual(B.reported, 1) |
| 5685 | |
| 5686 | |
| 5687 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5688 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5689 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5690 | |
| 5691 | def test_semaphore_in_repo(self): |
| 5692 | "Test semaphores in repo config" |
| 5693 | |
| 5694 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5695 | # max value should not be evaluated dynamically but must be updated |
| 5696 | # after the change lands. |
| 5697 | |
| 5698 | self.waitUntilSettled() |
| 5699 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5700 | |
| 5701 | in_repo_conf = textwrap.dedent( |
| 5702 | """ |
| 5703 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5704 | name: project-test1 |
| 5705 | |
| 5706 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5707 | name: project-test2 |
| 5708 | semaphore: test-semaphore |
| 5709 | |
| 5710 | - project: |
| 5711 | name: org/project |
| 5712 | tenant-one-gate: |
| 5713 | jobs: |
| 5714 | - project-test2 |
| 5715 | |
| 5716 | # the max value in dynamic layout must be ignored |
| 5717 | - semaphore: |
| 5718 | name: test-semaphore |
| 5719 | max: 2 |
| 5720 | """) |
| 5721 | |
| 5722 | in_repo_playbook = textwrap.dedent( |
| 5723 | """ |
| 5724 | - hosts: all |
| 5725 | tasks: [] |
| 5726 | """) |
| 5727 | |
| 5728 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5729 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5730 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5731 | files=file_dict) |
| 5732 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5733 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5734 | B.setDependsOn(A, 1) |
| 5735 | C.setDependsOn(A, 1) |
| 5736 | |
| 5737 | self.executor_server.hold_jobs_in_build = True |
| 5738 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5739 | A.addApproval('Code-Review', 2) |
| 5740 | B.addApproval('Code-Review', 2) |
| 5741 | C.addApproval('Code-Review', 2) |
| 5742 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5743 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5744 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5745 | self.waitUntilSettled() |
| 5746 | |
| 5747 | # check that the layout in a queue item still has max value of 1 |
| 5748 | # for test-semaphore |
| 5749 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5750 | queue = None |
| 5751 | for queue_candidate in pipeline.queues: |
| 5752 | if queue_candidate.name == 'org/project': |
| 5753 | queue = queue_candidate |
| 5754 | break |
| 5755 | queue_item = queue.queue[0] |
James E. Blair | 29a24fd | 2017-10-02 15:04:56 -0700 | [diff] [blame] | 5756 | item_dynamic_layout = queue_item.layout |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5757 | dynamic_test_semaphore = \ |
| 5758 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5759 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5760 | |
| 5761 | # one build must be in queue, one semaphores acquired |
| 5762 | self.assertEqual(len(self.builds), 1) |
| 5763 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5764 | self.assertTrue('test-semaphore' in |
| 5765 | tenant.semaphore_handler.semaphores) |
| 5766 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5767 | 'test-semaphore', [])), 1) |
| 5768 | |
| 5769 | self.executor_server.release('project-test2') |
| 5770 | self.waitUntilSettled() |
| 5771 | |
| 5772 | # change A must be merged |
| 5773 | self.assertEqual(A.data['status'], 'MERGED') |
| 5774 | self.assertEqual(A.reported, 2) |
| 5775 | |
| 5776 | # send change-merged event as the gerrit mock doesn't send it |
| 5777 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5778 | self.waitUntilSettled() |
| 5779 | |
| 5780 | # now that change A was merged, the new semaphore max must be effective |
| 5781 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5782 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5783 | |
| 5784 | # two builds must be in queue, two semaphores acquired |
| 5785 | self.assertEqual(len(self.builds), 2) |
| 5786 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5787 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5788 | self.assertTrue('test-semaphore' in |
| 5789 | tenant.semaphore_handler.semaphores) |
| 5790 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5791 | 'test-semaphore', [])), 2) |
| 5792 | |
| 5793 | self.executor_server.release('project-test2') |
| 5794 | self.waitUntilSettled() |
| 5795 | |
| 5796 | self.assertEqual(len(self.builds), 0) |
| 5797 | self.assertFalse('test-semaphore' in |
| 5798 | tenant.semaphore_handler.semaphores) |
| 5799 | |
| 5800 | self.executor_server.hold_jobs_in_build = False |
| 5801 | self.executor_server.release() |
| 5802 | |
| 5803 | self.waitUntilSettled() |
| 5804 | self.assertEqual(len(self.builds), 0) |
| 5805 | |
| 5806 | self.assertEqual(A.reported, 2) |
| 5807 | self.assertEqual(B.reported, 2) |
| 5808 | self.assertEqual(C.reported, 2) |
David Shrewsbury | f6dc176 | 2017-10-02 13:34:37 -0400 | [diff] [blame] | 5809 | |
| 5810 | |
| 5811 | class TestSchedulerBranchMatcher(ZuulTestCase): |
| 5812 | |
| 5813 | @simple_layout('layouts/matcher-test.yaml') |
| 5814 | def test_job_branch_ignored(self): |
| 5815 | ''' |
| 5816 | Test that branch matching logic works. |
| 5817 | |
| 5818 | The 'ignore-branch' job has a branch matcher that is supposed to |
| 5819 | match every branch except for the 'featureA' branch, so it should |
| 5820 | not be run on a change to that branch. |
| 5821 | ''' |
| 5822 | self.create_branch('org/project', 'featureA') |
| 5823 | A = self.fake_gerrit.addFakeChange('org/project', 'featureA', 'A') |
| 5824 | A.addApproval('Code-Review', 2) |
| 5825 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5826 | self.waitUntilSettled() |
| 5827 | self.printHistory() |
| 5828 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5829 | 'SUCCESS') |
| 5830 | self.assertJobNotInHistory('ignore-branch') |
| 5831 | self.assertEqual(A.data['status'], 'MERGED') |
| 5832 | self.assertEqual(A.reported, 2, |
| 5833 | "A should report start and success") |
| 5834 | self.assertIn('gate', A.messages[1], |
| 5835 | "A should transit gate") |