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 | b0a95ab | 2017-10-18 09:39:18 -0700 | [diff] [blame] | 878 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 879 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 880 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 881 | A.addApproval('Approved', 1) |
| 882 | B.addApproval('Approved', 1) |
| 883 | D.addApproval('Approved', 1) |
| 884 | E.addApproval('Approved', 1) |
| 885 | F.addApproval('Approved', 1) |
| 886 | G.addApproval('Approved', 1) |
| 887 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 888 | |
| 889 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 890 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 891 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 892 | self.executor_server.hold_jobs_in_build = False |
| 893 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 894 | self.waitUntilSettled() |
| 895 | |
| 896 | self.assertEqual(A.data['status'], 'MERGED') |
| 897 | self.assertEqual(B.data['status'], 'MERGED') |
| 898 | self.assertEqual(C.data['status'], 'MERGED') |
| 899 | self.assertEqual(D.data['status'], 'MERGED') |
| 900 | self.assertEqual(E.data['status'], 'MERGED') |
| 901 | self.assertEqual(F.data['status'], 'MERGED') |
| 902 | self.assertEqual(G.data['status'], 'MERGED') |
| 903 | self.assertEqual(A.reported, 2) |
| 904 | self.assertEqual(B.reported, 2) |
| 905 | self.assertEqual(C.reported, 2) |
| 906 | self.assertEqual(D.reported, 2) |
| 907 | self.assertEqual(E.reported, 2) |
| 908 | self.assertEqual(F.reported, 2) |
| 909 | self.assertEqual(G.reported, 2) |
| 910 | self.assertEqual(self.history[6].changes, |
| 911 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 912 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 913 | def test_source_cache(self): |
| 914 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 915 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 916 | |
| 917 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 918 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 919 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 920 | A.addApproval('Code-Review', 2) |
| 921 | B.addApproval('Code-Review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 922 | |
| 923 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 924 | M1.setMerged() |
| 925 | |
| 926 | B.setDependsOn(A, 1) |
| 927 | A.setDependsOn(M1, 1) |
| 928 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 929 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 930 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 931 | |
| 932 | self.waitUntilSettled() |
| 933 | |
| 934 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 935 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 936 | build.release() |
| 937 | self.waitUntilSettled() |
| 938 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 939 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 940 | build.release() |
| 941 | self.waitUntilSettled() |
| 942 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 943 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 944 | self.waitUntilSettled() |
| 945 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 946 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 947 | # there should still be changes in the cache |
James E. Blair | b0a95ab | 2017-10-18 09:39:18 -0700 | [diff] [blame] | 948 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 949 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 950 | self.executor_server.hold_jobs_in_build = False |
| 951 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 952 | self.waitUntilSettled() |
| 953 | |
| 954 | self.assertEqual(A.data['status'], 'MERGED') |
| 955 | self.assertEqual(B.data['status'], 'MERGED') |
| 956 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 957 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 958 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 959 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 960 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 961 | # TODO: move to test_gerrit (this is a unit test!) |
| 962 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 963 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 964 | (trusted, project) = tenant.getProject('org/project') |
| 965 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 966 | |
| 967 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 968 | # it easier for users to create events for testing. |
| 969 | event = zuul.model.TriggerEvent() |
| 970 | event.trigger_name = 'gerrit' |
| 971 | event.change_number = '1' |
| 972 | event.patch_number = '2' |
| 973 | |
| 974 | a = source.getChange(event) |
| 975 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 976 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 977 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 978 | A.addApproval('Code-Review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 979 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 980 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 981 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 982 | A.addApproval('Approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 983 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 984 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 985 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 986 | def test_project_merge_conflict(self): |
| 987 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 988 | |
| 989 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 990 | A = self.fake_gerrit.addFakeChange('org/project', |
| 991 | 'master', 'A', |
| 992 | files={'conflict': 'foo'}) |
| 993 | B = self.fake_gerrit.addFakeChange('org/project', |
| 994 | 'master', 'B', |
| 995 | files={'conflict': 'bar'}) |
| 996 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 997 | 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 998 | A.addApproval('Code-Review', 2) |
| 999 | B.addApproval('Code-Review', 2) |
| 1000 | C.addApproval('Code-Review', 2) |
| 1001 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1002 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1003 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1004 | self.waitUntilSettled() |
| 1005 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1006 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1007 | self.assertEqual(C.reported, 1) |
| 1008 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1009 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1010 | self.waitUntilSettled() |
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() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1015 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1016 | self.gearman_server.hold_jobs_in_queue = False |
| 1017 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1018 | self.waitUntilSettled() |
| 1019 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1020 | self.assertEqual(A.data['status'], 'MERGED') |
| 1021 | self.assertEqual(B.data['status'], 'NEW') |
| 1022 | self.assertEqual(C.data['status'], 'MERGED') |
| 1023 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1024 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1025 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1026 | |
| 1027 | self.assertHistory([ |
| 1028 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1029 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1030 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1031 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1032 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1033 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1034 | ], ordered=False) |
| 1035 | |
| 1036 | def test_delayed_merge_conflict(self): |
| 1037 | "Test that delayed check merge conflicts are handled properly" |
| 1038 | |
| 1039 | # 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] | 1040 | # the executor sucesfully merges a change based on an old |
| 1041 | # repo state (frozen by the scheduler) which would otherwise |
| 1042 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1043 | self.gearman_server.hold_jobs_in_queue = True |
| 1044 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1045 | 'master', 'A', |
| 1046 | files={'conflict': 'foo'}) |
| 1047 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1048 | 'master', 'B', |
| 1049 | files={'conflict': 'bar'}) |
| 1050 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1051 | 'master', 'C') |
| 1052 | C.setDependsOn(B, 1) |
| 1053 | |
| 1054 | # A enters the gate queue; B and C enter the check queue |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1055 | A.addApproval('Code-Review', 2) |
| 1056 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1057 | self.waitUntilSettled() |
| 1058 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1059 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1060 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1061 | self.waitUntilSettled() |
| 1062 | |
| 1063 | self.assertEqual(A.reported, 1) |
| 1064 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1065 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1066 | |
| 1067 | # A merges while B and C are queued in check |
| 1068 | # Release A project-merge |
| 1069 | queue = self.gearman_server.getQueue() |
| 1070 | self.release(queue[0]) |
| 1071 | self.waitUntilSettled() |
| 1072 | |
| 1073 | # Release A project-test* |
| 1074 | # gate has higher precedence, so A's test jobs are added in |
| 1075 | # front of the merge jobs for B and C |
| 1076 | queue = self.gearman_server.getQueue() |
| 1077 | self.release(queue[0]) |
| 1078 | self.release(queue[1]) |
| 1079 | self.waitUntilSettled() |
| 1080 | |
| 1081 | self.assertEqual(A.data['status'], 'MERGED') |
| 1082 | self.assertEqual(B.data['status'], 'NEW') |
| 1083 | self.assertEqual(C.data['status'], 'NEW') |
| 1084 | self.assertEqual(A.reported, 2) |
| 1085 | self.assertEqual(B.reported, 0) |
| 1086 | self.assertEqual(C.reported, 0) |
| 1087 | self.assertHistory([ |
| 1088 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1089 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1090 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1091 | ], ordered=False) |
| 1092 | |
| 1093 | # B and C report merge conflicts |
| 1094 | # Release B project-merge |
| 1095 | queue = self.gearman_server.getQueue() |
| 1096 | self.release(queue[0]) |
| 1097 | self.waitUntilSettled() |
| 1098 | |
| 1099 | # Release C |
| 1100 | self.gearman_server.hold_jobs_in_queue = False |
| 1101 | self.gearman_server.release() |
| 1102 | self.waitUntilSettled() |
| 1103 | |
| 1104 | self.assertEqual(A.data['status'], 'MERGED') |
| 1105 | self.assertEqual(B.data['status'], 'NEW') |
| 1106 | self.assertEqual(C.data['status'], 'NEW') |
| 1107 | self.assertEqual(A.reported, 2) |
| 1108 | self.assertEqual(B.reported, 1) |
| 1109 | self.assertEqual(C.reported, 1) |
| 1110 | |
| 1111 | self.assertHistory([ |
| 1112 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1113 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1114 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1115 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1116 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1117 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1118 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1119 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1120 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1121 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1122 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1123 | def test_post(self): |
| 1124 | "Test that post jobs run" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1125 | p = "review.example.com/org/project" |
| 1126 | upstream = self.getUpstreamRepos([p]) |
| 1127 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1128 | A.setMerged() |
| 1129 | A_commit = str(upstream[p].commit('master')) |
| 1130 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1131 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1132 | e = { |
| 1133 | "type": "ref-updated", |
| 1134 | "submitter": { |
| 1135 | "name": "User Name", |
| 1136 | }, |
| 1137 | "refUpdate": { |
| 1138 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1139 | "newRev": A_commit, |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1140 | "refName": "master", |
| 1141 | "project": "org/project", |
| 1142 | } |
| 1143 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1144 | self.fake_gerrit.addEvent(e) |
| 1145 | self.waitUntilSettled() |
| 1146 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1147 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1148 | self.assertEqual(len(self.history), 1) |
| 1149 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1150 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1151 | def test_post_ignore_deletes(self): |
| 1152 | "Test that deleting refs does not trigger post jobs" |
| 1153 | |
| 1154 | e = { |
| 1155 | "type": "ref-updated", |
| 1156 | "submitter": { |
| 1157 | "name": "User Name", |
| 1158 | }, |
| 1159 | "refUpdate": { |
| 1160 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1161 | "newRev": "0000000000000000000000000000000000000000", |
| 1162 | "refName": "master", |
| 1163 | "project": "org/project", |
| 1164 | } |
| 1165 | } |
| 1166 | self.fake_gerrit.addEvent(e) |
| 1167 | self.waitUntilSettled() |
| 1168 | |
| 1169 | job_names = [x.name for x in self.history] |
| 1170 | self.assertEqual(len(self.history), 0) |
| 1171 | self.assertNotIn('project-post', job_names) |
| 1172 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1173 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1174 | def test_post_ignore_deletes_negative(self): |
| 1175 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1176 | e = { |
| 1177 | "type": "ref-updated", |
| 1178 | "submitter": { |
| 1179 | "name": "User Name", |
| 1180 | }, |
| 1181 | "refUpdate": { |
| 1182 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1183 | "newRev": "0000000000000000000000000000000000000000", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1184 | "refName": "testbranch", |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1185 | "project": "org/project", |
| 1186 | } |
| 1187 | } |
| 1188 | self.fake_gerrit.addEvent(e) |
| 1189 | self.waitUntilSettled() |
| 1190 | |
| 1191 | job_names = [x.name for x in self.history] |
| 1192 | self.assertEqual(len(self.history), 1) |
| 1193 | self.assertIn('project-post', job_names) |
| 1194 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1195 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1196 | def test_build_configuration_branch_interaction(self): |
| 1197 | "Test that switching between branches works" |
| 1198 | self.test_build_configuration() |
| 1199 | self.test_build_configuration_branch() |
| 1200 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1201 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1202 | repo = git.Repo(path) |
| 1203 | repo.heads.master.commit = repo.commit('init') |
| 1204 | self.test_build_configuration() |
| 1205 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1206 | def test_dependent_changes_rebase(self): |
| 1207 | # Test that no errors occur when we walk a dependency tree |
| 1208 | # with an unused leaf node due to a rebase. |
| 1209 | # Start by constructing: C -> B -> A |
| 1210 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1211 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1212 | B.setDependsOn(A, 1) |
| 1213 | |
| 1214 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1215 | C.setDependsOn(B, 1) |
| 1216 | |
| 1217 | # Then rebase to form: D -> C -> A |
| 1218 | C.addPatchset() # C,2 |
| 1219 | C.setDependsOn(A, 1) |
| 1220 | |
| 1221 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1222 | D.setDependsOn(C, 2) |
| 1223 | |
| 1224 | # Walk the entire tree |
| 1225 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1226 | self.waitUntilSettled() |
| 1227 | self.assertEqual(len(self.history), 3) |
| 1228 | |
| 1229 | # Verify that walking just part of the tree still works |
| 1230 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1231 | self.waitUntilSettled() |
| 1232 | self.assertEqual(len(self.history), 6) |
| 1233 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1234 | def test_dependent_changes_dequeue(self): |
| 1235 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1236 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1237 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1238 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1239 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1240 | A.addApproval('Code-Review', 2) |
| 1241 | B.addApproval('Code-Review', 2) |
| 1242 | C.addApproval('Code-Review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1243 | |
| 1244 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1245 | M1.setMerged() |
| 1246 | |
| 1247 | # C -> B -> A -> M1 |
| 1248 | |
| 1249 | C.setDependsOn(B, 1) |
| 1250 | B.setDependsOn(A, 1) |
| 1251 | A.setDependsOn(M1, 1) |
| 1252 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1253 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1254 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1255 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1256 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1257 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1258 | |
| 1259 | self.waitUntilSettled() |
| 1260 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1261 | self.assertEqual(A.data['status'], 'NEW') |
| 1262 | self.assertEqual(A.reported, 2) |
| 1263 | self.assertEqual(B.data['status'], 'NEW') |
| 1264 | self.assertEqual(B.reported, 2) |
| 1265 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1266 | self.assertIn('This change depends on a change that failed to merge.', |
| 1267 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1268 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1269 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1270 | def test_failing_dependent_changes(self): |
| 1271 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1272 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1273 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1274 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1275 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1276 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1277 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1278 | A.addApproval('Code-Review', 2) |
| 1279 | B.addApproval('Code-Review', 2) |
| 1280 | C.addApproval('Code-Review', 2) |
| 1281 | D.addApproval('Code-Review', 2) |
| 1282 | E.addApproval('Code-Review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1283 | |
| 1284 | # E, D -> C -> B, A |
| 1285 | |
| 1286 | D.setDependsOn(C, 1) |
| 1287 | C.setDependsOn(B, 1) |
| 1288 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1289 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1290 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1291 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1292 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
| 1293 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1294 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1295 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1296 | |
| 1297 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1298 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 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() |
| 1308 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1309 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1310 | for build in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 1311 | if build.parameters['zuul']['change'] != '1': |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1312 | build.release() |
| 1313 | self.waitUntilSettled() |
| 1314 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1315 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1316 | self.waitUntilSettled() |
| 1317 | |
| 1318 | self.assertEqual(A.data['status'], 'MERGED') |
| 1319 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1320 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1321 | self.assertEqual(B.data['status'], 'NEW') |
| 1322 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1323 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1324 | self.assertEqual(C.data['status'], 'NEW') |
| 1325 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1326 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1327 | self.assertEqual(D.data['status'], 'NEW') |
| 1328 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1329 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1330 | self.assertEqual(E.data['status'], 'MERGED') |
| 1331 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1332 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1333 | self.assertEqual(len(self.history), 18) |
| 1334 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1335 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1336 | "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] | 1337 | # If it's dequeued more than once, we should see extra |
| 1338 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1339 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1340 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1341 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1342 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1343 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1344 | A.addApproval('Code-Review', 2) |
| 1345 | B.addApproval('Code-Review', 2) |
| 1346 | C.addApproval('Code-Review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1347 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1348 | self.executor_server.failJob('project-test1', A) |
| 1349 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1350 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1351 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1352 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1353 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1354 | |
| 1355 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1356 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1357 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1358 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1359 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1360 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1361 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1362 | self.waitUntilSettled() |
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() |
| 1367 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1368 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1369 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1370 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1371 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1372 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1373 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1374 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1375 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1376 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1377 | self.waitUntilSettled() |
| 1378 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1379 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1380 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1381 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1382 | self.executor_server.hold_jobs_in_build = False |
| 1383 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1384 | self.waitUntilSettled() |
| 1385 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1386 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1387 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1388 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1389 | self.assertEqual(A.data['status'], 'NEW') |
| 1390 | self.assertEqual(B.data['status'], 'MERGED') |
| 1391 | self.assertEqual(C.data['status'], 'MERGED') |
| 1392 | self.assertEqual(A.reported, 2) |
| 1393 | self.assertEqual(B.reported, 2) |
| 1394 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1395 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1396 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1397 | def test_nonvoting_job(self): |
| 1398 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1399 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1400 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1401 | 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1402 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1403 | self.executor_server.failJob('nonvoting-project-test2', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1404 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1405 | |
| 1406 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1407 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1408 | self.assertEqual(A.data['status'], 'MERGED') |
| 1409 | self.assertEqual(A.reported, 2) |
| 1410 | self.assertEqual( |
| 1411 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1412 | 'SUCCESS') |
| 1413 | self.assertEqual( |
| 1414 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1415 | 'SUCCESS') |
| 1416 | self.assertEqual( |
| 1417 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1418 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1419 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 1420 | self.assertTrue(self.getJobFromHistory('nonvoting-project-merge'). |
| 1421 | parameters['zuul']['voting']) |
| 1422 | self.assertTrue(self.getJobFromHistory('nonvoting-project-test1'). |
| 1423 | parameters['zuul']['voting']) |
| 1424 | self.assertFalse(self.getJobFromHistory('nonvoting-project-test2'). |
| 1425 | parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1426 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1427 | def test_check_queue_success(self): |
| 1428 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1429 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1430 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1431 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1432 | |
| 1433 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1434 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1435 | self.assertEqual(A.data['status'], 'NEW') |
| 1436 | self.assertEqual(A.reported, 1) |
| 1437 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1438 | 'SUCCESS') |
| 1439 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1440 | 'SUCCESS') |
| 1441 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1442 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1443 | |
| 1444 | def test_check_queue_failure(self): |
| 1445 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1446 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1447 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1448 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1449 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1450 | |
| 1451 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1452 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1453 | self.assertEqual(A.data['status'], 'NEW') |
| 1454 | self.assertEqual(A.reported, 1) |
| 1455 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1456 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1457 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1458 | 'SUCCESS') |
| 1459 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1460 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1461 | |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1462 | @simple_layout('layouts/autohold.yaml') |
| 1463 | def test_autohold(self): |
| 1464 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1465 | |
| 1466 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1467 | self.gearman_server.port) |
| 1468 | self.addCleanup(client.shutdown) |
David Shrewsbury | 36b2adf | 2017-07-31 15:40:13 -0400 | [diff] [blame] | 1469 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1470 | "reason text", 1) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1471 | self.assertTrue(r) |
| 1472 | |
| 1473 | self.executor_server.failJob('project-test2', A) |
| 1474 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1475 | |
| 1476 | self.waitUntilSettled() |
| 1477 | |
| 1478 | self.assertEqual(A.data['status'], 'NEW') |
| 1479 | self.assertEqual(A.reported, 1) |
| 1480 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1481 | 'FAILURE') |
| 1482 | |
| 1483 | # Check nodepool for a held node |
| 1484 | held_node = None |
| 1485 | for node in self.fake_nodepool.getNodes(): |
| 1486 | if node['state'] == zuul.model.STATE_HOLD: |
| 1487 | held_node = node |
| 1488 | break |
| 1489 | self.assertIsNotNone(held_node) |
| 1490 | |
| 1491 | # Validate node has recorded the failed job |
| 1492 | self.assertEqual( |
| 1493 | held_node['hold_job'], |
| 1494 | " ".join(['tenant-one', |
| 1495 | 'review.example.com/org/project', |
| 1496 | 'project-test2']) |
| 1497 | ) |
David Shrewsbury | f9af9df | 2017-08-01 15:19:26 -0400 | [diff] [blame] | 1498 | self.assertEqual(held_node['comment'], "reason text") |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1499 | |
| 1500 | # Another failed change should not hold any more nodes |
| 1501 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1502 | self.executor_server.failJob('project-test2', B) |
| 1503 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1504 | self.waitUntilSettled() |
| 1505 | self.assertEqual(B.data['status'], 'NEW') |
| 1506 | self.assertEqual(B.reported, 1) |
| 1507 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1508 | 'FAILURE') |
| 1509 | |
| 1510 | held_nodes = 0 |
| 1511 | for node in self.fake_nodepool.getNodes(): |
| 1512 | if node['state'] == zuul.model.STATE_HOLD: |
| 1513 | held_nodes += 1 |
| 1514 | self.assertEqual(held_nodes, 1) |
| 1515 | |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1516 | @simple_layout('layouts/autohold.yaml') |
| 1517 | def test_autohold_list(self): |
| 1518 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1519 | self.gearman_server.port) |
| 1520 | self.addCleanup(client.shutdown) |
| 1521 | |
| 1522 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1523 | "reason text", 1) |
| 1524 | self.assertTrue(r) |
| 1525 | |
| 1526 | autohold_requests = client.autohold_list() |
| 1527 | self.assertNotEqual({}, autohold_requests) |
| 1528 | self.assertEqual(1, len(autohold_requests.keys())) |
| 1529 | |
| 1530 | # The single dict key should be a CSV string value |
| 1531 | key = list(autohold_requests.keys())[0] |
| 1532 | tenant, project, job = key.split(',') |
| 1533 | |
| 1534 | self.assertEqual('tenant-one', tenant) |
| 1535 | self.assertIn('org/project', project) |
| 1536 | self.assertEqual('project-test2', job) |
| 1537 | |
| 1538 | # Note: the value is converted from set to list by json. |
| 1539 | self.assertEqual([1, "reason text"], autohold_requests[key]) |
| 1540 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1541 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1542 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1543 | # This particular test does a large amount of merges and needs a little |
| 1544 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1545 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1546 | "test that dependent changes behind dequeued changes work" |
| 1547 | # This complicated test is a reproduction of a real life bug |
| 1548 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1549 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1550 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1551 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1552 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1553 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1554 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1555 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1556 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1557 | D.setDependsOn(C, 1) |
| 1558 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1559 | A.addApproval('Code-Review', 2) |
| 1560 | B.addApproval('Code-Review', 2) |
| 1561 | C.addApproval('Code-Review', 2) |
| 1562 | D.addApproval('Code-Review', 2) |
| 1563 | E.addApproval('Code-Review', 2) |
| 1564 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1565 | |
| 1566 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1567 | |
| 1568 | # Change object re-use in the gerrit trigger is hidden if |
| 1569 | # changes are added in quick succession; waiting makes it more |
| 1570 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1571 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1572 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1573 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1574 | self.waitUntilSettled() |
| 1575 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1576 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1577 | self.waitUntilSettled() |
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() |
| 1580 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1581 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1582 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1583 | self.fake_gerrit.addEvent(D.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(E.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(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1588 | self.waitUntilSettled() |
| 1589 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1590 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1591 | self.waitUntilSettled() |
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() |
| 1598 | |
| 1599 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1600 | |
| 1601 | # Grab pointers to the jobs we want to release before |
| 1602 | # releasing any, because list indexes may change as |
| 1603 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1604 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1605 | a.release() |
| 1606 | b.release() |
| 1607 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1608 | self.waitUntilSettled() |
| 1609 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1610 | self.executor_server.hold_jobs_in_build = False |
| 1611 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1612 | self.waitUntilSettled() |
| 1613 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1614 | self.assertEqual(A.data['status'], 'NEW') |
| 1615 | self.assertEqual(B.data['status'], 'MERGED') |
| 1616 | self.assertEqual(C.data['status'], 'MERGED') |
| 1617 | self.assertEqual(D.data['status'], 'MERGED') |
| 1618 | self.assertEqual(E.data['status'], 'MERGED') |
| 1619 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1620 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1621 | self.assertEqual(A.reported, 2) |
| 1622 | self.assertEqual(B.reported, 2) |
| 1623 | self.assertEqual(C.reported, 2) |
| 1624 | self.assertEqual(D.reported, 2) |
| 1625 | self.assertEqual(E.reported, 2) |
| 1626 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1627 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1628 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1629 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1630 | |
| 1631 | def test_merger_repack(self): |
| 1632 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1633 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1634 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1635 | A.addApproval('Code-Review', 2) |
| 1636 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1637 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1638 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1639 | 'SUCCESS') |
| 1640 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1641 | 'SUCCESS') |
| 1642 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1643 | 'SUCCESS') |
| 1644 | self.assertEqual(A.data['status'], 'MERGED') |
| 1645 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1646 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1647 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1648 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1649 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1650 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1651 | if os.path.exists(path): |
| 1652 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1653 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1654 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1655 | if os.path.exists(path): |
| 1656 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1657 | |
| 1658 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1659 | A.addApproval('Code-Review', 2) |
| 1660 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1661 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1662 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1663 | 'SUCCESS') |
| 1664 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1665 | 'SUCCESS') |
| 1666 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1667 | 'SUCCESS') |
| 1668 | self.assertEqual(A.data['status'], 'MERGED') |
| 1669 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1670 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1671 | def test_merger_repack_large_change(self): |
| 1672 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1673 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1674 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1675 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1676 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1677 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1678 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1679 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1680 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1681 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1682 | # TODOv3(jeblair): add hostname to upstream root |
| 1683 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1684 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1685 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1686 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1687 | if os.path.exists(path): |
| 1688 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1689 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1690 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1691 | if os.path.exists(path): |
| 1692 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1693 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1694 | A.addApproval('Code-Review', 2) |
| 1695 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1696 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1697 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1698 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1699 | self.assertEqual(self.getJobFromHistory('project-test1').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-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1702 | 'SUCCESS') |
| 1703 | self.assertEqual(A.data['status'], 'MERGED') |
| 1704 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1705 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1706 | def test_new_patchset_dequeues_old(self): |
| 1707 | "Test that a new patchset causes the old to be dequeued" |
| 1708 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1709 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1710 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1711 | M.setMerged() |
| 1712 | |
| 1713 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1714 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1715 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1716 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1717 | A.addApproval('Code-Review', 2) |
| 1718 | B.addApproval('Code-Review', 2) |
| 1719 | C.addApproval('Code-Review', 2) |
| 1720 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1721 | |
| 1722 | C.setDependsOn(B, 1) |
| 1723 | B.setDependsOn(A, 1) |
| 1724 | A.setDependsOn(M, 1) |
| 1725 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1726 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1727 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1728 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1729 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1730 | self.waitUntilSettled() |
| 1731 | |
| 1732 | B.addPatchset() |
| 1733 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1734 | self.waitUntilSettled() |
| 1735 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1736 | self.executor_server.hold_jobs_in_build = False |
| 1737 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1738 | self.waitUntilSettled() |
| 1739 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1740 | self.assertEqual(A.data['status'], 'MERGED') |
| 1741 | self.assertEqual(A.reported, 2) |
| 1742 | self.assertEqual(B.data['status'], 'NEW') |
| 1743 | self.assertEqual(B.reported, 2) |
| 1744 | self.assertEqual(C.data['status'], 'NEW') |
| 1745 | self.assertEqual(C.reported, 2) |
| 1746 | self.assertEqual(D.data['status'], 'MERGED') |
| 1747 | self.assertEqual(D.reported, 2) |
| 1748 | 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] | 1749 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1750 | def test_new_patchset_check(self): |
| 1751 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1752 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1753 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1754 | |
| 1755 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1756 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1757 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1758 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1759 | |
| 1760 | # Add two git-dependent changes |
| 1761 | B.setDependsOn(A, 1) |
| 1762 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1763 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1764 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1765 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1766 | |
| 1767 | # A live item, and a non-live/live pair |
| 1768 | items = check_pipeline.getAllItems() |
| 1769 | self.assertEqual(len(items), 3) |
| 1770 | |
| 1771 | self.assertEqual(items[0].change.number, '1') |
| 1772 | self.assertEqual(items[0].change.patchset, '1') |
| 1773 | self.assertFalse(items[0].live) |
| 1774 | |
| 1775 | self.assertEqual(items[1].change.number, '2') |
| 1776 | self.assertEqual(items[1].change.patchset, '1') |
| 1777 | self.assertTrue(items[1].live) |
| 1778 | |
| 1779 | self.assertEqual(items[2].change.number, '1') |
| 1780 | self.assertEqual(items[2].change.patchset, '1') |
| 1781 | self.assertTrue(items[2].live) |
| 1782 | |
| 1783 | # Add a new patchset to A |
| 1784 | A.addPatchset() |
| 1785 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1786 | self.waitUntilSettled() |
| 1787 | |
| 1788 | # The live copy of A,1 should be gone, but the non-live and B |
| 1789 | # should continue, and we should have a new A,2 |
| 1790 | items = check_pipeline.getAllItems() |
| 1791 | self.assertEqual(len(items), 3) |
| 1792 | |
| 1793 | self.assertEqual(items[0].change.number, '1') |
| 1794 | self.assertEqual(items[0].change.patchset, '1') |
| 1795 | self.assertFalse(items[0].live) |
| 1796 | |
| 1797 | self.assertEqual(items[1].change.number, '2') |
| 1798 | self.assertEqual(items[1].change.patchset, '1') |
| 1799 | self.assertTrue(items[1].live) |
| 1800 | |
| 1801 | self.assertEqual(items[2].change.number, '1') |
| 1802 | self.assertEqual(items[2].change.patchset, '2') |
| 1803 | self.assertTrue(items[2].live) |
| 1804 | |
| 1805 | # Add a new patchset to B |
| 1806 | B.addPatchset() |
| 1807 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1808 | self.waitUntilSettled() |
| 1809 | |
| 1810 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1811 | # but we should have a new B,2 (still based on A,1) |
| 1812 | items = check_pipeline.getAllItems() |
| 1813 | self.assertEqual(len(items), 3) |
| 1814 | |
| 1815 | self.assertEqual(items[0].change.number, '1') |
| 1816 | self.assertEqual(items[0].change.patchset, '2') |
| 1817 | self.assertTrue(items[0].live) |
| 1818 | |
| 1819 | self.assertEqual(items[1].change.number, '1') |
| 1820 | self.assertEqual(items[1].change.patchset, '1') |
| 1821 | self.assertFalse(items[1].live) |
| 1822 | |
| 1823 | self.assertEqual(items[2].change.number, '2') |
| 1824 | self.assertEqual(items[2].change.patchset, '2') |
| 1825 | self.assertTrue(items[2].live) |
| 1826 | |
| 1827 | self.builds[0].release() |
| 1828 | self.waitUntilSettled() |
| 1829 | self.builds[0].release() |
| 1830 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1831 | self.executor_server.hold_jobs_in_build = False |
| 1832 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1833 | self.waitUntilSettled() |
| 1834 | |
| 1835 | self.assertEqual(A.reported, 1) |
| 1836 | self.assertEqual(B.reported, 1) |
| 1837 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1838 | self.assertEqual(self.history[0].changes, '1,1') |
| 1839 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1840 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1841 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1842 | self.assertEqual(self.history[2].changes, '1,2') |
| 1843 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1844 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1845 | |
| 1846 | def test_abandoned_gate(self): |
| 1847 | "Test that an abandoned change is dequeued from gate" |
| 1848 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1849 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1850 | |
| 1851 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1852 | A.addApproval('Code-Review', 2) |
| 1853 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1854 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1855 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1856 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1857 | |
| 1858 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1859 | self.waitUntilSettled() |
| 1860 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1861 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1862 | self.waitUntilSettled() |
| 1863 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1864 | self.assertBuilds([]) |
| 1865 | self.assertHistory([ |
| 1866 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1867 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1868 | self.assertEqual(A.reported, 1, |
| 1869 | "Abandoned gate change should report only start") |
| 1870 | |
| 1871 | def test_abandoned_check(self): |
| 1872 | "Test that an abandoned change is dequeued from check" |
| 1873 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1874 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1875 | |
| 1876 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1877 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1878 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1879 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1880 | |
| 1881 | # Add two git-dependent changes |
| 1882 | B.setDependsOn(A, 1) |
| 1883 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1884 | self.waitUntilSettled() |
| 1885 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1886 | self.waitUntilSettled() |
| 1887 | # A live item, and a non-live/live pair |
| 1888 | items = check_pipeline.getAllItems() |
| 1889 | self.assertEqual(len(items), 3) |
| 1890 | |
| 1891 | self.assertEqual(items[0].change.number, '1') |
| 1892 | self.assertFalse(items[0].live) |
| 1893 | |
| 1894 | self.assertEqual(items[1].change.number, '2') |
| 1895 | self.assertTrue(items[1].live) |
| 1896 | |
| 1897 | self.assertEqual(items[2].change.number, '1') |
| 1898 | self.assertTrue(items[2].live) |
| 1899 | |
| 1900 | # Abandon A |
| 1901 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1902 | self.waitUntilSettled() |
| 1903 | |
| 1904 | # The live copy of A should be gone, but the non-live and B |
| 1905 | # should continue |
| 1906 | items = check_pipeline.getAllItems() |
| 1907 | self.assertEqual(len(items), 2) |
| 1908 | |
| 1909 | self.assertEqual(items[0].change.number, '1') |
| 1910 | self.assertFalse(items[0].live) |
| 1911 | |
| 1912 | self.assertEqual(items[1].change.number, '2') |
| 1913 | self.assertTrue(items[1].live) |
| 1914 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1915 | self.executor_server.hold_jobs_in_build = False |
| 1916 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1917 | self.waitUntilSettled() |
| 1918 | |
| 1919 | self.assertEqual(len(self.history), 4) |
| 1920 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1921 | 'Build should have been aborted') |
| 1922 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1923 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1924 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1925 | def test_abandoned_not_timer(self): |
| 1926 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1927 | # This test can not use simple_layout because it must start |
| 1928 | # with a configuration which does not include a |
| 1929 | # timer-triggered job so that we have an opportunity to set |
| 1930 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1931 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1932 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1933 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1934 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1935 | # The pipeline triggers every second, so we should have seen |
| 1936 | # several by now. |
| 1937 | time.sleep(5) |
| 1938 | self.waitUntilSettled() |
| 1939 | # Stop queuing timer triggered jobs so that the assertions |
| 1940 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1941 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1942 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1943 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 1944 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 1945 | # If APScheduler is in mid-event when we remove the job, we |
| 1946 | # can end up with one more event firing, so give it an extra |
| 1947 | # second to settle. |
| 1948 | time.sleep(1) |
| 1949 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1950 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1951 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1952 | |
| 1953 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1954 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1955 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1956 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1957 | |
| 1958 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1959 | self.waitUntilSettled() |
| 1960 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1961 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1962 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1963 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1964 | self.waitUntilSettled() |
| 1965 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1966 | def test_new_patchset_dequeues_old_on_head(self): |
| 1967 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1968 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1969 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1970 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1971 | M.setMerged() |
| 1972 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1973 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1974 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1975 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1976 | A.addApproval('Code-Review', 2) |
| 1977 | B.addApproval('Code-Review', 2) |
| 1978 | C.addApproval('Code-Review', 2) |
| 1979 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1980 | |
| 1981 | C.setDependsOn(B, 1) |
| 1982 | B.setDependsOn(A, 1) |
| 1983 | A.setDependsOn(M, 1) |
| 1984 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1985 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1986 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1987 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1988 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1989 | self.waitUntilSettled() |
| 1990 | |
| 1991 | A.addPatchset() |
| 1992 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1993 | self.waitUntilSettled() |
| 1994 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1995 | self.executor_server.hold_jobs_in_build = False |
| 1996 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1997 | self.waitUntilSettled() |
| 1998 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1999 | self.assertEqual(A.data['status'], 'NEW') |
| 2000 | self.assertEqual(A.reported, 2) |
| 2001 | self.assertEqual(B.data['status'], 'NEW') |
| 2002 | self.assertEqual(B.reported, 2) |
| 2003 | self.assertEqual(C.data['status'], 'NEW') |
| 2004 | self.assertEqual(C.reported, 2) |
| 2005 | self.assertEqual(D.data['status'], 'MERGED') |
| 2006 | self.assertEqual(D.reported, 2) |
| 2007 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2008 | |
| 2009 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2010 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2011 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2012 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2013 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2014 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2015 | A.addApproval('Code-Review', 2) |
| 2016 | B.addApproval('Code-Review', 2) |
| 2017 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2018 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2019 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2020 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2021 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2022 | self.waitUntilSettled() |
| 2023 | |
| 2024 | B.addPatchset() |
| 2025 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2026 | self.waitUntilSettled() |
| 2027 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2028 | self.executor_server.hold_jobs_in_build = False |
| 2029 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2030 | self.waitUntilSettled() |
| 2031 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2032 | self.assertEqual(A.data['status'], 'MERGED') |
| 2033 | self.assertEqual(A.reported, 2) |
| 2034 | self.assertEqual(B.data['status'], 'NEW') |
| 2035 | self.assertEqual(B.reported, 2) |
| 2036 | self.assertEqual(C.data['status'], 'MERGED') |
| 2037 | self.assertEqual(C.reported, 2) |
| 2038 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2039 | |
| 2040 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2041 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2042 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2043 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2044 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2045 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2046 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2047 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2048 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2049 | self.waitUntilSettled() |
| 2050 | |
| 2051 | B.addPatchset() |
| 2052 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2053 | self.waitUntilSettled() |
| 2054 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2055 | self.executor_server.hold_jobs_in_build = False |
| 2056 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2057 | self.waitUntilSettled() |
| 2058 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2059 | self.assertEqual(A.data['status'], 'NEW') |
| 2060 | self.assertEqual(A.reported, 1) |
| 2061 | self.assertEqual(B.data['status'], 'NEW') |
| 2062 | self.assertEqual(B.reported, 1) |
| 2063 | self.assertEqual(C.data['status'], 'NEW') |
| 2064 | self.assertEqual(C.reported, 1) |
| 2065 | self.assertEqual(len(self.history), 10) |
| 2066 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2067 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2068 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2069 | def test_noop_job(self): |
| 2070 | "Test that the internal noop job works" |
| 2071 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2072 | A.addApproval('Code-Review', 2) |
| 2073 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2074 | self.waitUntilSettled() |
| 2075 | |
| 2076 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2077 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2078 | self.assertEqual(len(self.history), 0) |
| 2079 | self.assertEqual(A.data['status'], 'MERGED') |
| 2080 | self.assertEqual(A.reported, 2) |
| 2081 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2082 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2083 | def test_no_job_project(self): |
| 2084 | "Test that reports with no jobs don't get sent" |
| 2085 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2086 | 'master', 'A') |
| 2087 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2088 | self.waitUntilSettled() |
| 2089 | |
| 2090 | # Change wasn't reported to |
| 2091 | self.assertEqual(A.reported, False) |
| 2092 | |
| 2093 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2094 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2095 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2096 | items = check_pipeline.getAllItems() |
| 2097 | self.assertEqual(len(items), 0) |
| 2098 | |
| 2099 | self.assertEqual(len(self.history), 0) |
| 2100 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2101 | def test_zuul_refs(self): |
| 2102 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2103 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2104 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2105 | M1.setMerged() |
| 2106 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2107 | M2.setMerged() |
| 2108 | |
| 2109 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2110 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2111 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2112 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2113 | A.addApproval('Code-Review', 2) |
| 2114 | B.addApproval('Code-Review', 2) |
| 2115 | C.addApproval('Code-Review', 2) |
| 2116 | D.addApproval('Code-Review', 2) |
| 2117 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2118 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2119 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2120 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2121 | |
| 2122 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2123 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 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() |
| 2131 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2132 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2133 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2134 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2135 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2136 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2137 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2138 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2139 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2140 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2141 | d_build = x |
| 2142 | if a_build and b_build and c_build and d_build: |
| 2143 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2144 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2145 | # should have a, not b, and should not be in project2 |
| 2146 | self.assertTrue(a_build.hasChanges(A)) |
| 2147 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2148 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2149 | # should have a and b, and should not be in project2 |
| 2150 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2151 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2152 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2153 | # should have a and b in 1, c in 2 |
| 2154 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2155 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2156 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2157 | # should have a and b in 1, c and d in 2 |
| 2158 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2159 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2160 | self.executor_server.hold_jobs_in_build = False |
| 2161 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2162 | self.waitUntilSettled() |
| 2163 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2164 | self.assertEqual(A.data['status'], 'MERGED') |
| 2165 | self.assertEqual(A.reported, 2) |
| 2166 | self.assertEqual(B.data['status'], 'MERGED') |
| 2167 | self.assertEqual(B.reported, 2) |
| 2168 | self.assertEqual(C.data['status'], 'MERGED') |
| 2169 | self.assertEqual(C.reported, 2) |
| 2170 | self.assertEqual(D.data['status'], 'MERGED') |
| 2171 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2172 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2173 | def test_rerun_on_error(self): |
| 2174 | "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] | 2175 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2176 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2177 | A.addApproval('Code-Review', 2) |
| 2178 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2179 | self.waitUntilSettled() |
| 2180 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2181 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2182 | self.executor_server.hold_jobs_in_build = False |
| 2183 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2184 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2185 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2186 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2187 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2188 | def test_statsd(self): |
| 2189 | "Test each of the statsd methods used in the scheduler" |
James E. Blair | ded241e | 2017-10-10 13:22:40 -0700 | [diff] [blame] | 2190 | statsd = self.sched.statsd |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2191 | statsd.incr('test-incr') |
| 2192 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2193 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2194 | self.assertReportedStat('test-incr', '1|c') |
| 2195 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2196 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2197 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2198 | def test_stuck_job_cleanup(self): |
| 2199 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2200 | |
| 2201 | # 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] | 2202 | self.gearman_server.hold_jobs_in_queue = True |
| 2203 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2204 | A.addApproval('Code-Review', 2) |
| 2205 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2206 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2207 | # 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] | 2208 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2209 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2210 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2211 | self.sched.reconfigure(self.config) |
| 2212 | self.waitUntilSettled() |
| 2213 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2214 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2215 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2216 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2217 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2218 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2219 | |
| 2220 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2221 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2222 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2223 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2224 | def test_file_head(self): |
| 2225 | # This is a regression test for an observed bug. A change |
| 2226 | # with a file named "HEAD" in the root directory of the repo |
| 2227 | # was processed by a merger. It then was unable to reset the |
| 2228 | # repo because of: |
| 2229 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2230 | # with exit code 128 |
| 2231 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2232 | # and filename |
| 2233 | # Use '--' to separate filenames from revisions' |
| 2234 | |
| 2235 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2236 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2237 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2238 | |
| 2239 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2240 | self.waitUntilSettled() |
| 2241 | |
| 2242 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2243 | self.waitUntilSettled() |
| 2244 | |
| 2245 | self.assertIn('Build succeeded', A.messages[0]) |
| 2246 | self.assertIn('Build succeeded', B.messages[0]) |
| 2247 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2248 | def test_file_jobs(self): |
| 2249 | "Test that file jobs run only when appropriate" |
| 2250 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2251 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2252 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2253 | A.addApproval('Code-Review', 2) |
| 2254 | B.addApproval('Code-Review', 2) |
| 2255 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2256 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2257 | self.waitUntilSettled() |
| 2258 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2259 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2260 | if x.name == 'project-testfile'] |
| 2261 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2262 | self.assertEqual(len(testfile_jobs), 1) |
| 2263 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2264 | self.assertEqual(A.data['status'], 'MERGED') |
| 2265 | self.assertEqual(A.reported, 2) |
| 2266 | self.assertEqual(B.data['status'], 'MERGED') |
| 2267 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2268 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2269 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2270 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2271 | if should_skip: |
| 2272 | files = {'ignoreme': 'ignored\n'} |
| 2273 | else: |
| 2274 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2275 | |
| 2276 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2277 | 'master', |
| 2278 | 'test irrelevant-files', |
| 2279 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2280 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2281 | self.waitUntilSettled() |
| 2282 | |
| 2283 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2284 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2285 | |
| 2286 | if should_skip: |
| 2287 | self.assertEqual([], tested_change_ids) |
| 2288 | else: |
| 2289 | self.assertIn(change.data['number'], tested_change_ids) |
| 2290 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2291 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2292 | def test_irrelevant_files_match_skips_job(self): |
| 2293 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2294 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2295 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2296 | def test_irrelevant_files_no_match_runs_job(self): |
| 2297 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2298 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2299 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2300 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2301 | files = {'ignoreme': 'ignored\n'} |
| 2302 | |
| 2303 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2304 | 'master', |
| 2305 | 'test irrelevant-files', |
| 2306 | files=files) |
| 2307 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2308 | self.waitUntilSettled() |
| 2309 | |
| 2310 | run_jobs = set([build.name for build in self.history]) |
| 2311 | |
| 2312 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2313 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2314 | |
James E. Blair | af8b208 | 2017-10-03 15:38:27 -0700 | [diff] [blame] | 2315 | @simple_layout('layouts/job-vars.yaml') |
| 2316 | def test_inherited_job_variables(self): |
| 2317 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2318 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2319 | self.waitUntilSettled() |
| 2320 | self.assertHistory([ |
| 2321 | dict(name='parentjob', result='SUCCESS'), |
| 2322 | dict(name='child1', result='SUCCESS'), |
| 2323 | dict(name='child2', result='SUCCESS'), |
| 2324 | dict(name='child3', result='SUCCESS'), |
| 2325 | ], ordered=False) |
| 2326 | j = self.getJobFromHistory('parentjob') |
| 2327 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2328 | self.assertEqual(j.parameters['vars']['override'], 0) |
| 2329 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2330 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2331 | self.assertFalse('child1' in j.parameters['vars']) |
| 2332 | self.assertFalse('child2' in j.parameters['vars']) |
| 2333 | self.assertFalse('child3' in j.parameters['vars']) |
| 2334 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2335 | 'org/project0'])) |
| 2336 | j = self.getJobFromHistory('child1') |
| 2337 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2338 | self.assertEqual(j.parameters['vars']['override'], 1) |
| 2339 | self.assertEqual(j.parameters['vars']['child1override'], 1) |
| 2340 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2341 | self.assertEqual(j.parameters['vars']['child1'], 1) |
| 2342 | self.assertFalse('child2' in j.parameters['vars']) |
| 2343 | self.assertFalse('child3' in j.parameters['vars']) |
| 2344 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2345 | 'org/project1'])) |
| 2346 | j = self.getJobFromHistory('child2') |
| 2347 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2348 | self.assertEqual(j.parameters['vars']['override'], 2) |
| 2349 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2350 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2351 | self.assertFalse('child1' in j.parameters['vars']) |
| 2352 | self.assertEqual(j.parameters['vars']['child2'], 2) |
| 2353 | self.assertFalse('child3' in j.parameters['vars']) |
| 2354 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2355 | 'org/project2'])) |
| 2356 | j = self.getJobFromHistory('child3') |
| 2357 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2358 | self.assertEqual(j.parameters['vars']['override'], 3) |
| 2359 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2360 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2361 | self.assertFalse('child1' in j.parameters['vars']) |
| 2362 | self.assertFalse('child2' in j.parameters['vars']) |
| 2363 | self.assertEqual(j.parameters['vars']['child3'], 3) |
| 2364 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2365 | 'org/project3'])) |
| 2366 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2367 | def test_queue_names(self): |
| 2368 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2369 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2370 | (trusted, project1) = tenant.getProject('org/project1') |
| 2371 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2372 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2373 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2374 | self.assertEqual(q1.name, 'integrated') |
| 2375 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2376 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2377 | def test_queue_precedence(self): |
| 2378 | "Test that queue precedence works" |
| 2379 | |
| 2380 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2381 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2382 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2383 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2384 | A.addApproval('Code-Review', 2) |
| 2385 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2386 | |
| 2387 | self.waitUntilSettled() |
| 2388 | self.gearman_server.hold_jobs_in_queue = False |
| 2389 | self.gearman_server.release() |
| 2390 | self.waitUntilSettled() |
| 2391 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2392 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2393 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2394 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2395 | self.waitUntilSettled() |
| 2396 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2397 | self.log.debug(self.history) |
| 2398 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2399 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2400 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2401 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2402 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2403 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2404 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2405 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2406 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2407 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2408 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2409 | A.addApproval('Code-Review', 2) |
| 2410 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2411 | self.waitUntilSettled() |
| 2412 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2413 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2414 | self.waitUntilSettled() |
| 2415 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2416 | port = self.webapp.server.socket.getsockname()[1] |
| 2417 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2418 | req = urllib.request.Request( |
| 2419 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2420 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2421 | headers = f.info() |
| 2422 | self.assertIn('Content-Length', headers) |
| 2423 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2424 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2425 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2426 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2427 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2428 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2429 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2430 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2431 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2432 | self.executor_server.hold_jobs_in_build = False |
| 2433 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2434 | self.waitUntilSettled() |
| 2435 | |
| 2436 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2437 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2438 | for p in data['pipelines']: |
| 2439 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2440 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2441 | self.assertEqual(q['window'], 20) |
| 2442 | else: |
| 2443 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2444 | for head in q['heads']: |
| 2445 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2446 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2447 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2448 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2449 | status_jobs.append(job) |
| 2450 | self.assertEqual('project-merge', status_jobs[0]['name']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2451 | # TODO(mordred) pull uuids from self.builds |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2452 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2453 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2454 | uuid=status_jobs[0]['uuid']), |
| 2455 | status_jobs[0]['url']) |
| 2456 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2457 | 'finger://{hostname}/{uuid}'.format( |
| 2458 | hostname=self.executor_server.hostname, |
| 2459 | uuid=status_jobs[0]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2460 | status_jobs[0]['finger_url']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2461 | # TOOD(mordred) configure a success-url on the base job |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2462 | self.assertEqual( |
| 2463 | 'finger://{hostname}/{uuid}'.format( |
| 2464 | hostname=self.executor_server.hostname, |
| 2465 | uuid=status_jobs[0]['uuid']), |
| 2466 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2467 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2468 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2469 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2470 | uuid=status_jobs[1]['uuid']), |
| 2471 | status_jobs[1]['url']) |
| 2472 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2473 | 'finger://{hostname}/{uuid}'.format( |
| 2474 | hostname=self.executor_server.hostname, |
| 2475 | uuid=status_jobs[1]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2476 | status_jobs[1]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2477 | self.assertEqual( |
| 2478 | 'finger://{hostname}/{uuid}'.format( |
| 2479 | hostname=self.executor_server.hostname, |
| 2480 | uuid=status_jobs[1]['uuid']), |
| 2481 | status_jobs[1]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2482 | |
| 2483 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2484 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2485 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2486 | uuid=status_jobs[2]['uuid']), |
| 2487 | status_jobs[2]['url']) |
| 2488 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2489 | 'finger://{hostname}/{uuid}'.format( |
| 2490 | hostname=self.executor_server.hostname, |
| 2491 | uuid=status_jobs[2]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2492 | status_jobs[2]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2493 | self.assertEqual( |
| 2494 | 'finger://{hostname}/{uuid}'.format( |
| 2495 | hostname=self.executor_server.hostname, |
| 2496 | uuid=status_jobs[2]['uuid']), |
| 2497 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2498 | |
Tobias Henkel | 65639f8 | 2017-07-10 10:25:42 +0200 | [diff] [blame] | 2499 | # check job dependencies |
| 2500 | self.assertIsNotNone(status_jobs[0]['dependencies']) |
| 2501 | self.assertIsNotNone(status_jobs[1]['dependencies']) |
| 2502 | self.assertIsNotNone(status_jobs[2]['dependencies']) |
| 2503 | self.assertEqual(len(status_jobs[0]['dependencies']), 0) |
| 2504 | self.assertEqual(len(status_jobs[1]['dependencies']), 1) |
| 2505 | self.assertEqual(len(status_jobs[2]['dependencies']), 1) |
| 2506 | self.assertIn('project-merge', status_jobs[1]['dependencies']) |
| 2507 | self.assertIn('project-merge', status_jobs[2]['dependencies']) |
| 2508 | |
James E. Blair | 419a867 | 2017-10-18 14:48:25 -0700 | [diff] [blame^] | 2509 | def test_reconfigure_merge(self): |
| 2510 | """Test that two reconfigure events are merged""" |
| 2511 | |
| 2512 | tenant = self.sched.abide.tenants['tenant-one'] |
| 2513 | (trusted, project) = tenant.getProject('org/project') |
| 2514 | |
| 2515 | self.sched.run_handler_lock.acquire() |
| 2516 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2517 | |
| 2518 | self.sched.reconfigureTenant(tenant, project) |
| 2519 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2520 | |
| 2521 | self.sched.reconfigureTenant(tenant, project) |
| 2522 | # The second event should have been combined with the first |
| 2523 | # so we should still only have one entry. |
| 2524 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2525 | |
| 2526 | self.sched.run_handler_lock.release() |
| 2527 | self.waitUntilSettled() |
| 2528 | |
| 2529 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2530 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2531 | def test_live_reconfiguration(self): |
| 2532 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2533 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2534 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2535 | A.addApproval('Code-Review', 2) |
| 2536 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2537 | self.waitUntilSettled() |
| 2538 | |
| 2539 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2540 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2541 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2542 | self.executor_server.hold_jobs_in_build = False |
| 2543 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2544 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2545 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2546 | 'SUCCESS') |
| 2547 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2548 | 'SUCCESS') |
| 2549 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2550 | 'SUCCESS') |
| 2551 | self.assertEqual(A.data['status'], 'MERGED') |
| 2552 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2553 | |
James E. Blair | 027ba99 | 2017-09-20 13:48:32 -0700 | [diff] [blame] | 2554 | def test_live_reconfiguration_abort(self): |
| 2555 | # Raise an exception during reconfiguration and verify we |
| 2556 | # still function. |
| 2557 | self.executor_server.hold_jobs_in_build = True |
| 2558 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2559 | A.addApproval('Code-Review', 2) |
| 2560 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2561 | self.waitUntilSettled() |
| 2562 | |
| 2563 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2564 | pipeline = tenant.layout.pipelines['gate'] |
| 2565 | change = pipeline.getAllItems()[0].change |
| 2566 | # Set this to an invalid value to cause an exception during |
| 2567 | # reconfiguration. |
| 2568 | change.branch = None |
| 2569 | |
| 2570 | self.sched.reconfigure(self.config) |
| 2571 | self.waitUntilSettled() |
| 2572 | |
| 2573 | self.executor_server.hold_jobs_in_build = False |
| 2574 | self.executor_server.release() |
| 2575 | |
| 2576 | self.waitUntilSettled() |
| 2577 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2578 | 'ABORTED') |
| 2579 | self.assertEqual(A.data['status'], 'NEW') |
| 2580 | # The final report fails because of the invalid value set above. |
| 2581 | self.assertEqual(A.reported, 1) |
| 2582 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2583 | def test_live_reconfiguration_merge_conflict(self): |
| 2584 | # A real-world bug: a change in a gate queue has a merge |
| 2585 | # conflict and a job is added to its project while it's |
| 2586 | # sitting in the queue. The job gets added to the change and |
| 2587 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2588 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2589 | |
| 2590 | # This change is fine. It's here to stop the queue long |
| 2591 | # enough for the next change to be subject to the |
| 2592 | # reconfiguration, as well as to provide a conflict for the |
| 2593 | # next change. This change will succeed and merge. |
| 2594 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2595 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2596 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2597 | |
| 2598 | # This change will be in merge conflict. During the |
| 2599 | # reconfiguration, we will add a job. We want to make sure |
| 2600 | # that doesn't cause it to get stuck. |
| 2601 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2602 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2603 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2604 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2605 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2606 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2607 | |
| 2608 | self.waitUntilSettled() |
| 2609 | |
| 2610 | # No jobs have run yet |
| 2611 | self.assertEqual(A.data['status'], 'NEW') |
| 2612 | self.assertEqual(A.reported, 1) |
| 2613 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2614 | self.assertEqual(len(self.history), 0) |
| 2615 | |
| 2616 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2617 | self.commitConfigUpdate('common-config', |
| 2618 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2619 | self.sched.reconfigure(self.config) |
| 2620 | self.waitUntilSettled() |
| 2621 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2622 | self.executor_server.hold_jobs_in_build = False |
| 2623 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2624 | self.waitUntilSettled() |
| 2625 | |
| 2626 | self.assertEqual(A.data['status'], 'MERGED') |
| 2627 | self.assertEqual(A.reported, 2) |
| 2628 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2629 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2630 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2631 | 'SUCCESS') |
| 2632 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2633 | 'SUCCESS') |
| 2634 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2635 | 'SUCCESS') |
| 2636 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2637 | 'SUCCESS') |
| 2638 | self.assertEqual(len(self.history), 4) |
| 2639 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2640 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2641 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2642 | # that tests a job added to a job tree with a failed root does |
| 2643 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2644 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2645 | |
| 2646 | # This change is fine. It's here to stop the queue long |
| 2647 | # enough for the next change to be subject to the |
| 2648 | # reconfiguration. This change will succeed and merge. |
| 2649 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2650 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2651 | A.addApproval('Code-Review', 2) |
| 2652 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2653 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2654 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2655 | self.waitUntilSettled() |
| 2656 | |
| 2657 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2658 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2659 | B.addApproval('Code-Review', 2) |
| 2660 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2661 | self.waitUntilSettled() |
| 2662 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2663 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2664 | self.waitUntilSettled() |
| 2665 | |
| 2666 | # Both -merge jobs have run, but no others. |
| 2667 | self.assertEqual(A.data['status'], 'NEW') |
| 2668 | self.assertEqual(A.reported, 1) |
| 2669 | self.assertEqual(B.data['status'], 'NEW') |
| 2670 | self.assertEqual(B.reported, 1) |
| 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(len(self.history), 2) |
| 2676 | |
| 2677 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2678 | self.commitConfigUpdate('common-config', |
| 2679 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2680 | self.sched.reconfigure(self.config) |
| 2681 | self.waitUntilSettled() |
| 2682 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2683 | self.executor_server.hold_jobs_in_build = False |
| 2684 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2685 | self.waitUntilSettled() |
| 2686 | |
| 2687 | self.assertEqual(A.data['status'], 'MERGED') |
| 2688 | self.assertEqual(A.reported, 2) |
| 2689 | self.assertEqual(B.data['status'], 'NEW') |
| 2690 | self.assertEqual(B.reported, 2) |
| 2691 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2692 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2693 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2694 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2695 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2696 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2697 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2698 | self.assertEqual(len(self.history), 5) |
| 2699 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2700 | def test_live_reconfiguration_failed_job(self): |
| 2701 | # Test that a change with a removed failing job does not |
| 2702 | # disrupt reconfiguration. If a change has a failed job and |
| 2703 | # that job is removed during a reconfiguration, we observed a |
| 2704 | # bug where the code to re-set build statuses would run on |
| 2705 | # that build and raise an exception because the job no longer |
| 2706 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2707 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2708 | |
| 2709 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2710 | |
| 2711 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2712 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2713 | |
| 2714 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2715 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2716 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2717 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2718 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2719 | self.waitUntilSettled() |
| 2720 | |
| 2721 | self.assertEqual(A.data['status'], 'NEW') |
| 2722 | self.assertEqual(A.reported, 0) |
| 2723 | |
| 2724 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2725 | 'SUCCESS') |
| 2726 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2727 | 'FAILURE') |
| 2728 | self.assertEqual(len(self.history), 2) |
| 2729 | |
| 2730 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2731 | self.commitConfigUpdate('common-config', |
| 2732 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2733 | self.sched.reconfigure(self.config) |
| 2734 | self.waitUntilSettled() |
| 2735 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2736 | self.executor_server.hold_jobs_in_build = False |
| 2737 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2738 | self.waitUntilSettled() |
| 2739 | |
| 2740 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2741 | 'SUCCESS') |
| 2742 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2743 | 'SUCCESS') |
| 2744 | self.assertEqual(len(self.history), 4) |
| 2745 | |
| 2746 | self.assertEqual(A.data['status'], 'NEW') |
| 2747 | self.assertEqual(A.reported, 1) |
| 2748 | self.assertIn('Build succeeded', A.messages[0]) |
| 2749 | # Ensure the removed job was not included in the report. |
| 2750 | self.assertNotIn('project-test1', A.messages[0]) |
| 2751 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2752 | def test_live_reconfiguration_shared_queue(self): |
| 2753 | # Test that a change with a failing job which was removed from |
| 2754 | # this project but otherwise still exists in the system does |
| 2755 | # not disrupt reconfiguration. |
| 2756 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2757 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2758 | |
| 2759 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2760 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2761 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2762 | |
| 2763 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2764 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2765 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2766 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2767 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2768 | self.waitUntilSettled() |
| 2769 | |
| 2770 | self.assertEqual(A.data['status'], 'NEW') |
| 2771 | self.assertEqual(A.reported, 0) |
| 2772 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2773 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2774 | 'SUCCESS') |
| 2775 | self.assertEqual(self.getJobFromHistory( |
| 2776 | 'project1-project2-integration').result, 'FAILURE') |
| 2777 | self.assertEqual(len(self.history), 2) |
| 2778 | |
| 2779 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2780 | self.commitConfigUpdate( |
| 2781 | 'common-config', |
| 2782 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2783 | self.sched.reconfigure(self.config) |
| 2784 | self.waitUntilSettled() |
| 2785 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2786 | self.executor_server.hold_jobs_in_build = False |
| 2787 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2788 | self.waitUntilSettled() |
| 2789 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2790 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2791 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2792 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2793 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2794 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2795 | 'SUCCESS') |
| 2796 | self.assertEqual(self.getJobFromHistory( |
| 2797 | 'project1-project2-integration').result, 'FAILURE') |
| 2798 | self.assertEqual(len(self.history), 4) |
| 2799 | |
| 2800 | self.assertEqual(A.data['status'], 'NEW') |
| 2801 | self.assertEqual(A.reported, 1) |
| 2802 | self.assertIn('Build succeeded', A.messages[0]) |
| 2803 | # Ensure the removed job was not included in the report. |
| 2804 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2805 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2806 | def test_double_live_reconfiguration_shared_queue(self): |
| 2807 | # This was a real-world regression. A change is added to |
| 2808 | # gate; a reconfigure happens, a second change which depends |
| 2809 | # on the first is added, and a second reconfiguration happens. |
| 2810 | # Ensure that both changes merge. |
| 2811 | |
| 2812 | # A failure may indicate incorrect caching or cleaning up of |
| 2813 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2814 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2815 | |
| 2816 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2817 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2818 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2819 | A.addApproval('Code-Review', 2) |
| 2820 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2821 | |
| 2822 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2823 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2824 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2825 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2826 | self.waitUntilSettled() |
| 2827 | |
| 2828 | # Reconfigure (with only one change in the pipeline). |
| 2829 | self.sched.reconfigure(self.config) |
| 2830 | self.waitUntilSettled() |
| 2831 | |
| 2832 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2833 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2834 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2835 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2836 | self.waitUntilSettled() |
| 2837 | |
| 2838 | # Reconfigure (with both in the pipeline). |
| 2839 | self.sched.reconfigure(self.config) |
| 2840 | self.waitUntilSettled() |
| 2841 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2842 | self.executor_server.hold_jobs_in_build = False |
| 2843 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2844 | self.waitUntilSettled() |
| 2845 | |
| 2846 | self.assertEqual(len(self.history), 8) |
| 2847 | |
| 2848 | self.assertEqual(A.data['status'], 'MERGED') |
| 2849 | self.assertEqual(A.reported, 2) |
| 2850 | self.assertEqual(B.data['status'], 'MERGED') |
| 2851 | self.assertEqual(B.reported, 2) |
| 2852 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2853 | def test_live_reconfiguration_del_project(self): |
| 2854 | # Test project deletion from layout |
| 2855 | # while changes are enqueued |
| 2856 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2857 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2858 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2859 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2860 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2861 | |
| 2862 | # A Depends-On: B |
| 2863 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2864 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2865 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2866 | |
| 2867 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2868 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2869 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2870 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2871 | self.waitUntilSettled() |
| 2872 | self.assertEqual(len(self.builds), 5) |
| 2873 | |
| 2874 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2875 | self.commitConfigUpdate( |
| 2876 | 'common-config', |
| 2877 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2878 | self.sched.reconfigure(self.config) |
| 2879 | self.waitUntilSettled() |
| 2880 | |
| 2881 | # Builds for C aborted, builds for A succeed, |
| 2882 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2883 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2884 | self.assertEqual(job_c.changes, '3,1') |
| 2885 | self.assertEqual(job_c.result, 'ABORTED') |
| 2886 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2887 | self.executor_server.hold_jobs_in_build = False |
| 2888 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2889 | self.waitUntilSettled() |
| 2890 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2891 | self.assertEqual( |
| 2892 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2893 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2894 | |
| 2895 | self.assertEqual(A.data['status'], 'NEW') |
| 2896 | self.assertEqual(B.data['status'], 'NEW') |
| 2897 | self.assertEqual(C.data['status'], 'NEW') |
| 2898 | self.assertEqual(A.reported, 1) |
| 2899 | self.assertEqual(B.reported, 0) |
| 2900 | self.assertEqual(C.reported, 0) |
| 2901 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2902 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2903 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2904 | self.assertIn('Build succeeded', A.messages[0]) |
| 2905 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2906 | def test_delayed_repo_init(self): |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2907 | self.init_repo("org/new-project") |
Clint Byrum | 627ba36 | 2017-08-14 13:20:40 -0700 | [diff] [blame] | 2908 | files = {'README': ''} |
| 2909 | self.addCommitToRepo("org/new-project", 'Initial commit', |
| 2910 | files=files, tag='init') |
| 2911 | self.newTenantConfig('tenants/delayed-repo-init.yaml') |
| 2912 | self.commitConfigUpdate( |
| 2913 | 'common-config', |
| 2914 | 'layouts/delayed-repo-init.yaml') |
| 2915 | self.sched.reconfigure(self.config) |
| 2916 | self.waitUntilSettled() |
| 2917 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2918 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2919 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2920 | A.addApproval('Code-Review', 2) |
| 2921 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2922 | self.waitUntilSettled() |
| 2923 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2924 | 'SUCCESS') |
| 2925 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2926 | 'SUCCESS') |
| 2927 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2928 | 'SUCCESS') |
| 2929 | self.assertEqual(A.data['status'], 'MERGED') |
| 2930 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2931 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2932 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2933 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2934 | self.init_repo("org/delete-project") |
| 2935 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2936 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2937 | A.addApproval('Code-Review', 2) |
| 2938 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2939 | self.waitUntilSettled() |
| 2940 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2941 | 'SUCCESS') |
| 2942 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2943 | 'SUCCESS') |
| 2944 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2945 | 'SUCCESS') |
| 2946 | self.assertEqual(A.data['status'], 'MERGED') |
| 2947 | self.assertEqual(A.reported, 2) |
| 2948 | |
| 2949 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2950 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2951 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2952 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2953 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2954 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2955 | |
| 2956 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2957 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2958 | B.addApproval('Code-Review', 2) |
| 2959 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2960 | self.waitUntilSettled() |
| 2961 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2962 | 'SUCCESS') |
| 2963 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2964 | 'SUCCESS') |
| 2965 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2966 | 'SUCCESS') |
| 2967 | self.assertEqual(B.data['status'], 'MERGED') |
| 2968 | self.assertEqual(B.reported, 2) |
| 2969 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 2970 | @simple_layout('layouts/untrusted-secrets.yaml') |
| 2971 | def test_untrusted_secrets(self): |
| 2972 | "Test untrusted secrets" |
| 2973 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2974 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2975 | self.waitUntilSettled() |
| 2976 | |
| 2977 | self.assertHistory([]) |
| 2978 | self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") |
James E. Blair | 8eb564a | 2017-08-10 09:21:41 -0700 | [diff] [blame] | 2979 | self.assertIn('does not allow post-review job', |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 2980 | A.messages[0]) |
| 2981 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2982 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2983 | def test_tags(self): |
| 2984 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2985 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2986 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2987 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2988 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2989 | self.waitUntilSettled() |
| 2990 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2991 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2992 | |
| 2993 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2994 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2995 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2996 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2997 | |
| 2998 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2999 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3000 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3001 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3002 | def test_timer(self): |
| 3003 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3004 | # This test can not use simple_layout because it must start |
| 3005 | # with a configuration which does not include a |
| 3006 | # timer-triggered job so that we have an opportunity to set |
| 3007 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3008 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3009 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3010 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3011 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3012 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3013 | # The pipeline triggers every second, so we should have seen |
| 3014 | # several by now. |
| 3015 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3016 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3017 | |
| 3018 | self.assertEqual(len(self.builds), 2) |
| 3019 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3020 | port = self.webapp.server.socket.getsockname()[1] |
| 3021 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 3022 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3023 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 3024 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 3025 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3026 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3027 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3028 | # Stop queuing timer triggered jobs so that the assertions |
| 3029 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3030 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3031 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3032 | self.waitUntilSettled() |
| 3033 | # If APScheduler is in mid-event when we remove the job, we |
| 3034 | # can end up with one more event firing, so give it an extra |
| 3035 | # second to settle. |
| 3036 | time.sleep(1) |
| 3037 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3038 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3039 | self.waitUntilSettled() |
| 3040 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3041 | self.assertHistory([ |
| 3042 | dict(name='project-bitrot', result='SUCCESS', |
| 3043 | ref='refs/heads/master'), |
| 3044 | dict(name='project-bitrot', result='SUCCESS', |
| 3045 | ref='refs/heads/stable'), |
| 3046 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3047 | |
| 3048 | data = json.loads(data) |
| 3049 | status_jobs = set() |
| 3050 | for p in data['pipelines']: |
| 3051 | for q in p['change_queues']: |
| 3052 | for head in q['heads']: |
| 3053 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3054 | for job in change['jobs']: |
| 3055 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3056 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3057 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3058 | def test_idle(self): |
| 3059 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3060 | # This test can not use simple_layout because it must start |
| 3061 | # with a configuration which does not include a |
| 3062 | # timer-triggered job so that we have an opportunity to set |
| 3063 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3064 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3065 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3066 | for x in range(1, 3): |
| 3067 | # Test that timer triggers periodic jobs even across |
| 3068 | # layout config reloads. |
| 3069 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3070 | self.commitConfigUpdate('common-config', |
| 3071 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3072 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3073 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3074 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3075 | # The pipeline triggers every second, so we should have seen |
| 3076 | # several by now. |
| 3077 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3078 | |
| 3079 | # Stop queuing timer triggered jobs so that the assertions |
| 3080 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3081 | self.commitConfigUpdate('common-config', |
| 3082 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3083 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3084 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3085 | # If APScheduler is in mid-event when we remove the job, |
| 3086 | # we can end up with one more event firing, so give it an |
| 3087 | # extra second to settle. |
| 3088 | time.sleep(1) |
| 3089 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3090 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3091 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3092 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3093 | self.waitUntilSettled() |
| 3094 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3095 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3096 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3097 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3098 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3099 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3100 | self.waitUntilSettled() |
| 3101 | |
| 3102 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3103 | self.waitUntilSettled() |
| 3104 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3105 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3106 | |
| 3107 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3108 | # work on the knowledge of what the first message should be as |
| 3109 | # it is only configured to go to SMTP. |
| 3110 | |
| 3111 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3112 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3113 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3114 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3115 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3116 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3117 | |
| 3118 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3119 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3120 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3121 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3122 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3123 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3124 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3125 | def test_timer_smtp(self): |
| 3126 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3127 | # This test can not use simple_layout because it must start |
| 3128 | # with a configuration which does not include a |
| 3129 | # timer-triggered job so that we have an opportunity to set |
| 3130 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3131 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3132 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3133 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3134 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3135 | # The pipeline triggers every second, so we should have seen |
| 3136 | # several by now. |
| 3137 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3138 | self.waitUntilSettled() |
| 3139 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3140 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3141 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3142 | self.waitUntilSettled() |
| 3143 | self.assertEqual(len(self.history), 2) |
| 3144 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3145 | self.assertEqual(self.getJobFromHistory( |
| 3146 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3147 | self.assertEqual(self.getJobFromHistory( |
| 3148 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3149 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3150 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3151 | |
| 3152 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3153 | # work on the knowledge of what the first message should be as |
| 3154 | # it is only configured to go to SMTP. |
| 3155 | |
| 3156 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3157 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3158 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3159 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3160 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3161 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3162 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3163 | # Stop queuing timer triggered jobs and let any that may have |
| 3164 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3165 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3166 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3167 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3168 | # If APScheduler is in mid-event when we remove the job, we |
| 3169 | # can end up with one more event firing, so give it an extra |
| 3170 | # second to settle. |
| 3171 | time.sleep(1) |
| 3172 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3173 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3174 | self.waitUntilSettled() |
| 3175 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3176 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3177 | def test_timer_sshkey(self): |
| 3178 | "Test that a periodic job can setup SSH key authentication" |
| 3179 | self.worker.hold_jobs_in_build = True |
| 3180 | self.config.set('zuul', 'layout_config', |
| 3181 | 'tests/fixtures/layout-timer.yaml') |
| 3182 | self.sched.reconfigure(self.config) |
| 3183 | self.registerJobs() |
| 3184 | |
| 3185 | # The pipeline triggers every second, so we should have seen |
| 3186 | # several by now. |
| 3187 | time.sleep(5) |
| 3188 | self.waitUntilSettled() |
| 3189 | |
| 3190 | self.assertEqual(len(self.builds), 2) |
| 3191 | |
| 3192 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3193 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3194 | with open(ssh_wrapper) as f: |
| 3195 | ssh_wrapper_content = f.read() |
| 3196 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3197 | # In the unit tests Merger runs in the same process, |
| 3198 | # so we see its' environment variables |
| 3199 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3200 | |
| 3201 | self.worker.release('.*') |
| 3202 | self.waitUntilSettled() |
| 3203 | self.assertEqual(len(self.history), 2) |
| 3204 | |
| 3205 | self.assertEqual(self.getJobFromHistory( |
| 3206 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3207 | self.assertEqual(self.getJobFromHistory( |
| 3208 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3209 | |
| 3210 | # Stop queuing timer triggered jobs and let any that may have |
| 3211 | # queued through so that end of test assertions pass. |
| 3212 | self.config.set('zuul', 'layout_config', |
| 3213 | 'tests/fixtures/layout-no-timer.yaml') |
| 3214 | self.sched.reconfigure(self.config) |
| 3215 | self.registerJobs() |
| 3216 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3217 | # If APScheduler is in mid-event when we remove the job, we |
| 3218 | # can end up with one more event firing, so give it an extra |
| 3219 | # second to settle. |
| 3220 | time.sleep(1) |
| 3221 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3222 | self.worker.release('.*') |
| 3223 | self.waitUntilSettled() |
| 3224 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3225 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3226 | "Test that the RPC client can enqueue a change" |
| 3227 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3228 | A.addApproval('Code-Review', 2) |
| 3229 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3230 | |
| 3231 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3232 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3233 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3234 | r = client.enqueue(tenant='tenant-one', |
| 3235 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3236 | project='org/project', |
| 3237 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3238 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3239 | self.waitUntilSettled() |
| 3240 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3241 | 'SUCCESS') |
| 3242 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3243 | 'SUCCESS') |
| 3244 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3245 | 'SUCCESS') |
| 3246 | self.assertEqual(A.data['status'], 'MERGED') |
| 3247 | self.assertEqual(A.reported, 2) |
| 3248 | self.assertEqual(r, True) |
| 3249 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3250 | def test_client_enqueue_ref(self): |
| 3251 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3252 | p = "review.example.com/org/project" |
| 3253 | upstream = self.getUpstreamRepos([p]) |
| 3254 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3255 | A.setMerged() |
| 3256 | A_commit = str(upstream[p].commit('master')) |
| 3257 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3258 | |
| 3259 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3260 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3261 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3262 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3263 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3264 | pipeline='post', |
| 3265 | project='org/project', |
| 3266 | trigger='gerrit', |
| 3267 | ref='master', |
| 3268 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3269 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3270 | self.waitUntilSettled() |
| 3271 | job_names = [x.name for x in self.history] |
| 3272 | self.assertEqual(len(self.history), 1) |
| 3273 | self.assertIn('project-post', job_names) |
| 3274 | self.assertEqual(r, True) |
| 3275 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3276 | def test_client_enqueue_negative(self): |
| 3277 | "Test that the RPC client returns errors" |
| 3278 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3279 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3280 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3281 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3282 | "Invalid tenant"): |
| 3283 | r = client.enqueue(tenant='tenant-foo', |
| 3284 | pipeline='gate', |
| 3285 | project='org/project', |
| 3286 | trigger='gerrit', |
| 3287 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3288 | self.assertEqual(r, False) |
| 3289 | |
| 3290 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3291 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3292 | r = client.enqueue(tenant='tenant-one', |
| 3293 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3294 | project='project-does-not-exist', |
| 3295 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3296 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3297 | self.assertEqual(r, False) |
| 3298 | |
| 3299 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3300 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3301 | r = client.enqueue(tenant='tenant-one', |
| 3302 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3303 | project='org/project', |
| 3304 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3305 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3306 | self.assertEqual(r, False) |
| 3307 | |
| 3308 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3309 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3310 | r = client.enqueue(tenant='tenant-one', |
| 3311 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3312 | project='org/project', |
| 3313 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3314 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3315 | self.assertEqual(r, False) |
| 3316 | |
| 3317 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3318 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3319 | r = client.enqueue(tenant='tenant-one', |
| 3320 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3321 | project='org/project', |
| 3322 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3323 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3324 | self.assertEqual(r, False) |
| 3325 | |
| 3326 | self.waitUntilSettled() |
| 3327 | self.assertEqual(len(self.history), 0) |
| 3328 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3329 | |
| 3330 | def test_client_promote(self): |
| 3331 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3332 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3333 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3334 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3335 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3336 | A.addApproval('Code-Review', 2) |
| 3337 | B.addApproval('Code-Review', 2) |
| 3338 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3339 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3340 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3341 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3342 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3343 | |
| 3344 | self.waitUntilSettled() |
| 3345 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3346 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3347 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3348 | enqueue_times = {} |
| 3349 | for item in items: |
| 3350 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3351 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3352 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3353 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3354 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3355 | r = client.promote(tenant='tenant-one', |
| 3356 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3357 | change_ids=['2,1', '3,1']) |
| 3358 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3359 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3360 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3361 | for item in items: |
| 3362 | self.assertEqual( |
| 3363 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3364 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3365 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3366 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3367 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3368 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3369 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3370 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3371 | self.waitUntilSettled() |
| 3372 | |
| 3373 | self.assertEqual(len(self.builds), 6) |
| 3374 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3375 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3376 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3377 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3378 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3379 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3380 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3381 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3382 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3383 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3384 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3385 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3386 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3387 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3388 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3389 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3390 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3391 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3392 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3393 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3394 | self.waitUntilSettled() |
| 3395 | |
| 3396 | self.assertEqual(A.data['status'], 'MERGED') |
| 3397 | self.assertEqual(A.reported, 2) |
| 3398 | self.assertEqual(B.data['status'], 'MERGED') |
| 3399 | self.assertEqual(B.reported, 2) |
| 3400 | self.assertEqual(C.data['status'], 'MERGED') |
| 3401 | self.assertEqual(C.reported, 2) |
| 3402 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3403 | self.assertEqual(r, True) |
| 3404 | |
| 3405 | def test_client_promote_dependent(self): |
| 3406 | "Test that the RPC client can promote a dependent change" |
| 3407 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3408 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3409 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3410 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3411 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3412 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3413 | |
| 3414 | C.setDependsOn(B, 1) |
| 3415 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3416 | A.addApproval('Code-Review', 2) |
| 3417 | B.addApproval('Code-Review', 2) |
| 3418 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3419 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3420 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3421 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3422 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3423 | |
| 3424 | self.waitUntilSettled() |
| 3425 | |
| 3426 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3427 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3428 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3429 | r = client.promote(tenant='tenant-one', |
| 3430 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3431 | change_ids=['3,1']) |
| 3432 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3433 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3434 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3435 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3436 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3437 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3438 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3439 | self.waitUntilSettled() |
| 3440 | |
| 3441 | self.assertEqual(len(self.builds), 6) |
| 3442 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3443 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3444 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3445 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3446 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3447 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3448 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3449 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3450 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3451 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3452 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3453 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3454 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3455 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3456 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3457 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3458 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3459 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3460 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3461 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3462 | self.waitUntilSettled() |
| 3463 | |
| 3464 | self.assertEqual(A.data['status'], 'MERGED') |
| 3465 | self.assertEqual(A.reported, 2) |
| 3466 | self.assertEqual(B.data['status'], 'MERGED') |
| 3467 | self.assertEqual(B.reported, 2) |
| 3468 | self.assertEqual(C.data['status'], 'MERGED') |
| 3469 | self.assertEqual(C.reported, 2) |
| 3470 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3471 | self.assertEqual(r, True) |
| 3472 | |
| 3473 | def test_client_promote_negative(self): |
| 3474 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3475 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3476 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3477 | A.addApproval('Code-Review', 2) |
| 3478 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3479 | self.waitUntilSettled() |
| 3480 | |
| 3481 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3482 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3483 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3484 | |
| 3485 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3486 | r = client.promote(tenant='tenant-one', |
| 3487 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3488 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3489 | self.assertEqual(r, False) |
| 3490 | |
| 3491 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3492 | r = client.promote(tenant='tenant-one', |
| 3493 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3494 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3495 | self.assertEqual(r, False) |
| 3496 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3497 | self.executor_server.hold_jobs_in_build = False |
| 3498 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3499 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3500 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3501 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3502 | def test_queue_rate_limiting(self): |
| 3503 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3504 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3505 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3506 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3507 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3508 | |
| 3509 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3510 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3511 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3512 | A.addApproval('Code-Review', 2) |
| 3513 | B.addApproval('Code-Review', 2) |
| 3514 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3515 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3516 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3517 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3518 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3519 | self.waitUntilSettled() |
| 3520 | |
| 3521 | # Only A and B will have their merge jobs queued because |
| 3522 | # window is 2. |
| 3523 | self.assertEqual(len(self.builds), 2) |
| 3524 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3525 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3526 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3527 | # Release the merge jobs one at a time. |
| 3528 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3529 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3530 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3531 | self.waitUntilSettled() |
| 3532 | |
| 3533 | # Only A and B will have their test jobs queued because |
| 3534 | # window is 2. |
| 3535 | self.assertEqual(len(self.builds), 4) |
| 3536 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3537 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3538 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3539 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3540 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3541 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3542 | self.waitUntilSettled() |
| 3543 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3544 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3545 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3546 | # A failed so window is reduced by 1 to 1. |
| 3547 | self.assertEqual(queue.window, 1) |
| 3548 | self.assertEqual(queue.window_floor, 1) |
| 3549 | self.assertEqual(A.data['status'], 'NEW') |
| 3550 | |
| 3551 | # Gate is reset and only B's merge job is queued because |
| 3552 | # window shrunk to 1. |
| 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 | # Only B's test jobs are queued because window is still 1. |
| 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 | # B was successfully merged so window is increased to 2. |
| 3568 | self.assertEqual(queue.window, 2) |
| 3569 | self.assertEqual(queue.window_floor, 1) |
| 3570 | self.assertEqual(B.data['status'], 'MERGED') |
| 3571 | |
| 3572 | # Only C is left and its merge job is queued. |
| 3573 | self.assertEqual(len(self.builds), 1) |
| 3574 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3575 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3576 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3577 | self.waitUntilSettled() |
| 3578 | |
| 3579 | # After successful merge job the test jobs for C are queued. |
| 3580 | self.assertEqual(len(self.builds), 2) |
| 3581 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3582 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3583 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3584 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3585 | self.waitUntilSettled() |
| 3586 | |
| 3587 | # C successfully merged so window is bumped to 3. |
| 3588 | self.assertEqual(queue.window, 3) |
| 3589 | self.assertEqual(queue.window_floor, 1) |
| 3590 | self.assertEqual(C.data['status'], 'MERGED') |
| 3591 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3592 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3593 | def test_queue_rate_limiting_dependent(self): |
| 3594 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3595 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3596 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3597 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3598 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3599 | |
| 3600 | B.setDependsOn(A, 1) |
| 3601 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3602 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3603 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3604 | A.addApproval('Code-Review', 2) |
| 3605 | B.addApproval('Code-Review', 2) |
| 3606 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3607 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3608 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3609 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3610 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3611 | self.waitUntilSettled() |
| 3612 | |
| 3613 | # Only A and B will have their merge jobs queued because |
| 3614 | # window is 2. |
| 3615 | self.assertEqual(len(self.builds), 2) |
| 3616 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3617 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3618 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3619 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3620 | |
| 3621 | # Only A and B will have their test jobs queued because |
| 3622 | # window is 2. |
| 3623 | self.assertEqual(len(self.builds), 4) |
| 3624 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3625 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3626 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3627 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3628 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3629 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3630 | self.waitUntilSettled() |
| 3631 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3632 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3633 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3634 | # A failed so window is reduced by 1 to 1. |
| 3635 | self.assertEqual(queue.window, 1) |
| 3636 | self.assertEqual(queue.window_floor, 1) |
| 3637 | self.assertEqual(A.data['status'], 'NEW') |
| 3638 | self.assertEqual(B.data['status'], 'NEW') |
| 3639 | |
| 3640 | # Gate is reset and only C's merge job is queued because |
| 3641 | # window shrunk to 1 and A and B were dequeued. |
| 3642 | self.assertEqual(len(self.builds), 1) |
| 3643 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3644 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3645 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3646 | |
| 3647 | # Only C's test jobs are queued because window is still 1. |
| 3648 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3649 | builds = self.getSortedBuilds() |
| 3650 | self.assertEqual(builds[0].name, 'project-test1') |
| 3651 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3652 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3653 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3654 | self.waitUntilSettled() |
| 3655 | |
| 3656 | # C was successfully merged so window is increased to 2. |
| 3657 | self.assertEqual(queue.window, 2) |
| 3658 | self.assertEqual(queue.window_floor, 1) |
| 3659 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3660 | |
| 3661 | def test_worker_update_metadata(self): |
| 3662 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3663 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3664 | |
| 3665 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3666 | A.addApproval('Code-Review', 2) |
| 3667 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3668 | self.waitUntilSettled() |
| 3669 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3670 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3671 | |
| 3672 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3673 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3674 | |
| 3675 | start = time.time() |
| 3676 | while True: |
| 3677 | if time.time() - start > 10: |
| 3678 | raise Exception("Timeout waiting for gearman server to report " |
| 3679 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3680 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3681 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3682 | break |
| 3683 | else: |
| 3684 | time.sleep(0) |
| 3685 | |
| 3686 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3687 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3688 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3689 | self.executor_server.hold_jobs_in_build = False |
| 3690 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3691 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3692 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3693 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3694 | def test_footer_message(self): |
| 3695 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3696 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3697 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3698 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3699 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3700 | self.waitUntilSettled() |
| 3701 | |
| 3702 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3703 | B.addApproval('Code-Review', 2) |
| 3704 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3705 | self.waitUntilSettled() |
| 3706 | |
| 3707 | self.assertEqual(2, len(self.smtp_messages)) |
| 3708 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3709 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3710 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3711 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3712 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3713 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3714 | For CI problems and help debugging, contact ci@example.org""" |
| 3715 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3716 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3717 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3718 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3719 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3720 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3721 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3722 | def test_unmanaged_project_start_message(self): |
| 3723 | "Test start reporting is not done for unmanaged projects." |
| 3724 | self.init_repo("org/project", tag='init') |
| 3725 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3726 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3727 | self.waitUntilSettled() |
| 3728 | |
| 3729 | self.assertEqual(0, len(A.messages)) |
| 3730 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3731 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3732 | def test_merge_failure_reporters(self): |
| 3733 | """Check that the config is set up correctly""" |
| 3734 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3735 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3736 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3737 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3738 | "dependencies was unable to be automatically merged with the " |
| 3739 | "current state of its repository. Please rebase the change and " |
| 3740 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3741 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3742 | self.assertEqual( |
| 3743 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3744 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3745 | |
| 3746 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3747 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3748 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3749 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3750 | |
| 3751 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3752 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 3753 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3754 | |
| 3755 | self.assertTrue( |
| 3756 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3757 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3758 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3759 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 3760 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3761 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3762 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3763 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3764 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3765 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3766 | gerritreporter.GerritReporter) and |
| 3767 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3768 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3769 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3770 | ) |
| 3771 | ) |
| 3772 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3773 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3774 | def test_merge_failure_reports(self): |
| 3775 | """Check that when a change fails to merge the correct message is sent |
| 3776 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3777 | self.updateConfigLayout( |
| 3778 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3779 | self.sched.reconfigure(self.config) |
| 3780 | self.registerJobs() |
| 3781 | |
| 3782 | # Check a test failure isn't reported to SMTP |
| 3783 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3784 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3785 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3786 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3787 | self.waitUntilSettled() |
| 3788 | |
| 3789 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3790 | self.assertEqual(0, len(self.smtp_messages)) |
| 3791 | |
| 3792 | # Check a merge failure is reported to SMTP |
| 3793 | # B should be merged, but C will conflict with B |
| 3794 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3795 | B.addPatchset(['conflict']) |
| 3796 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3797 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3798 | B.addApproval('Code-Review', 2) |
| 3799 | C.addApproval('Code-Review', 2) |
| 3800 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3801 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3802 | self.waitUntilSettled() |
| 3803 | |
| 3804 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3805 | self.assertEqual(1, len(self.smtp_messages)) |
| 3806 | self.assertEqual('The merge failed! For more information...', |
| 3807 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3808 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3809 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3810 | def test_default_merge_failure_reports(self): |
| 3811 | """Check that the default merge failure reports are correct.""" |
| 3812 | |
| 3813 | # A should report success, B should report merge failure. |
| 3814 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3815 | A.addPatchset(['conflict']) |
| 3816 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3817 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3818 | A.addApproval('Code-Review', 2) |
| 3819 | B.addApproval('Code-Review', 2) |
| 3820 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3821 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3822 | self.waitUntilSettled() |
| 3823 | |
| 3824 | self.assertEqual(3, len(self.history)) # A jobs |
| 3825 | self.assertEqual(A.reported, 2) |
| 3826 | self.assertEqual(B.reported, 2) |
| 3827 | self.assertEqual(A.data['status'], 'MERGED') |
| 3828 | self.assertEqual(B.data['status'], 'NEW') |
| 3829 | self.assertIn('Build succeeded', A.messages[1]) |
| 3830 | self.assertIn('Merge Failed', B.messages[1]) |
| 3831 | self.assertIn('automatically merged', B.messages[1]) |
| 3832 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3833 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3834 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3835 | def test_client_get_running_jobs(self): |
| 3836 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3837 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3838 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3839 | A.addApproval('Code-Review', 2) |
| 3840 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3841 | self.waitUntilSettled() |
| 3842 | |
| 3843 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3844 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3845 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3846 | |
| 3847 | # Wait for gearman server to send the initial workData back to zuul |
| 3848 | start = time.time() |
| 3849 | while True: |
| 3850 | if time.time() - start > 10: |
| 3851 | raise Exception("Timeout waiting for gearman server to report " |
| 3852 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3853 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3854 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3855 | break |
| 3856 | else: |
| 3857 | time.sleep(0) |
| 3858 | |
| 3859 | running_items = client.get_running_jobs() |
| 3860 | |
| 3861 | self.assertEqual(1, len(running_items)) |
| 3862 | running_item = running_items[0] |
| 3863 | self.assertEqual([], running_item['failing_reasons']) |
| 3864 | self.assertEqual([], running_item['items_behind']) |
| 3865 | self.assertEqual('https://hostname/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3866 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3867 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3868 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3869 | self.assertEqual(True, running_item['active']) |
| 3870 | self.assertEqual('1,1', running_item['id']) |
| 3871 | |
| 3872 | self.assertEqual(3, len(running_item['jobs'])) |
| 3873 | for job in running_item['jobs']: |
| 3874 | if job['name'] == 'project-merge': |
| 3875 | self.assertEqual('project-merge', job['name']) |
| 3876 | self.assertEqual('gate', job['pipeline']) |
| 3877 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3878 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3879 | 'static/stream.html?uuid={uuid}&logfile=console.log' |
| 3880 | .format(uuid=job['uuid']), job['url']) |
| 3881 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3882 | 'finger://{hostname}/{uuid}'.format( |
| 3883 | hostname=self.executor_server.hostname, |
| 3884 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3885 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3886 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3887 | self.assertEqual(False, job['canceled']) |
| 3888 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3889 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3890 | self.assertEqual('gate', job['pipeline']) |
| 3891 | break |
| 3892 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3893 | self.executor_server.hold_jobs_in_build = False |
| 3894 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3895 | self.waitUntilSettled() |
| 3896 | |
| 3897 | running_items = client.get_running_jobs() |
| 3898 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3899 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3900 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3901 | def test_nonvoting_pipeline(self): |
| 3902 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3903 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3904 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3905 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3906 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3907 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3908 | |
| 3909 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3910 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3911 | self.assertEqual( |
| 3912 | self.getJobFromHistory('experimental-project-test').result, |
| 3913 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3914 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3915 | |
| 3916 | def test_crd_gate(self): |
| 3917 | "Test cross-repo dependencies" |
| 3918 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3919 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3920 | A.addApproval('Code-Review', 2) |
| 3921 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3922 | |
| 3923 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3924 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3925 | AM2.setMerged() |
| 3926 | AM1.setMerged() |
| 3927 | |
| 3928 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3929 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3930 | BM2.setMerged() |
| 3931 | BM1.setMerged() |
| 3932 | |
| 3933 | # A -> AM1 -> AM2 |
| 3934 | # B -> BM1 -> BM2 |
| 3935 | # A Depends-On: B |
| 3936 | # M2 is here to make sure it is never queried. If it is, it |
| 3937 | # means zuul is walking down the entire history of merged |
| 3938 | # changes. |
| 3939 | |
| 3940 | B.setDependsOn(BM1, 1) |
| 3941 | BM1.setDependsOn(BM2, 1) |
| 3942 | |
| 3943 | A.setDependsOn(AM1, 1) |
| 3944 | AM1.setDependsOn(AM2, 1) |
| 3945 | |
| 3946 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3947 | A.subject, B.data['id']) |
| 3948 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3949 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3950 | self.waitUntilSettled() |
| 3951 | |
| 3952 | self.assertEqual(A.data['status'], 'NEW') |
| 3953 | self.assertEqual(B.data['status'], 'NEW') |
| 3954 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3955 | for connection in self.connections.connections.values(): |
James E. Blair | b0a95ab | 2017-10-18 09:39:18 -0700 | [diff] [blame] | 3956 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3957 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3958 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3959 | B.addApproval('Approved', 1) |
| 3960 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3961 | self.waitUntilSettled() |
| 3962 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3963 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3964 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3965 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3966 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3967 | self.executor_server.hold_jobs_in_build = False |
| 3968 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3969 | self.waitUntilSettled() |
| 3970 | |
| 3971 | self.assertEqual(AM2.queried, 0) |
| 3972 | self.assertEqual(BM2.queried, 0) |
| 3973 | self.assertEqual(A.data['status'], 'MERGED') |
| 3974 | self.assertEqual(B.data['status'], 'MERGED') |
| 3975 | self.assertEqual(A.reported, 2) |
| 3976 | self.assertEqual(B.reported, 2) |
| 3977 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3978 | changes = self.getJobFromHistory( |
| 3979 | 'project-merge', 'org/project1').changes |
| 3980 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3981 | |
| 3982 | def test_crd_branch(self): |
| 3983 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3984 | |
| 3985 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3986 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3987 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3988 | C1 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C1') |
| 3989 | C2 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C2', |
| 3990 | status='ABANDONED') |
| 3991 | C1.data['id'] = B.data['id'] |
| 3992 | C2.data['id'] = B.data['id'] |
| 3993 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3994 | A.addApproval('Code-Review', 2) |
| 3995 | B.addApproval('Code-Review', 2) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3996 | C1.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3997 | |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3998 | # A Depends-On: B+C1 |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3999 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4000 | A.subject, B.data['id']) |
| 4001 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4002 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4003 | B.addApproval('Approved', 1) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 4004 | C1.addApproval('Approved', 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4005 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4006 | self.waitUntilSettled() |
| 4007 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4008 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4009 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4010 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4011 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4012 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4013 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4014 | self.executor_server.hold_jobs_in_build = False |
| 4015 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4016 | self.waitUntilSettled() |
| 4017 | |
| 4018 | self.assertEqual(A.data['status'], 'MERGED') |
| 4019 | self.assertEqual(B.data['status'], 'MERGED') |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 4020 | self.assertEqual(C1.data['status'], 'MERGED') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4021 | self.assertEqual(A.reported, 2) |
| 4022 | self.assertEqual(B.reported, 2) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 4023 | self.assertEqual(C1.reported, 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4024 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 4025 | changes = self.getJobFromHistory( |
| 4026 | 'project-merge', 'org/project1').changes |
| 4027 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4028 | |
| 4029 | def test_crd_multiline(self): |
| 4030 | "Test multiple depends-on lines in commit" |
| 4031 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4032 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4033 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4034 | A.addApproval('Code-Review', 2) |
| 4035 | B.addApproval('Code-Review', 2) |
| 4036 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4037 | |
| 4038 | # A Depends-On: B+C |
| 4039 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 4040 | A.subject, B.data['id'], C.data['id']) |
| 4041 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4042 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4043 | B.addApproval('Approved', 1) |
| 4044 | C.addApproval('Approved', 1) |
| 4045 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4046 | self.waitUntilSettled() |
| 4047 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4048 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4049 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4050 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4051 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4052 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4053 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4054 | self.executor_server.hold_jobs_in_build = False |
| 4055 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4056 | self.waitUntilSettled() |
| 4057 | |
| 4058 | self.assertEqual(A.data['status'], 'MERGED') |
| 4059 | self.assertEqual(B.data['status'], 'MERGED') |
| 4060 | self.assertEqual(C.data['status'], 'MERGED') |
| 4061 | self.assertEqual(A.reported, 2) |
| 4062 | self.assertEqual(B.reported, 2) |
| 4063 | self.assertEqual(C.reported, 2) |
| 4064 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4065 | changes = self.getJobFromHistory( |
| 4066 | 'project-merge', 'org/project1').changes |
| 4067 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4068 | |
| 4069 | def test_crd_unshared_gate(self): |
| 4070 | "Test cross-repo dependencies in unshared gate queues" |
| 4071 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4072 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4073 | A.addApproval('Code-Review', 2) |
| 4074 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4075 | |
| 4076 | # A Depends-On: B |
| 4077 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4078 | A.subject, B.data['id']) |
| 4079 | |
| 4080 | # A and B do not share a queue, make sure that A is unable to |
| 4081 | # enqueue B (and therefore, A is unable to be enqueued). |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4082 | B.addApproval('Approved', 1) |
| 4083 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4084 | self.waitUntilSettled() |
| 4085 | |
| 4086 | self.assertEqual(A.data['status'], 'NEW') |
| 4087 | self.assertEqual(B.data['status'], 'NEW') |
| 4088 | self.assertEqual(A.reported, 0) |
| 4089 | self.assertEqual(B.reported, 0) |
| 4090 | self.assertEqual(len(self.history), 0) |
| 4091 | |
| 4092 | # Enqueue and merge B alone. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4093 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4094 | self.waitUntilSettled() |
| 4095 | |
| 4096 | self.assertEqual(B.data['status'], 'MERGED') |
| 4097 | self.assertEqual(B.reported, 2) |
| 4098 | |
| 4099 | # Now that B is merged, A should be able to be enqueued and |
| 4100 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4101 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4102 | self.waitUntilSettled() |
| 4103 | |
| 4104 | self.assertEqual(A.data['status'], 'MERGED') |
| 4105 | self.assertEqual(A.reported, 2) |
| 4106 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4107 | def test_crd_gate_reverse(self): |
| 4108 | "Test reverse cross-repo dependencies" |
| 4109 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4110 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4111 | A.addApproval('Code-Review', 2) |
| 4112 | B.addApproval('Code-Review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4113 | |
| 4114 | # A Depends-On: B |
| 4115 | |
| 4116 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4117 | A.subject, B.data['id']) |
| 4118 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4119 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4120 | self.waitUntilSettled() |
| 4121 | |
| 4122 | self.assertEqual(A.data['status'], 'NEW') |
| 4123 | self.assertEqual(B.data['status'], 'NEW') |
| 4124 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4125 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4126 | A.addApproval('Approved', 1) |
| 4127 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4128 | self.waitUntilSettled() |
| 4129 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4130 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4131 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4132 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4133 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4134 | self.executor_server.hold_jobs_in_build = False |
| 4135 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4136 | self.waitUntilSettled() |
| 4137 | |
| 4138 | self.assertEqual(A.data['status'], 'MERGED') |
| 4139 | self.assertEqual(B.data['status'], 'MERGED') |
| 4140 | self.assertEqual(A.reported, 2) |
| 4141 | self.assertEqual(B.reported, 2) |
| 4142 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4143 | changes = self.getJobFromHistory( |
| 4144 | 'project-merge', 'org/project1').changes |
| 4145 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4146 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4147 | def test_crd_cycle(self): |
| 4148 | "Test cross-repo dependency cycles" |
| 4149 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4150 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4151 | A.addApproval('Code-Review', 2) |
| 4152 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4153 | |
| 4154 | # A -> B -> A (via commit-depends) |
| 4155 | |
| 4156 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4157 | A.subject, B.data['id']) |
| 4158 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4159 | B.subject, A.data['id']) |
| 4160 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4161 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4162 | self.waitUntilSettled() |
| 4163 | |
| 4164 | self.assertEqual(A.reported, 0) |
| 4165 | self.assertEqual(B.reported, 0) |
| 4166 | self.assertEqual(A.data['status'], 'NEW') |
| 4167 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4168 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4169 | def test_crd_gate_unknown(self): |
| 4170 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4171 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4172 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4173 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4174 | A.addApproval('Code-Review', 2) |
| 4175 | B.addApproval('Code-Review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4176 | |
| 4177 | # A Depends-On: B |
| 4178 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4179 | A.subject, B.data['id']) |
| 4180 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4181 | B.addApproval('Approved', 1) |
| 4182 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4183 | self.waitUntilSettled() |
| 4184 | |
| 4185 | # Unknown projects cannot share a queue with any other |
| 4186 | # since they don't have common jobs with any other (they have no jobs). |
| 4187 | # Changes which depend on unknown project changes |
| 4188 | # should not be processed in dependent pipeline |
| 4189 | self.assertEqual(A.data['status'], 'NEW') |
| 4190 | self.assertEqual(B.data['status'], 'NEW') |
| 4191 | self.assertEqual(A.reported, 0) |
| 4192 | self.assertEqual(B.reported, 0) |
| 4193 | self.assertEqual(len(self.history), 0) |
| 4194 | |
James E. Blair | 7720b40 | 2017-06-07 08:51:49 -0700 | [diff] [blame] | 4195 | # Simulate change B being gated outside this layout Set the |
| 4196 | # change merged before submitting the event so that when the |
| 4197 | # event triggers a gerrit query to update the change, we get |
| 4198 | # the information that it was merged. |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4199 | B.setMerged() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4200 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4201 | self.waitUntilSettled() |
| 4202 | self.assertEqual(len(self.history), 0) |
| 4203 | |
| 4204 | # Now that B is merged, A should be able to be enqueued and |
| 4205 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4206 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4207 | self.waitUntilSettled() |
| 4208 | |
| 4209 | self.assertEqual(A.data['status'], 'MERGED') |
| 4210 | self.assertEqual(A.reported, 2) |
| 4211 | self.assertEqual(B.data['status'], 'MERGED') |
| 4212 | self.assertEqual(B.reported, 0) |
| 4213 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4214 | def test_crd_check(self): |
| 4215 | "Test cross-repo dependencies in independent pipelines" |
| 4216 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4217 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4218 | self.gearman_server.hold_jobs_in_queue = True |
| 4219 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4220 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4221 | |
| 4222 | # A Depends-On: B |
| 4223 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4224 | A.subject, B.data['id']) |
| 4225 | |
| 4226 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4227 | self.waitUntilSettled() |
| 4228 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4229 | self.gearman_server.hold_jobs_in_queue = False |
| 4230 | self.gearman_server.release() |
| 4231 | self.waitUntilSettled() |
| 4232 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4233 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4234 | self.waitUntilSettled() |
| 4235 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4236 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4237 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4238 | self.executor_server.hold_jobs_in_build = False |
| 4239 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4240 | self.waitUntilSettled() |
| 4241 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4242 | self.assertEqual(A.data['status'], 'NEW') |
| 4243 | self.assertEqual(B.data['status'], 'NEW') |
| 4244 | self.assertEqual(A.reported, 1) |
| 4245 | self.assertEqual(B.reported, 0) |
| 4246 | |
| 4247 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4248 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4249 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4250 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4251 | def test_crd_check_git_depends(self): |
| 4252 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4253 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4254 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4255 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4256 | |
| 4257 | # Add two git-dependent changes and make sure they both report |
| 4258 | # success. |
| 4259 | B.setDependsOn(A, 1) |
| 4260 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4261 | self.waitUntilSettled() |
| 4262 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4263 | self.waitUntilSettled() |
| 4264 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4265 | self.orderedRelease() |
| 4266 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4267 | self.waitUntilSettled() |
| 4268 | |
| 4269 | self.assertEqual(A.data['status'], 'NEW') |
| 4270 | self.assertEqual(B.data['status'], 'NEW') |
| 4271 | self.assertEqual(A.reported, 1) |
| 4272 | self.assertEqual(B.reported, 1) |
| 4273 | |
| 4274 | self.assertEqual(self.history[0].changes, '1,1') |
| 4275 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4276 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4277 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4278 | |
| 4279 | self.assertIn('Build succeeded', A.messages[0]) |
| 4280 | self.assertIn('Build succeeded', B.messages[0]) |
| 4281 | |
| 4282 | def test_crd_check_duplicate(self): |
| 4283 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4284 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4285 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4286 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4287 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4288 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4289 | |
| 4290 | # Add two git-dependent changes... |
| 4291 | B.setDependsOn(A, 1) |
| 4292 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4293 | self.waitUntilSettled() |
| 4294 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4295 | |
| 4296 | # ...make sure the live one is not duplicated... |
| 4297 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4298 | self.waitUntilSettled() |
| 4299 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4300 | |
| 4301 | # ...but the non-live one is able to be. |
| 4302 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4303 | self.waitUntilSettled() |
| 4304 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4305 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4306 | # Release jobs in order to avoid races with change A jobs |
| 4307 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4308 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4309 | self.executor_server.hold_jobs_in_build = False |
| 4310 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4311 | self.waitUntilSettled() |
| 4312 | |
| 4313 | self.assertEqual(A.data['status'], 'NEW') |
| 4314 | self.assertEqual(B.data['status'], 'NEW') |
| 4315 | self.assertEqual(A.reported, 1) |
| 4316 | self.assertEqual(B.reported, 1) |
| 4317 | |
| 4318 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4319 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4320 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4321 | |
| 4322 | self.assertIn('Build succeeded', A.messages[0]) |
| 4323 | self.assertIn('Build succeeded', B.messages[0]) |
| 4324 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4325 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4326 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4327 | |
| 4328 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4329 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4330 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4331 | |
| 4332 | # A Depends-On: B |
| 4333 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4334 | A.subject, B.data['id']) |
| 4335 | |
| 4336 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4337 | self.waitUntilSettled() |
| 4338 | |
| 4339 | self.sched.reconfigure(self.config) |
| 4340 | |
| 4341 | # Make sure the items still share a change queue, and the |
| 4342 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4343 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4344 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4345 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4346 | first_item = queue.queue[0] |
| 4347 | for item in queue.queue: |
| 4348 | self.assertEqual(item.queue, first_item.queue) |
| 4349 | self.assertFalse(first_item.live) |
| 4350 | self.assertTrue(queue.queue[1].live) |
| 4351 | |
| 4352 | self.gearman_server.hold_jobs_in_queue = False |
| 4353 | self.gearman_server.release() |
| 4354 | self.waitUntilSettled() |
| 4355 | |
| 4356 | self.assertEqual(A.data['status'], 'NEW') |
| 4357 | self.assertEqual(B.data['status'], 'NEW') |
| 4358 | self.assertEqual(A.reported, 1) |
| 4359 | self.assertEqual(B.reported, 0) |
| 4360 | |
| 4361 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4362 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4363 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4364 | def test_crd_check_reconfiguration(self): |
| 4365 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4366 | |
| 4367 | def test_crd_undefined_project(self): |
| 4368 | """Test that undefined projects in dependencies are handled for |
| 4369 | independent pipelines""" |
| 4370 | # It's a hack for fake gerrit, |
| 4371 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4372 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4373 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4374 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4375 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4376 | def test_crd_check_ignore_dependencies(self): |
| 4377 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4378 | |
| 4379 | self.gearman_server.hold_jobs_in_queue = True |
| 4380 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4381 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4382 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4383 | |
| 4384 | # A Depends-On: B |
| 4385 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4386 | A.subject, B.data['id']) |
| 4387 | # C git-depends on B |
| 4388 | C.setDependsOn(B, 1) |
| 4389 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4390 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4391 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4392 | self.waitUntilSettled() |
| 4393 | |
| 4394 | # Make sure none of the items share a change queue, and all |
| 4395 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4396 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4397 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4398 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4399 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4400 | for item in check_pipeline.getAllItems(): |
| 4401 | self.assertTrue(item.live) |
| 4402 | |
| 4403 | self.gearman_server.hold_jobs_in_queue = False |
| 4404 | self.gearman_server.release() |
| 4405 | self.waitUntilSettled() |
| 4406 | |
| 4407 | self.assertEqual(A.data['status'], 'NEW') |
| 4408 | self.assertEqual(B.data['status'], 'NEW') |
| 4409 | self.assertEqual(C.data['status'], 'NEW') |
| 4410 | self.assertEqual(A.reported, 1) |
| 4411 | self.assertEqual(B.reported, 1) |
| 4412 | self.assertEqual(C.reported, 1) |
| 4413 | |
| 4414 | # Each job should have tested exactly one change |
| 4415 | for job in self.history: |
| 4416 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4417 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4418 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4419 | def test_crd_check_transitive(self): |
| 4420 | "Test transitive cross-repo dependencies" |
| 4421 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4422 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4423 | # and C,2 (not C,1 which would indicate stale data in the |
| 4424 | # cache for B). |
| 4425 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4426 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4427 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4428 | |
| 4429 | # A Depends-On: B |
| 4430 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4431 | A.subject, B.data['id']) |
| 4432 | |
| 4433 | # B Depends-On: C |
| 4434 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4435 | B.subject, C.data['id']) |
| 4436 | |
| 4437 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4438 | self.waitUntilSettled() |
| 4439 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4440 | |
| 4441 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4442 | self.waitUntilSettled() |
| 4443 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4444 | |
| 4445 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4446 | self.waitUntilSettled() |
| 4447 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4448 | |
| 4449 | C.addPatchset() |
| 4450 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4451 | self.waitUntilSettled() |
| 4452 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4453 | |
| 4454 | A.addPatchset() |
| 4455 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4456 | self.waitUntilSettled() |
| 4457 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4458 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4459 | def test_crd_check_unknown(self): |
| 4460 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4461 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4462 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4463 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4464 | # A Depends-On: B |
| 4465 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4466 | A.subject, B.data['id']) |
| 4467 | |
| 4468 | # Make sure zuul has seen an event on B. |
| 4469 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4470 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4471 | self.waitUntilSettled() |
| 4472 | |
| 4473 | self.assertEqual(A.data['status'], 'NEW') |
| 4474 | self.assertEqual(A.reported, 1) |
| 4475 | self.assertEqual(B.data['status'], 'NEW') |
| 4476 | self.assertEqual(B.reported, 0) |
| 4477 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4478 | def test_crd_cycle_join(self): |
| 4479 | "Test an updated change creates a cycle" |
| 4480 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4481 | |
| 4482 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4483 | self.waitUntilSettled() |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4484 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4485 | |
| 4486 | # Create B->A |
| 4487 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4488 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4489 | B.subject, A.data['id']) |
| 4490 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4491 | self.waitUntilSettled() |
| 4492 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4493 | # Dep is there so zuul should have reported on B |
| 4494 | self.assertEqual(B.reported, 1) |
| 4495 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4496 | # Update A to add A->B (a cycle). |
| 4497 | A.addPatchset() |
| 4498 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4499 | A.subject, B.data['id']) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4500 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4501 | self.waitUntilSettled() |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4502 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4503 | # Dependency cycle injected so zuul should not have reported again on A |
| 4504 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4505 | |
| 4506 | # Now if we update B to remove the depends-on, everything |
| 4507 | # should be okay. B; A->B |
| 4508 | |
| 4509 | B.addPatchset() |
| 4510 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4511 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4512 | self.waitUntilSettled() |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4513 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4514 | # Cycle was removed so now zuul should have reported again on A |
| 4515 | self.assertEqual(A.reported, 2) |
| 4516 | |
| 4517 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 4518 | self.waitUntilSettled() |
| 4519 | self.assertEqual(B.reported, 2) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4520 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4521 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4522 | def test_disable_at(self): |
| 4523 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4524 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4525 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4526 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4527 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4528 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4529 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4530 | |
| 4531 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4532 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4533 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4534 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4535 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4536 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4537 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4538 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4539 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4540 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4541 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4542 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4543 | self.executor_server.failJob('project-test1', A) |
| 4544 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4545 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4546 | self.executor_server.failJob('project-test1', D) |
| 4547 | self.executor_server.failJob('project-test1', E) |
| 4548 | self.executor_server.failJob('project-test1', F) |
| 4549 | self.executor_server.failJob('project-test1', G) |
| 4550 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4551 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4552 | self.executor_server.failJob('project-test1', J) |
| 4553 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4554 | |
| 4555 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4556 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4557 | self.waitUntilSettled() |
| 4558 | |
| 4559 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4560 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4561 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4562 | |
| 4563 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4564 | self.waitUntilSettled() |
| 4565 | |
| 4566 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4567 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4568 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4569 | |
| 4570 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4571 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4572 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4573 | self.waitUntilSettled() |
| 4574 | |
| 4575 | # We should be disabled now |
| 4576 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4577 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4578 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4579 | |
| 4580 | # We need to wait between each of these patches to make sure the |
| 4581 | # smtp messages come back in an expected order |
| 4582 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4583 | self.waitUntilSettled() |
| 4584 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4585 | self.waitUntilSettled() |
| 4586 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4587 | self.waitUntilSettled() |
| 4588 | |
| 4589 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4590 | # leaving a message on each change |
| 4591 | self.assertEqual(1, len(A.messages)) |
| 4592 | self.assertIn('Build failed.', A.messages[0]) |
| 4593 | self.assertEqual(1, len(B.messages)) |
| 4594 | self.assertIn('Build failed.', B.messages[0]) |
| 4595 | self.assertEqual(1, len(C.messages)) |
| 4596 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4597 | self.assertEqual(1, len(D.messages)) |
| 4598 | self.assertIn('Build failed.', D.messages[0]) |
| 4599 | self.assertEqual(1, len(E.messages)) |
| 4600 | self.assertIn('Build failed.', E.messages[0]) |
| 4601 | self.assertEqual(1, len(F.messages)) |
| 4602 | self.assertIn('Build failed.', F.messages[0]) |
| 4603 | |
| 4604 | # The last 3 (GHI) would have only reported via smtp. |
| 4605 | self.assertEqual(3, len(self.smtp_messages)) |
| 4606 | self.assertEqual(0, len(G.messages)) |
| 4607 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4608 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4609 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4610 | self.assertEqual(0, len(H.messages)) |
| 4611 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4612 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4613 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4614 | self.assertEqual(0, len(I.messages)) |
| 4615 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4616 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4617 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4618 | |
| 4619 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4620 | # comes out of disabled |
| 4621 | self.sched.reconfigure(self.config) |
| 4622 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4623 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4624 | |
| 4625 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4626 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4627 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4628 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4629 | |
| 4630 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4631 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4632 | self.waitUntilSettled() |
| 4633 | |
| 4634 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4635 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4636 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4637 | |
| 4638 | # J and K went back to gerrit |
| 4639 | self.assertEqual(1, len(J.messages)) |
| 4640 | self.assertIn('Build failed.', J.messages[0]) |
| 4641 | self.assertEqual(1, len(K.messages)) |
| 4642 | self.assertIn('Build failed.', K.messages[0]) |
| 4643 | # No more messages reported via smtp |
| 4644 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4645 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4646 | @simple_layout('layouts/one-job-project.yaml') |
| 4647 | def test_one_job_project(self): |
| 4648 | "Test that queueing works with one job" |
| 4649 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4650 | 'master', 'A') |
| 4651 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4652 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4653 | A.addApproval('Code-Review', 2) |
| 4654 | B.addApproval('Code-Review', 2) |
| 4655 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4656 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4657 | self.waitUntilSettled() |
| 4658 | |
| 4659 | self.assertEqual(A.data['status'], 'MERGED') |
| 4660 | self.assertEqual(A.reported, 2) |
| 4661 | self.assertEqual(B.data['status'], 'MERGED') |
| 4662 | self.assertEqual(B.reported, 2) |
| 4663 | |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4664 | def test_job_aborted(self): |
| 4665 | "Test that if a execute server aborts a job, it is run again" |
| 4666 | self.executor_server.hold_jobs_in_build = True |
| 4667 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4668 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4669 | self.waitUntilSettled() |
| 4670 | |
| 4671 | self.executor_server.release('.*-merge') |
| 4672 | self.waitUntilSettled() |
| 4673 | |
| 4674 | self.assertEqual(len(self.builds), 2) |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4675 | |
| 4676 | # first abort |
| 4677 | self.builds[0].aborted = True |
| 4678 | self.executor_server.release('.*-test*') |
| 4679 | self.waitUntilSettled() |
| 4680 | self.assertEqual(len(self.builds), 1) |
| 4681 | |
| 4682 | # second abort |
| 4683 | self.builds[0].aborted = True |
| 4684 | self.executor_server.release('.*-test*') |
| 4685 | self.waitUntilSettled() |
| 4686 | self.assertEqual(len(self.builds), 1) |
| 4687 | |
| 4688 | # third abort |
| 4689 | self.builds[0].aborted = True |
| 4690 | self.executor_server.release('.*-test*') |
| 4691 | self.waitUntilSettled() |
| 4692 | self.assertEqual(len(self.builds), 1) |
| 4693 | |
| 4694 | # fourth abort |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4695 | self.builds[0].aborted = True |
| 4696 | self.executor_server.release('.*-test*') |
| 4697 | self.waitUntilSettled() |
| 4698 | self.assertEqual(len(self.builds), 1) |
| 4699 | |
| 4700 | self.executor_server.hold_jobs_in_build = False |
| 4701 | self.executor_server.release() |
| 4702 | self.waitUntilSettled() |
| 4703 | |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4704 | self.assertEqual(len(self.history), 7) |
| 4705 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4706 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 4707 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4708 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4709 | "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] | 4710 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4711 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4712 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4713 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4714 | self.waitUntilSettled() |
| 4715 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4716 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4717 | self.waitUntilSettled() |
| 4718 | |
| 4719 | self.assertEqual(len(self.builds), 2) |
| 4720 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4721 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4722 | self.waitUntilSettled() |
| 4723 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4724 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4725 | self.assertEqual(len(self.builds), 1, |
| 4726 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4727 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4728 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4729 | self.waitUntilSettled() |
| 4730 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4731 | self.executor_server.hold_jobs_in_build = False |
| 4732 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4733 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4734 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4735 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4736 | self.assertEqual(A.reported, 1) |
| 4737 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4738 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4739 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4740 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4741 | |
| 4742 | self.fake_nodepool.paused = True |
| 4743 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4744 | A.addApproval('Code-Review', 2) |
| 4745 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4746 | self.waitUntilSettled() |
| 4747 | |
| 4748 | self.zk.client.stop() |
| 4749 | self.zk.client.start() |
| 4750 | self.fake_nodepool.paused = False |
| 4751 | self.waitUntilSettled() |
| 4752 | |
| 4753 | self.assertEqual(A.data['status'], 'MERGED') |
| 4754 | self.assertEqual(A.reported, 2) |
| 4755 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4756 | def test_nodepool_failure(self): |
| 4757 | "Test that jobs are reported after a nodepool failure" |
| 4758 | |
| 4759 | self.fake_nodepool.paused = True |
| 4760 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4761 | A.addApproval('Code-Review', 2) |
| 4762 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4763 | self.waitUntilSettled() |
| 4764 | |
| 4765 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4766 | self.fake_nodepool.addFailRequest(req) |
| 4767 | |
| 4768 | self.fake_nodepool.paused = False |
| 4769 | self.waitUntilSettled() |
| 4770 | |
| 4771 | self.assertEqual(A.data['status'], 'NEW') |
| 4772 | self.assertEqual(A.reported, 2) |
| 4773 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4774 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4775 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4776 | |
Monty Taylor | 6dc5bc1 | 2017-09-29 15:47:31 -0500 | [diff] [blame] | 4777 | def test_nodepool_priority(self): |
| 4778 | "Test that nodes are requested at the correct priority" |
| 4779 | |
| 4780 | self.fake_nodepool.paused = True |
| 4781 | |
| 4782 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4783 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4784 | |
| 4785 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4786 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4787 | |
| 4788 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4789 | C.addApproval('Code-Review', 2) |
| 4790 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 4791 | |
| 4792 | self.waitUntilSettled() |
| 4793 | |
| 4794 | reqs = self.fake_nodepool.getNodeRequests() |
| 4795 | |
| 4796 | # The requests come back sorted by oid. Since we have three requests |
| 4797 | # for the three changes each with a different priority. |
| 4798 | # Also they get a serial number based on order they were received |
| 4799 | # so the number on the endof the oid should map to order submitted. |
| 4800 | |
| 4801 | # * gate first - high priority - change C |
| 4802 | self.assertEqual(reqs[0]['_oid'], '100-0000000002') |
| 4803 | self.assertEqual(reqs[0]['node_types'], ['label1']) |
| 4804 | # * check second - normal priority - change B |
| 4805 | self.assertEqual(reqs[1]['_oid'], '200-0000000001') |
| 4806 | self.assertEqual(reqs[1]['node_types'], ['label1']) |
| 4807 | # * post third - low priority - change A |
| 4808 | # additionally, the post job defined uses an ubuntu-xenial node, |
| 4809 | # so we include that check just as an extra verification |
| 4810 | self.assertEqual(reqs[2]['_oid'], '300-0000000000') |
| 4811 | self.assertEqual(reqs[2]['node_types'], ['ubuntu-xenial']) |
| 4812 | |
| 4813 | self.fake_nodepool.paused = False |
| 4814 | self.waitUntilSettled() |
| 4815 | |
James E. Blair | fceaf41 | 2017-09-29 13:44:57 -0700 | [diff] [blame] | 4816 | @simple_layout('layouts/multiple-templates.yaml') |
| 4817 | def test_multiple_project_templates(self): |
| 4818 | # Test that applying multiple project templates to a project |
| 4819 | # doesn't alter them when used for a second project. |
| 4820 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4821 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4822 | self.waitUntilSettled() |
| 4823 | |
| 4824 | build = self.getJobFromHistory('py27') |
| 4825 | self.assertEqual(build.parameters['zuul']['jobtags'], []) |
| 4826 | |
James E. Blair | 29c7700 | 2017-10-05 14:56:35 -0700 | [diff] [blame] | 4827 | def test_pending_merge_in_reconfig(self): |
| 4828 | # Test that if we are waiting for an outstanding merge on |
| 4829 | # reconfiguration that we continue to do so. |
| 4830 | self.gearman_server.hold_merge_jobs_in_queue = True |
| 4831 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4832 | A.setMerged() |
| 4833 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4834 | self.waitUntilSettled() |
| 4835 | # Reconfigure while we still have an outstanding merge job |
| 4836 | self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'], |
| 4837 | None) |
| 4838 | self.waitUntilSettled() |
| 4839 | # Verify the merge job is still running and that the item is |
| 4840 | # in the pipeline |
| 4841 | self.assertEqual(len(self.sched.merger.jobs), 1) |
| 4842 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4843 | pipeline = tenant.layout.pipelines['post'] |
| 4844 | self.assertEqual(len(pipeline.getAllItems()), 1) |
| 4845 | self.gearman_server.hold_merge_jobs_in_queue = False |
| 4846 | self.gearman_server.release() |
| 4847 | self.waitUntilSettled() |
| 4848 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4849 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4850 | class TestExecutor(ZuulTestCase): |
| 4851 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4852 | |
| 4853 | def assertFinalState(self): |
| 4854 | # In this test, we expect to shut down in a non-final state, |
| 4855 | # so skip these checks. |
| 4856 | pass |
| 4857 | |
| 4858 | def assertCleanShutdown(self): |
| 4859 | self.log.debug("Assert clean shutdown") |
| 4860 | |
| 4861 | # After shutdown, make sure no jobs are running |
| 4862 | self.assertEqual({}, self.executor_server.job_workers) |
| 4863 | |
| 4864 | # Make sure that git.Repo objects have been garbage collected. |
| 4865 | repos = [] |
| 4866 | gc.collect() |
| 4867 | for obj in gc.get_objects(): |
| 4868 | if isinstance(obj, git.Repo): |
| 4869 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4870 | repos.append(obj) |
| 4871 | self.assertEqual(len(repos), 0) |
| 4872 | |
| 4873 | def test_executor_shutdown(self): |
| 4874 | "Test that the executor can shut down with jobs running" |
| 4875 | |
| 4876 | self.executor_server.hold_jobs_in_build = True |
| 4877 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4878 | A.addApproval('Code-Review', 2) |
| 4879 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4880 | self.waitUntilSettled() |
| 4881 | |
| 4882 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4883 | class TestDependencyGraph(ZuulTestCase): |
| 4884 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4885 | |
| 4886 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4887 | "Test a job in a dependency graph is queued only once" |
| 4888 | # Job dependencies, starting with A |
| 4889 | # A |
| 4890 | # / \ |
| 4891 | # B C |
| 4892 | # / \ / \ |
| 4893 | # D F E |
| 4894 | # | |
| 4895 | # G |
| 4896 | |
| 4897 | self.executor_server.hold_jobs_in_build = True |
| 4898 | change = self.fake_gerrit.addFakeChange( |
| 4899 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4900 | change.addApproval('Code-Review', 2) |
| 4901 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4902 | |
| 4903 | self.waitUntilSettled() |
| 4904 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4905 | |
| 4906 | self.executor_server.release('A') |
| 4907 | self.waitUntilSettled() |
| 4908 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4909 | |
| 4910 | self.executor_server.release('B') |
| 4911 | self.waitUntilSettled() |
| 4912 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4913 | |
| 4914 | self.executor_server.release('D') |
| 4915 | self.waitUntilSettled() |
| 4916 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4917 | |
| 4918 | self.executor_server.release('C') |
| 4919 | self.waitUntilSettled() |
| 4920 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4921 | |
| 4922 | self.executor_server.release('F') |
| 4923 | self.waitUntilSettled() |
| 4924 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4925 | |
| 4926 | self.executor_server.release('G') |
| 4927 | self.waitUntilSettled() |
| 4928 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4929 | |
| 4930 | self.executor_server.release('E') |
| 4931 | self.waitUntilSettled() |
| 4932 | self.assertEqual(len(self.builds), 0) |
| 4933 | |
| 4934 | self.executor_server.hold_jobs_in_build = False |
| 4935 | self.executor_server.release() |
| 4936 | self.waitUntilSettled() |
| 4937 | |
| 4938 | self.assertEqual(len(self.builds), 0) |
| 4939 | self.assertEqual(len(self.history), 7) |
| 4940 | |
| 4941 | self.assertEqual(change.data['status'], 'MERGED') |
| 4942 | self.assertEqual(change.reported, 2) |
| 4943 | |
| 4944 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4945 | "Test that a job waits till all dependencies are successful" |
| 4946 | # Job dependencies, starting with A |
| 4947 | # A |
| 4948 | # / \ |
| 4949 | # B C* |
| 4950 | # / \ / \ |
| 4951 | # D F E |
| 4952 | # | |
| 4953 | # G |
| 4954 | |
| 4955 | self.executor_server.hold_jobs_in_build = True |
| 4956 | change = self.fake_gerrit.addFakeChange( |
| 4957 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4958 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4959 | |
| 4960 | self.executor_server.failJob('C', change) |
| 4961 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4962 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4963 | |
| 4964 | self.waitUntilSettled() |
| 4965 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4966 | |
| 4967 | self.executor_server.release('A') |
| 4968 | self.waitUntilSettled() |
| 4969 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4970 | |
| 4971 | self.executor_server.release('B') |
| 4972 | self.waitUntilSettled() |
| 4973 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4974 | |
| 4975 | self.executor_server.release('D') |
| 4976 | self.waitUntilSettled() |
| 4977 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4978 | |
| 4979 | self.executor_server.release('C') |
| 4980 | self.waitUntilSettled() |
| 4981 | self.assertEqual(len(self.builds), 0) |
| 4982 | |
| 4983 | self.executor_server.hold_jobs_in_build = False |
| 4984 | self.executor_server.release() |
| 4985 | self.waitUntilSettled() |
| 4986 | |
| 4987 | self.assertEqual(len(self.builds), 0) |
| 4988 | self.assertEqual(len(self.history), 4) |
| 4989 | |
| 4990 | self.assertEqual(change.data['status'], 'NEW') |
| 4991 | self.assertEqual(change.reported, 2) |
| 4992 | |
| 4993 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4994 | class TestDuplicatePipeline(ZuulTestCase): |
| 4995 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4996 | |
| 4997 | def test_duplicate_pipelines(self): |
| 4998 | "Test that a change matching multiple pipelines works" |
| 4999 | |
| 5000 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5001 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 5002 | self.waitUntilSettled() |
| 5003 | |
| 5004 | self.assertHistory([ |
| 5005 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 5006 | pipeline='dup1'), |
| 5007 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 5008 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 5009 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 5010 | |
| 5011 | self.assertEqual(len(A.messages), 2) |
| 5012 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 5013 | if 'dup1' in A.messages[0]: |
| 5014 | self.assertIn('dup1', A.messages[0]) |
| 5015 | self.assertNotIn('dup2', A.messages[0]) |
| 5016 | self.assertIn('project-test1', A.messages[0]) |
| 5017 | self.assertIn('dup2', A.messages[1]) |
| 5018 | self.assertNotIn('dup1', A.messages[1]) |
| 5019 | self.assertIn('project-test1', A.messages[1]) |
| 5020 | else: |
| 5021 | self.assertIn('dup1', A.messages[1]) |
| 5022 | self.assertNotIn('dup2', A.messages[1]) |
| 5023 | self.assertIn('project-test1', A.messages[1]) |
| 5024 | self.assertIn('dup2', A.messages[0]) |
| 5025 | self.assertNotIn('dup1', A.messages[0]) |
| 5026 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 5027 | |
| 5028 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 5029 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 5030 | tenant_config_file = 'config/templated-project/main.yaml' |
| 5031 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5032 | def test_job_from_templates_executed(self): |
| 5033 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 5034 | |
| 5035 | A = self.fake_gerrit.addFakeChange( |
| 5036 | 'org/templated-project', 'master', 'A') |
| 5037 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5038 | self.waitUntilSettled() |
| 5039 | |
| 5040 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5041 | 'SUCCESS') |
| 5042 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 5043 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 5044 | |
| 5045 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5046 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 5047 | |
| 5048 | A = self.fake_gerrit.addFakeChange( |
| 5049 | 'org/layered-project', 'master', 'A') |
| 5050 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5051 | self.waitUntilSettled() |
| 5052 | |
| 5053 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5054 | 'SUCCESS') |
| 5055 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 5056 | 'SUCCESS') |
| 5057 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 5058 | ).result, 'SUCCESS') |
| 5059 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 5060 | ).result, 'SUCCESS') |
| 5061 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 5062 | ).result, 'SUCCESS') |
| 5063 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 5064 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5065 | |
James E. Blair | e74f571 | 2017-09-29 15:14:31 -0700 | [diff] [blame] | 5066 | def test_unimplied_branch_matchers(self): |
| 5067 | # This tests that there are no implied branch matchers added |
| 5068 | # by project templates. |
| 5069 | self.create_branch('org/layered-project', 'stable') |
| 5070 | |
| 5071 | A = self.fake_gerrit.addFakeChange( |
| 5072 | 'org/layered-project', 'stable', 'A') |
| 5073 | |
| 5074 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5075 | self.waitUntilSettled() |
| 5076 | |
| 5077 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5078 | 'SUCCESS') |
| 5079 | print(self.getJobFromHistory('project-test1'). |
| 5080 | parameters['zuul']['_inheritance_path']) |
| 5081 | |
| 5082 | def test_implied_branch_matchers(self): |
| 5083 | # This tests that there is an implied branch matcher when a |
| 5084 | # template is used on an in-repo project pipeline definition. |
| 5085 | self.create_branch('untrusted-config', 'stable') |
| 5086 | self.fake_gerrit.addEvent( |
| 5087 | self.fake_gerrit.getFakeBranchCreatedEvent( |
| 5088 | 'untrusted-config', 'stable')) |
| 5089 | self.waitUntilSettled() |
| 5090 | |
| 5091 | A = self.fake_gerrit.addFakeChange( |
| 5092 | 'untrusted-config', 'stable', 'A') |
| 5093 | |
| 5094 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5095 | self.waitUntilSettled() |
| 5096 | |
| 5097 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5098 | 'SUCCESS') |
| 5099 | print(self.getJobFromHistory('project-test1'). |
| 5100 | parameters['zuul']['_inheritance_path']) |
| 5101 | |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5102 | |
| 5103 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 5104 | tenant_config_file = 'config/success-url/main.yaml' |
| 5105 | |
| 5106 | def test_success_url(self): |
| 5107 | "Ensure bad build params are ignored" |
| 5108 | self.sched.reconfigure(self.config) |
| 5109 | self.init_repo('org/docs') |
| 5110 | |
| 5111 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 5112 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5113 | self.waitUntilSettled() |
| 5114 | |
| 5115 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 5116 | self.assertEqual(len(self.history), 2) |
| 5117 | |
| 5118 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 5119 | for build in self.history: |
| 5120 | if build.name == 'docs-draft-test': |
| 5121 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5122 | elif build.name == 'docs-draft-test2': |
| 5123 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5124 | |
| 5125 | # Two msgs: 'Starting...' + results |
| 5126 | self.assertEqual(len(self.smtp_messages), 2) |
| 5127 | body = self.smtp_messages[1]['body'].splitlines() |
| 5128 | self.assertEqual('Build succeeded.', body[0]) |
| 5129 | |
| 5130 | self.assertIn( |
| 5131 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 5132 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 5133 | body[2]) |
| 5134 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5135 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5136 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 5137 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 5138 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5139 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5140 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5141 | |
| 5142 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5143 | class TestSchedulerMerges(ZuulTestCase): |
| 5144 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5145 | |
| 5146 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5147 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5148 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5149 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5150 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 5151 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 5152 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5153 | A.addApproval('Code-Review', 2) |
| 5154 | B.addApproval('Code-Review', 2) |
| 5155 | C.addApproval('Code-Review', 2) |
| 5156 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5157 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5158 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5159 | self.waitUntilSettled() |
| 5160 | |
| 5161 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5162 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5163 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5164 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5165 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5166 | repo_messages.reverse() |
| 5167 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5168 | self.executor_server.hold_jobs_in_build = False |
| 5169 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5170 | self.waitUntilSettled() |
| 5171 | |
| 5172 | return repo_messages |
| 5173 | |
| 5174 | def _test_merge(self, mode): |
| 5175 | us_path = os.path.join( |
| 5176 | self.upstream_root, 'org/project-%s' % mode) |
| 5177 | expected_messages = [ |
| 5178 | 'initial commit', |
| 5179 | 'add content from fixture', |
| 5180 | # the intermediate commits order is nondeterministic |
| 5181 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 5182 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 5183 | ] |
| 5184 | result = self._test_project_merge_mode(mode) |
| 5185 | self.assertEqual(result[:2], expected_messages[:2]) |
| 5186 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 5187 | |
| 5188 | def test_project_merge_mode_merge(self): |
| 5189 | self._test_merge('merge') |
| 5190 | |
| 5191 | def test_project_merge_mode_merge_resolve(self): |
| 5192 | self._test_merge('merge-resolve') |
| 5193 | |
| 5194 | def test_project_merge_mode_cherrypick(self): |
| 5195 | expected_messages = [ |
| 5196 | 'initial commit', |
| 5197 | 'add content from fixture', |
| 5198 | 'A-1', |
| 5199 | 'B-1', |
| 5200 | 'C-1'] |
| 5201 | result = self._test_project_merge_mode('cherry-pick') |
| 5202 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5203 | |
| 5204 | def test_merge_branch(self): |
| 5205 | "Test that the right commits are on alternate branches" |
| 5206 | self.create_branch('org/project-merge-branches', 'mp') |
| 5207 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5208 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5209 | A = self.fake_gerrit.addFakeChange( |
| 5210 | 'org/project-merge-branches', 'mp', 'A') |
| 5211 | B = self.fake_gerrit.addFakeChange( |
| 5212 | 'org/project-merge-branches', 'mp', 'B') |
| 5213 | C = self.fake_gerrit.addFakeChange( |
| 5214 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5215 | A.addApproval('Code-Review', 2) |
| 5216 | B.addApproval('Code-Review', 2) |
| 5217 | C.addApproval('Code-Review', 2) |
| 5218 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5219 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5220 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5221 | self.waitUntilSettled() |
| 5222 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5223 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5224 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5225 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5226 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5227 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5228 | self.waitUntilSettled() |
| 5229 | |
| 5230 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 5231 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5232 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5233 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5234 | repo = git.Repo(path) |
| 5235 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5236 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5237 | repo_messages.reverse() |
| 5238 | correct_messages = [ |
| 5239 | 'initial commit', |
| 5240 | 'add content from fixture', |
| 5241 | 'mp commit', |
| 5242 | 'A-1', 'B-1', 'C-1'] |
| 5243 | self.assertEqual(repo_messages, correct_messages) |
| 5244 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5245 | self.executor_server.hold_jobs_in_build = False |
| 5246 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5247 | self.waitUntilSettled() |
| 5248 | |
| 5249 | def test_merge_multi_branch(self): |
| 5250 | "Test that dependent changes on multiple branches are merged" |
| 5251 | self.create_branch('org/project-merge-branches', 'mp') |
| 5252 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5253 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5254 | A = self.fake_gerrit.addFakeChange( |
| 5255 | 'org/project-merge-branches', 'master', 'A') |
| 5256 | B = self.fake_gerrit.addFakeChange( |
| 5257 | 'org/project-merge-branches', 'mp', 'B') |
| 5258 | C = self.fake_gerrit.addFakeChange( |
| 5259 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5260 | A.addApproval('Code-Review', 2) |
| 5261 | B.addApproval('Code-Review', 2) |
| 5262 | C.addApproval('Code-Review', 2) |
| 5263 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5264 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5265 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5266 | self.waitUntilSettled() |
| 5267 | |
| 5268 | job_A = None |
| 5269 | for job in self.builds: |
| 5270 | if 'project-merge' in job.name: |
| 5271 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5272 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5273 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 5274 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5275 | repo = git.Repo(path) |
| 5276 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5277 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5278 | repo_messages.reverse() |
| 5279 | correct_messages = [ |
| 5280 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5281 | self.assertEqual(repo_messages, correct_messages) |
| 5282 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5283 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5284 | self.waitUntilSettled() |
| 5285 | |
| 5286 | job_B = None |
| 5287 | for job in self.builds: |
| 5288 | if 'project-merge' in job.name: |
| 5289 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5290 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5291 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 5292 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5293 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5294 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5295 | repo_messages.reverse() |
| 5296 | correct_messages = [ |
| 5297 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5298 | self.assertEqual(repo_messages, correct_messages) |
| 5299 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5300 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5301 | self.waitUntilSettled() |
| 5302 | |
| 5303 | job_C = None |
| 5304 | for job in self.builds: |
| 5305 | if 'project-merge' in job.name: |
| 5306 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 5307 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5308 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 5309 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5310 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5311 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5312 | |
| 5313 | repo_messages.reverse() |
| 5314 | correct_messages = [ |
| 5315 | 'initial commit', 'add content from fixture', |
| 5316 | 'A-1', 'C-1'] |
| 5317 | # Ensure the right commits are in the history for this ref |
| 5318 | self.assertEqual(repo_messages, correct_messages) |
| 5319 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5320 | self.executor_server.hold_jobs_in_build = False |
| 5321 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5322 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5323 | |
| 5324 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5325 | class TestSemaphore(ZuulTestCase): |
| 5326 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5327 | |
| 5328 | def test_semaphore_one(self): |
| 5329 | "Test semaphores with max=1 (mutex)" |
| 5330 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5331 | |
| 5332 | self.executor_server.hold_jobs_in_build = True |
| 5333 | |
| 5334 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5335 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5336 | self.assertFalse('test-semaphore' in |
| 5337 | tenant.semaphore_handler.semaphores) |
| 5338 | |
| 5339 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5340 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5341 | self.waitUntilSettled() |
| 5342 | |
| 5343 | self.assertEqual(len(self.builds), 3) |
| 5344 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5345 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5346 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5347 | |
| 5348 | self.executor_server.release('semaphore-one-test1') |
| 5349 | self.waitUntilSettled() |
| 5350 | |
| 5351 | self.assertEqual(len(self.builds), 3) |
| 5352 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5353 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5354 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5355 | self.assertTrue('test-semaphore' in |
| 5356 | tenant.semaphore_handler.semaphores) |
| 5357 | |
| 5358 | self.executor_server.release('semaphore-one-test2') |
| 5359 | self.waitUntilSettled() |
| 5360 | |
| 5361 | self.assertEqual(len(self.builds), 3) |
| 5362 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5363 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5364 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5365 | self.assertTrue('test-semaphore' in |
| 5366 | tenant.semaphore_handler.semaphores) |
| 5367 | |
| 5368 | self.executor_server.release('semaphore-one-test1') |
| 5369 | self.waitUntilSettled() |
| 5370 | |
| 5371 | self.assertEqual(len(self.builds), 3) |
| 5372 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5373 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5374 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5375 | self.assertTrue('test-semaphore' in |
| 5376 | tenant.semaphore_handler.semaphores) |
| 5377 | |
| 5378 | self.executor_server.release('semaphore-one-test2') |
| 5379 | self.waitUntilSettled() |
| 5380 | |
| 5381 | self.assertEqual(len(self.builds), 2) |
| 5382 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5383 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5384 | self.assertFalse('test-semaphore' in |
| 5385 | tenant.semaphore_handler.semaphores) |
| 5386 | |
| 5387 | self.executor_server.hold_jobs_in_build = False |
| 5388 | self.executor_server.release() |
| 5389 | |
| 5390 | self.waitUntilSettled() |
| 5391 | self.assertEqual(len(self.builds), 0) |
| 5392 | |
| 5393 | self.assertEqual(A.reported, 1) |
| 5394 | self.assertEqual(B.reported, 1) |
| 5395 | self.assertFalse('test-semaphore' in |
| 5396 | tenant.semaphore_handler.semaphores) |
| 5397 | |
| 5398 | def test_semaphore_two(self): |
| 5399 | "Test semaphores with max>1" |
| 5400 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5401 | |
| 5402 | self.executor_server.hold_jobs_in_build = True |
| 5403 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5404 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5405 | self.assertFalse('test-semaphore-two' in |
| 5406 | tenant.semaphore_handler.semaphores) |
| 5407 | |
| 5408 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5409 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5410 | self.waitUntilSettled() |
| 5411 | |
| 5412 | self.assertEqual(len(self.builds), 4) |
| 5413 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5414 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5415 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5416 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5417 | self.assertTrue('test-semaphore-two' in |
| 5418 | tenant.semaphore_handler.semaphores) |
| 5419 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5420 | 'test-semaphore-two', [])), 2) |
| 5421 | |
| 5422 | self.executor_server.release('semaphore-two-test1') |
| 5423 | self.waitUntilSettled() |
| 5424 | |
| 5425 | self.assertEqual(len(self.builds), 4) |
| 5426 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5427 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5428 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5429 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5430 | self.assertTrue('test-semaphore-two' in |
| 5431 | tenant.semaphore_handler.semaphores) |
| 5432 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5433 | 'test-semaphore-two', [])), 2) |
| 5434 | |
| 5435 | self.executor_server.release('semaphore-two-test2') |
| 5436 | self.waitUntilSettled() |
| 5437 | |
| 5438 | self.assertEqual(len(self.builds), 4) |
| 5439 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5440 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5441 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5442 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5443 | self.assertTrue('test-semaphore-two' in |
| 5444 | tenant.semaphore_handler.semaphores) |
| 5445 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5446 | 'test-semaphore-two', [])), 2) |
| 5447 | |
| 5448 | self.executor_server.release('semaphore-two-test1') |
| 5449 | self.waitUntilSettled() |
| 5450 | |
| 5451 | self.assertEqual(len(self.builds), 3) |
| 5452 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5453 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5454 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5455 | self.assertTrue('test-semaphore-two' in |
| 5456 | tenant.semaphore_handler.semaphores) |
| 5457 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5458 | 'test-semaphore-two', [])), 1) |
| 5459 | |
| 5460 | self.executor_server.release('semaphore-two-test2') |
| 5461 | self.waitUntilSettled() |
| 5462 | |
| 5463 | self.assertEqual(len(self.builds), 2) |
| 5464 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5465 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5466 | self.assertFalse('test-semaphore-two' in |
| 5467 | tenant.semaphore_handler.semaphores) |
| 5468 | |
| 5469 | self.executor_server.hold_jobs_in_build = False |
| 5470 | self.executor_server.release() |
| 5471 | |
| 5472 | self.waitUntilSettled() |
| 5473 | self.assertEqual(len(self.builds), 0) |
| 5474 | |
| 5475 | self.assertEqual(A.reported, 1) |
| 5476 | self.assertEqual(B.reported, 1) |
| 5477 | |
| 5478 | def test_semaphore_abandon(self): |
| 5479 | "Test abandon with job semaphores" |
| 5480 | self.executor_server.hold_jobs_in_build = True |
| 5481 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5482 | check_pipeline = tenant.layout.pipelines['check'] |
| 5483 | |
| 5484 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5485 | self.assertFalse('test-semaphore' in |
| 5486 | tenant.semaphore_handler.semaphores) |
| 5487 | |
| 5488 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5489 | self.waitUntilSettled() |
| 5490 | |
| 5491 | self.assertTrue('test-semaphore' in |
| 5492 | tenant.semaphore_handler.semaphores) |
| 5493 | |
| 5494 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5495 | self.waitUntilSettled() |
| 5496 | |
| 5497 | # The check pipeline should be empty |
| 5498 | items = check_pipeline.getAllItems() |
| 5499 | self.assertEqual(len(items), 0) |
| 5500 | |
| 5501 | # The semaphore should be released |
| 5502 | self.assertFalse('test-semaphore' in |
| 5503 | tenant.semaphore_handler.semaphores) |
| 5504 | |
| 5505 | self.executor_server.hold_jobs_in_build = False |
| 5506 | self.executor_server.release() |
| 5507 | self.waitUntilSettled() |
| 5508 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5509 | def test_semaphore_new_patchset(self): |
| 5510 | "Test new patchset with job semaphores" |
| 5511 | self.executor_server.hold_jobs_in_build = True |
| 5512 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5513 | check_pipeline = tenant.layout.pipelines['check'] |
| 5514 | |
| 5515 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5516 | self.assertFalse('test-semaphore' in |
| 5517 | tenant.semaphore_handler.semaphores) |
| 5518 | |
| 5519 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5520 | self.waitUntilSettled() |
| 5521 | |
| 5522 | self.assertTrue('test-semaphore' in |
| 5523 | tenant.semaphore_handler.semaphores) |
| 5524 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5525 | self.assertEqual(len(semaphore), 1) |
| 5526 | |
| 5527 | A.addPatchset() |
| 5528 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5529 | self.waitUntilSettled() |
| 5530 | |
| 5531 | self.assertTrue('test-semaphore' in |
| 5532 | tenant.semaphore_handler.semaphores) |
| 5533 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5534 | self.assertEqual(len(semaphore), 1) |
| 5535 | |
| 5536 | items = check_pipeline.getAllItems() |
| 5537 | self.assertEqual(items[0].change.number, '1') |
| 5538 | self.assertEqual(items[0].change.patchset, '2') |
| 5539 | self.assertTrue(items[0].live) |
| 5540 | |
| 5541 | self.executor_server.hold_jobs_in_build = False |
| 5542 | self.executor_server.release() |
| 5543 | self.waitUntilSettled() |
| 5544 | |
| 5545 | # The semaphore should be released |
| 5546 | self.assertFalse('test-semaphore' in |
| 5547 | tenant.semaphore_handler.semaphores) |
| 5548 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5549 | def test_semaphore_reconfigure(self): |
| 5550 | "Test reconfigure with job semaphores" |
| 5551 | self.executor_server.hold_jobs_in_build = True |
| 5552 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5553 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5554 | self.assertFalse('test-semaphore' in |
| 5555 | tenant.semaphore_handler.semaphores) |
| 5556 | |
| 5557 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5558 | self.waitUntilSettled() |
| 5559 | |
| 5560 | self.assertTrue('test-semaphore' in |
| 5561 | tenant.semaphore_handler.semaphores) |
| 5562 | |
| 5563 | # reconfigure without layout change |
| 5564 | self.sched.reconfigure(self.config) |
| 5565 | self.waitUntilSettled() |
| 5566 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5567 | |
| 5568 | # semaphore still must be held |
| 5569 | self.assertTrue('test-semaphore' in |
| 5570 | tenant.semaphore_handler.semaphores) |
| 5571 | |
| 5572 | self.commitConfigUpdate( |
| 5573 | 'common-config', |
| 5574 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5575 | self.sched.reconfigure(self.config) |
| 5576 | self.waitUntilSettled() |
| 5577 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5578 | |
| 5579 | self.executor_server.release('project-test1') |
| 5580 | self.waitUntilSettled() |
| 5581 | |
| 5582 | # There should be no builds anymore |
| 5583 | self.assertEqual(len(self.builds), 0) |
| 5584 | |
| 5585 | # The semaphore should be released |
| 5586 | self.assertFalse('test-semaphore' in |
| 5587 | tenant.semaphore_handler.semaphores) |
| 5588 | |
| 5589 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5590 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5591 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5592 | |
| 5593 | def test_semaphore_tenant_isolation(self): |
| 5594 | "Test semaphores in multiple tenants" |
| 5595 | |
| 5596 | self.waitUntilSettled() |
| 5597 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5598 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5599 | |
| 5600 | self.executor_server.hold_jobs_in_build = True |
| 5601 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5602 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5603 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5604 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5605 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5606 | self.assertFalse('test-semaphore' in |
| 5607 | tenant_one.semaphore_handler.semaphores) |
| 5608 | self.assertFalse('test-semaphore' in |
| 5609 | tenant_two.semaphore_handler.semaphores) |
| 5610 | |
| 5611 | # add patches to project1 of tenant-one |
| 5612 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5613 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5614 | self.waitUntilSettled() |
| 5615 | |
| 5616 | # one build of project1-test1 must run |
| 5617 | # semaphore of tenant-one must be acquired once |
| 5618 | # semaphore of tenant-two must not be acquired |
| 5619 | self.assertEqual(len(self.builds), 1) |
| 5620 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5621 | self.assertTrue('test-semaphore' in |
| 5622 | tenant_one.semaphore_handler.semaphores) |
| 5623 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5624 | 'test-semaphore', [])), 1) |
| 5625 | self.assertFalse('test-semaphore' in |
| 5626 | tenant_two.semaphore_handler.semaphores) |
| 5627 | |
| 5628 | # add patches to project2 of tenant-two |
| 5629 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5630 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5631 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5632 | self.waitUntilSettled() |
| 5633 | |
| 5634 | # one build of project1-test1 must run |
| 5635 | # two builds of project2-test1 must run |
| 5636 | # semaphore of tenant-one must be acquired once |
| 5637 | # semaphore of tenant-two must be acquired twice |
| 5638 | self.assertEqual(len(self.builds), 3) |
| 5639 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5640 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5641 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5642 | self.assertTrue('test-semaphore' in |
| 5643 | tenant_one.semaphore_handler.semaphores) |
| 5644 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5645 | 'test-semaphore', [])), 1) |
| 5646 | self.assertTrue('test-semaphore' in |
| 5647 | tenant_two.semaphore_handler.semaphores) |
| 5648 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5649 | 'test-semaphore', [])), 2) |
| 5650 | |
| 5651 | self.executor_server.release('project1-test1') |
| 5652 | self.waitUntilSettled() |
| 5653 | |
| 5654 | # one build of project1-test1 must run |
| 5655 | # two builds of project2-test1 must run |
| 5656 | # semaphore of tenant-one must be acquired once |
| 5657 | # semaphore of tenant-two must be acquired twice |
| 5658 | self.assertEqual(len(self.builds), 3) |
| 5659 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5660 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5661 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5662 | self.assertTrue('test-semaphore' in |
| 5663 | tenant_one.semaphore_handler.semaphores) |
| 5664 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5665 | 'test-semaphore', [])), 1) |
| 5666 | self.assertTrue('test-semaphore' in |
| 5667 | tenant_two.semaphore_handler.semaphores) |
| 5668 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5669 | 'test-semaphore', [])), 2) |
| 5670 | |
| 5671 | self.executor_server.release('project2-test1') |
| 5672 | self.waitUntilSettled() |
| 5673 | |
| 5674 | # one build of project1-test1 must run |
| 5675 | # one build of project2-test1 must run |
| 5676 | # semaphore of tenant-one must be acquired once |
| 5677 | # semaphore of tenant-two must be acquired once |
| 5678 | self.assertEqual(len(self.builds), 2) |
| 5679 | self.assertTrue('test-semaphore' in |
| 5680 | tenant_one.semaphore_handler.semaphores) |
| 5681 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5682 | 'test-semaphore', [])), 1) |
| 5683 | self.assertTrue('test-semaphore' in |
| 5684 | tenant_two.semaphore_handler.semaphores) |
| 5685 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5686 | 'test-semaphore', [])), 1) |
| 5687 | |
| 5688 | self.executor_server.hold_jobs_in_build = False |
| 5689 | self.executor_server.release() |
| 5690 | |
| 5691 | self.waitUntilSettled() |
| 5692 | |
| 5693 | # no build must run |
| 5694 | # semaphore of tenant-one must not be acquired |
| 5695 | # semaphore of tenant-two must not be acquired |
| 5696 | self.assertEqual(len(self.builds), 0) |
| 5697 | self.assertFalse('test-semaphore' in |
| 5698 | tenant_one.semaphore_handler.semaphores) |
| 5699 | self.assertFalse('test-semaphore' in |
| 5700 | tenant_two.semaphore_handler.semaphores) |
| 5701 | |
| 5702 | self.assertEqual(A.reported, 1) |
| 5703 | self.assertEqual(B.reported, 1) |
| 5704 | |
| 5705 | |
| 5706 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5707 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5708 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5709 | |
| 5710 | def test_semaphore_in_repo(self): |
| 5711 | "Test semaphores in repo config" |
| 5712 | |
| 5713 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5714 | # max value should not be evaluated dynamically but must be updated |
| 5715 | # after the change lands. |
| 5716 | |
| 5717 | self.waitUntilSettled() |
| 5718 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5719 | |
| 5720 | in_repo_conf = textwrap.dedent( |
| 5721 | """ |
| 5722 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5723 | name: project-test1 |
| 5724 | |
| 5725 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5726 | name: project-test2 |
| 5727 | semaphore: test-semaphore |
| 5728 | |
| 5729 | - project: |
| 5730 | name: org/project |
| 5731 | tenant-one-gate: |
| 5732 | jobs: |
| 5733 | - project-test2 |
| 5734 | |
| 5735 | # the max value in dynamic layout must be ignored |
| 5736 | - semaphore: |
| 5737 | name: test-semaphore |
| 5738 | max: 2 |
| 5739 | """) |
| 5740 | |
| 5741 | in_repo_playbook = textwrap.dedent( |
| 5742 | """ |
| 5743 | - hosts: all |
| 5744 | tasks: [] |
| 5745 | """) |
| 5746 | |
| 5747 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5748 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5749 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5750 | files=file_dict) |
| 5751 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5752 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5753 | B.setDependsOn(A, 1) |
| 5754 | C.setDependsOn(A, 1) |
| 5755 | |
| 5756 | self.executor_server.hold_jobs_in_build = True |
| 5757 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5758 | A.addApproval('Code-Review', 2) |
| 5759 | B.addApproval('Code-Review', 2) |
| 5760 | C.addApproval('Code-Review', 2) |
| 5761 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5762 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5763 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5764 | self.waitUntilSettled() |
| 5765 | |
| 5766 | # check that the layout in a queue item still has max value of 1 |
| 5767 | # for test-semaphore |
| 5768 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5769 | queue = None |
| 5770 | for queue_candidate in pipeline.queues: |
| 5771 | if queue_candidate.name == 'org/project': |
| 5772 | queue = queue_candidate |
| 5773 | break |
| 5774 | queue_item = queue.queue[0] |
James E. Blair | 29a24fd | 2017-10-02 15:04:56 -0700 | [diff] [blame] | 5775 | item_dynamic_layout = queue_item.layout |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5776 | dynamic_test_semaphore = \ |
| 5777 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5778 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5779 | |
| 5780 | # one build must be in queue, one semaphores acquired |
| 5781 | self.assertEqual(len(self.builds), 1) |
| 5782 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5783 | self.assertTrue('test-semaphore' in |
| 5784 | tenant.semaphore_handler.semaphores) |
| 5785 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5786 | 'test-semaphore', [])), 1) |
| 5787 | |
| 5788 | self.executor_server.release('project-test2') |
| 5789 | self.waitUntilSettled() |
| 5790 | |
| 5791 | # change A must be merged |
| 5792 | self.assertEqual(A.data['status'], 'MERGED') |
| 5793 | self.assertEqual(A.reported, 2) |
| 5794 | |
| 5795 | # send change-merged event as the gerrit mock doesn't send it |
| 5796 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5797 | self.waitUntilSettled() |
| 5798 | |
| 5799 | # now that change A was merged, the new semaphore max must be effective |
| 5800 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5801 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5802 | |
| 5803 | # two builds must be in queue, two semaphores acquired |
| 5804 | self.assertEqual(len(self.builds), 2) |
| 5805 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5806 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5807 | self.assertTrue('test-semaphore' in |
| 5808 | tenant.semaphore_handler.semaphores) |
| 5809 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5810 | 'test-semaphore', [])), 2) |
| 5811 | |
| 5812 | self.executor_server.release('project-test2') |
| 5813 | self.waitUntilSettled() |
| 5814 | |
| 5815 | self.assertEqual(len(self.builds), 0) |
| 5816 | self.assertFalse('test-semaphore' in |
| 5817 | tenant.semaphore_handler.semaphores) |
| 5818 | |
| 5819 | self.executor_server.hold_jobs_in_build = False |
| 5820 | self.executor_server.release() |
| 5821 | |
| 5822 | self.waitUntilSettled() |
| 5823 | self.assertEqual(len(self.builds), 0) |
| 5824 | |
| 5825 | self.assertEqual(A.reported, 2) |
| 5826 | self.assertEqual(B.reported, 2) |
| 5827 | self.assertEqual(C.reported, 2) |
David Shrewsbury | f6dc176 | 2017-10-02 13:34:37 -0400 | [diff] [blame] | 5828 | |
| 5829 | |
| 5830 | class TestSchedulerBranchMatcher(ZuulTestCase): |
| 5831 | |
| 5832 | @simple_layout('layouts/matcher-test.yaml') |
| 5833 | def test_job_branch_ignored(self): |
| 5834 | ''' |
| 5835 | Test that branch matching logic works. |
| 5836 | |
| 5837 | The 'ignore-branch' job has a branch matcher that is supposed to |
| 5838 | match every branch except for the 'featureA' branch, so it should |
| 5839 | not be run on a change to that branch. |
| 5840 | ''' |
| 5841 | self.create_branch('org/project', 'featureA') |
| 5842 | A = self.fake_gerrit.addFakeChange('org/project', 'featureA', 'A') |
| 5843 | A.addApproval('Code-Review', 2) |
| 5844 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5845 | self.waitUntilSettled() |
| 5846 | self.printHistory() |
| 5847 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5848 | 'SUCCESS') |
| 5849 | self.assertJobNotInHistory('ignore-branch') |
| 5850 | self.assertEqual(A.data['status'], 'MERGED') |
| 5851 | self.assertEqual(A.reported, 2, |
| 5852 | "A should report start and success") |
| 5853 | self.assertIn('gate', A.messages[1], |
| 5854 | "A should transit gate") |