James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 17 | import gc |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 18 | import json |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 19 | import textwrap |
| 20 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 21 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 22 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 23 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | import time |
Clint Byrum | 03454a5 | 2017-05-26 17:14:02 -0700 | [diff] [blame] | 25 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 27 | import git |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 28 | import testtools |
Monty Taylor | b934c1a | 2017-06-16 19:31:47 -0500 | [diff] [blame] | 29 | import urllib |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 31 | import zuul.change_matcher |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 32 | from zuul.driver.gerrit import gerritreporter |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 33 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 34 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 35 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 36 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | from tests.base import ( |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 38 | SSLZuulTestCase, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 39 | ZuulTestCase, |
| 40 | repack_repo, |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 41 | simple_layout, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 42 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 43 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 44 | |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 45 | class TestSchedulerSSL(SSLZuulTestCase): |
| 46 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 47 | |
| 48 | def test_jobs_executed(self): |
| 49 | "Test that jobs are executed and a change is merged" |
| 50 | |
| 51 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 52 | A.addApproval('Code-Review', 2) |
| 53 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 54 | self.waitUntilSettled() |
| 55 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 56 | 'SUCCESS') |
| 57 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 58 | 'SUCCESS') |
| 59 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 60 | 'SUCCESS') |
| 61 | self.assertEqual(A.data['status'], 'MERGED') |
| 62 | self.assertEqual(A.reported, 2) |
| 63 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 64 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 65 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 66 | 'label1') |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 67 | |
| 68 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 69 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 70 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 71 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 72 | def test_jobs_executed(self): |
| 73 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 74 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 75 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 76 | A.addApproval('Code-Review', 2) |
| 77 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 78 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 79 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 80 | 'SUCCESS') |
| 81 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 82 | 'SUCCESS') |
| 83 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 84 | 'SUCCESS') |
| 85 | self.assertEqual(A.data['status'], 'MERGED') |
| 86 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 87 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 88 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 89 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 90 | 'label1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 91 | |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 92 | for stat in self.statsd.stats: |
| 93 | k, v = stat.decode('utf-8').split(':') |
| 94 | self.log.debug('stat %s:%s', k, v) |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 95 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 96 | # Per-driver |
| 97 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 98 | # Per-driver per-connection |
| 99 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 100 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 101 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 102 | 'zuul.tenant.tenant-one.pipeline.gate.current_changes', |
| 103 | value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 104 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 105 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 106 | 'org_project.master.job.project-merge.SUCCESS', kind='ms') |
| 107 | self.assertReportedStat( |
| 108 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 109 | 'org_project.master.job.project-merge.SUCCESS', value='1|c') |
| 110 | self.assertReportedStat( |
| 111 | 'zuul.tenant.tenant-one.pipeline.gate.resident_time', kind='ms') |
| 112 | self.assertReportedStat( |
| 113 | 'zuul.tenant.tenant-one.pipeline.gate.total_changes', value='1|c') |
| 114 | self.assertReportedStat( |
| 115 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 116 | 'org_project.master.resident_time', kind='ms') |
| 117 | self.assertReportedStat( |
| 118 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 119 | 'org_project.master.total_changes', value='1|c') |
James E. Blair | faf8198 | 2017-10-10 15:42:26 -0700 | [diff] [blame] | 120 | exec_key = 'zuul.executor.%s' % self.executor_server.hostname |
| 121 | self.assertReportedStat(exec_key + '.builds', value='1|c') |
James E. Blair | 4f1731b | 2017-10-10 18:11:42 -0700 | [diff] [blame] | 122 | self.assertReportedStat('zuul.nodepool.requested', value='1|c') |
| 123 | self.assertReportedStat('zuul.nodepool.requested.label.label1', |
| 124 | value='1|c') |
| 125 | self.assertReportedStat('zuul.nodepool.fulfilled.label.label1', |
| 126 | value='1|c') |
| 127 | self.assertReportedStat('zuul.nodepool.requested.size.1', value='1|c') |
| 128 | self.assertReportedStat('zuul.nodepool.fulfilled.size.1', value='1|c') |
| 129 | self.assertReportedStat('zuul.nodepool.current_requests', value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 130 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 131 | for build in self.history: |
| 132 | self.assertTrue(build.parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 133 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 134 | def test_initial_pipeline_gauges(self): |
| 135 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 136 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 137 | value='0|g') |
| 138 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 139 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 140 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 141 | def test_job_branch(self): |
| 142 | "Test the correct variant of a job runs on a branch" |
| 143 | self.create_branch('org/project', 'stable') |
| 144 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 145 | A.addApproval('Code-Review', 2) |
| 146 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 147 | self.waitUntilSettled() |
| 148 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 149 | 'SUCCESS') |
| 150 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 151 | 'SUCCESS') |
| 152 | self.assertEqual(A.data['status'], 'MERGED') |
| 153 | self.assertEqual(A.reported, 2, |
| 154 | "A should report start and success") |
| 155 | self.assertIn('gate', A.messages[1], |
| 156 | "A should transit gate") |
| 157 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 158 | 'label2') |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 159 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 160 | def test_parallel_changes(self): |
| 161 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 162 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 163 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 164 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 165 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 166 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 167 | A.addApproval('Code-Review', 2) |
| 168 | B.addApproval('Code-Review', 2) |
| 169 | C.addApproval('Code-Review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 170 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 171 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 172 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 173 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 174 | |
| 175 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 176 | self.assertEqual(len(self.builds), 1) |
| 177 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 178 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 179 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 180 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 181 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 182 | self.assertEqual(len(self.builds), 3) |
| 183 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 184 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 185 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 186 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 187 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 188 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 189 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 190 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 191 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 192 | self.assertEqual(len(self.builds), 5) |
| 193 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 194 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 195 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 196 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 197 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 198 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 199 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 200 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 201 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 202 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 203 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 204 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 205 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 206 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 207 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 208 | self.assertEqual(len(self.builds), 6) |
| 209 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 210 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 211 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 212 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 213 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 214 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 215 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 216 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 217 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 218 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 219 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 220 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 221 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 222 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 223 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 224 | self.executor_server.hold_jobs_in_build = False |
| 225 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 226 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 227 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 228 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 229 | self.assertEqual(len(self.history), 9) |
| 230 | self.assertEqual(A.data['status'], 'MERGED') |
| 231 | self.assertEqual(B.data['status'], 'MERGED') |
| 232 | self.assertEqual(C.data['status'], 'MERGED') |
| 233 | self.assertEqual(A.reported, 2) |
| 234 | self.assertEqual(B.reported, 2) |
| 235 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 236 | |
| 237 | def test_failed_changes(self): |
| 238 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 239 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 240 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 241 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 242 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 243 | A.addApproval('Code-Review', 2) |
| 244 | B.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 245 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 246 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 247 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 248 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 249 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 250 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 251 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 252 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 253 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 254 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 255 | # A/project-merge is complete |
| 256 | self.assertBuilds([ |
| 257 | dict(name='project-test1', changes='1,1'), |
| 258 | dict(name='project-test2', changes='1,1'), |
| 259 | dict(name='project-merge', changes='1,1 2,1'), |
| 260 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 261 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 262 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 263 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 264 | # A/project-merge is complete |
| 265 | # B/project-merge is complete |
| 266 | self.assertBuilds([ |
| 267 | dict(name='project-test1', changes='1,1'), |
| 268 | dict(name='project-test2', changes='1,1'), |
| 269 | dict(name='project-test1', changes='1,1 2,1'), |
| 270 | dict(name='project-test2', changes='1,1 2,1'), |
| 271 | ]) |
| 272 | |
| 273 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 274 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 275 | self.builds[0].release() |
| 276 | self.waitUntilSettled() |
| 277 | |
| 278 | self.orderedRelease() |
| 279 | self.assertHistory([ |
| 280 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 281 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 282 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 283 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 284 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 285 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 286 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 287 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 288 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 289 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 290 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 291 | self.assertEqual(A.data['status'], 'NEW') |
| 292 | self.assertEqual(B.data['status'], 'MERGED') |
| 293 | self.assertEqual(A.reported, 2) |
| 294 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 295 | |
| 296 | def test_independent_queues(self): |
| 297 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 298 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 299 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 300 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 301 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 302 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 303 | A.addApproval('Code-Review', 2) |
| 304 | B.addApproval('Code-Review', 2) |
| 305 | C.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 306 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 307 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 308 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 309 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 310 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 311 | self.waitUntilSettled() |
| 312 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 313 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 314 | self.waitUntilSettled() |
| 315 | |
| 316 | # There should be one merge job at the head of each queue running |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 317 | self.assertBuilds([ |
| 318 | dict(name='project-merge', changes='1,1'), |
| 319 | dict(name='project-merge', changes='2,1'), |
| 320 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 321 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 322 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 323 | self.builds[0].release() |
| 324 | self.waitUntilSettled() |
| 325 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 326 | self.waitUntilSettled() |
| 327 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 328 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 329 | self.waitUntilSettled() |
| 330 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 331 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 332 | self.assertBuilds([ |
| 333 | dict(name='project-test1', changes='1,1'), |
| 334 | dict(name='project-test2', changes='1,1'), |
| 335 | dict(name='project-test1', changes='2,1'), |
| 336 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 337 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 338 | dict(name='project-test1', changes='2,1 3,1'), |
| 339 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 340 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 341 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 342 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 343 | self.orderedRelease() |
| 344 | self.assertHistory([ |
| 345 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 346 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 347 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 348 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 349 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 350 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 351 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 352 | dict( |
| 353 | name='project1-project2-integration', |
| 354 | result='SUCCESS', |
| 355 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 356 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 357 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 358 | dict(name='project1-project2-integration', |
| 359 | result='SUCCESS', |
| 360 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 361 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 362 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 363 | self.assertEqual(A.data['status'], 'MERGED') |
| 364 | self.assertEqual(B.data['status'], 'MERGED') |
| 365 | self.assertEqual(C.data['status'], 'MERGED') |
| 366 | self.assertEqual(A.reported, 2) |
| 367 | self.assertEqual(B.reported, 2) |
| 368 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 369 | |
| 370 | def test_failed_change_at_head(self): |
| 371 | "Test that if a change at the head fails, jobs behind it are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 372 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 373 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 374 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 375 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 376 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 377 | A.addApproval('Code-Review', 2) |
| 378 | B.addApproval('Code-Review', 2) |
| 379 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 380 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 381 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 382 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 383 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 384 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 385 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 386 | |
| 387 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 388 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 389 | self.assertBuilds([ |
| 390 | dict(name='project-merge', changes='1,1'), |
| 391 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 392 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 393 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 394 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 395 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 396 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 397 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 398 | self.waitUntilSettled() |
| 399 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 400 | self.assertBuilds([ |
| 401 | dict(name='project-test1', changes='1,1'), |
| 402 | dict(name='project-test2', changes='1,1'), |
| 403 | dict(name='project-test1', changes='1,1 2,1'), |
| 404 | dict(name='project-test2', changes='1,1 2,1'), |
| 405 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 406 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 407 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 408 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 409 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 410 | self.waitUntilSettled() |
| 411 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 412 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 413 | self.assertBuilds([ |
| 414 | dict(name='project-test2', changes='1,1'), |
| 415 | dict(name='project-merge', changes='2,1'), |
| 416 | ]) |
| 417 | # Unordered history comparison because the aborts can finish |
| 418 | # in any order. |
| 419 | self.assertHistory([ |
| 420 | dict(name='project-merge', result='SUCCESS', |
| 421 | changes='1,1'), |
| 422 | dict(name='project-merge', result='SUCCESS', |
| 423 | changes='1,1 2,1'), |
| 424 | dict(name='project-merge', result='SUCCESS', |
| 425 | changes='1,1 2,1 3,1'), |
| 426 | dict(name='project-test1', result='FAILURE', |
| 427 | changes='1,1'), |
| 428 | dict(name='project-test1', result='ABORTED', |
| 429 | changes='1,1 2,1'), |
| 430 | dict(name='project-test2', result='ABORTED', |
| 431 | changes='1,1 2,1'), |
| 432 | dict(name='project-test1', result='ABORTED', |
| 433 | changes='1,1 2,1 3,1'), |
| 434 | dict(name='project-test2', result='ABORTED', |
| 435 | changes='1,1 2,1 3,1'), |
| 436 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 437 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 438 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 439 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 440 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 441 | self.waitUntilSettled() |
| 442 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 443 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 444 | self.assertBuilds([]) |
| 445 | self.assertHistory([ |
| 446 | dict(name='project-merge', result='SUCCESS', |
| 447 | changes='1,1'), |
| 448 | dict(name='project-merge', result='SUCCESS', |
| 449 | changes='1,1 2,1'), |
| 450 | dict(name='project-merge', result='SUCCESS', |
| 451 | changes='1,1 2,1 3,1'), |
| 452 | dict(name='project-test1', result='FAILURE', |
| 453 | changes='1,1'), |
| 454 | dict(name='project-test1', result='ABORTED', |
| 455 | changes='1,1 2,1'), |
| 456 | dict(name='project-test2', result='ABORTED', |
| 457 | changes='1,1 2,1'), |
| 458 | dict(name='project-test1', result='ABORTED', |
| 459 | changes='1,1 2,1 3,1'), |
| 460 | dict(name='project-test2', result='ABORTED', |
| 461 | changes='1,1 2,1 3,1'), |
| 462 | dict(name='project-merge', result='SUCCESS', |
| 463 | changes='2,1'), |
| 464 | dict(name='project-merge', result='SUCCESS', |
| 465 | changes='2,1 3,1'), |
| 466 | dict(name='project-test2', result='SUCCESS', |
| 467 | changes='1,1'), |
| 468 | dict(name='project-test1', result='SUCCESS', |
| 469 | changes='2,1'), |
| 470 | dict(name='project-test2', result='SUCCESS', |
| 471 | changes='2,1'), |
| 472 | dict(name='project-test1', result='SUCCESS', |
| 473 | changes='2,1 3,1'), |
| 474 | dict(name='project-test2', result='SUCCESS', |
| 475 | changes='2,1 3,1'), |
| 476 | ], ordered=False) |
| 477 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 478 | self.assertEqual(A.data['status'], 'NEW') |
| 479 | self.assertEqual(B.data['status'], 'MERGED') |
| 480 | self.assertEqual(C.data['status'], 'MERGED') |
| 481 | self.assertEqual(A.reported, 2) |
| 482 | self.assertEqual(B.reported, 2) |
| 483 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 484 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 485 | def test_failed_change_in_middle(self): |
| 486 | "Test a failed change in the middle of the queue" |
| 487 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 488 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 489 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 490 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 491 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 492 | A.addApproval('Code-Review', 2) |
| 493 | B.addApproval('Code-Review', 2) |
| 494 | C.addApproval('Code-Review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 495 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 496 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 497 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 498 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 499 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 500 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 501 | |
| 502 | self.waitUntilSettled() |
| 503 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 504 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 505 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 506 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 507 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 508 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 509 | self.waitUntilSettled() |
| 510 | |
| 511 | self.assertEqual(len(self.builds), 6) |
| 512 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 513 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 514 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 515 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 516 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 517 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 518 | |
| 519 | self.release(self.builds[2]) |
| 520 | self.waitUntilSettled() |
| 521 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 522 | # project-test1 and project-test2 for A |
| 523 | # project-test2 for B |
| 524 | # project-merge for C (without B) |
| 525 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 526 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 527 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 528 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 529 | self.waitUntilSettled() |
| 530 | |
| 531 | # project-test1 and project-test2 for A |
| 532 | # project-test2 for B |
| 533 | # project-test1 and project-test2 for C |
| 534 | self.assertEqual(len(self.builds), 5) |
| 535 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 536 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 537 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 538 | builds = items[0].current_build_set.getBuilds() |
| 539 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 540 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 541 | builds = items[1].current_build_set.getBuilds() |
| 542 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 543 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 544 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 545 | builds = items[2].current_build_set.getBuilds() |
| 546 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 547 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 548 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 549 | self.executor_server.hold_jobs_in_build = False |
| 550 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 551 | self.waitUntilSettled() |
| 552 | |
| 553 | self.assertEqual(len(self.builds), 0) |
| 554 | self.assertEqual(len(self.history), 12) |
| 555 | self.assertEqual(A.data['status'], 'MERGED') |
| 556 | self.assertEqual(B.data['status'], 'NEW') |
| 557 | self.assertEqual(C.data['status'], 'MERGED') |
| 558 | self.assertEqual(A.reported, 2) |
| 559 | self.assertEqual(B.reported, 2) |
| 560 | self.assertEqual(C.reported, 2) |
| 561 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 562 | def test_failed_change_at_head_with_queue(self): |
| 563 | "Test that if a change at the head fails, queued jobs are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 564 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 565 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 566 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 567 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 568 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 569 | A.addApproval('Code-Review', 2) |
| 570 | B.addApproval('Code-Review', 2) |
| 571 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 572 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 573 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 574 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 575 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 576 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 577 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 578 | |
| 579 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 580 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 581 | self.assertEqual(len(self.builds), 0) |
| 582 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 583 | self.assertEqual(queue[0].name, b'executor:execute') |
| 584 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 585 | self.assertEqual(job_args['job'], 'project-merge') |
| 586 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 587 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 588 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 589 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 590 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 591 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 592 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 593 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 594 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 595 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 596 | self.assertEqual(len(self.builds), 0) |
| 597 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 598 | |
| 599 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 600 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 601 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 602 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 603 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 604 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 605 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 606 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 607 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 608 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 609 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 610 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 611 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 612 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 613 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 614 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 615 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 616 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 617 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 618 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 619 | self.waitUntilSettled() |
| 620 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 621 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 622 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 623 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 624 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 625 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 626 | self.gearman_server.hold_jobs_in_queue = False |
| 627 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 628 | self.waitUntilSettled() |
| 629 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 630 | self.assertEqual(len(self.builds), 0) |
| 631 | self.assertEqual(len(self.history), 11) |
| 632 | self.assertEqual(A.data['status'], 'NEW') |
| 633 | self.assertEqual(B.data['status'], 'MERGED') |
| 634 | self.assertEqual(C.data['status'], 'MERGED') |
| 635 | self.assertEqual(A.reported, 2) |
| 636 | self.assertEqual(B.reported, 2) |
| 637 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 638 | |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 639 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 640 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 641 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 642 | A.addApproval('Code-Review', 2) |
| 643 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 644 | self.waitUntilSettled() |
| 645 | time.sleep(2) |
| 646 | |
James E. Blair | ae0f23c | 2017-09-13 10:55:15 -0600 | [diff] [blame] | 647 | data = json.loads(self.sched.formatStatusJSON('tenant-one')) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 648 | found_job = None |
| 649 | for pipeline in data['pipelines']: |
| 650 | if pipeline['name'] != 'gate': |
| 651 | continue |
| 652 | for queue in pipeline['change_queues']: |
| 653 | for head in queue['heads']: |
| 654 | for item in head: |
| 655 | for job in item['jobs']: |
| 656 | if job['name'] == 'project-merge': |
| 657 | found_job = job |
| 658 | break |
| 659 | |
| 660 | self.assertIsNotNone(found_job) |
| 661 | if iteration == 1: |
| 662 | self.assertIsNotNone(found_job['estimated_time']) |
| 663 | self.assertIsNone(found_job['remaining_time']) |
| 664 | else: |
| 665 | self.assertIsNotNone(found_job['estimated_time']) |
| 666 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 667 | self.assertIsNotNone(found_job['remaining_time']) |
| 668 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 669 | self.executor_server.hold_jobs_in_build = False |
| 670 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 671 | self.waitUntilSettled() |
| 672 | |
| 673 | def test_time_database(self): |
| 674 | "Test the time database" |
| 675 | |
| 676 | self._test_time_database(1) |
| 677 | self._test_time_database(2) |
| 678 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 679 | def test_two_failed_changes_at_head(self): |
| 680 | "Test that changes are reparented correctly if 2 fail at head" |
| 681 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 682 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 683 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 684 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 685 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 686 | A.addApproval('Code-Review', 2) |
| 687 | B.addApproval('Code-Review', 2) |
| 688 | C.addApproval('Code-Review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 689 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 690 | self.executor_server.failJob('project-test1', A) |
| 691 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 692 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 693 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 694 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 695 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 696 | self.waitUntilSettled() |
| 697 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 698 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 699 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 700 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 701 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 702 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 703 | self.waitUntilSettled() |
| 704 | |
| 705 | self.assertEqual(len(self.builds), 6) |
| 706 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 707 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 708 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 709 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 710 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 711 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 712 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 713 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 714 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 715 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 716 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 717 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 718 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 719 | |
| 720 | # Fail change B first |
| 721 | self.release(self.builds[2]) |
| 722 | self.waitUntilSettled() |
| 723 | |
| 724 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 725 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 726 | self.waitUntilSettled() |
| 727 | |
| 728 | self.assertEqual(len(self.builds), 5) |
| 729 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 730 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 731 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 732 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 733 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 734 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 735 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 736 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 737 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 738 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 739 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 740 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 741 | |
| 742 | # Finish running all passing jobs for change A |
| 743 | self.release(self.builds[1]) |
| 744 | self.waitUntilSettled() |
| 745 | # Fail and report change A |
| 746 | self.release(self.builds[0]) |
| 747 | self.waitUntilSettled() |
| 748 | |
| 749 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 750 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 751 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 752 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 753 | self.waitUntilSettled() |
| 754 | |
| 755 | self.assertEqual(len(self.builds), 4) |
| 756 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 757 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 758 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 759 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 760 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 761 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 762 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 763 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 764 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 765 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 766 | # After A failed and B and C restarted, B should be back in |
| 767 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 768 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 769 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 770 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 771 | self.executor_server.hold_jobs_in_build = False |
| 772 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 773 | self.waitUntilSettled() |
| 774 | |
| 775 | self.assertEqual(len(self.builds), 0) |
| 776 | self.assertEqual(len(self.history), 21) |
| 777 | self.assertEqual(A.data['status'], 'NEW') |
| 778 | self.assertEqual(B.data['status'], 'NEW') |
| 779 | self.assertEqual(C.data['status'], 'MERGED') |
| 780 | self.assertEqual(A.reported, 2) |
| 781 | self.assertEqual(B.reported, 2) |
| 782 | self.assertEqual(C.reported, 2) |
| 783 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 784 | def test_patch_order(self): |
| 785 | "Test that dependent patches are tested in the right order" |
| 786 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 787 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 788 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 789 | A.addApproval('Code-Review', 2) |
| 790 | B.addApproval('Code-Review', 2) |
| 791 | C.addApproval('Code-Review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 792 | |
| 793 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 794 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 795 | M2.setMerged() |
| 796 | M1.setMerged() |
| 797 | |
| 798 | # C -> B -> A -> M1 -> M2 |
| 799 | # M2 is here to make sure it is never queried. If it is, it |
| 800 | # means zuul is walking down the entire history of merged |
| 801 | # changes. |
| 802 | |
| 803 | C.setDependsOn(B, 1) |
| 804 | B.setDependsOn(A, 1) |
| 805 | A.setDependsOn(M1, 1) |
| 806 | M1.setDependsOn(M2, 1) |
| 807 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 808 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 809 | |
| 810 | self.waitUntilSettled() |
| 811 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 812 | self.assertEqual(A.data['status'], 'NEW') |
| 813 | self.assertEqual(B.data['status'], 'NEW') |
| 814 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 815 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 816 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 817 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 818 | |
| 819 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 820 | self.assertEqual(M2.queried, 0) |
| 821 | self.assertEqual(A.data['status'], 'MERGED') |
| 822 | self.assertEqual(B.data['status'], 'MERGED') |
| 823 | self.assertEqual(C.data['status'], 'MERGED') |
| 824 | self.assertEqual(A.reported, 2) |
| 825 | self.assertEqual(B.reported, 2) |
| 826 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 827 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 828 | def test_needed_changes_enqueue(self): |
| 829 | "Test that a needed change is enqueued ahead" |
| 830 | # A Given a git tree like this, if we enqueue |
| 831 | # / \ change C, we should walk up and down the tree |
| 832 | # B G and enqueue changes in the order ABCDEFG. |
| 833 | # /|\ This is also the order that you would get if |
| 834 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 835 | # / the ordering is stable across re-enqueue events. |
| 836 | # D |
| 837 | |
| 838 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 839 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 840 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 841 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 842 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 843 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 844 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 845 | B.setDependsOn(A, 1) |
| 846 | C.setDependsOn(B, 1) |
| 847 | D.setDependsOn(C, 1) |
| 848 | E.setDependsOn(B, 1) |
| 849 | F.setDependsOn(B, 1) |
| 850 | G.setDependsOn(A, 1) |
| 851 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 852 | A.addApproval('Code-Review', 2) |
| 853 | B.addApproval('Code-Review', 2) |
| 854 | C.addApproval('Code-Review', 2) |
| 855 | D.addApproval('Code-Review', 2) |
| 856 | E.addApproval('Code-Review', 2) |
| 857 | F.addApproval('Code-Review', 2) |
| 858 | G.addApproval('Code-Review', 2) |
| 859 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 860 | |
| 861 | self.waitUntilSettled() |
| 862 | |
| 863 | self.assertEqual(A.data['status'], 'NEW') |
| 864 | self.assertEqual(B.data['status'], 'NEW') |
| 865 | self.assertEqual(C.data['status'], 'NEW') |
| 866 | self.assertEqual(D.data['status'], 'NEW') |
| 867 | self.assertEqual(E.data['status'], 'NEW') |
| 868 | self.assertEqual(F.data['status'], 'NEW') |
| 869 | self.assertEqual(G.data['status'], 'NEW') |
| 870 | |
| 871 | # We're about to add approvals to changes without adding the |
| 872 | # triggering events to Zuul, so that we can be sure that it is |
| 873 | # enqueing the changes based on dependencies, not because of |
| 874 | # triggering events. Since it will have the changes cached |
| 875 | # already (without approvals), we need to clear the cache |
| 876 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 877 | for connection in self.connections.connections.values(): |
James E. Blair | b970430 | 2017-10-11 16:42:18 -0700 | [diff] [blame] | 878 | if hasattr(connection, '_change_cache'): |
| 879 | connection._change_cache.clear() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 880 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 881 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 882 | A.addApproval('Approved', 1) |
| 883 | B.addApproval('Approved', 1) |
| 884 | D.addApproval('Approved', 1) |
| 885 | E.addApproval('Approved', 1) |
| 886 | F.addApproval('Approved', 1) |
| 887 | G.addApproval('Approved', 1) |
| 888 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 889 | |
| 890 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 891 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 892 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 893 | self.executor_server.hold_jobs_in_build = False |
| 894 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 895 | self.waitUntilSettled() |
| 896 | |
| 897 | self.assertEqual(A.data['status'], 'MERGED') |
| 898 | self.assertEqual(B.data['status'], 'MERGED') |
| 899 | self.assertEqual(C.data['status'], 'MERGED') |
| 900 | self.assertEqual(D.data['status'], 'MERGED') |
| 901 | self.assertEqual(E.data['status'], 'MERGED') |
| 902 | self.assertEqual(F.data['status'], 'MERGED') |
| 903 | self.assertEqual(G.data['status'], 'MERGED') |
| 904 | self.assertEqual(A.reported, 2) |
| 905 | self.assertEqual(B.reported, 2) |
| 906 | self.assertEqual(C.reported, 2) |
| 907 | self.assertEqual(D.reported, 2) |
| 908 | self.assertEqual(E.reported, 2) |
| 909 | self.assertEqual(F.reported, 2) |
| 910 | self.assertEqual(G.reported, 2) |
| 911 | self.assertEqual(self.history[6].changes, |
| 912 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 913 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 914 | def test_source_cache(self): |
| 915 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 916 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 917 | |
| 918 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 919 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 920 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 921 | A.addApproval('Code-Review', 2) |
| 922 | B.addApproval('Code-Review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 923 | |
| 924 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 925 | M1.setMerged() |
| 926 | |
| 927 | B.setDependsOn(A, 1) |
| 928 | A.setDependsOn(M1, 1) |
| 929 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 930 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 931 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 932 | |
| 933 | self.waitUntilSettled() |
| 934 | |
| 935 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 936 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 937 | build.release() |
| 938 | self.waitUntilSettled() |
| 939 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 940 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 941 | build.release() |
| 942 | self.waitUntilSettled() |
| 943 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 944 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 945 | self.waitUntilSettled() |
| 946 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 947 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 948 | # there should still be changes in the cache |
James E. Blair | b970430 | 2017-10-11 16:42:18 -0700 | [diff] [blame] | 949 | self.assertNotEqual(len(list(self.fake_gerrit._change_cache.keys())), |
| 950 | 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 951 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 952 | self.executor_server.hold_jobs_in_build = False |
| 953 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 954 | self.waitUntilSettled() |
| 955 | |
| 956 | self.assertEqual(A.data['status'], 'MERGED') |
| 957 | self.assertEqual(B.data['status'], 'MERGED') |
| 958 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 959 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 960 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 961 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 962 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 963 | # TODO: move to test_gerrit (this is a unit test!) |
| 964 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 965 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 966 | (trusted, project) = tenant.getProject('org/project') |
| 967 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 968 | |
| 969 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 970 | # it easier for users to create events for testing. |
| 971 | event = zuul.model.TriggerEvent() |
| 972 | event.trigger_name = 'gerrit' |
| 973 | event.change_number = '1' |
| 974 | event.patch_number = '2' |
| 975 | |
| 976 | a = source.getChange(event) |
| 977 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 978 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 979 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 980 | A.addApproval('Code-Review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 981 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 982 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 983 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 984 | A.addApproval('Approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 985 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 986 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 987 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 988 | def test_project_merge_conflict(self): |
| 989 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 990 | |
| 991 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 992 | A = self.fake_gerrit.addFakeChange('org/project', |
| 993 | 'master', 'A', |
| 994 | files={'conflict': 'foo'}) |
| 995 | B = self.fake_gerrit.addFakeChange('org/project', |
| 996 | 'master', 'B', |
| 997 | files={'conflict': 'bar'}) |
| 998 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 999 | 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1000 | A.addApproval('Code-Review', 2) |
| 1001 | B.addApproval('Code-Review', 2) |
| 1002 | C.addApproval('Code-Review', 2) |
| 1003 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1004 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1005 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1006 | self.waitUntilSettled() |
| 1007 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1008 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1009 | self.assertEqual(C.reported, 1) |
| 1010 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1011 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1012 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1013 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1014 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1015 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1016 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1017 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1018 | self.gearman_server.hold_jobs_in_queue = False |
| 1019 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1020 | self.waitUntilSettled() |
| 1021 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1022 | self.assertEqual(A.data['status'], 'MERGED') |
| 1023 | self.assertEqual(B.data['status'], 'NEW') |
| 1024 | self.assertEqual(C.data['status'], 'MERGED') |
| 1025 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1026 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1027 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1028 | |
| 1029 | self.assertHistory([ |
| 1030 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1031 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1032 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1033 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1034 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1035 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1036 | ], ordered=False) |
| 1037 | |
| 1038 | def test_delayed_merge_conflict(self): |
| 1039 | "Test that delayed check merge conflicts are handled properly" |
| 1040 | |
| 1041 | # Hold jobs in the gearman queue so that we can test whether |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1042 | # the executor sucesfully merges a change based on an old |
| 1043 | # repo state (frozen by the scheduler) which would otherwise |
| 1044 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1045 | self.gearman_server.hold_jobs_in_queue = True |
| 1046 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1047 | 'master', 'A', |
| 1048 | files={'conflict': 'foo'}) |
| 1049 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1050 | 'master', 'B', |
| 1051 | files={'conflict': 'bar'}) |
| 1052 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1053 | 'master', 'C') |
| 1054 | C.setDependsOn(B, 1) |
| 1055 | |
| 1056 | # A enters the gate queue; B and C enter the check queue |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1057 | A.addApproval('Code-Review', 2) |
| 1058 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1059 | self.waitUntilSettled() |
| 1060 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1061 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1062 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1063 | self.waitUntilSettled() |
| 1064 | |
| 1065 | self.assertEqual(A.reported, 1) |
| 1066 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1067 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1068 | |
| 1069 | # A merges while B and C are queued in check |
| 1070 | # Release A project-merge |
| 1071 | queue = self.gearman_server.getQueue() |
| 1072 | self.release(queue[0]) |
| 1073 | self.waitUntilSettled() |
| 1074 | |
| 1075 | # Release A project-test* |
| 1076 | # gate has higher precedence, so A's test jobs are added in |
| 1077 | # front of the merge jobs for B and C |
| 1078 | queue = self.gearman_server.getQueue() |
| 1079 | self.release(queue[0]) |
| 1080 | self.release(queue[1]) |
| 1081 | self.waitUntilSettled() |
| 1082 | |
| 1083 | self.assertEqual(A.data['status'], 'MERGED') |
| 1084 | self.assertEqual(B.data['status'], 'NEW') |
| 1085 | self.assertEqual(C.data['status'], 'NEW') |
| 1086 | self.assertEqual(A.reported, 2) |
| 1087 | self.assertEqual(B.reported, 0) |
| 1088 | self.assertEqual(C.reported, 0) |
| 1089 | self.assertHistory([ |
| 1090 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1091 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1092 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1093 | ], ordered=False) |
| 1094 | |
| 1095 | # B and C report merge conflicts |
| 1096 | # Release B project-merge |
| 1097 | queue = self.gearman_server.getQueue() |
| 1098 | self.release(queue[0]) |
| 1099 | self.waitUntilSettled() |
| 1100 | |
| 1101 | # Release C |
| 1102 | self.gearman_server.hold_jobs_in_queue = False |
| 1103 | self.gearman_server.release() |
| 1104 | self.waitUntilSettled() |
| 1105 | |
| 1106 | self.assertEqual(A.data['status'], 'MERGED') |
| 1107 | self.assertEqual(B.data['status'], 'NEW') |
| 1108 | self.assertEqual(C.data['status'], 'NEW') |
| 1109 | self.assertEqual(A.reported, 2) |
| 1110 | self.assertEqual(B.reported, 1) |
| 1111 | self.assertEqual(C.reported, 1) |
| 1112 | |
| 1113 | self.assertHistory([ |
| 1114 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1115 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1116 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1117 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1118 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1119 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1120 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1121 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1122 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1123 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1124 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1125 | def test_post(self): |
| 1126 | "Test that post jobs run" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1127 | p = "review.example.com/org/project" |
| 1128 | upstream = self.getUpstreamRepos([p]) |
| 1129 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1130 | A.setMerged() |
| 1131 | A_commit = str(upstream[p].commit('master')) |
| 1132 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1133 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1134 | e = { |
| 1135 | "type": "ref-updated", |
| 1136 | "submitter": { |
| 1137 | "name": "User Name", |
| 1138 | }, |
| 1139 | "refUpdate": { |
| 1140 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1141 | "newRev": A_commit, |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1142 | "refName": "master", |
| 1143 | "project": "org/project", |
| 1144 | } |
| 1145 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1146 | self.fake_gerrit.addEvent(e) |
| 1147 | self.waitUntilSettled() |
| 1148 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1149 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1150 | self.assertEqual(len(self.history), 1) |
| 1151 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1152 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1153 | def test_post_ignore_deletes(self): |
| 1154 | "Test that deleting refs does not trigger post jobs" |
| 1155 | |
| 1156 | e = { |
| 1157 | "type": "ref-updated", |
| 1158 | "submitter": { |
| 1159 | "name": "User Name", |
| 1160 | }, |
| 1161 | "refUpdate": { |
| 1162 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1163 | "newRev": "0000000000000000000000000000000000000000", |
| 1164 | "refName": "master", |
| 1165 | "project": "org/project", |
| 1166 | } |
| 1167 | } |
| 1168 | self.fake_gerrit.addEvent(e) |
| 1169 | self.waitUntilSettled() |
| 1170 | |
| 1171 | job_names = [x.name for x in self.history] |
| 1172 | self.assertEqual(len(self.history), 0) |
| 1173 | self.assertNotIn('project-post', job_names) |
| 1174 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1175 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1176 | def test_post_ignore_deletes_negative(self): |
| 1177 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1178 | e = { |
| 1179 | "type": "ref-updated", |
| 1180 | "submitter": { |
| 1181 | "name": "User Name", |
| 1182 | }, |
| 1183 | "refUpdate": { |
| 1184 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1185 | "newRev": "0000000000000000000000000000000000000000", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1186 | "refName": "testbranch", |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1187 | "project": "org/project", |
| 1188 | } |
| 1189 | } |
| 1190 | self.fake_gerrit.addEvent(e) |
| 1191 | self.waitUntilSettled() |
| 1192 | |
| 1193 | job_names = [x.name for x in self.history] |
| 1194 | self.assertEqual(len(self.history), 1) |
| 1195 | self.assertIn('project-post', job_names) |
| 1196 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1197 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1198 | def test_build_configuration_branch_interaction(self): |
| 1199 | "Test that switching between branches works" |
| 1200 | self.test_build_configuration() |
| 1201 | self.test_build_configuration_branch() |
| 1202 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1203 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1204 | repo = git.Repo(path) |
| 1205 | repo.heads.master.commit = repo.commit('init') |
| 1206 | self.test_build_configuration() |
| 1207 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1208 | def test_dependent_changes_rebase(self): |
| 1209 | # Test that no errors occur when we walk a dependency tree |
| 1210 | # with an unused leaf node due to a rebase. |
| 1211 | # Start by constructing: C -> B -> A |
| 1212 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1213 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1214 | B.setDependsOn(A, 1) |
| 1215 | |
| 1216 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1217 | C.setDependsOn(B, 1) |
| 1218 | |
| 1219 | # Then rebase to form: D -> C -> A |
| 1220 | C.addPatchset() # C,2 |
| 1221 | C.setDependsOn(A, 1) |
| 1222 | |
| 1223 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1224 | D.setDependsOn(C, 2) |
| 1225 | |
| 1226 | # Walk the entire tree |
| 1227 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1228 | self.waitUntilSettled() |
| 1229 | self.assertEqual(len(self.history), 3) |
| 1230 | |
| 1231 | # Verify that walking just part of the tree still works |
| 1232 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1233 | self.waitUntilSettled() |
| 1234 | self.assertEqual(len(self.history), 6) |
| 1235 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1236 | def test_dependent_changes_dequeue(self): |
| 1237 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1238 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1239 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1240 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1241 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1242 | A.addApproval('Code-Review', 2) |
| 1243 | B.addApproval('Code-Review', 2) |
| 1244 | C.addApproval('Code-Review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1245 | |
| 1246 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1247 | M1.setMerged() |
| 1248 | |
| 1249 | # C -> B -> A -> M1 |
| 1250 | |
| 1251 | C.setDependsOn(B, 1) |
| 1252 | B.setDependsOn(A, 1) |
| 1253 | A.setDependsOn(M1, 1) |
| 1254 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1255 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1256 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1257 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1258 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1259 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1260 | |
| 1261 | self.waitUntilSettled() |
| 1262 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1263 | self.assertEqual(A.data['status'], 'NEW') |
| 1264 | self.assertEqual(A.reported, 2) |
| 1265 | self.assertEqual(B.data['status'], 'NEW') |
| 1266 | self.assertEqual(B.reported, 2) |
| 1267 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1268 | self.assertIn('This change depends on a change that failed to merge.', |
| 1269 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1270 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1271 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1272 | def test_failing_dependent_changes(self): |
| 1273 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1274 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1275 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1276 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1277 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1278 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1279 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1280 | A.addApproval('Code-Review', 2) |
| 1281 | B.addApproval('Code-Review', 2) |
| 1282 | C.addApproval('Code-Review', 2) |
| 1283 | D.addApproval('Code-Review', 2) |
| 1284 | E.addApproval('Code-Review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1285 | |
| 1286 | # E, D -> C -> B, A |
| 1287 | |
| 1288 | D.setDependsOn(C, 1) |
| 1289 | C.setDependsOn(B, 1) |
| 1290 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1291 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1292 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1293 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1294 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
| 1295 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1296 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1297 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1298 | |
| 1299 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1300 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1301 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1302 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1303 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1304 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1305 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1306 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1307 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1308 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1309 | self.waitUntilSettled() |
| 1310 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1311 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1312 | for build in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 1313 | if build.parameters['zuul']['change'] != '1': |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1314 | build.release() |
| 1315 | self.waitUntilSettled() |
| 1316 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1317 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1318 | self.waitUntilSettled() |
| 1319 | |
| 1320 | self.assertEqual(A.data['status'], 'MERGED') |
| 1321 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1322 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1323 | self.assertEqual(B.data['status'], 'NEW') |
| 1324 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1325 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1326 | self.assertEqual(C.data['status'], 'NEW') |
| 1327 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1328 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1329 | self.assertEqual(D.data['status'], 'NEW') |
| 1330 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1331 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1332 | self.assertEqual(E.data['status'], 'MERGED') |
| 1333 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1334 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1335 | self.assertEqual(len(self.history), 18) |
| 1336 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1337 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1338 | "Test that if a change at the head fails it is dequeued only once" |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1339 | # If it's dequeued more than once, we should see extra |
| 1340 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1341 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1342 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1343 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1344 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1345 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1346 | A.addApproval('Code-Review', 2) |
| 1347 | B.addApproval('Code-Review', 2) |
| 1348 | C.addApproval('Code-Review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1349 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1350 | self.executor_server.failJob('project-test1', A) |
| 1351 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1352 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1353 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1354 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1355 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1356 | |
| 1357 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1358 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1359 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1360 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1361 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1362 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1363 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1364 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1365 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1366 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1367 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1368 | self.waitUntilSettled() |
| 1369 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1370 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1371 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1372 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1373 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1374 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1375 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1376 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1377 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1378 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1379 | self.waitUntilSettled() |
| 1380 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1381 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1382 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1383 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1384 | self.executor_server.hold_jobs_in_build = False |
| 1385 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1386 | self.waitUntilSettled() |
| 1387 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1388 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1389 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1390 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1391 | self.assertEqual(A.data['status'], 'NEW') |
| 1392 | self.assertEqual(B.data['status'], 'MERGED') |
| 1393 | self.assertEqual(C.data['status'], 'MERGED') |
| 1394 | self.assertEqual(A.reported, 2) |
| 1395 | self.assertEqual(B.reported, 2) |
| 1396 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1397 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1398 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1399 | def test_nonvoting_job(self): |
| 1400 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1401 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1402 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1403 | 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1404 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1405 | self.executor_server.failJob('nonvoting-project-test2', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1406 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1407 | |
| 1408 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1409 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1410 | self.assertEqual(A.data['status'], 'MERGED') |
| 1411 | self.assertEqual(A.reported, 2) |
| 1412 | self.assertEqual( |
| 1413 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1414 | 'SUCCESS') |
| 1415 | self.assertEqual( |
| 1416 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1417 | 'SUCCESS') |
| 1418 | self.assertEqual( |
| 1419 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1420 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1421 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 1422 | self.assertTrue(self.getJobFromHistory('nonvoting-project-merge'). |
| 1423 | parameters['zuul']['voting']) |
| 1424 | self.assertTrue(self.getJobFromHistory('nonvoting-project-test1'). |
| 1425 | parameters['zuul']['voting']) |
| 1426 | self.assertFalse(self.getJobFromHistory('nonvoting-project-test2'). |
| 1427 | parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1428 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1429 | def test_check_queue_success(self): |
| 1430 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1431 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1432 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1433 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1434 | |
| 1435 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1436 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1437 | self.assertEqual(A.data['status'], 'NEW') |
| 1438 | self.assertEqual(A.reported, 1) |
| 1439 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1440 | 'SUCCESS') |
| 1441 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1442 | 'SUCCESS') |
| 1443 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1444 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1445 | |
| 1446 | def test_check_queue_failure(self): |
| 1447 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1448 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1449 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1450 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1451 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1452 | |
| 1453 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1454 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1455 | self.assertEqual(A.data['status'], 'NEW') |
| 1456 | self.assertEqual(A.reported, 1) |
| 1457 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1458 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1459 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1460 | 'SUCCESS') |
| 1461 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1462 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1463 | |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1464 | @simple_layout('layouts/autohold.yaml') |
| 1465 | def test_autohold(self): |
| 1466 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1467 | |
| 1468 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1469 | self.gearman_server.port) |
| 1470 | self.addCleanup(client.shutdown) |
David Shrewsbury | 36b2adf | 2017-07-31 15:40:13 -0400 | [diff] [blame] | 1471 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1472 | "reason text", 1) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1473 | self.assertTrue(r) |
| 1474 | |
| 1475 | self.executor_server.failJob('project-test2', A) |
| 1476 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1477 | |
| 1478 | self.waitUntilSettled() |
| 1479 | |
| 1480 | self.assertEqual(A.data['status'], 'NEW') |
| 1481 | self.assertEqual(A.reported, 1) |
| 1482 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1483 | 'FAILURE') |
| 1484 | |
| 1485 | # Check nodepool for a held node |
| 1486 | held_node = None |
| 1487 | for node in self.fake_nodepool.getNodes(): |
| 1488 | if node['state'] == zuul.model.STATE_HOLD: |
| 1489 | held_node = node |
| 1490 | break |
| 1491 | self.assertIsNotNone(held_node) |
| 1492 | |
| 1493 | # Validate node has recorded the failed job |
| 1494 | self.assertEqual( |
| 1495 | held_node['hold_job'], |
| 1496 | " ".join(['tenant-one', |
| 1497 | 'review.example.com/org/project', |
| 1498 | 'project-test2']) |
| 1499 | ) |
David Shrewsbury | f9af9df | 2017-08-01 15:19:26 -0400 | [diff] [blame] | 1500 | self.assertEqual(held_node['comment'], "reason text") |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1501 | |
| 1502 | # Another failed change should not hold any more nodes |
| 1503 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1504 | self.executor_server.failJob('project-test2', B) |
| 1505 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1506 | self.waitUntilSettled() |
| 1507 | self.assertEqual(B.data['status'], 'NEW') |
| 1508 | self.assertEqual(B.reported, 1) |
| 1509 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1510 | 'FAILURE') |
| 1511 | |
| 1512 | held_nodes = 0 |
| 1513 | for node in self.fake_nodepool.getNodes(): |
| 1514 | if node['state'] == zuul.model.STATE_HOLD: |
| 1515 | held_nodes += 1 |
| 1516 | self.assertEqual(held_nodes, 1) |
| 1517 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1518 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1519 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1520 | # This particular test does a large amount of merges and needs a little |
| 1521 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1522 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1523 | "test that dependent changes behind dequeued changes work" |
| 1524 | # This complicated test is a reproduction of a real life bug |
| 1525 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1526 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1527 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1528 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1529 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1530 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1531 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1532 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1533 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1534 | D.setDependsOn(C, 1) |
| 1535 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1536 | A.addApproval('Code-Review', 2) |
| 1537 | B.addApproval('Code-Review', 2) |
| 1538 | C.addApproval('Code-Review', 2) |
| 1539 | D.addApproval('Code-Review', 2) |
| 1540 | E.addApproval('Code-Review', 2) |
| 1541 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1542 | |
| 1543 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1544 | |
| 1545 | # Change object re-use in the gerrit trigger is hidden if |
| 1546 | # changes are added in quick succession; waiting makes it more |
| 1547 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1548 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1549 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1550 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1551 | self.waitUntilSettled() |
| 1552 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1553 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1554 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1555 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1556 | self.waitUntilSettled() |
| 1557 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1558 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1559 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1560 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1561 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1562 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1563 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1564 | self.fake_gerrit.addEvent(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1565 | self.waitUntilSettled() |
| 1566 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1567 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1568 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1569 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1570 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1571 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1572 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1573 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1574 | self.waitUntilSettled() |
| 1575 | |
| 1576 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1577 | |
| 1578 | # Grab pointers to the jobs we want to release before |
| 1579 | # releasing any, because list indexes may change as |
| 1580 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1581 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1582 | a.release() |
| 1583 | b.release() |
| 1584 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1585 | self.waitUntilSettled() |
| 1586 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1587 | self.executor_server.hold_jobs_in_build = False |
| 1588 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1589 | self.waitUntilSettled() |
| 1590 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1591 | self.assertEqual(A.data['status'], 'NEW') |
| 1592 | self.assertEqual(B.data['status'], 'MERGED') |
| 1593 | self.assertEqual(C.data['status'], 'MERGED') |
| 1594 | self.assertEqual(D.data['status'], 'MERGED') |
| 1595 | self.assertEqual(E.data['status'], 'MERGED') |
| 1596 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1597 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1598 | self.assertEqual(A.reported, 2) |
| 1599 | self.assertEqual(B.reported, 2) |
| 1600 | self.assertEqual(C.reported, 2) |
| 1601 | self.assertEqual(D.reported, 2) |
| 1602 | self.assertEqual(E.reported, 2) |
| 1603 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1604 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1605 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1606 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1607 | |
| 1608 | def test_merger_repack(self): |
| 1609 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1610 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1611 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1612 | A.addApproval('Code-Review', 2) |
| 1613 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1614 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1615 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1616 | 'SUCCESS') |
| 1617 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1618 | 'SUCCESS') |
| 1619 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1620 | 'SUCCESS') |
| 1621 | self.assertEqual(A.data['status'], 'MERGED') |
| 1622 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1623 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1624 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1625 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1626 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1627 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1628 | if os.path.exists(path): |
| 1629 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1630 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1631 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1632 | if os.path.exists(path): |
| 1633 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1634 | |
| 1635 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1636 | A.addApproval('Code-Review', 2) |
| 1637 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1638 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1639 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1640 | 'SUCCESS') |
| 1641 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1642 | 'SUCCESS') |
| 1643 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1644 | 'SUCCESS') |
| 1645 | self.assertEqual(A.data['status'], 'MERGED') |
| 1646 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1647 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1648 | def test_merger_repack_large_change(self): |
| 1649 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1650 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1651 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1652 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1653 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1654 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1655 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1656 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1657 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1658 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1659 | # TODOv3(jeblair): add hostname to upstream root |
| 1660 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1661 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1662 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1663 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1664 | if os.path.exists(path): |
| 1665 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1666 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1667 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1668 | if os.path.exists(path): |
| 1669 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1670 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1671 | A.addApproval('Code-Review', 2) |
| 1672 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1673 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1674 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1675 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1676 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1677 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1678 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1679 | 'SUCCESS') |
| 1680 | self.assertEqual(A.data['status'], 'MERGED') |
| 1681 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1682 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1683 | def test_new_patchset_dequeues_old(self): |
| 1684 | "Test that a new patchset causes the old to be dequeued" |
| 1685 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1686 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1687 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1688 | M.setMerged() |
| 1689 | |
| 1690 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1691 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1692 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1693 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1694 | A.addApproval('Code-Review', 2) |
| 1695 | B.addApproval('Code-Review', 2) |
| 1696 | C.addApproval('Code-Review', 2) |
| 1697 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1698 | |
| 1699 | C.setDependsOn(B, 1) |
| 1700 | B.setDependsOn(A, 1) |
| 1701 | A.setDependsOn(M, 1) |
| 1702 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1703 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1704 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1705 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1706 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1707 | self.waitUntilSettled() |
| 1708 | |
| 1709 | B.addPatchset() |
| 1710 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1711 | self.waitUntilSettled() |
| 1712 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1713 | self.executor_server.hold_jobs_in_build = False |
| 1714 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1715 | self.waitUntilSettled() |
| 1716 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1717 | self.assertEqual(A.data['status'], 'MERGED') |
| 1718 | self.assertEqual(A.reported, 2) |
| 1719 | self.assertEqual(B.data['status'], 'NEW') |
| 1720 | self.assertEqual(B.reported, 2) |
| 1721 | self.assertEqual(C.data['status'], 'NEW') |
| 1722 | self.assertEqual(C.reported, 2) |
| 1723 | self.assertEqual(D.data['status'], 'MERGED') |
| 1724 | self.assertEqual(D.reported, 2) |
| 1725 | 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] | 1726 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1727 | def test_new_patchset_check(self): |
| 1728 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1729 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1730 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1731 | |
| 1732 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1733 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1734 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1735 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1736 | |
| 1737 | # Add two git-dependent changes |
| 1738 | B.setDependsOn(A, 1) |
| 1739 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1740 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1741 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1742 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1743 | |
| 1744 | # A live item, and a non-live/live pair |
| 1745 | items = check_pipeline.getAllItems() |
| 1746 | self.assertEqual(len(items), 3) |
| 1747 | |
| 1748 | self.assertEqual(items[0].change.number, '1') |
| 1749 | self.assertEqual(items[0].change.patchset, '1') |
| 1750 | self.assertFalse(items[0].live) |
| 1751 | |
| 1752 | self.assertEqual(items[1].change.number, '2') |
| 1753 | self.assertEqual(items[1].change.patchset, '1') |
| 1754 | self.assertTrue(items[1].live) |
| 1755 | |
| 1756 | self.assertEqual(items[2].change.number, '1') |
| 1757 | self.assertEqual(items[2].change.patchset, '1') |
| 1758 | self.assertTrue(items[2].live) |
| 1759 | |
| 1760 | # Add a new patchset to A |
| 1761 | A.addPatchset() |
| 1762 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1763 | self.waitUntilSettled() |
| 1764 | |
| 1765 | # The live copy of A,1 should be gone, but the non-live and B |
| 1766 | # should continue, and we should have a new A,2 |
| 1767 | items = check_pipeline.getAllItems() |
| 1768 | self.assertEqual(len(items), 3) |
| 1769 | |
| 1770 | self.assertEqual(items[0].change.number, '1') |
| 1771 | self.assertEqual(items[0].change.patchset, '1') |
| 1772 | self.assertFalse(items[0].live) |
| 1773 | |
| 1774 | self.assertEqual(items[1].change.number, '2') |
| 1775 | self.assertEqual(items[1].change.patchset, '1') |
| 1776 | self.assertTrue(items[1].live) |
| 1777 | |
| 1778 | self.assertEqual(items[2].change.number, '1') |
| 1779 | self.assertEqual(items[2].change.patchset, '2') |
| 1780 | self.assertTrue(items[2].live) |
| 1781 | |
| 1782 | # Add a new patchset to B |
| 1783 | B.addPatchset() |
| 1784 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1785 | self.waitUntilSettled() |
| 1786 | |
| 1787 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1788 | # but we should have a new B,2 (still based on A,1) |
| 1789 | items = check_pipeline.getAllItems() |
| 1790 | self.assertEqual(len(items), 3) |
| 1791 | |
| 1792 | self.assertEqual(items[0].change.number, '1') |
| 1793 | self.assertEqual(items[0].change.patchset, '2') |
| 1794 | self.assertTrue(items[0].live) |
| 1795 | |
| 1796 | self.assertEqual(items[1].change.number, '1') |
| 1797 | self.assertEqual(items[1].change.patchset, '1') |
| 1798 | self.assertFalse(items[1].live) |
| 1799 | |
| 1800 | self.assertEqual(items[2].change.number, '2') |
| 1801 | self.assertEqual(items[2].change.patchset, '2') |
| 1802 | self.assertTrue(items[2].live) |
| 1803 | |
| 1804 | self.builds[0].release() |
| 1805 | self.waitUntilSettled() |
| 1806 | self.builds[0].release() |
| 1807 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1808 | self.executor_server.hold_jobs_in_build = False |
| 1809 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1810 | self.waitUntilSettled() |
| 1811 | |
| 1812 | self.assertEqual(A.reported, 1) |
| 1813 | self.assertEqual(B.reported, 1) |
| 1814 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1815 | self.assertEqual(self.history[0].changes, '1,1') |
| 1816 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1817 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1818 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1819 | self.assertEqual(self.history[2].changes, '1,2') |
| 1820 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1821 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1822 | |
| 1823 | def test_abandoned_gate(self): |
| 1824 | "Test that an abandoned change is dequeued from gate" |
| 1825 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1826 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1827 | |
| 1828 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1829 | A.addApproval('Code-Review', 2) |
| 1830 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1831 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1832 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1833 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1834 | |
| 1835 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1836 | self.waitUntilSettled() |
| 1837 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1838 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1839 | self.waitUntilSettled() |
| 1840 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1841 | self.assertBuilds([]) |
| 1842 | self.assertHistory([ |
| 1843 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1844 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1845 | self.assertEqual(A.reported, 1, |
| 1846 | "Abandoned gate change should report only start") |
| 1847 | |
| 1848 | def test_abandoned_check(self): |
| 1849 | "Test that an abandoned change is dequeued from check" |
| 1850 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1851 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1852 | |
| 1853 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1854 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1855 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1856 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1857 | |
| 1858 | # Add two git-dependent changes |
| 1859 | B.setDependsOn(A, 1) |
| 1860 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1861 | self.waitUntilSettled() |
| 1862 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1863 | self.waitUntilSettled() |
| 1864 | # A live item, and a non-live/live pair |
| 1865 | items = check_pipeline.getAllItems() |
| 1866 | self.assertEqual(len(items), 3) |
| 1867 | |
| 1868 | self.assertEqual(items[0].change.number, '1') |
| 1869 | self.assertFalse(items[0].live) |
| 1870 | |
| 1871 | self.assertEqual(items[1].change.number, '2') |
| 1872 | self.assertTrue(items[1].live) |
| 1873 | |
| 1874 | self.assertEqual(items[2].change.number, '1') |
| 1875 | self.assertTrue(items[2].live) |
| 1876 | |
| 1877 | # Abandon A |
| 1878 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1879 | self.waitUntilSettled() |
| 1880 | |
| 1881 | # The live copy of A should be gone, but the non-live and B |
| 1882 | # should continue |
| 1883 | items = check_pipeline.getAllItems() |
| 1884 | self.assertEqual(len(items), 2) |
| 1885 | |
| 1886 | self.assertEqual(items[0].change.number, '1') |
| 1887 | self.assertFalse(items[0].live) |
| 1888 | |
| 1889 | self.assertEqual(items[1].change.number, '2') |
| 1890 | self.assertTrue(items[1].live) |
| 1891 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1892 | self.executor_server.hold_jobs_in_build = False |
| 1893 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1894 | self.waitUntilSettled() |
| 1895 | |
| 1896 | self.assertEqual(len(self.history), 4) |
| 1897 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1898 | 'Build should have been aborted') |
| 1899 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1900 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1901 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1902 | def test_abandoned_not_timer(self): |
| 1903 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1904 | # This test can not use simple_layout because it must start |
| 1905 | # with a configuration which does not include a |
| 1906 | # timer-triggered job so that we have an opportunity to set |
| 1907 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1908 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1909 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1910 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1911 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1912 | # The pipeline triggers every second, so we should have seen |
| 1913 | # several by now. |
| 1914 | time.sleep(5) |
| 1915 | self.waitUntilSettled() |
| 1916 | # Stop queuing timer triggered jobs so that the assertions |
| 1917 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1918 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1919 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1920 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 1921 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 1922 | # If APScheduler is in mid-event when we remove the job, we |
| 1923 | # can end up with one more event firing, so give it an extra |
| 1924 | # second to settle. |
| 1925 | time.sleep(1) |
| 1926 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1927 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1928 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1929 | |
| 1930 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1931 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1932 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1933 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1934 | |
| 1935 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1936 | self.waitUntilSettled() |
| 1937 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1938 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1939 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1940 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1941 | self.waitUntilSettled() |
| 1942 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1943 | def test_new_patchset_dequeues_old_on_head(self): |
| 1944 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1945 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1946 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1947 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1948 | M.setMerged() |
| 1949 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1950 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1951 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1952 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1953 | A.addApproval('Code-Review', 2) |
| 1954 | B.addApproval('Code-Review', 2) |
| 1955 | C.addApproval('Code-Review', 2) |
| 1956 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1957 | |
| 1958 | C.setDependsOn(B, 1) |
| 1959 | B.setDependsOn(A, 1) |
| 1960 | A.setDependsOn(M, 1) |
| 1961 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1962 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1963 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1964 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1965 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1966 | self.waitUntilSettled() |
| 1967 | |
| 1968 | A.addPatchset() |
| 1969 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1970 | self.waitUntilSettled() |
| 1971 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1972 | self.executor_server.hold_jobs_in_build = False |
| 1973 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1974 | self.waitUntilSettled() |
| 1975 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1976 | self.assertEqual(A.data['status'], 'NEW') |
| 1977 | self.assertEqual(A.reported, 2) |
| 1978 | self.assertEqual(B.data['status'], 'NEW') |
| 1979 | self.assertEqual(B.reported, 2) |
| 1980 | self.assertEqual(C.data['status'], 'NEW') |
| 1981 | self.assertEqual(C.reported, 2) |
| 1982 | self.assertEqual(D.data['status'], 'MERGED') |
| 1983 | self.assertEqual(D.reported, 2) |
| 1984 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1985 | |
| 1986 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1987 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1988 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1989 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1990 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1991 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1992 | A.addApproval('Code-Review', 2) |
| 1993 | B.addApproval('Code-Review', 2) |
| 1994 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1995 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1996 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1997 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1998 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1999 | self.waitUntilSettled() |
| 2000 | |
| 2001 | B.addPatchset() |
| 2002 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2003 | self.waitUntilSettled() |
| 2004 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2005 | self.executor_server.hold_jobs_in_build = False |
| 2006 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2007 | self.waitUntilSettled() |
| 2008 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2009 | self.assertEqual(A.data['status'], 'MERGED') |
| 2010 | self.assertEqual(A.reported, 2) |
| 2011 | self.assertEqual(B.data['status'], 'NEW') |
| 2012 | self.assertEqual(B.reported, 2) |
| 2013 | self.assertEqual(C.data['status'], 'MERGED') |
| 2014 | self.assertEqual(C.reported, 2) |
| 2015 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2016 | |
| 2017 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2018 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2019 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2020 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2021 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2022 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2023 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2024 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2025 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2026 | self.waitUntilSettled() |
| 2027 | |
| 2028 | B.addPatchset() |
| 2029 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2030 | self.waitUntilSettled() |
| 2031 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2032 | self.executor_server.hold_jobs_in_build = False |
| 2033 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2034 | self.waitUntilSettled() |
| 2035 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2036 | self.assertEqual(A.data['status'], 'NEW') |
| 2037 | self.assertEqual(A.reported, 1) |
| 2038 | self.assertEqual(B.data['status'], 'NEW') |
| 2039 | self.assertEqual(B.reported, 1) |
| 2040 | self.assertEqual(C.data['status'], 'NEW') |
| 2041 | self.assertEqual(C.reported, 1) |
| 2042 | self.assertEqual(len(self.history), 10) |
| 2043 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2044 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2045 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2046 | def test_noop_job(self): |
| 2047 | "Test that the internal noop job works" |
| 2048 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2049 | A.addApproval('Code-Review', 2) |
| 2050 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2051 | self.waitUntilSettled() |
| 2052 | |
| 2053 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2054 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2055 | self.assertEqual(len(self.history), 0) |
| 2056 | self.assertEqual(A.data['status'], 'MERGED') |
| 2057 | self.assertEqual(A.reported, 2) |
| 2058 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2059 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2060 | def test_no_job_project(self): |
| 2061 | "Test that reports with no jobs don't get sent" |
| 2062 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2063 | 'master', 'A') |
| 2064 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2065 | self.waitUntilSettled() |
| 2066 | |
| 2067 | # Change wasn't reported to |
| 2068 | self.assertEqual(A.reported, False) |
| 2069 | |
| 2070 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2071 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2072 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2073 | items = check_pipeline.getAllItems() |
| 2074 | self.assertEqual(len(items), 0) |
| 2075 | |
| 2076 | self.assertEqual(len(self.history), 0) |
| 2077 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2078 | def test_zuul_refs(self): |
| 2079 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2080 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2081 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2082 | M1.setMerged() |
| 2083 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2084 | M2.setMerged() |
| 2085 | |
| 2086 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2087 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2088 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2089 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2090 | A.addApproval('Code-Review', 2) |
| 2091 | B.addApproval('Code-Review', 2) |
| 2092 | C.addApproval('Code-Review', 2) |
| 2093 | D.addApproval('Code-Review', 2) |
| 2094 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2095 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2096 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2097 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2098 | |
| 2099 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2100 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2101 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2102 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2103 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2104 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2105 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2106 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2107 | self.waitUntilSettled() |
| 2108 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2109 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2110 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2111 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2112 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2113 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2114 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2115 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2116 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2117 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2118 | d_build = x |
| 2119 | if a_build and b_build and c_build and d_build: |
| 2120 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2121 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2122 | # should have a, not b, and should not be in project2 |
| 2123 | self.assertTrue(a_build.hasChanges(A)) |
| 2124 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2125 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2126 | # should have a and b, and should not be in project2 |
| 2127 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2128 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2129 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2130 | # should have a and b in 1, c in 2 |
| 2131 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2132 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2133 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2134 | # should have a and b in 1, c and d in 2 |
| 2135 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2136 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2137 | self.executor_server.hold_jobs_in_build = False |
| 2138 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2139 | self.waitUntilSettled() |
| 2140 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2141 | self.assertEqual(A.data['status'], 'MERGED') |
| 2142 | self.assertEqual(A.reported, 2) |
| 2143 | self.assertEqual(B.data['status'], 'MERGED') |
| 2144 | self.assertEqual(B.reported, 2) |
| 2145 | self.assertEqual(C.data['status'], 'MERGED') |
| 2146 | self.assertEqual(C.reported, 2) |
| 2147 | self.assertEqual(D.data['status'], 'MERGED') |
| 2148 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2149 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2150 | def test_rerun_on_error(self): |
| 2151 | "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] | 2152 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2153 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2154 | A.addApproval('Code-Review', 2) |
| 2155 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2156 | self.waitUntilSettled() |
| 2157 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2158 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2159 | self.executor_server.hold_jobs_in_build = False |
| 2160 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2161 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2162 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2163 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2164 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2165 | def test_statsd(self): |
| 2166 | "Test each of the statsd methods used in the scheduler" |
James E. Blair | ded241e | 2017-10-10 13:22:40 -0700 | [diff] [blame] | 2167 | statsd = self.sched.statsd |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2168 | statsd.incr('test-incr') |
| 2169 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2170 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2171 | self.assertReportedStat('test-incr', '1|c') |
| 2172 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2173 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2174 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2175 | def test_stuck_job_cleanup(self): |
| 2176 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2177 | |
| 2178 | # 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] | 2179 | self.gearman_server.hold_jobs_in_queue = True |
| 2180 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2181 | A.addApproval('Code-Review', 2) |
| 2182 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2183 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2184 | # 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] | 2185 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2186 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2187 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2188 | self.sched.reconfigure(self.config) |
| 2189 | self.waitUntilSettled() |
| 2190 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2191 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2192 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2193 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2194 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2195 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2196 | |
| 2197 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2198 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2199 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2200 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2201 | def test_file_head(self): |
| 2202 | # This is a regression test for an observed bug. A change |
| 2203 | # with a file named "HEAD" in the root directory of the repo |
| 2204 | # was processed by a merger. It then was unable to reset the |
| 2205 | # repo because of: |
| 2206 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2207 | # with exit code 128 |
| 2208 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2209 | # and filename |
| 2210 | # Use '--' to separate filenames from revisions' |
| 2211 | |
| 2212 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2213 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2214 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2215 | |
| 2216 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2217 | self.waitUntilSettled() |
| 2218 | |
| 2219 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2220 | self.waitUntilSettled() |
| 2221 | |
| 2222 | self.assertIn('Build succeeded', A.messages[0]) |
| 2223 | self.assertIn('Build succeeded', B.messages[0]) |
| 2224 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2225 | def test_file_jobs(self): |
| 2226 | "Test that file jobs run only when appropriate" |
| 2227 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2228 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2229 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2230 | A.addApproval('Code-Review', 2) |
| 2231 | B.addApproval('Code-Review', 2) |
| 2232 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2233 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2234 | self.waitUntilSettled() |
| 2235 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2236 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2237 | if x.name == 'project-testfile'] |
| 2238 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2239 | self.assertEqual(len(testfile_jobs), 1) |
| 2240 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2241 | self.assertEqual(A.data['status'], 'MERGED') |
| 2242 | self.assertEqual(A.reported, 2) |
| 2243 | self.assertEqual(B.data['status'], 'MERGED') |
| 2244 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2245 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2246 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2247 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2248 | if should_skip: |
| 2249 | files = {'ignoreme': 'ignored\n'} |
| 2250 | else: |
| 2251 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2252 | |
| 2253 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2254 | 'master', |
| 2255 | 'test irrelevant-files', |
| 2256 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2257 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2258 | self.waitUntilSettled() |
| 2259 | |
| 2260 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2261 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2262 | |
| 2263 | if should_skip: |
| 2264 | self.assertEqual([], tested_change_ids) |
| 2265 | else: |
| 2266 | self.assertIn(change.data['number'], tested_change_ids) |
| 2267 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2268 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2269 | def test_irrelevant_files_match_skips_job(self): |
| 2270 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2271 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2272 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2273 | def test_irrelevant_files_no_match_runs_job(self): |
| 2274 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2275 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2276 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2277 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2278 | files = {'ignoreme': 'ignored\n'} |
| 2279 | |
| 2280 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2281 | 'master', |
| 2282 | 'test irrelevant-files', |
| 2283 | files=files) |
| 2284 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2285 | self.waitUntilSettled() |
| 2286 | |
| 2287 | run_jobs = set([build.name for build in self.history]) |
| 2288 | |
| 2289 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2290 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2291 | |
James E. Blair | af8b208 | 2017-10-03 15:38:27 -0700 | [diff] [blame] | 2292 | @simple_layout('layouts/job-vars.yaml') |
| 2293 | def test_inherited_job_variables(self): |
| 2294 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2295 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2296 | self.waitUntilSettled() |
| 2297 | self.assertHistory([ |
| 2298 | dict(name='parentjob', result='SUCCESS'), |
| 2299 | dict(name='child1', result='SUCCESS'), |
| 2300 | dict(name='child2', result='SUCCESS'), |
| 2301 | dict(name='child3', result='SUCCESS'), |
| 2302 | ], ordered=False) |
| 2303 | j = self.getJobFromHistory('parentjob') |
| 2304 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2305 | self.assertEqual(j.parameters['vars']['override'], 0) |
| 2306 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2307 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2308 | self.assertFalse('child1' in j.parameters['vars']) |
| 2309 | self.assertFalse('child2' in j.parameters['vars']) |
| 2310 | self.assertFalse('child3' in j.parameters['vars']) |
| 2311 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2312 | 'org/project0'])) |
| 2313 | j = self.getJobFromHistory('child1') |
| 2314 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2315 | self.assertEqual(j.parameters['vars']['override'], 1) |
| 2316 | self.assertEqual(j.parameters['vars']['child1override'], 1) |
| 2317 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2318 | self.assertEqual(j.parameters['vars']['child1'], 1) |
| 2319 | self.assertFalse('child2' in j.parameters['vars']) |
| 2320 | self.assertFalse('child3' in j.parameters['vars']) |
| 2321 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2322 | 'org/project1'])) |
| 2323 | j = self.getJobFromHistory('child2') |
| 2324 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2325 | self.assertEqual(j.parameters['vars']['override'], 2) |
| 2326 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2327 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2328 | self.assertFalse('child1' in j.parameters['vars']) |
| 2329 | self.assertEqual(j.parameters['vars']['child2'], 2) |
| 2330 | self.assertFalse('child3' in j.parameters['vars']) |
| 2331 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2332 | 'org/project2'])) |
| 2333 | j = self.getJobFromHistory('child3') |
| 2334 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2335 | self.assertEqual(j.parameters['vars']['override'], 3) |
| 2336 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2337 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2338 | self.assertFalse('child1' in j.parameters['vars']) |
| 2339 | self.assertFalse('child2' in j.parameters['vars']) |
| 2340 | self.assertEqual(j.parameters['vars']['child3'], 3) |
| 2341 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2342 | 'org/project3'])) |
| 2343 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2344 | def test_queue_names(self): |
| 2345 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2346 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2347 | (trusted, project1) = tenant.getProject('org/project1') |
| 2348 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2349 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2350 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2351 | self.assertEqual(q1.name, 'integrated') |
| 2352 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2353 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2354 | def test_queue_precedence(self): |
| 2355 | "Test that queue precedence works" |
| 2356 | |
| 2357 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2358 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2359 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2360 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2361 | A.addApproval('Code-Review', 2) |
| 2362 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2363 | |
| 2364 | self.waitUntilSettled() |
| 2365 | self.gearman_server.hold_jobs_in_queue = False |
| 2366 | self.gearman_server.release() |
| 2367 | self.waitUntilSettled() |
| 2368 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2369 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2370 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2371 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2372 | self.waitUntilSettled() |
| 2373 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2374 | self.log.debug(self.history) |
| 2375 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2376 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2377 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2378 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2379 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2380 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2381 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2382 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2383 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2384 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2385 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2386 | A.addApproval('Code-Review', 2) |
| 2387 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2388 | self.waitUntilSettled() |
| 2389 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2390 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2391 | self.waitUntilSettled() |
| 2392 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2393 | port = self.webapp.server.socket.getsockname()[1] |
| 2394 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2395 | req = urllib.request.Request( |
| 2396 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2397 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2398 | headers = f.info() |
| 2399 | self.assertIn('Content-Length', headers) |
| 2400 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2401 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2402 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2403 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2404 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2405 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2406 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2407 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2408 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2409 | self.executor_server.hold_jobs_in_build = False |
| 2410 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2411 | self.waitUntilSettled() |
| 2412 | |
| 2413 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2414 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2415 | for p in data['pipelines']: |
| 2416 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2417 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2418 | self.assertEqual(q['window'], 20) |
| 2419 | else: |
| 2420 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2421 | for head in q['heads']: |
| 2422 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2423 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2424 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2425 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2426 | status_jobs.append(job) |
| 2427 | self.assertEqual('project-merge', status_jobs[0]['name']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2428 | # TODO(mordred) pull uuids from self.builds |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2429 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2430 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2431 | uuid=status_jobs[0]['uuid']), |
| 2432 | status_jobs[0]['url']) |
| 2433 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2434 | 'finger://{hostname}/{uuid}'.format( |
| 2435 | hostname=self.executor_server.hostname, |
| 2436 | uuid=status_jobs[0]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2437 | status_jobs[0]['finger_url']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2438 | # TOOD(mordred) configure a success-url on the base job |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2439 | self.assertEqual( |
| 2440 | 'finger://{hostname}/{uuid}'.format( |
| 2441 | hostname=self.executor_server.hostname, |
| 2442 | uuid=status_jobs[0]['uuid']), |
| 2443 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2444 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2445 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2446 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2447 | uuid=status_jobs[1]['uuid']), |
| 2448 | status_jobs[1]['url']) |
| 2449 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2450 | 'finger://{hostname}/{uuid}'.format( |
| 2451 | hostname=self.executor_server.hostname, |
| 2452 | uuid=status_jobs[1]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2453 | status_jobs[1]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2454 | self.assertEqual( |
| 2455 | 'finger://{hostname}/{uuid}'.format( |
| 2456 | hostname=self.executor_server.hostname, |
| 2457 | uuid=status_jobs[1]['uuid']), |
| 2458 | status_jobs[1]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2459 | |
| 2460 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2461 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2462 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2463 | uuid=status_jobs[2]['uuid']), |
| 2464 | status_jobs[2]['url']) |
| 2465 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2466 | 'finger://{hostname}/{uuid}'.format( |
| 2467 | hostname=self.executor_server.hostname, |
| 2468 | uuid=status_jobs[2]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2469 | status_jobs[2]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2470 | self.assertEqual( |
| 2471 | 'finger://{hostname}/{uuid}'.format( |
| 2472 | hostname=self.executor_server.hostname, |
| 2473 | uuid=status_jobs[2]['uuid']), |
| 2474 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2475 | |
Tobias Henkel | 65639f8 | 2017-07-10 10:25:42 +0200 | [diff] [blame] | 2476 | # check job dependencies |
| 2477 | self.assertIsNotNone(status_jobs[0]['dependencies']) |
| 2478 | self.assertIsNotNone(status_jobs[1]['dependencies']) |
| 2479 | self.assertIsNotNone(status_jobs[2]['dependencies']) |
| 2480 | self.assertEqual(len(status_jobs[0]['dependencies']), 0) |
| 2481 | self.assertEqual(len(status_jobs[1]['dependencies']), 1) |
| 2482 | self.assertEqual(len(status_jobs[2]['dependencies']), 1) |
| 2483 | self.assertIn('project-merge', status_jobs[1]['dependencies']) |
| 2484 | self.assertIn('project-merge', status_jobs[2]['dependencies']) |
| 2485 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2486 | def test_live_reconfiguration(self): |
| 2487 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2488 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2489 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2490 | A.addApproval('Code-Review', 2) |
| 2491 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2492 | self.waitUntilSettled() |
| 2493 | |
| 2494 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2495 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2496 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2497 | self.executor_server.hold_jobs_in_build = False |
| 2498 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2499 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2500 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2501 | 'SUCCESS') |
| 2502 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2503 | 'SUCCESS') |
| 2504 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2505 | 'SUCCESS') |
| 2506 | self.assertEqual(A.data['status'], 'MERGED') |
| 2507 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2508 | |
James E. Blair | 027ba99 | 2017-09-20 13:48:32 -0700 | [diff] [blame] | 2509 | def test_live_reconfiguration_abort(self): |
| 2510 | # Raise an exception during reconfiguration and verify we |
| 2511 | # still function. |
| 2512 | self.executor_server.hold_jobs_in_build = True |
| 2513 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2514 | A.addApproval('Code-Review', 2) |
| 2515 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2516 | self.waitUntilSettled() |
| 2517 | |
| 2518 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2519 | pipeline = tenant.layout.pipelines['gate'] |
| 2520 | change = pipeline.getAllItems()[0].change |
| 2521 | # Set this to an invalid value to cause an exception during |
| 2522 | # reconfiguration. |
| 2523 | change.branch = None |
| 2524 | |
| 2525 | self.sched.reconfigure(self.config) |
| 2526 | self.waitUntilSettled() |
| 2527 | |
| 2528 | self.executor_server.hold_jobs_in_build = False |
| 2529 | self.executor_server.release() |
| 2530 | |
| 2531 | self.waitUntilSettled() |
| 2532 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2533 | 'ABORTED') |
| 2534 | self.assertEqual(A.data['status'], 'NEW') |
| 2535 | # The final report fails because of the invalid value set above. |
| 2536 | self.assertEqual(A.reported, 1) |
| 2537 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2538 | def test_live_reconfiguration_merge_conflict(self): |
| 2539 | # A real-world bug: a change in a gate queue has a merge |
| 2540 | # conflict and a job is added to its project while it's |
| 2541 | # sitting in the queue. The job gets added to the change and |
| 2542 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2543 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2544 | |
| 2545 | # This change is fine. It's here to stop the queue long |
| 2546 | # enough for the next change to be subject to the |
| 2547 | # reconfiguration, as well as to provide a conflict for the |
| 2548 | # next change. This change will succeed and merge. |
| 2549 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2550 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2551 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2552 | |
| 2553 | # This change will be in merge conflict. During the |
| 2554 | # reconfiguration, we will add a job. We want to make sure |
| 2555 | # that doesn't cause it to get stuck. |
| 2556 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2557 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2558 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2559 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2560 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2561 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2562 | |
| 2563 | self.waitUntilSettled() |
| 2564 | |
| 2565 | # No jobs have run yet |
| 2566 | self.assertEqual(A.data['status'], 'NEW') |
| 2567 | self.assertEqual(A.reported, 1) |
| 2568 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2569 | self.assertEqual(len(self.history), 0) |
| 2570 | |
| 2571 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2572 | self.commitConfigUpdate('common-config', |
| 2573 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2574 | self.sched.reconfigure(self.config) |
| 2575 | self.waitUntilSettled() |
| 2576 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2577 | self.executor_server.hold_jobs_in_build = False |
| 2578 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2579 | self.waitUntilSettled() |
| 2580 | |
| 2581 | self.assertEqual(A.data['status'], 'MERGED') |
| 2582 | self.assertEqual(A.reported, 2) |
| 2583 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2584 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2585 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2586 | 'SUCCESS') |
| 2587 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2588 | 'SUCCESS') |
| 2589 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2590 | 'SUCCESS') |
| 2591 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2592 | 'SUCCESS') |
| 2593 | self.assertEqual(len(self.history), 4) |
| 2594 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2595 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2596 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2597 | # that tests a job added to a job tree with a failed root does |
| 2598 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2599 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2600 | |
| 2601 | # This change is fine. It's here to stop the queue long |
| 2602 | # enough for the next change to be subject to the |
| 2603 | # reconfiguration. This change will succeed and merge. |
| 2604 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2605 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2606 | A.addApproval('Code-Review', 2) |
| 2607 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2608 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2609 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2610 | self.waitUntilSettled() |
| 2611 | |
| 2612 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2613 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2614 | B.addApproval('Code-Review', 2) |
| 2615 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2616 | self.waitUntilSettled() |
| 2617 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2618 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2619 | self.waitUntilSettled() |
| 2620 | |
| 2621 | # Both -merge jobs have run, but no others. |
| 2622 | self.assertEqual(A.data['status'], 'NEW') |
| 2623 | self.assertEqual(A.reported, 1) |
| 2624 | self.assertEqual(B.data['status'], 'NEW') |
| 2625 | self.assertEqual(B.reported, 1) |
| 2626 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2627 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2628 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2629 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2630 | self.assertEqual(len(self.history), 2) |
| 2631 | |
| 2632 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2633 | self.commitConfigUpdate('common-config', |
| 2634 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2635 | self.sched.reconfigure(self.config) |
| 2636 | self.waitUntilSettled() |
| 2637 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2638 | self.executor_server.hold_jobs_in_build = False |
| 2639 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2640 | self.waitUntilSettled() |
| 2641 | |
| 2642 | self.assertEqual(A.data['status'], 'MERGED') |
| 2643 | self.assertEqual(A.reported, 2) |
| 2644 | self.assertEqual(B.data['status'], 'NEW') |
| 2645 | self.assertEqual(B.reported, 2) |
| 2646 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2647 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2648 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2649 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2650 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2651 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2652 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2653 | self.assertEqual(len(self.history), 5) |
| 2654 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2655 | def test_live_reconfiguration_failed_job(self): |
| 2656 | # Test that a change with a removed failing job does not |
| 2657 | # disrupt reconfiguration. If a change has a failed job and |
| 2658 | # that job is removed during a reconfiguration, we observed a |
| 2659 | # bug where the code to re-set build statuses would run on |
| 2660 | # that build and raise an exception because the job no longer |
| 2661 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2662 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2663 | |
| 2664 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2665 | |
| 2666 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2667 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2668 | |
| 2669 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2670 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2671 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2672 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2673 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2674 | self.waitUntilSettled() |
| 2675 | |
| 2676 | self.assertEqual(A.data['status'], 'NEW') |
| 2677 | self.assertEqual(A.reported, 0) |
| 2678 | |
| 2679 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2680 | 'SUCCESS') |
| 2681 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2682 | 'FAILURE') |
| 2683 | self.assertEqual(len(self.history), 2) |
| 2684 | |
| 2685 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2686 | self.commitConfigUpdate('common-config', |
| 2687 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2688 | self.sched.reconfigure(self.config) |
| 2689 | self.waitUntilSettled() |
| 2690 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2691 | self.executor_server.hold_jobs_in_build = False |
| 2692 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2693 | self.waitUntilSettled() |
| 2694 | |
| 2695 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2696 | 'SUCCESS') |
| 2697 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2698 | 'SUCCESS') |
| 2699 | self.assertEqual(len(self.history), 4) |
| 2700 | |
| 2701 | self.assertEqual(A.data['status'], 'NEW') |
| 2702 | self.assertEqual(A.reported, 1) |
| 2703 | self.assertIn('Build succeeded', A.messages[0]) |
| 2704 | # Ensure the removed job was not included in the report. |
| 2705 | self.assertNotIn('project-test1', A.messages[0]) |
| 2706 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2707 | def test_live_reconfiguration_shared_queue(self): |
| 2708 | # Test that a change with a failing job which was removed from |
| 2709 | # this project but otherwise still exists in the system does |
| 2710 | # not disrupt reconfiguration. |
| 2711 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2712 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2713 | |
| 2714 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2715 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2716 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2717 | |
| 2718 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2719 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2720 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2721 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2722 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2723 | self.waitUntilSettled() |
| 2724 | |
| 2725 | self.assertEqual(A.data['status'], 'NEW') |
| 2726 | self.assertEqual(A.reported, 0) |
| 2727 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2728 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2729 | 'SUCCESS') |
| 2730 | self.assertEqual(self.getJobFromHistory( |
| 2731 | 'project1-project2-integration').result, 'FAILURE') |
| 2732 | self.assertEqual(len(self.history), 2) |
| 2733 | |
| 2734 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2735 | self.commitConfigUpdate( |
| 2736 | 'common-config', |
| 2737 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2738 | self.sched.reconfigure(self.config) |
| 2739 | self.waitUntilSettled() |
| 2740 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2741 | self.executor_server.hold_jobs_in_build = False |
| 2742 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2743 | self.waitUntilSettled() |
| 2744 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2745 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2746 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2747 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2748 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2749 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2750 | 'SUCCESS') |
| 2751 | self.assertEqual(self.getJobFromHistory( |
| 2752 | 'project1-project2-integration').result, 'FAILURE') |
| 2753 | self.assertEqual(len(self.history), 4) |
| 2754 | |
| 2755 | self.assertEqual(A.data['status'], 'NEW') |
| 2756 | self.assertEqual(A.reported, 1) |
| 2757 | self.assertIn('Build succeeded', A.messages[0]) |
| 2758 | # Ensure the removed job was not included in the report. |
| 2759 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2760 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2761 | def test_double_live_reconfiguration_shared_queue(self): |
| 2762 | # This was a real-world regression. A change is added to |
| 2763 | # gate; a reconfigure happens, a second change which depends |
| 2764 | # on the first is added, and a second reconfiguration happens. |
| 2765 | # Ensure that both changes merge. |
| 2766 | |
| 2767 | # A failure may indicate incorrect caching or cleaning up of |
| 2768 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2769 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2770 | |
| 2771 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2772 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2773 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2774 | A.addApproval('Code-Review', 2) |
| 2775 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2776 | |
| 2777 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2778 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2779 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2780 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2781 | self.waitUntilSettled() |
| 2782 | |
| 2783 | # Reconfigure (with only one change in the pipeline). |
| 2784 | self.sched.reconfigure(self.config) |
| 2785 | self.waitUntilSettled() |
| 2786 | |
| 2787 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2788 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2789 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2790 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2791 | self.waitUntilSettled() |
| 2792 | |
| 2793 | # Reconfigure (with both in the pipeline). |
| 2794 | self.sched.reconfigure(self.config) |
| 2795 | self.waitUntilSettled() |
| 2796 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2797 | self.executor_server.hold_jobs_in_build = False |
| 2798 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2799 | self.waitUntilSettled() |
| 2800 | |
| 2801 | self.assertEqual(len(self.history), 8) |
| 2802 | |
| 2803 | self.assertEqual(A.data['status'], 'MERGED') |
| 2804 | self.assertEqual(A.reported, 2) |
| 2805 | self.assertEqual(B.data['status'], 'MERGED') |
| 2806 | self.assertEqual(B.reported, 2) |
| 2807 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2808 | def test_live_reconfiguration_del_project(self): |
| 2809 | # Test project deletion from layout |
| 2810 | # while changes are enqueued |
| 2811 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2812 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2813 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2814 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2815 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2816 | |
| 2817 | # A Depends-On: B |
| 2818 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2819 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2820 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2821 | |
| 2822 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2823 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2824 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2825 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2826 | self.waitUntilSettled() |
| 2827 | self.assertEqual(len(self.builds), 5) |
| 2828 | |
| 2829 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2830 | self.commitConfigUpdate( |
| 2831 | 'common-config', |
| 2832 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2833 | self.sched.reconfigure(self.config) |
| 2834 | self.waitUntilSettled() |
| 2835 | |
| 2836 | # Builds for C aborted, builds for A succeed, |
| 2837 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2838 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2839 | self.assertEqual(job_c.changes, '3,1') |
| 2840 | self.assertEqual(job_c.result, 'ABORTED') |
| 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() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2844 | self.waitUntilSettled() |
| 2845 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2846 | self.assertEqual( |
| 2847 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2848 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2849 | |
| 2850 | self.assertEqual(A.data['status'], 'NEW') |
| 2851 | self.assertEqual(B.data['status'], 'NEW') |
| 2852 | self.assertEqual(C.data['status'], 'NEW') |
| 2853 | self.assertEqual(A.reported, 1) |
| 2854 | self.assertEqual(B.reported, 0) |
| 2855 | self.assertEqual(C.reported, 0) |
| 2856 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2857 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2858 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2859 | self.assertIn('Build succeeded', A.messages[0]) |
| 2860 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2861 | def test_delayed_repo_init(self): |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2862 | self.init_repo("org/new-project") |
Clint Byrum | 627ba36 | 2017-08-14 13:20:40 -0700 | [diff] [blame] | 2863 | files = {'README': ''} |
| 2864 | self.addCommitToRepo("org/new-project", 'Initial commit', |
| 2865 | files=files, tag='init') |
| 2866 | self.newTenantConfig('tenants/delayed-repo-init.yaml') |
| 2867 | self.commitConfigUpdate( |
| 2868 | 'common-config', |
| 2869 | 'layouts/delayed-repo-init.yaml') |
| 2870 | self.sched.reconfigure(self.config) |
| 2871 | self.waitUntilSettled() |
| 2872 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2873 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2874 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2875 | A.addApproval('Code-Review', 2) |
| 2876 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2877 | self.waitUntilSettled() |
| 2878 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2879 | 'SUCCESS') |
| 2880 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2881 | 'SUCCESS') |
| 2882 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2883 | 'SUCCESS') |
| 2884 | self.assertEqual(A.data['status'], 'MERGED') |
| 2885 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2886 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2887 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2888 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2889 | self.init_repo("org/delete-project") |
| 2890 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2891 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2892 | A.addApproval('Code-Review', 2) |
| 2893 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2894 | self.waitUntilSettled() |
| 2895 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2896 | 'SUCCESS') |
| 2897 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2898 | 'SUCCESS') |
| 2899 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2900 | 'SUCCESS') |
| 2901 | self.assertEqual(A.data['status'], 'MERGED') |
| 2902 | self.assertEqual(A.reported, 2) |
| 2903 | |
| 2904 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2905 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2906 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2907 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2908 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2909 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2910 | |
| 2911 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2912 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2913 | B.addApproval('Code-Review', 2) |
| 2914 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2915 | self.waitUntilSettled() |
| 2916 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2917 | 'SUCCESS') |
| 2918 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2919 | 'SUCCESS') |
| 2920 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2921 | 'SUCCESS') |
| 2922 | self.assertEqual(B.data['status'], 'MERGED') |
| 2923 | self.assertEqual(B.reported, 2) |
| 2924 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 2925 | @simple_layout('layouts/untrusted-secrets.yaml') |
| 2926 | def test_untrusted_secrets(self): |
| 2927 | "Test untrusted secrets" |
| 2928 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2929 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2930 | self.waitUntilSettled() |
| 2931 | |
| 2932 | self.assertHistory([]) |
| 2933 | self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") |
James E. Blair | 8eb564a | 2017-08-10 09:21:41 -0700 | [diff] [blame] | 2934 | self.assertIn('does not allow post-review job', |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 2935 | A.messages[0]) |
| 2936 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2937 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2938 | def test_tags(self): |
| 2939 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2940 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2941 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2942 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2943 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2944 | self.waitUntilSettled() |
| 2945 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2946 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2947 | |
| 2948 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2949 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2950 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2951 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2952 | |
| 2953 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2954 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2955 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2956 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2957 | def test_timer(self): |
| 2958 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2959 | # This test can not use simple_layout because it must start |
| 2960 | # with a configuration which does not include a |
| 2961 | # timer-triggered job so that we have an opportunity to set |
| 2962 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2963 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2964 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2965 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2966 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2967 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2968 | # The pipeline triggers every second, so we should have seen |
| 2969 | # several by now. |
| 2970 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2971 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2972 | |
| 2973 | self.assertEqual(len(self.builds), 2) |
| 2974 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2975 | port = self.webapp.server.socket.getsockname()[1] |
| 2976 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2977 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2978 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2979 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2980 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2981 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2982 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2983 | # Stop queuing timer triggered jobs so that the assertions |
| 2984 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2985 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2986 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2987 | self.waitUntilSettled() |
| 2988 | # If APScheduler is in mid-event when we remove the job, we |
| 2989 | # can end up with one more event firing, so give it an extra |
| 2990 | # second to settle. |
| 2991 | time.sleep(1) |
| 2992 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2993 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2994 | self.waitUntilSettled() |
| 2995 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2996 | self.assertHistory([ |
| 2997 | dict(name='project-bitrot', result='SUCCESS', |
| 2998 | ref='refs/heads/master'), |
| 2999 | dict(name='project-bitrot', result='SUCCESS', |
| 3000 | ref='refs/heads/stable'), |
| 3001 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3002 | |
| 3003 | data = json.loads(data) |
| 3004 | status_jobs = set() |
| 3005 | for p in data['pipelines']: |
| 3006 | for q in p['change_queues']: |
| 3007 | for head in q['heads']: |
| 3008 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3009 | for job in change['jobs']: |
| 3010 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3011 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3012 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3013 | def test_idle(self): |
| 3014 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3015 | # This test can not use simple_layout because it must start |
| 3016 | # with a configuration which does not include a |
| 3017 | # timer-triggered job so that we have an opportunity to set |
| 3018 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3019 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3020 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3021 | for x in range(1, 3): |
| 3022 | # Test that timer triggers periodic jobs even across |
| 3023 | # layout config reloads. |
| 3024 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3025 | self.commitConfigUpdate('common-config', |
| 3026 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3027 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3028 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3029 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3030 | # The pipeline triggers every second, so we should have seen |
| 3031 | # several by now. |
| 3032 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3033 | |
| 3034 | # Stop queuing timer triggered jobs so that the assertions |
| 3035 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3036 | self.commitConfigUpdate('common-config', |
| 3037 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3038 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3039 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3040 | # If APScheduler is in mid-event when we remove the job, |
| 3041 | # we can end up with one more event firing, so give it an |
| 3042 | # extra second to settle. |
| 3043 | time.sleep(1) |
| 3044 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3045 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3046 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3047 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3048 | self.waitUntilSettled() |
| 3049 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3050 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3051 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3052 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3053 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3054 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3055 | self.waitUntilSettled() |
| 3056 | |
| 3057 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3058 | self.waitUntilSettled() |
| 3059 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3060 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3061 | |
| 3062 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3063 | # work on the knowledge of what the first message should be as |
| 3064 | # it is only configured to go to SMTP. |
| 3065 | |
| 3066 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3067 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3068 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3069 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3070 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3071 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3072 | |
| 3073 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3074 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3075 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3076 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3077 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3078 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3079 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3080 | def test_timer_smtp(self): |
| 3081 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3082 | # This test can not use simple_layout because it must start |
| 3083 | # with a configuration which does not include a |
| 3084 | # timer-triggered job so that we have an opportunity to set |
| 3085 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3086 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3087 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3088 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3089 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3090 | # The pipeline triggers every second, so we should have seen |
| 3091 | # several by now. |
| 3092 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3093 | self.waitUntilSettled() |
| 3094 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3095 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3096 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3097 | self.waitUntilSettled() |
| 3098 | self.assertEqual(len(self.history), 2) |
| 3099 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3100 | self.assertEqual(self.getJobFromHistory( |
| 3101 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3102 | self.assertEqual(self.getJobFromHistory( |
| 3103 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3104 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3105 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [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_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3112 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3113 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3114 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3115 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3116 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3117 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3118 | # Stop queuing timer triggered jobs and let any that may have |
| 3119 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3120 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3121 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3122 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3123 | # If APScheduler is in mid-event when we remove the job, we |
| 3124 | # can end up with one more event firing, so give it an extra |
| 3125 | # second to settle. |
| 3126 | time.sleep(1) |
| 3127 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3128 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3129 | self.waitUntilSettled() |
| 3130 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3131 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3132 | def test_timer_sshkey(self): |
| 3133 | "Test that a periodic job can setup SSH key authentication" |
| 3134 | self.worker.hold_jobs_in_build = True |
| 3135 | self.config.set('zuul', 'layout_config', |
| 3136 | 'tests/fixtures/layout-timer.yaml') |
| 3137 | self.sched.reconfigure(self.config) |
| 3138 | self.registerJobs() |
| 3139 | |
| 3140 | # The pipeline triggers every second, so we should have seen |
| 3141 | # several by now. |
| 3142 | time.sleep(5) |
| 3143 | self.waitUntilSettled() |
| 3144 | |
| 3145 | self.assertEqual(len(self.builds), 2) |
| 3146 | |
| 3147 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3148 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3149 | with open(ssh_wrapper) as f: |
| 3150 | ssh_wrapper_content = f.read() |
| 3151 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3152 | # In the unit tests Merger runs in the same process, |
| 3153 | # so we see its' environment variables |
| 3154 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3155 | |
| 3156 | self.worker.release('.*') |
| 3157 | self.waitUntilSettled() |
| 3158 | self.assertEqual(len(self.history), 2) |
| 3159 | |
| 3160 | self.assertEqual(self.getJobFromHistory( |
| 3161 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3162 | self.assertEqual(self.getJobFromHistory( |
| 3163 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3164 | |
| 3165 | # Stop queuing timer triggered jobs and let any that may have |
| 3166 | # queued through so that end of test assertions pass. |
| 3167 | self.config.set('zuul', 'layout_config', |
| 3168 | 'tests/fixtures/layout-no-timer.yaml') |
| 3169 | self.sched.reconfigure(self.config) |
| 3170 | self.registerJobs() |
| 3171 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3172 | # If APScheduler is in mid-event when we remove the job, we |
| 3173 | # can end up with one more event firing, so give it an extra |
| 3174 | # second to settle. |
| 3175 | time.sleep(1) |
| 3176 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3177 | self.worker.release('.*') |
| 3178 | self.waitUntilSettled() |
| 3179 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3180 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3181 | "Test that the RPC client can enqueue a change" |
| 3182 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3183 | A.addApproval('Code-Review', 2) |
| 3184 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3185 | |
| 3186 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3187 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3188 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3189 | r = client.enqueue(tenant='tenant-one', |
| 3190 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3191 | project='org/project', |
| 3192 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3193 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3194 | self.waitUntilSettled() |
| 3195 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3196 | 'SUCCESS') |
| 3197 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3198 | 'SUCCESS') |
| 3199 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3200 | 'SUCCESS') |
| 3201 | self.assertEqual(A.data['status'], 'MERGED') |
| 3202 | self.assertEqual(A.reported, 2) |
| 3203 | self.assertEqual(r, True) |
| 3204 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3205 | def test_client_enqueue_ref(self): |
| 3206 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3207 | p = "review.example.com/org/project" |
| 3208 | upstream = self.getUpstreamRepos([p]) |
| 3209 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3210 | A.setMerged() |
| 3211 | A_commit = str(upstream[p].commit('master')) |
| 3212 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3213 | |
| 3214 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3215 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3216 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3217 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3218 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3219 | pipeline='post', |
| 3220 | project='org/project', |
| 3221 | trigger='gerrit', |
| 3222 | ref='master', |
| 3223 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3224 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3225 | self.waitUntilSettled() |
| 3226 | job_names = [x.name for x in self.history] |
| 3227 | self.assertEqual(len(self.history), 1) |
| 3228 | self.assertIn('project-post', job_names) |
| 3229 | self.assertEqual(r, True) |
| 3230 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3231 | def test_client_enqueue_negative(self): |
| 3232 | "Test that the RPC client returns errors" |
| 3233 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3234 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3235 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3236 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3237 | "Invalid tenant"): |
| 3238 | r = client.enqueue(tenant='tenant-foo', |
| 3239 | pipeline='gate', |
| 3240 | project='org/project', |
| 3241 | trigger='gerrit', |
| 3242 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3243 | self.assertEqual(r, False) |
| 3244 | |
| 3245 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3246 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3247 | r = client.enqueue(tenant='tenant-one', |
| 3248 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3249 | project='project-does-not-exist', |
| 3250 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3251 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3252 | self.assertEqual(r, False) |
| 3253 | |
| 3254 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3255 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3256 | r = client.enqueue(tenant='tenant-one', |
| 3257 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3258 | project='org/project', |
| 3259 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3260 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3261 | self.assertEqual(r, False) |
| 3262 | |
| 3263 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3264 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3265 | r = client.enqueue(tenant='tenant-one', |
| 3266 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3267 | project='org/project', |
| 3268 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3269 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3270 | self.assertEqual(r, False) |
| 3271 | |
| 3272 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3273 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3274 | r = client.enqueue(tenant='tenant-one', |
| 3275 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3276 | project='org/project', |
| 3277 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3278 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3279 | self.assertEqual(r, False) |
| 3280 | |
| 3281 | self.waitUntilSettled() |
| 3282 | self.assertEqual(len(self.history), 0) |
| 3283 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3284 | |
| 3285 | def test_client_promote(self): |
| 3286 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3287 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3288 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3289 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3290 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3291 | A.addApproval('Code-Review', 2) |
| 3292 | B.addApproval('Code-Review', 2) |
| 3293 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3294 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3295 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3296 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3297 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3298 | |
| 3299 | self.waitUntilSettled() |
| 3300 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3301 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3302 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3303 | enqueue_times = {} |
| 3304 | for item in items: |
| 3305 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3306 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3307 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3308 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3309 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3310 | r = client.promote(tenant='tenant-one', |
| 3311 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3312 | change_ids=['2,1', '3,1']) |
| 3313 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3314 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3315 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3316 | for item in items: |
| 3317 | self.assertEqual( |
| 3318 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3319 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3320 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3321 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3322 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3323 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3324 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3325 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3326 | self.waitUntilSettled() |
| 3327 | |
| 3328 | self.assertEqual(len(self.builds), 6) |
| 3329 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3330 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3331 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3332 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3333 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3334 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3335 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3336 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3337 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3338 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3339 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3340 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3341 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3342 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3343 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3344 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3345 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3346 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3347 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3348 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3349 | self.waitUntilSettled() |
| 3350 | |
| 3351 | self.assertEqual(A.data['status'], 'MERGED') |
| 3352 | self.assertEqual(A.reported, 2) |
| 3353 | self.assertEqual(B.data['status'], 'MERGED') |
| 3354 | self.assertEqual(B.reported, 2) |
| 3355 | self.assertEqual(C.data['status'], 'MERGED') |
| 3356 | self.assertEqual(C.reported, 2) |
| 3357 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3358 | self.assertEqual(r, True) |
| 3359 | |
| 3360 | def test_client_promote_dependent(self): |
| 3361 | "Test that the RPC client can promote a dependent change" |
| 3362 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3363 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3364 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3365 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3366 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3367 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3368 | |
| 3369 | C.setDependsOn(B, 1) |
| 3370 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3371 | A.addApproval('Code-Review', 2) |
| 3372 | B.addApproval('Code-Review', 2) |
| 3373 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3374 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3375 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3376 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3377 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3378 | |
| 3379 | self.waitUntilSettled() |
| 3380 | |
| 3381 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3382 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3383 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3384 | r = client.promote(tenant='tenant-one', |
| 3385 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3386 | change_ids=['3,1']) |
| 3387 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3388 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3389 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3390 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3391 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3392 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3393 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3394 | self.waitUntilSettled() |
| 3395 | |
| 3396 | self.assertEqual(len(self.builds), 6) |
| 3397 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3398 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3399 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3400 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3401 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3402 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3403 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3404 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3405 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3406 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3407 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3408 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3409 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3410 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3411 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3412 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3413 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3414 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3415 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3416 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3417 | self.waitUntilSettled() |
| 3418 | |
| 3419 | self.assertEqual(A.data['status'], 'MERGED') |
| 3420 | self.assertEqual(A.reported, 2) |
| 3421 | self.assertEqual(B.data['status'], 'MERGED') |
| 3422 | self.assertEqual(B.reported, 2) |
| 3423 | self.assertEqual(C.data['status'], 'MERGED') |
| 3424 | self.assertEqual(C.reported, 2) |
| 3425 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3426 | self.assertEqual(r, True) |
| 3427 | |
| 3428 | def test_client_promote_negative(self): |
| 3429 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3430 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3431 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3432 | A.addApproval('Code-Review', 2) |
| 3433 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3434 | self.waitUntilSettled() |
| 3435 | |
| 3436 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3437 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3438 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3439 | |
| 3440 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3441 | r = client.promote(tenant='tenant-one', |
| 3442 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3443 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3444 | self.assertEqual(r, False) |
| 3445 | |
| 3446 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3447 | r = client.promote(tenant='tenant-one', |
| 3448 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3449 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3450 | self.assertEqual(r, False) |
| 3451 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3452 | self.executor_server.hold_jobs_in_build = False |
| 3453 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3454 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3455 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3456 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3457 | def test_queue_rate_limiting(self): |
| 3458 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3459 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3460 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3461 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3462 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3463 | |
| 3464 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3465 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3466 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3467 | A.addApproval('Code-Review', 2) |
| 3468 | B.addApproval('Code-Review', 2) |
| 3469 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3470 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3471 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3472 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3473 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3474 | self.waitUntilSettled() |
| 3475 | |
| 3476 | # Only A and B will have their merge jobs queued because |
| 3477 | # window is 2. |
| 3478 | self.assertEqual(len(self.builds), 2) |
| 3479 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3480 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3481 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3482 | # Release the merge jobs one at a time. |
| 3483 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3484 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3485 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3486 | self.waitUntilSettled() |
| 3487 | |
| 3488 | # Only A and B will have their test jobs queued because |
| 3489 | # window is 2. |
| 3490 | self.assertEqual(len(self.builds), 4) |
| 3491 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3492 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3493 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3494 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3495 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3496 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3497 | self.waitUntilSettled() |
| 3498 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3499 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3500 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3501 | # A failed so window is reduced by 1 to 1. |
| 3502 | self.assertEqual(queue.window, 1) |
| 3503 | self.assertEqual(queue.window_floor, 1) |
| 3504 | self.assertEqual(A.data['status'], 'NEW') |
| 3505 | |
| 3506 | # Gate is reset and only B's merge job is queued because |
| 3507 | # window shrunk to 1. |
| 3508 | self.assertEqual(len(self.builds), 1) |
| 3509 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3510 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3511 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3512 | self.waitUntilSettled() |
| 3513 | |
| 3514 | # Only B's test jobs are queued because window is still 1. |
| 3515 | self.assertEqual(len(self.builds), 2) |
| 3516 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3517 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3518 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3519 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3520 | self.waitUntilSettled() |
| 3521 | |
| 3522 | # B was successfully merged so window is increased to 2. |
| 3523 | self.assertEqual(queue.window, 2) |
| 3524 | self.assertEqual(queue.window_floor, 1) |
| 3525 | self.assertEqual(B.data['status'], 'MERGED') |
| 3526 | |
| 3527 | # Only C is left and its merge job is queued. |
| 3528 | self.assertEqual(len(self.builds), 1) |
| 3529 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3530 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3531 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3532 | self.waitUntilSettled() |
| 3533 | |
| 3534 | # After successful merge job the test jobs for C are queued. |
| 3535 | self.assertEqual(len(self.builds), 2) |
| 3536 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3537 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3538 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3539 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3540 | self.waitUntilSettled() |
| 3541 | |
| 3542 | # C successfully merged so window is bumped to 3. |
| 3543 | self.assertEqual(queue.window, 3) |
| 3544 | self.assertEqual(queue.window_floor, 1) |
| 3545 | self.assertEqual(C.data['status'], 'MERGED') |
| 3546 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3547 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3548 | def test_queue_rate_limiting_dependent(self): |
| 3549 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3550 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3551 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3552 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3553 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3554 | |
| 3555 | B.setDependsOn(A, 1) |
| 3556 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3557 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3558 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3559 | A.addApproval('Code-Review', 2) |
| 3560 | B.addApproval('Code-Review', 2) |
| 3561 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3562 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3563 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3564 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3565 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3566 | self.waitUntilSettled() |
| 3567 | |
| 3568 | # Only A and B will have their merge jobs queued because |
| 3569 | # window is 2. |
| 3570 | self.assertEqual(len(self.builds), 2) |
| 3571 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3572 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3573 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3574 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3575 | |
| 3576 | # Only A and B will have their test jobs queued because |
| 3577 | # window is 2. |
| 3578 | self.assertEqual(len(self.builds), 4) |
| 3579 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3580 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3581 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3582 | self.assertEqual(self.builds[3].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 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3587 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3588 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3589 | # A failed so window is reduced by 1 to 1. |
| 3590 | self.assertEqual(queue.window, 1) |
| 3591 | self.assertEqual(queue.window_floor, 1) |
| 3592 | self.assertEqual(A.data['status'], 'NEW') |
| 3593 | self.assertEqual(B.data['status'], 'NEW') |
| 3594 | |
| 3595 | # Gate is reset and only C's merge job is queued because |
| 3596 | # window shrunk to 1 and A and B were dequeued. |
| 3597 | self.assertEqual(len(self.builds), 1) |
| 3598 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3599 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3600 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3601 | |
| 3602 | # Only C's test jobs are queued because window is still 1. |
| 3603 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3604 | builds = self.getSortedBuilds() |
| 3605 | self.assertEqual(builds[0].name, 'project-test1') |
| 3606 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3607 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3608 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3609 | self.waitUntilSettled() |
| 3610 | |
| 3611 | # C was successfully merged so window is increased to 2. |
| 3612 | self.assertEqual(queue.window, 2) |
| 3613 | self.assertEqual(queue.window_floor, 1) |
| 3614 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3615 | |
| 3616 | def test_worker_update_metadata(self): |
| 3617 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3618 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3619 | |
| 3620 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3621 | A.addApproval('Code-Review', 2) |
| 3622 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3623 | self.waitUntilSettled() |
| 3624 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3625 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3626 | |
| 3627 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3628 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3629 | |
| 3630 | start = time.time() |
| 3631 | while True: |
| 3632 | if time.time() - start > 10: |
| 3633 | raise Exception("Timeout waiting for gearman server to report " |
| 3634 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3635 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3636 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3637 | break |
| 3638 | else: |
| 3639 | time.sleep(0) |
| 3640 | |
| 3641 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3642 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3643 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3644 | self.executor_server.hold_jobs_in_build = False |
| 3645 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3646 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3647 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3648 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3649 | def test_footer_message(self): |
| 3650 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3651 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3652 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3653 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3654 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3655 | self.waitUntilSettled() |
| 3656 | |
| 3657 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3658 | B.addApproval('Code-Review', 2) |
| 3659 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3660 | self.waitUntilSettled() |
| 3661 | |
| 3662 | self.assertEqual(2, len(self.smtp_messages)) |
| 3663 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3664 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3665 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3666 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3667 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3668 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3669 | For CI problems and help debugging, contact ci@example.org""" |
| 3670 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3671 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3672 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3673 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3674 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3675 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3676 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3677 | def test_unmanaged_project_start_message(self): |
| 3678 | "Test start reporting is not done for unmanaged projects." |
| 3679 | self.init_repo("org/project", tag='init') |
| 3680 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3681 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3682 | self.waitUntilSettled() |
| 3683 | |
| 3684 | self.assertEqual(0, len(A.messages)) |
| 3685 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3686 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3687 | def test_merge_failure_reporters(self): |
| 3688 | """Check that the config is set up correctly""" |
| 3689 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3690 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3691 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3692 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3693 | "dependencies was unable to be automatically merged with the " |
| 3694 | "current state of its repository. Please rebase the change and " |
| 3695 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3696 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3697 | self.assertEqual( |
| 3698 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3699 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3700 | |
| 3701 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3702 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3703 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3704 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3705 | |
| 3706 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3707 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 3708 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3709 | |
| 3710 | self.assertTrue( |
| 3711 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3712 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3713 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3714 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 3715 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3716 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3717 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3718 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3719 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3720 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3721 | gerritreporter.GerritReporter) and |
| 3722 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3723 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3724 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3725 | ) |
| 3726 | ) |
| 3727 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3728 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3729 | def test_merge_failure_reports(self): |
| 3730 | """Check that when a change fails to merge the correct message is sent |
| 3731 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3732 | self.updateConfigLayout( |
| 3733 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3734 | self.sched.reconfigure(self.config) |
| 3735 | self.registerJobs() |
| 3736 | |
| 3737 | # Check a test failure isn't reported to SMTP |
| 3738 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3739 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3740 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3741 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3742 | self.waitUntilSettled() |
| 3743 | |
| 3744 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3745 | self.assertEqual(0, len(self.smtp_messages)) |
| 3746 | |
| 3747 | # Check a merge failure is reported to SMTP |
| 3748 | # B should be merged, but C will conflict with B |
| 3749 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3750 | B.addPatchset(['conflict']) |
| 3751 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3752 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3753 | B.addApproval('Code-Review', 2) |
| 3754 | C.addApproval('Code-Review', 2) |
| 3755 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3756 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3757 | self.waitUntilSettled() |
| 3758 | |
| 3759 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3760 | self.assertEqual(1, len(self.smtp_messages)) |
| 3761 | self.assertEqual('The merge failed! For more information...', |
| 3762 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3763 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3764 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3765 | def test_default_merge_failure_reports(self): |
| 3766 | """Check that the default merge failure reports are correct.""" |
| 3767 | |
| 3768 | # A should report success, B should report merge failure. |
| 3769 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3770 | A.addPatchset(['conflict']) |
| 3771 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3772 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3773 | A.addApproval('Code-Review', 2) |
| 3774 | B.addApproval('Code-Review', 2) |
| 3775 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3776 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3777 | self.waitUntilSettled() |
| 3778 | |
| 3779 | self.assertEqual(3, len(self.history)) # A jobs |
| 3780 | self.assertEqual(A.reported, 2) |
| 3781 | self.assertEqual(B.reported, 2) |
| 3782 | self.assertEqual(A.data['status'], 'MERGED') |
| 3783 | self.assertEqual(B.data['status'], 'NEW') |
| 3784 | self.assertIn('Build succeeded', A.messages[1]) |
| 3785 | self.assertIn('Merge Failed', B.messages[1]) |
| 3786 | self.assertIn('automatically merged', B.messages[1]) |
| 3787 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3788 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3789 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3790 | def test_client_get_running_jobs(self): |
| 3791 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3792 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3793 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3794 | A.addApproval('Code-Review', 2) |
| 3795 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3796 | self.waitUntilSettled() |
| 3797 | |
| 3798 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3799 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3800 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3801 | |
| 3802 | # Wait for gearman server to send the initial workData back to zuul |
| 3803 | start = time.time() |
| 3804 | while True: |
| 3805 | if time.time() - start > 10: |
| 3806 | raise Exception("Timeout waiting for gearman server to report " |
| 3807 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3808 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3809 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3810 | break |
| 3811 | else: |
| 3812 | time.sleep(0) |
| 3813 | |
| 3814 | running_items = client.get_running_jobs() |
| 3815 | |
| 3816 | self.assertEqual(1, len(running_items)) |
| 3817 | running_item = running_items[0] |
| 3818 | self.assertEqual([], running_item['failing_reasons']) |
| 3819 | self.assertEqual([], running_item['items_behind']) |
| 3820 | self.assertEqual('https://hostname/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3821 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3822 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3823 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3824 | self.assertEqual(True, running_item['active']) |
| 3825 | self.assertEqual('1,1', running_item['id']) |
| 3826 | |
| 3827 | self.assertEqual(3, len(running_item['jobs'])) |
| 3828 | for job in running_item['jobs']: |
| 3829 | if job['name'] == 'project-merge': |
| 3830 | self.assertEqual('project-merge', job['name']) |
| 3831 | self.assertEqual('gate', job['pipeline']) |
| 3832 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3833 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3834 | 'static/stream.html?uuid={uuid}&logfile=console.log' |
| 3835 | .format(uuid=job['uuid']), job['url']) |
| 3836 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3837 | 'finger://{hostname}/{uuid}'.format( |
| 3838 | hostname=self.executor_server.hostname, |
| 3839 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3840 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3841 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3842 | self.assertEqual(False, job['canceled']) |
| 3843 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3844 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3845 | self.assertEqual('gate', job['pipeline']) |
| 3846 | break |
| 3847 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3848 | self.executor_server.hold_jobs_in_build = False |
| 3849 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3850 | self.waitUntilSettled() |
| 3851 | |
| 3852 | running_items = client.get_running_jobs() |
| 3853 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3854 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3855 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3856 | def test_nonvoting_pipeline(self): |
| 3857 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3858 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3859 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3860 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3861 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3862 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3863 | |
| 3864 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3865 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3866 | self.assertEqual( |
| 3867 | self.getJobFromHistory('experimental-project-test').result, |
| 3868 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3869 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3870 | |
| 3871 | def test_crd_gate(self): |
| 3872 | "Test cross-repo dependencies" |
| 3873 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3874 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3875 | A.addApproval('Code-Review', 2) |
| 3876 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3877 | |
| 3878 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3879 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3880 | AM2.setMerged() |
| 3881 | AM1.setMerged() |
| 3882 | |
| 3883 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3884 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3885 | BM2.setMerged() |
| 3886 | BM1.setMerged() |
| 3887 | |
| 3888 | # A -> AM1 -> AM2 |
| 3889 | # B -> BM1 -> BM2 |
| 3890 | # A Depends-On: B |
| 3891 | # M2 is here to make sure it is never queried. If it is, it |
| 3892 | # means zuul is walking down the entire history of merged |
| 3893 | # changes. |
| 3894 | |
| 3895 | B.setDependsOn(BM1, 1) |
| 3896 | BM1.setDependsOn(BM2, 1) |
| 3897 | |
| 3898 | A.setDependsOn(AM1, 1) |
| 3899 | AM1.setDependsOn(AM2, 1) |
| 3900 | |
| 3901 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3902 | A.subject, B.data['id']) |
| 3903 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3904 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3905 | self.waitUntilSettled() |
| 3906 | |
| 3907 | self.assertEqual(A.data['status'], 'NEW') |
| 3908 | self.assertEqual(B.data['status'], 'NEW') |
| 3909 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3910 | for connection in self.connections.connections.values(): |
James E. Blair | b970430 | 2017-10-11 16:42:18 -0700 | [diff] [blame] | 3911 | if hasattr(connection, '_change_cache'): |
| 3912 | connection._change_cache.clear() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3913 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3914 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3915 | B.addApproval('Approved', 1) |
| 3916 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3917 | self.waitUntilSettled() |
| 3918 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3919 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3920 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3921 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3922 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3923 | self.executor_server.hold_jobs_in_build = False |
| 3924 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3925 | self.waitUntilSettled() |
| 3926 | |
| 3927 | self.assertEqual(AM2.queried, 0) |
| 3928 | self.assertEqual(BM2.queried, 0) |
| 3929 | self.assertEqual(A.data['status'], 'MERGED') |
| 3930 | self.assertEqual(B.data['status'], 'MERGED') |
| 3931 | self.assertEqual(A.reported, 2) |
| 3932 | self.assertEqual(B.reported, 2) |
| 3933 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3934 | changes = self.getJobFromHistory( |
| 3935 | 'project-merge', 'org/project1').changes |
| 3936 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3937 | |
| 3938 | def test_crd_branch(self): |
| 3939 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3940 | |
| 3941 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3942 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3943 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3944 | C1 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C1') |
| 3945 | C2 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C2', |
| 3946 | status='ABANDONED') |
| 3947 | C1.data['id'] = B.data['id'] |
| 3948 | C2.data['id'] = B.data['id'] |
| 3949 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3950 | A.addApproval('Code-Review', 2) |
| 3951 | B.addApproval('Code-Review', 2) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3952 | C1.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3953 | |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3954 | # A Depends-On: B+C1 |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3955 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3956 | A.subject, B.data['id']) |
| 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) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3960 | C1.addApproval('Approved', 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3961 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3962 | self.waitUntilSettled() |
| 3963 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3964 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3965 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3966 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3967 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3968 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3969 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3970 | self.executor_server.hold_jobs_in_build = False |
| 3971 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3972 | self.waitUntilSettled() |
| 3973 | |
| 3974 | self.assertEqual(A.data['status'], 'MERGED') |
| 3975 | self.assertEqual(B.data['status'], 'MERGED') |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3976 | self.assertEqual(C1.data['status'], 'MERGED') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3977 | self.assertEqual(A.reported, 2) |
| 3978 | self.assertEqual(B.reported, 2) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3979 | self.assertEqual(C1.reported, 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3980 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3981 | changes = self.getJobFromHistory( |
| 3982 | 'project-merge', 'org/project1').changes |
| 3983 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3984 | |
| 3985 | def test_crd_multiline(self): |
| 3986 | "Test multiple depends-on lines in commit" |
| 3987 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3988 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3989 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3990 | A.addApproval('Code-Review', 2) |
| 3991 | B.addApproval('Code-Review', 2) |
| 3992 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3993 | |
| 3994 | # A Depends-On: B+C |
| 3995 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3996 | A.subject, B.data['id'], C.data['id']) |
| 3997 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3998 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3999 | B.addApproval('Approved', 1) |
| 4000 | C.addApproval('Approved', 1) |
| 4001 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4002 | self.waitUntilSettled() |
| 4003 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4004 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4005 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4006 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4007 | self.waitUntilSettled() |
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.hold_jobs_in_build = False |
| 4011 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4012 | self.waitUntilSettled() |
| 4013 | |
| 4014 | self.assertEqual(A.data['status'], 'MERGED') |
| 4015 | self.assertEqual(B.data['status'], 'MERGED') |
| 4016 | self.assertEqual(C.data['status'], 'MERGED') |
| 4017 | self.assertEqual(A.reported, 2) |
| 4018 | self.assertEqual(B.reported, 2) |
| 4019 | self.assertEqual(C.reported, 2) |
| 4020 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4021 | changes = self.getJobFromHistory( |
| 4022 | 'project-merge', 'org/project1').changes |
| 4023 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4024 | |
| 4025 | def test_crd_unshared_gate(self): |
| 4026 | "Test cross-repo dependencies in unshared gate queues" |
| 4027 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4028 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4029 | A.addApproval('Code-Review', 2) |
| 4030 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4031 | |
| 4032 | # A Depends-On: B |
| 4033 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4034 | A.subject, B.data['id']) |
| 4035 | |
| 4036 | # A and B do not share a queue, make sure that A is unable to |
| 4037 | # enqueue B (and therefore, A is unable to be enqueued). |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4038 | B.addApproval('Approved', 1) |
| 4039 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4040 | self.waitUntilSettled() |
| 4041 | |
| 4042 | self.assertEqual(A.data['status'], 'NEW') |
| 4043 | self.assertEqual(B.data['status'], 'NEW') |
| 4044 | self.assertEqual(A.reported, 0) |
| 4045 | self.assertEqual(B.reported, 0) |
| 4046 | self.assertEqual(len(self.history), 0) |
| 4047 | |
| 4048 | # Enqueue and merge B alone. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4049 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4050 | self.waitUntilSettled() |
| 4051 | |
| 4052 | self.assertEqual(B.data['status'], 'MERGED') |
| 4053 | self.assertEqual(B.reported, 2) |
| 4054 | |
| 4055 | # Now that B is merged, A should be able to be enqueued and |
| 4056 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4057 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4058 | self.waitUntilSettled() |
| 4059 | |
| 4060 | self.assertEqual(A.data['status'], 'MERGED') |
| 4061 | self.assertEqual(A.reported, 2) |
| 4062 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4063 | def test_crd_gate_reverse(self): |
| 4064 | "Test reverse cross-repo dependencies" |
| 4065 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4066 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4067 | A.addApproval('Code-Review', 2) |
| 4068 | B.addApproval('Code-Review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4069 | |
| 4070 | # A Depends-On: B |
| 4071 | |
| 4072 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4073 | A.subject, B.data['id']) |
| 4074 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4075 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4076 | self.waitUntilSettled() |
| 4077 | |
| 4078 | self.assertEqual(A.data['status'], 'NEW') |
| 4079 | self.assertEqual(B.data['status'], 'NEW') |
| 4080 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4081 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4082 | A.addApproval('Approved', 1) |
| 4083 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4084 | self.waitUntilSettled() |
| 4085 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4086 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4087 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4088 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4089 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4090 | self.executor_server.hold_jobs_in_build = False |
| 4091 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4092 | self.waitUntilSettled() |
| 4093 | |
| 4094 | self.assertEqual(A.data['status'], 'MERGED') |
| 4095 | self.assertEqual(B.data['status'], 'MERGED') |
| 4096 | self.assertEqual(A.reported, 2) |
| 4097 | self.assertEqual(B.reported, 2) |
| 4098 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4099 | changes = self.getJobFromHistory( |
| 4100 | 'project-merge', 'org/project1').changes |
| 4101 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4102 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4103 | def test_crd_cycle(self): |
| 4104 | "Test cross-repo dependency cycles" |
| 4105 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4106 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4107 | A.addApproval('Code-Review', 2) |
| 4108 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4109 | |
| 4110 | # A -> B -> A (via commit-depends) |
| 4111 | |
| 4112 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4113 | A.subject, B.data['id']) |
| 4114 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4115 | B.subject, A.data['id']) |
| 4116 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4117 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4118 | self.waitUntilSettled() |
| 4119 | |
| 4120 | self.assertEqual(A.reported, 0) |
| 4121 | self.assertEqual(B.reported, 0) |
| 4122 | self.assertEqual(A.data['status'], 'NEW') |
| 4123 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4124 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4125 | def test_crd_gate_unknown(self): |
| 4126 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4127 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4128 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4129 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4130 | A.addApproval('Code-Review', 2) |
| 4131 | B.addApproval('Code-Review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4132 | |
| 4133 | # A Depends-On: B |
| 4134 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4135 | A.subject, B.data['id']) |
| 4136 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4137 | B.addApproval('Approved', 1) |
| 4138 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4139 | self.waitUntilSettled() |
| 4140 | |
| 4141 | # Unknown projects cannot share a queue with any other |
| 4142 | # since they don't have common jobs with any other (they have no jobs). |
| 4143 | # Changes which depend on unknown project changes |
| 4144 | # should not be processed in dependent pipeline |
| 4145 | self.assertEqual(A.data['status'], 'NEW') |
| 4146 | self.assertEqual(B.data['status'], 'NEW') |
| 4147 | self.assertEqual(A.reported, 0) |
| 4148 | self.assertEqual(B.reported, 0) |
| 4149 | self.assertEqual(len(self.history), 0) |
| 4150 | |
James E. Blair | 7720b40 | 2017-06-07 08:51:49 -0700 | [diff] [blame] | 4151 | # Simulate change B being gated outside this layout Set the |
| 4152 | # change merged before submitting the event so that when the |
| 4153 | # event triggers a gerrit query to update the change, we get |
| 4154 | # the information that it was merged. |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4155 | B.setMerged() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4156 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4157 | self.waitUntilSettled() |
| 4158 | self.assertEqual(len(self.history), 0) |
| 4159 | |
| 4160 | # Now that B is merged, A should be able to be enqueued and |
| 4161 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4162 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4163 | self.waitUntilSettled() |
| 4164 | |
| 4165 | self.assertEqual(A.data['status'], 'MERGED') |
| 4166 | self.assertEqual(A.reported, 2) |
| 4167 | self.assertEqual(B.data['status'], 'MERGED') |
| 4168 | self.assertEqual(B.reported, 0) |
| 4169 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4170 | def test_crd_check(self): |
| 4171 | "Test cross-repo dependencies in independent pipelines" |
| 4172 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4173 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4174 | self.gearman_server.hold_jobs_in_queue = True |
| 4175 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4176 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4177 | |
| 4178 | # A Depends-On: B |
| 4179 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4180 | A.subject, B.data['id']) |
| 4181 | |
| 4182 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4183 | self.waitUntilSettled() |
| 4184 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4185 | self.gearman_server.hold_jobs_in_queue = False |
| 4186 | self.gearman_server.release() |
| 4187 | self.waitUntilSettled() |
| 4188 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4189 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4190 | self.waitUntilSettled() |
| 4191 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4192 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4193 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4194 | self.executor_server.hold_jobs_in_build = False |
| 4195 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4196 | self.waitUntilSettled() |
| 4197 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4198 | self.assertEqual(A.data['status'], 'NEW') |
| 4199 | self.assertEqual(B.data['status'], 'NEW') |
| 4200 | self.assertEqual(A.reported, 1) |
| 4201 | self.assertEqual(B.reported, 0) |
| 4202 | |
| 4203 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4204 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4205 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4206 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4207 | def test_crd_check_git_depends(self): |
| 4208 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4209 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4210 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4211 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4212 | |
| 4213 | # Add two git-dependent changes and make sure they both report |
| 4214 | # success. |
| 4215 | B.setDependsOn(A, 1) |
| 4216 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4217 | self.waitUntilSettled() |
| 4218 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4219 | self.waitUntilSettled() |
| 4220 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4221 | self.orderedRelease() |
| 4222 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4223 | self.waitUntilSettled() |
| 4224 | |
| 4225 | self.assertEqual(A.data['status'], 'NEW') |
| 4226 | self.assertEqual(B.data['status'], 'NEW') |
| 4227 | self.assertEqual(A.reported, 1) |
| 4228 | self.assertEqual(B.reported, 1) |
| 4229 | |
| 4230 | self.assertEqual(self.history[0].changes, '1,1') |
| 4231 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4232 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4233 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4234 | |
| 4235 | self.assertIn('Build succeeded', A.messages[0]) |
| 4236 | self.assertIn('Build succeeded', B.messages[0]) |
| 4237 | |
| 4238 | def test_crd_check_duplicate(self): |
| 4239 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4240 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4241 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4242 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4243 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4244 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4245 | |
| 4246 | # Add two git-dependent changes... |
| 4247 | B.setDependsOn(A, 1) |
| 4248 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4249 | self.waitUntilSettled() |
| 4250 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4251 | |
| 4252 | # ...make sure the live one is not duplicated... |
| 4253 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4254 | self.waitUntilSettled() |
| 4255 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4256 | |
| 4257 | # ...but the non-live one is able to be. |
| 4258 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4259 | self.waitUntilSettled() |
| 4260 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4261 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4262 | # Release jobs in order to avoid races with change A jobs |
| 4263 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4264 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4265 | self.executor_server.hold_jobs_in_build = False |
| 4266 | self.executor_server.release() |
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 2,1') |
| 4275 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4276 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4277 | |
| 4278 | self.assertIn('Build succeeded', A.messages[0]) |
| 4279 | self.assertIn('Build succeeded', B.messages[0]) |
| 4280 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4281 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4282 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4283 | |
| 4284 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4285 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4286 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4287 | |
| 4288 | # A Depends-On: B |
| 4289 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4290 | A.subject, B.data['id']) |
| 4291 | |
| 4292 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4293 | self.waitUntilSettled() |
| 4294 | |
| 4295 | self.sched.reconfigure(self.config) |
| 4296 | |
| 4297 | # Make sure the items still share a change queue, and the |
| 4298 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4299 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4300 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4301 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4302 | first_item = queue.queue[0] |
| 4303 | for item in queue.queue: |
| 4304 | self.assertEqual(item.queue, first_item.queue) |
| 4305 | self.assertFalse(first_item.live) |
| 4306 | self.assertTrue(queue.queue[1].live) |
| 4307 | |
| 4308 | self.gearman_server.hold_jobs_in_queue = False |
| 4309 | self.gearman_server.release() |
| 4310 | self.waitUntilSettled() |
| 4311 | |
| 4312 | self.assertEqual(A.data['status'], 'NEW') |
| 4313 | self.assertEqual(B.data['status'], 'NEW') |
| 4314 | self.assertEqual(A.reported, 1) |
| 4315 | self.assertEqual(B.reported, 0) |
| 4316 | |
| 4317 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4318 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4319 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4320 | def test_crd_check_reconfiguration(self): |
| 4321 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4322 | |
| 4323 | def test_crd_undefined_project(self): |
| 4324 | """Test that undefined projects in dependencies are handled for |
| 4325 | independent pipelines""" |
| 4326 | # It's a hack for fake gerrit, |
| 4327 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4328 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4329 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4330 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4331 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4332 | def test_crd_check_ignore_dependencies(self): |
| 4333 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4334 | |
| 4335 | self.gearman_server.hold_jobs_in_queue = True |
| 4336 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4337 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4338 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4339 | |
| 4340 | # A Depends-On: B |
| 4341 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4342 | A.subject, B.data['id']) |
| 4343 | # C git-depends on B |
| 4344 | C.setDependsOn(B, 1) |
| 4345 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4346 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4347 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4348 | self.waitUntilSettled() |
| 4349 | |
| 4350 | # Make sure none of the items share a change queue, and all |
| 4351 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4352 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4353 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4354 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4355 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4356 | for item in check_pipeline.getAllItems(): |
| 4357 | self.assertTrue(item.live) |
| 4358 | |
| 4359 | self.gearman_server.hold_jobs_in_queue = False |
| 4360 | self.gearman_server.release() |
| 4361 | self.waitUntilSettled() |
| 4362 | |
| 4363 | self.assertEqual(A.data['status'], 'NEW') |
| 4364 | self.assertEqual(B.data['status'], 'NEW') |
| 4365 | self.assertEqual(C.data['status'], 'NEW') |
| 4366 | self.assertEqual(A.reported, 1) |
| 4367 | self.assertEqual(B.reported, 1) |
| 4368 | self.assertEqual(C.reported, 1) |
| 4369 | |
| 4370 | # Each job should have tested exactly one change |
| 4371 | for job in self.history: |
| 4372 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4373 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4374 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4375 | def test_crd_check_transitive(self): |
| 4376 | "Test transitive cross-repo dependencies" |
| 4377 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4378 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4379 | # and C,2 (not C,1 which would indicate stale data in the |
| 4380 | # cache for B). |
| 4381 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4382 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4383 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4384 | |
| 4385 | # A Depends-On: B |
| 4386 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4387 | A.subject, B.data['id']) |
| 4388 | |
| 4389 | # B Depends-On: C |
| 4390 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4391 | B.subject, C.data['id']) |
| 4392 | |
| 4393 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4394 | self.waitUntilSettled() |
| 4395 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4396 | |
| 4397 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4398 | self.waitUntilSettled() |
| 4399 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4400 | |
| 4401 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4402 | self.waitUntilSettled() |
| 4403 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4404 | |
| 4405 | C.addPatchset() |
| 4406 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4407 | self.waitUntilSettled() |
| 4408 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4409 | |
| 4410 | A.addPatchset() |
| 4411 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4412 | self.waitUntilSettled() |
| 4413 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4414 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4415 | def test_crd_check_unknown(self): |
| 4416 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4417 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4418 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4419 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4420 | # A Depends-On: B |
| 4421 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4422 | A.subject, B.data['id']) |
| 4423 | |
| 4424 | # Make sure zuul has seen an event on B. |
| 4425 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4426 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4427 | self.waitUntilSettled() |
| 4428 | |
| 4429 | self.assertEqual(A.data['status'], 'NEW') |
| 4430 | self.assertEqual(A.reported, 1) |
| 4431 | self.assertEqual(B.data['status'], 'NEW') |
| 4432 | self.assertEqual(B.reported, 0) |
| 4433 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4434 | def test_crd_cycle_join(self): |
| 4435 | "Test an updated change creates a cycle" |
| 4436 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4437 | |
| 4438 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4439 | self.waitUntilSettled() |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4440 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4441 | |
| 4442 | # Create B->A |
| 4443 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4444 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4445 | B.subject, A.data['id']) |
| 4446 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4447 | self.waitUntilSettled() |
| 4448 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4449 | # Dep is there so zuul should have reported on B |
| 4450 | self.assertEqual(B.reported, 1) |
| 4451 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4452 | # Update A to add A->B (a cycle). |
| 4453 | A.addPatchset() |
| 4454 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4455 | A.subject, B.data['id']) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4456 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4457 | self.waitUntilSettled() |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4458 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4459 | # Dependency cycle injected so zuul should not have reported again on A |
| 4460 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4461 | |
| 4462 | # Now if we update B to remove the depends-on, everything |
| 4463 | # should be okay. B; A->B |
| 4464 | |
| 4465 | B.addPatchset() |
| 4466 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4467 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4468 | self.waitUntilSettled() |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4469 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4470 | # Cycle was removed so now zuul should have reported again on A |
| 4471 | self.assertEqual(A.reported, 2) |
| 4472 | |
| 4473 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 4474 | self.waitUntilSettled() |
| 4475 | self.assertEqual(B.reported, 2) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4476 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4477 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4478 | def test_disable_at(self): |
| 4479 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4480 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4481 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4482 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4483 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4484 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4485 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4486 | |
| 4487 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4488 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4489 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4490 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4491 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4492 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4493 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4494 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4495 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4496 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4497 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4498 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4499 | self.executor_server.failJob('project-test1', A) |
| 4500 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4501 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4502 | self.executor_server.failJob('project-test1', D) |
| 4503 | self.executor_server.failJob('project-test1', E) |
| 4504 | self.executor_server.failJob('project-test1', F) |
| 4505 | self.executor_server.failJob('project-test1', G) |
| 4506 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4507 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4508 | self.executor_server.failJob('project-test1', J) |
| 4509 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4510 | |
| 4511 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4512 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4513 | self.waitUntilSettled() |
| 4514 | |
| 4515 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4516 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4517 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4518 | |
| 4519 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4520 | self.waitUntilSettled() |
| 4521 | |
| 4522 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4523 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4524 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4525 | |
| 4526 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4527 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4528 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4529 | self.waitUntilSettled() |
| 4530 | |
| 4531 | # We should be disabled now |
| 4532 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4533 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4534 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4535 | |
| 4536 | # We need to wait between each of these patches to make sure the |
| 4537 | # smtp messages come back in an expected order |
| 4538 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4539 | self.waitUntilSettled() |
| 4540 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4541 | self.waitUntilSettled() |
| 4542 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4543 | self.waitUntilSettled() |
| 4544 | |
| 4545 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4546 | # leaving a message on each change |
| 4547 | self.assertEqual(1, len(A.messages)) |
| 4548 | self.assertIn('Build failed.', A.messages[0]) |
| 4549 | self.assertEqual(1, len(B.messages)) |
| 4550 | self.assertIn('Build failed.', B.messages[0]) |
| 4551 | self.assertEqual(1, len(C.messages)) |
| 4552 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4553 | self.assertEqual(1, len(D.messages)) |
| 4554 | self.assertIn('Build failed.', D.messages[0]) |
| 4555 | self.assertEqual(1, len(E.messages)) |
| 4556 | self.assertIn('Build failed.', E.messages[0]) |
| 4557 | self.assertEqual(1, len(F.messages)) |
| 4558 | self.assertIn('Build failed.', F.messages[0]) |
| 4559 | |
| 4560 | # The last 3 (GHI) would have only reported via smtp. |
| 4561 | self.assertEqual(3, len(self.smtp_messages)) |
| 4562 | self.assertEqual(0, len(G.messages)) |
| 4563 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4564 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4565 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4566 | self.assertEqual(0, len(H.messages)) |
| 4567 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4568 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4569 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4570 | self.assertEqual(0, len(I.messages)) |
| 4571 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4572 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4573 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4574 | |
| 4575 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4576 | # comes out of disabled |
| 4577 | self.sched.reconfigure(self.config) |
| 4578 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4579 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4580 | |
| 4581 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4582 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4583 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4584 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4585 | |
| 4586 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4587 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4588 | self.waitUntilSettled() |
| 4589 | |
| 4590 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4591 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4592 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4593 | |
| 4594 | # J and K went back to gerrit |
| 4595 | self.assertEqual(1, len(J.messages)) |
| 4596 | self.assertIn('Build failed.', J.messages[0]) |
| 4597 | self.assertEqual(1, len(K.messages)) |
| 4598 | self.assertIn('Build failed.', K.messages[0]) |
| 4599 | # No more messages reported via smtp |
| 4600 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4601 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4602 | @simple_layout('layouts/one-job-project.yaml') |
| 4603 | def test_one_job_project(self): |
| 4604 | "Test that queueing works with one job" |
| 4605 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4606 | 'master', 'A') |
| 4607 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4608 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4609 | A.addApproval('Code-Review', 2) |
| 4610 | B.addApproval('Code-Review', 2) |
| 4611 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4612 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4613 | self.waitUntilSettled() |
| 4614 | |
| 4615 | self.assertEqual(A.data['status'], 'MERGED') |
| 4616 | self.assertEqual(A.reported, 2) |
| 4617 | self.assertEqual(B.data['status'], 'MERGED') |
| 4618 | self.assertEqual(B.reported, 2) |
| 4619 | |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4620 | def test_job_aborted(self): |
| 4621 | "Test that if a execute server aborts a job, it is run again" |
| 4622 | self.executor_server.hold_jobs_in_build = True |
| 4623 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4624 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4625 | self.waitUntilSettled() |
| 4626 | |
| 4627 | self.executor_server.release('.*-merge') |
| 4628 | self.waitUntilSettled() |
| 4629 | |
| 4630 | self.assertEqual(len(self.builds), 2) |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4631 | |
| 4632 | # first abort |
| 4633 | self.builds[0].aborted = True |
| 4634 | self.executor_server.release('.*-test*') |
| 4635 | self.waitUntilSettled() |
| 4636 | self.assertEqual(len(self.builds), 1) |
| 4637 | |
| 4638 | # second abort |
| 4639 | self.builds[0].aborted = True |
| 4640 | self.executor_server.release('.*-test*') |
| 4641 | self.waitUntilSettled() |
| 4642 | self.assertEqual(len(self.builds), 1) |
| 4643 | |
| 4644 | # third abort |
| 4645 | self.builds[0].aborted = True |
| 4646 | self.executor_server.release('.*-test*') |
| 4647 | self.waitUntilSettled() |
| 4648 | self.assertEqual(len(self.builds), 1) |
| 4649 | |
| 4650 | # fourth abort |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4651 | self.builds[0].aborted = True |
| 4652 | self.executor_server.release('.*-test*') |
| 4653 | self.waitUntilSettled() |
| 4654 | self.assertEqual(len(self.builds), 1) |
| 4655 | |
| 4656 | self.executor_server.hold_jobs_in_build = False |
| 4657 | self.executor_server.release() |
| 4658 | self.waitUntilSettled() |
| 4659 | |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4660 | self.assertEqual(len(self.history), 7) |
| 4661 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4662 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 4663 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4664 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4665 | "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] | 4666 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4667 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4668 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4669 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4670 | self.waitUntilSettled() |
| 4671 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4672 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4673 | self.waitUntilSettled() |
| 4674 | |
| 4675 | self.assertEqual(len(self.builds), 2) |
| 4676 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4677 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4678 | self.waitUntilSettled() |
| 4679 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4680 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4681 | self.assertEqual(len(self.builds), 1, |
| 4682 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4683 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4684 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4685 | self.waitUntilSettled() |
| 4686 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4687 | self.executor_server.hold_jobs_in_build = False |
| 4688 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4689 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4690 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4691 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4692 | self.assertEqual(A.reported, 1) |
| 4693 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4694 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4695 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4696 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4697 | |
| 4698 | self.fake_nodepool.paused = True |
| 4699 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4700 | A.addApproval('Code-Review', 2) |
| 4701 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4702 | self.waitUntilSettled() |
| 4703 | |
| 4704 | self.zk.client.stop() |
| 4705 | self.zk.client.start() |
| 4706 | self.fake_nodepool.paused = False |
| 4707 | self.waitUntilSettled() |
| 4708 | |
| 4709 | self.assertEqual(A.data['status'], 'MERGED') |
| 4710 | self.assertEqual(A.reported, 2) |
| 4711 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4712 | def test_nodepool_failure(self): |
| 4713 | "Test that jobs are reported after a nodepool failure" |
| 4714 | |
| 4715 | self.fake_nodepool.paused = True |
| 4716 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4717 | A.addApproval('Code-Review', 2) |
| 4718 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4719 | self.waitUntilSettled() |
| 4720 | |
| 4721 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4722 | self.fake_nodepool.addFailRequest(req) |
| 4723 | |
| 4724 | self.fake_nodepool.paused = False |
| 4725 | self.waitUntilSettled() |
| 4726 | |
| 4727 | self.assertEqual(A.data['status'], 'NEW') |
| 4728 | self.assertEqual(A.reported, 2) |
| 4729 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4730 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4731 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4732 | |
Monty Taylor | 6dc5bc1 | 2017-09-29 15:47:31 -0500 | [diff] [blame] | 4733 | def test_nodepool_priority(self): |
| 4734 | "Test that nodes are requested at the correct priority" |
| 4735 | |
| 4736 | self.fake_nodepool.paused = True |
| 4737 | |
| 4738 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4739 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4740 | |
| 4741 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4742 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4743 | |
| 4744 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4745 | C.addApproval('Code-Review', 2) |
| 4746 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 4747 | |
| 4748 | self.waitUntilSettled() |
| 4749 | |
| 4750 | reqs = self.fake_nodepool.getNodeRequests() |
| 4751 | |
| 4752 | # The requests come back sorted by oid. Since we have three requests |
| 4753 | # for the three changes each with a different priority. |
| 4754 | # Also they get a serial number based on order they were received |
| 4755 | # so the number on the endof the oid should map to order submitted. |
| 4756 | |
| 4757 | # * gate first - high priority - change C |
| 4758 | self.assertEqual(reqs[0]['_oid'], '100-0000000002') |
| 4759 | self.assertEqual(reqs[0]['node_types'], ['label1']) |
| 4760 | # * check second - normal priority - change B |
| 4761 | self.assertEqual(reqs[1]['_oid'], '200-0000000001') |
| 4762 | self.assertEqual(reqs[1]['node_types'], ['label1']) |
| 4763 | # * post third - low priority - change A |
| 4764 | # additionally, the post job defined uses an ubuntu-xenial node, |
| 4765 | # so we include that check just as an extra verification |
| 4766 | self.assertEqual(reqs[2]['_oid'], '300-0000000000') |
| 4767 | self.assertEqual(reqs[2]['node_types'], ['ubuntu-xenial']) |
| 4768 | |
| 4769 | self.fake_nodepool.paused = False |
| 4770 | self.waitUntilSettled() |
| 4771 | |
James E. Blair | fceaf41 | 2017-09-29 13:44:57 -0700 | [diff] [blame] | 4772 | @simple_layout('layouts/multiple-templates.yaml') |
| 4773 | def test_multiple_project_templates(self): |
| 4774 | # Test that applying multiple project templates to a project |
| 4775 | # doesn't alter them when used for a second project. |
| 4776 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4777 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4778 | self.waitUntilSettled() |
| 4779 | |
| 4780 | build = self.getJobFromHistory('py27') |
| 4781 | self.assertEqual(build.parameters['zuul']['jobtags'], []) |
| 4782 | |
James E. Blair | 29c7700 | 2017-10-05 14:56:35 -0700 | [diff] [blame] | 4783 | def test_pending_merge_in_reconfig(self): |
| 4784 | # Test that if we are waiting for an outstanding merge on |
| 4785 | # reconfiguration that we continue to do so. |
| 4786 | self.gearman_server.hold_merge_jobs_in_queue = True |
| 4787 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4788 | A.setMerged() |
| 4789 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4790 | self.waitUntilSettled() |
| 4791 | # Reconfigure while we still have an outstanding merge job |
| 4792 | self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'], |
| 4793 | None) |
| 4794 | self.waitUntilSettled() |
| 4795 | # Verify the merge job is still running and that the item is |
| 4796 | # in the pipeline |
| 4797 | self.assertEqual(len(self.sched.merger.jobs), 1) |
| 4798 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4799 | pipeline = tenant.layout.pipelines['post'] |
| 4800 | self.assertEqual(len(pipeline.getAllItems()), 1) |
| 4801 | self.gearman_server.hold_merge_jobs_in_queue = False |
| 4802 | self.gearman_server.release() |
| 4803 | self.waitUntilSettled() |
| 4804 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4805 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4806 | class TestExecutor(ZuulTestCase): |
| 4807 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4808 | |
| 4809 | def assertFinalState(self): |
| 4810 | # In this test, we expect to shut down in a non-final state, |
| 4811 | # so skip these checks. |
| 4812 | pass |
| 4813 | |
| 4814 | def assertCleanShutdown(self): |
| 4815 | self.log.debug("Assert clean shutdown") |
| 4816 | |
| 4817 | # After shutdown, make sure no jobs are running |
| 4818 | self.assertEqual({}, self.executor_server.job_workers) |
| 4819 | |
| 4820 | # Make sure that git.Repo objects have been garbage collected. |
| 4821 | repos = [] |
| 4822 | gc.collect() |
| 4823 | for obj in gc.get_objects(): |
| 4824 | if isinstance(obj, git.Repo): |
| 4825 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4826 | repos.append(obj) |
| 4827 | self.assertEqual(len(repos), 0) |
| 4828 | |
| 4829 | def test_executor_shutdown(self): |
| 4830 | "Test that the executor can shut down with jobs running" |
| 4831 | |
| 4832 | self.executor_server.hold_jobs_in_build = True |
| 4833 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4834 | A.addApproval('Code-Review', 2) |
| 4835 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4836 | self.waitUntilSettled() |
| 4837 | |
| 4838 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4839 | class TestDependencyGraph(ZuulTestCase): |
| 4840 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4841 | |
| 4842 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4843 | "Test a job in a dependency graph is queued only once" |
| 4844 | # Job dependencies, starting with A |
| 4845 | # A |
| 4846 | # / \ |
| 4847 | # B C |
| 4848 | # / \ / \ |
| 4849 | # D F E |
| 4850 | # | |
| 4851 | # G |
| 4852 | |
| 4853 | self.executor_server.hold_jobs_in_build = True |
| 4854 | change = self.fake_gerrit.addFakeChange( |
| 4855 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4856 | change.addApproval('Code-Review', 2) |
| 4857 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4858 | |
| 4859 | self.waitUntilSettled() |
| 4860 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4861 | |
| 4862 | self.executor_server.release('A') |
| 4863 | self.waitUntilSettled() |
| 4864 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4865 | |
| 4866 | self.executor_server.release('B') |
| 4867 | self.waitUntilSettled() |
| 4868 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4869 | |
| 4870 | self.executor_server.release('D') |
| 4871 | self.waitUntilSettled() |
| 4872 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4873 | |
| 4874 | self.executor_server.release('C') |
| 4875 | self.waitUntilSettled() |
| 4876 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4877 | |
| 4878 | self.executor_server.release('F') |
| 4879 | self.waitUntilSettled() |
| 4880 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4881 | |
| 4882 | self.executor_server.release('G') |
| 4883 | self.waitUntilSettled() |
| 4884 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4885 | |
| 4886 | self.executor_server.release('E') |
| 4887 | self.waitUntilSettled() |
| 4888 | self.assertEqual(len(self.builds), 0) |
| 4889 | |
| 4890 | self.executor_server.hold_jobs_in_build = False |
| 4891 | self.executor_server.release() |
| 4892 | self.waitUntilSettled() |
| 4893 | |
| 4894 | self.assertEqual(len(self.builds), 0) |
| 4895 | self.assertEqual(len(self.history), 7) |
| 4896 | |
| 4897 | self.assertEqual(change.data['status'], 'MERGED') |
| 4898 | self.assertEqual(change.reported, 2) |
| 4899 | |
| 4900 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4901 | "Test that a job waits till all dependencies are successful" |
| 4902 | # Job dependencies, starting with A |
| 4903 | # A |
| 4904 | # / \ |
| 4905 | # B C* |
| 4906 | # / \ / \ |
| 4907 | # D F E |
| 4908 | # | |
| 4909 | # G |
| 4910 | |
| 4911 | self.executor_server.hold_jobs_in_build = True |
| 4912 | change = self.fake_gerrit.addFakeChange( |
| 4913 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4914 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4915 | |
| 4916 | self.executor_server.failJob('C', change) |
| 4917 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4918 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4919 | |
| 4920 | self.waitUntilSettled() |
| 4921 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4922 | |
| 4923 | self.executor_server.release('A') |
| 4924 | self.waitUntilSettled() |
| 4925 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4926 | |
| 4927 | self.executor_server.release('B') |
| 4928 | self.waitUntilSettled() |
| 4929 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4930 | |
| 4931 | self.executor_server.release('D') |
| 4932 | self.waitUntilSettled() |
| 4933 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4934 | |
| 4935 | self.executor_server.release('C') |
| 4936 | self.waitUntilSettled() |
| 4937 | self.assertEqual(len(self.builds), 0) |
| 4938 | |
| 4939 | self.executor_server.hold_jobs_in_build = False |
| 4940 | self.executor_server.release() |
| 4941 | self.waitUntilSettled() |
| 4942 | |
| 4943 | self.assertEqual(len(self.builds), 0) |
| 4944 | self.assertEqual(len(self.history), 4) |
| 4945 | |
| 4946 | self.assertEqual(change.data['status'], 'NEW') |
| 4947 | self.assertEqual(change.reported, 2) |
| 4948 | |
| 4949 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4950 | class TestDuplicatePipeline(ZuulTestCase): |
| 4951 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4952 | |
| 4953 | def test_duplicate_pipelines(self): |
| 4954 | "Test that a change matching multiple pipelines works" |
| 4955 | |
| 4956 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4957 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4958 | self.waitUntilSettled() |
| 4959 | |
| 4960 | self.assertHistory([ |
| 4961 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4962 | pipeline='dup1'), |
| 4963 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4964 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4965 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4966 | |
| 4967 | self.assertEqual(len(A.messages), 2) |
| 4968 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4969 | if 'dup1' in A.messages[0]: |
| 4970 | self.assertIn('dup1', A.messages[0]) |
| 4971 | self.assertNotIn('dup2', A.messages[0]) |
| 4972 | self.assertIn('project-test1', A.messages[0]) |
| 4973 | self.assertIn('dup2', A.messages[1]) |
| 4974 | self.assertNotIn('dup1', A.messages[1]) |
| 4975 | self.assertIn('project-test1', A.messages[1]) |
| 4976 | else: |
| 4977 | self.assertIn('dup1', A.messages[1]) |
| 4978 | self.assertNotIn('dup2', A.messages[1]) |
| 4979 | self.assertIn('project-test1', A.messages[1]) |
| 4980 | self.assertIn('dup2', A.messages[0]) |
| 4981 | self.assertNotIn('dup1', A.messages[0]) |
| 4982 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4983 | |
| 4984 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4985 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4986 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4987 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4988 | def test_job_from_templates_executed(self): |
| 4989 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4990 | |
| 4991 | A = self.fake_gerrit.addFakeChange( |
| 4992 | 'org/templated-project', 'master', 'A') |
| 4993 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4994 | self.waitUntilSettled() |
| 4995 | |
| 4996 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4997 | 'SUCCESS') |
| 4998 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4999 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 5000 | |
| 5001 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5002 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 5003 | |
| 5004 | A = self.fake_gerrit.addFakeChange( |
| 5005 | 'org/layered-project', 'master', 'A') |
| 5006 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5007 | self.waitUntilSettled() |
| 5008 | |
| 5009 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5010 | 'SUCCESS') |
| 5011 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 5012 | 'SUCCESS') |
| 5013 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 5014 | ).result, 'SUCCESS') |
| 5015 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 5016 | ).result, 'SUCCESS') |
| 5017 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 5018 | ).result, 'SUCCESS') |
| 5019 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 5020 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5021 | |
James E. Blair | e74f571 | 2017-09-29 15:14:31 -0700 | [diff] [blame] | 5022 | def test_unimplied_branch_matchers(self): |
| 5023 | # This tests that there are no implied branch matchers added |
| 5024 | # by project templates. |
| 5025 | self.create_branch('org/layered-project', 'stable') |
| 5026 | |
| 5027 | A = self.fake_gerrit.addFakeChange( |
| 5028 | 'org/layered-project', 'stable', 'A') |
| 5029 | |
| 5030 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5031 | self.waitUntilSettled() |
| 5032 | |
| 5033 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5034 | 'SUCCESS') |
| 5035 | print(self.getJobFromHistory('project-test1'). |
| 5036 | parameters['zuul']['_inheritance_path']) |
| 5037 | |
| 5038 | def test_implied_branch_matchers(self): |
| 5039 | # This tests that there is an implied branch matcher when a |
| 5040 | # template is used on an in-repo project pipeline definition. |
| 5041 | self.create_branch('untrusted-config', 'stable') |
| 5042 | self.fake_gerrit.addEvent( |
| 5043 | self.fake_gerrit.getFakeBranchCreatedEvent( |
| 5044 | 'untrusted-config', 'stable')) |
| 5045 | self.waitUntilSettled() |
| 5046 | |
| 5047 | A = self.fake_gerrit.addFakeChange( |
| 5048 | 'untrusted-config', 'stable', 'A') |
| 5049 | |
| 5050 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5051 | self.waitUntilSettled() |
| 5052 | |
| 5053 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5054 | 'SUCCESS') |
| 5055 | print(self.getJobFromHistory('project-test1'). |
| 5056 | parameters['zuul']['_inheritance_path']) |
| 5057 | |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5058 | |
| 5059 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 5060 | tenant_config_file = 'config/success-url/main.yaml' |
| 5061 | |
| 5062 | def test_success_url(self): |
| 5063 | "Ensure bad build params are ignored" |
| 5064 | self.sched.reconfigure(self.config) |
| 5065 | self.init_repo('org/docs') |
| 5066 | |
| 5067 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 5068 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5069 | self.waitUntilSettled() |
| 5070 | |
| 5071 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 5072 | self.assertEqual(len(self.history), 2) |
| 5073 | |
| 5074 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 5075 | for build in self.history: |
| 5076 | if build.name == 'docs-draft-test': |
| 5077 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5078 | elif build.name == 'docs-draft-test2': |
| 5079 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5080 | |
| 5081 | # Two msgs: 'Starting...' + results |
| 5082 | self.assertEqual(len(self.smtp_messages), 2) |
| 5083 | body = self.smtp_messages[1]['body'].splitlines() |
| 5084 | self.assertEqual('Build succeeded.', body[0]) |
| 5085 | |
| 5086 | self.assertIn( |
| 5087 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 5088 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 5089 | body[2]) |
| 5090 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5091 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5092 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 5093 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 5094 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5095 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5096 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5097 | |
| 5098 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5099 | class TestSchedulerMerges(ZuulTestCase): |
| 5100 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5101 | |
| 5102 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5103 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5104 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5105 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5106 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 5107 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 5108 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5109 | A.addApproval('Code-Review', 2) |
| 5110 | B.addApproval('Code-Review', 2) |
| 5111 | C.addApproval('Code-Review', 2) |
| 5112 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5113 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5114 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5115 | self.waitUntilSettled() |
| 5116 | |
| 5117 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5118 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5119 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5120 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5121 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5122 | repo_messages.reverse() |
| 5123 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5124 | self.executor_server.hold_jobs_in_build = False |
| 5125 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5126 | self.waitUntilSettled() |
| 5127 | |
| 5128 | return repo_messages |
| 5129 | |
| 5130 | def _test_merge(self, mode): |
| 5131 | us_path = os.path.join( |
| 5132 | self.upstream_root, 'org/project-%s' % mode) |
| 5133 | expected_messages = [ |
| 5134 | 'initial commit', |
| 5135 | 'add content from fixture', |
| 5136 | # the intermediate commits order is nondeterministic |
| 5137 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 5138 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 5139 | ] |
| 5140 | result = self._test_project_merge_mode(mode) |
| 5141 | self.assertEqual(result[:2], expected_messages[:2]) |
| 5142 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 5143 | |
| 5144 | def test_project_merge_mode_merge(self): |
| 5145 | self._test_merge('merge') |
| 5146 | |
| 5147 | def test_project_merge_mode_merge_resolve(self): |
| 5148 | self._test_merge('merge-resolve') |
| 5149 | |
| 5150 | def test_project_merge_mode_cherrypick(self): |
| 5151 | expected_messages = [ |
| 5152 | 'initial commit', |
| 5153 | 'add content from fixture', |
| 5154 | 'A-1', |
| 5155 | 'B-1', |
| 5156 | 'C-1'] |
| 5157 | result = self._test_project_merge_mode('cherry-pick') |
| 5158 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5159 | |
| 5160 | def test_merge_branch(self): |
| 5161 | "Test that the right commits are on alternate branches" |
| 5162 | self.create_branch('org/project-merge-branches', 'mp') |
| 5163 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5164 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5165 | A = self.fake_gerrit.addFakeChange( |
| 5166 | 'org/project-merge-branches', 'mp', 'A') |
| 5167 | B = self.fake_gerrit.addFakeChange( |
| 5168 | 'org/project-merge-branches', 'mp', 'B') |
| 5169 | C = self.fake_gerrit.addFakeChange( |
| 5170 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5171 | A.addApproval('Code-Review', 2) |
| 5172 | B.addApproval('Code-Review', 2) |
| 5173 | C.addApproval('Code-Review', 2) |
| 5174 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5175 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5176 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5177 | self.waitUntilSettled() |
| 5178 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5179 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5180 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5181 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5182 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5183 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5184 | self.waitUntilSettled() |
| 5185 | |
| 5186 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 5187 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5188 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5189 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5190 | repo = git.Repo(path) |
| 5191 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5192 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5193 | repo_messages.reverse() |
| 5194 | correct_messages = [ |
| 5195 | 'initial commit', |
| 5196 | 'add content from fixture', |
| 5197 | 'mp commit', |
| 5198 | 'A-1', 'B-1', 'C-1'] |
| 5199 | self.assertEqual(repo_messages, correct_messages) |
| 5200 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5201 | self.executor_server.hold_jobs_in_build = False |
| 5202 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5203 | self.waitUntilSettled() |
| 5204 | |
| 5205 | def test_merge_multi_branch(self): |
| 5206 | "Test that dependent changes on multiple branches are merged" |
| 5207 | self.create_branch('org/project-merge-branches', 'mp') |
| 5208 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5209 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5210 | A = self.fake_gerrit.addFakeChange( |
| 5211 | 'org/project-merge-branches', 'master', 'A') |
| 5212 | B = self.fake_gerrit.addFakeChange( |
| 5213 | 'org/project-merge-branches', 'mp', 'B') |
| 5214 | C = self.fake_gerrit.addFakeChange( |
| 5215 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5216 | A.addApproval('Code-Review', 2) |
| 5217 | B.addApproval('Code-Review', 2) |
| 5218 | C.addApproval('Code-Review', 2) |
| 5219 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5220 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5221 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5222 | self.waitUntilSettled() |
| 5223 | |
| 5224 | job_A = None |
| 5225 | for job in self.builds: |
| 5226 | if 'project-merge' in job.name: |
| 5227 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5228 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5229 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 5230 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5231 | repo = git.Repo(path) |
| 5232 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5233 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5234 | repo_messages.reverse() |
| 5235 | correct_messages = [ |
| 5236 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5237 | self.assertEqual(repo_messages, correct_messages) |
| 5238 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5239 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5240 | self.waitUntilSettled() |
| 5241 | |
| 5242 | job_B = None |
| 5243 | for job in self.builds: |
| 5244 | if 'project-merge' in job.name: |
| 5245 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5246 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5247 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 5248 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5249 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5250 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5251 | repo_messages.reverse() |
| 5252 | correct_messages = [ |
| 5253 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5254 | self.assertEqual(repo_messages, correct_messages) |
| 5255 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5256 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5257 | self.waitUntilSettled() |
| 5258 | |
| 5259 | job_C = None |
| 5260 | for job in self.builds: |
| 5261 | if 'project-merge' in job.name: |
| 5262 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 5263 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5264 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 5265 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5266 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5267 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5268 | |
| 5269 | repo_messages.reverse() |
| 5270 | correct_messages = [ |
| 5271 | 'initial commit', 'add content from fixture', |
| 5272 | 'A-1', 'C-1'] |
| 5273 | # Ensure the right commits are in the history for this ref |
| 5274 | self.assertEqual(repo_messages, correct_messages) |
| 5275 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5276 | self.executor_server.hold_jobs_in_build = False |
| 5277 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5278 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5279 | |
| 5280 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5281 | class TestSemaphore(ZuulTestCase): |
| 5282 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5283 | |
| 5284 | def test_semaphore_one(self): |
| 5285 | "Test semaphores with max=1 (mutex)" |
| 5286 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5287 | |
| 5288 | self.executor_server.hold_jobs_in_build = True |
| 5289 | |
| 5290 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5291 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5292 | self.assertFalse('test-semaphore' in |
| 5293 | tenant.semaphore_handler.semaphores) |
| 5294 | |
| 5295 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5296 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5297 | self.waitUntilSettled() |
| 5298 | |
| 5299 | self.assertEqual(len(self.builds), 3) |
| 5300 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5301 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5302 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5303 | |
| 5304 | self.executor_server.release('semaphore-one-test1') |
| 5305 | self.waitUntilSettled() |
| 5306 | |
| 5307 | self.assertEqual(len(self.builds), 3) |
| 5308 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5309 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5310 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5311 | self.assertTrue('test-semaphore' in |
| 5312 | tenant.semaphore_handler.semaphores) |
| 5313 | |
| 5314 | self.executor_server.release('semaphore-one-test2') |
| 5315 | self.waitUntilSettled() |
| 5316 | |
| 5317 | self.assertEqual(len(self.builds), 3) |
| 5318 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5319 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5320 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5321 | self.assertTrue('test-semaphore' in |
| 5322 | tenant.semaphore_handler.semaphores) |
| 5323 | |
| 5324 | self.executor_server.release('semaphore-one-test1') |
| 5325 | self.waitUntilSettled() |
| 5326 | |
| 5327 | self.assertEqual(len(self.builds), 3) |
| 5328 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5329 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5330 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5331 | self.assertTrue('test-semaphore' in |
| 5332 | tenant.semaphore_handler.semaphores) |
| 5333 | |
| 5334 | self.executor_server.release('semaphore-one-test2') |
| 5335 | self.waitUntilSettled() |
| 5336 | |
| 5337 | self.assertEqual(len(self.builds), 2) |
| 5338 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5339 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5340 | self.assertFalse('test-semaphore' in |
| 5341 | tenant.semaphore_handler.semaphores) |
| 5342 | |
| 5343 | self.executor_server.hold_jobs_in_build = False |
| 5344 | self.executor_server.release() |
| 5345 | |
| 5346 | self.waitUntilSettled() |
| 5347 | self.assertEqual(len(self.builds), 0) |
| 5348 | |
| 5349 | self.assertEqual(A.reported, 1) |
| 5350 | self.assertEqual(B.reported, 1) |
| 5351 | self.assertFalse('test-semaphore' in |
| 5352 | tenant.semaphore_handler.semaphores) |
| 5353 | |
| 5354 | def test_semaphore_two(self): |
| 5355 | "Test semaphores with max>1" |
| 5356 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5357 | |
| 5358 | self.executor_server.hold_jobs_in_build = True |
| 5359 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5360 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5361 | self.assertFalse('test-semaphore-two' in |
| 5362 | tenant.semaphore_handler.semaphores) |
| 5363 | |
| 5364 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5365 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5366 | self.waitUntilSettled() |
| 5367 | |
| 5368 | self.assertEqual(len(self.builds), 4) |
| 5369 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5370 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5371 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5372 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5373 | self.assertTrue('test-semaphore-two' in |
| 5374 | tenant.semaphore_handler.semaphores) |
| 5375 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5376 | 'test-semaphore-two', [])), 2) |
| 5377 | |
| 5378 | self.executor_server.release('semaphore-two-test1') |
| 5379 | self.waitUntilSettled() |
| 5380 | |
| 5381 | self.assertEqual(len(self.builds), 4) |
| 5382 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5383 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5384 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5385 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5386 | self.assertTrue('test-semaphore-two' in |
| 5387 | tenant.semaphore_handler.semaphores) |
| 5388 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5389 | 'test-semaphore-two', [])), 2) |
| 5390 | |
| 5391 | self.executor_server.release('semaphore-two-test2') |
| 5392 | self.waitUntilSettled() |
| 5393 | |
| 5394 | self.assertEqual(len(self.builds), 4) |
| 5395 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5396 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5397 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5398 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5399 | self.assertTrue('test-semaphore-two' in |
| 5400 | tenant.semaphore_handler.semaphores) |
| 5401 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5402 | 'test-semaphore-two', [])), 2) |
| 5403 | |
| 5404 | self.executor_server.release('semaphore-two-test1') |
| 5405 | self.waitUntilSettled() |
| 5406 | |
| 5407 | self.assertEqual(len(self.builds), 3) |
| 5408 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5409 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5410 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5411 | self.assertTrue('test-semaphore-two' in |
| 5412 | tenant.semaphore_handler.semaphores) |
| 5413 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5414 | 'test-semaphore-two', [])), 1) |
| 5415 | |
| 5416 | self.executor_server.release('semaphore-two-test2') |
| 5417 | self.waitUntilSettled() |
| 5418 | |
| 5419 | self.assertEqual(len(self.builds), 2) |
| 5420 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5421 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5422 | self.assertFalse('test-semaphore-two' in |
| 5423 | tenant.semaphore_handler.semaphores) |
| 5424 | |
| 5425 | self.executor_server.hold_jobs_in_build = False |
| 5426 | self.executor_server.release() |
| 5427 | |
| 5428 | self.waitUntilSettled() |
| 5429 | self.assertEqual(len(self.builds), 0) |
| 5430 | |
| 5431 | self.assertEqual(A.reported, 1) |
| 5432 | self.assertEqual(B.reported, 1) |
| 5433 | |
| 5434 | def test_semaphore_abandon(self): |
| 5435 | "Test abandon with job semaphores" |
| 5436 | self.executor_server.hold_jobs_in_build = True |
| 5437 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5438 | check_pipeline = tenant.layout.pipelines['check'] |
| 5439 | |
| 5440 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5441 | self.assertFalse('test-semaphore' in |
| 5442 | tenant.semaphore_handler.semaphores) |
| 5443 | |
| 5444 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5445 | self.waitUntilSettled() |
| 5446 | |
| 5447 | self.assertTrue('test-semaphore' in |
| 5448 | tenant.semaphore_handler.semaphores) |
| 5449 | |
| 5450 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5451 | self.waitUntilSettled() |
| 5452 | |
| 5453 | # The check pipeline should be empty |
| 5454 | items = check_pipeline.getAllItems() |
| 5455 | self.assertEqual(len(items), 0) |
| 5456 | |
| 5457 | # The semaphore should be released |
| 5458 | self.assertFalse('test-semaphore' in |
| 5459 | tenant.semaphore_handler.semaphores) |
| 5460 | |
| 5461 | self.executor_server.hold_jobs_in_build = False |
| 5462 | self.executor_server.release() |
| 5463 | self.waitUntilSettled() |
| 5464 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5465 | def test_semaphore_new_patchset(self): |
| 5466 | "Test new patchset with job semaphores" |
| 5467 | self.executor_server.hold_jobs_in_build = True |
| 5468 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5469 | check_pipeline = tenant.layout.pipelines['check'] |
| 5470 | |
| 5471 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5472 | self.assertFalse('test-semaphore' in |
| 5473 | tenant.semaphore_handler.semaphores) |
| 5474 | |
| 5475 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5476 | self.waitUntilSettled() |
| 5477 | |
| 5478 | self.assertTrue('test-semaphore' in |
| 5479 | tenant.semaphore_handler.semaphores) |
| 5480 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5481 | self.assertEqual(len(semaphore), 1) |
| 5482 | |
| 5483 | A.addPatchset() |
| 5484 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5485 | self.waitUntilSettled() |
| 5486 | |
| 5487 | self.assertTrue('test-semaphore' in |
| 5488 | tenant.semaphore_handler.semaphores) |
| 5489 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5490 | self.assertEqual(len(semaphore), 1) |
| 5491 | |
| 5492 | items = check_pipeline.getAllItems() |
| 5493 | self.assertEqual(items[0].change.number, '1') |
| 5494 | self.assertEqual(items[0].change.patchset, '2') |
| 5495 | self.assertTrue(items[0].live) |
| 5496 | |
| 5497 | self.executor_server.hold_jobs_in_build = False |
| 5498 | self.executor_server.release() |
| 5499 | self.waitUntilSettled() |
| 5500 | |
| 5501 | # The semaphore should be released |
| 5502 | self.assertFalse('test-semaphore' in |
| 5503 | tenant.semaphore_handler.semaphores) |
| 5504 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5505 | def test_semaphore_reconfigure(self): |
| 5506 | "Test reconfigure with job semaphores" |
| 5507 | self.executor_server.hold_jobs_in_build = True |
| 5508 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5509 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5510 | self.assertFalse('test-semaphore' in |
| 5511 | tenant.semaphore_handler.semaphores) |
| 5512 | |
| 5513 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5514 | self.waitUntilSettled() |
| 5515 | |
| 5516 | self.assertTrue('test-semaphore' in |
| 5517 | tenant.semaphore_handler.semaphores) |
| 5518 | |
| 5519 | # reconfigure without layout change |
| 5520 | self.sched.reconfigure(self.config) |
| 5521 | self.waitUntilSettled() |
| 5522 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5523 | |
| 5524 | # semaphore still must be held |
| 5525 | self.assertTrue('test-semaphore' in |
| 5526 | tenant.semaphore_handler.semaphores) |
| 5527 | |
| 5528 | self.commitConfigUpdate( |
| 5529 | 'common-config', |
| 5530 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5531 | self.sched.reconfigure(self.config) |
| 5532 | self.waitUntilSettled() |
| 5533 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5534 | |
| 5535 | self.executor_server.release('project-test1') |
| 5536 | self.waitUntilSettled() |
| 5537 | |
| 5538 | # There should be no builds anymore |
| 5539 | self.assertEqual(len(self.builds), 0) |
| 5540 | |
| 5541 | # The semaphore should be released |
| 5542 | self.assertFalse('test-semaphore' in |
| 5543 | tenant.semaphore_handler.semaphores) |
| 5544 | |
| 5545 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5546 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5547 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5548 | |
| 5549 | def test_semaphore_tenant_isolation(self): |
| 5550 | "Test semaphores in multiple tenants" |
| 5551 | |
| 5552 | self.waitUntilSettled() |
| 5553 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5554 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5555 | |
| 5556 | self.executor_server.hold_jobs_in_build = True |
| 5557 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5558 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5559 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5560 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5561 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5562 | self.assertFalse('test-semaphore' in |
| 5563 | tenant_one.semaphore_handler.semaphores) |
| 5564 | self.assertFalse('test-semaphore' in |
| 5565 | tenant_two.semaphore_handler.semaphores) |
| 5566 | |
| 5567 | # add patches to project1 of tenant-one |
| 5568 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5569 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5570 | self.waitUntilSettled() |
| 5571 | |
| 5572 | # one build of project1-test1 must run |
| 5573 | # semaphore of tenant-one must be acquired once |
| 5574 | # semaphore of tenant-two must not be acquired |
| 5575 | self.assertEqual(len(self.builds), 1) |
| 5576 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5577 | self.assertTrue('test-semaphore' in |
| 5578 | tenant_one.semaphore_handler.semaphores) |
| 5579 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5580 | 'test-semaphore', [])), 1) |
| 5581 | self.assertFalse('test-semaphore' in |
| 5582 | tenant_two.semaphore_handler.semaphores) |
| 5583 | |
| 5584 | # add patches to project2 of tenant-two |
| 5585 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5586 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5587 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5588 | self.waitUntilSettled() |
| 5589 | |
| 5590 | # one build of project1-test1 must run |
| 5591 | # two builds of project2-test1 must run |
| 5592 | # semaphore of tenant-one must be acquired once |
| 5593 | # semaphore of tenant-two must be acquired twice |
| 5594 | self.assertEqual(len(self.builds), 3) |
| 5595 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5596 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5597 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5598 | self.assertTrue('test-semaphore' in |
| 5599 | tenant_one.semaphore_handler.semaphores) |
| 5600 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5601 | 'test-semaphore', [])), 1) |
| 5602 | self.assertTrue('test-semaphore' in |
| 5603 | tenant_two.semaphore_handler.semaphores) |
| 5604 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5605 | 'test-semaphore', [])), 2) |
| 5606 | |
| 5607 | self.executor_server.release('project1-test1') |
| 5608 | self.waitUntilSettled() |
| 5609 | |
| 5610 | # one build of project1-test1 must run |
| 5611 | # two builds of project2-test1 must run |
| 5612 | # semaphore of tenant-one must be acquired once |
| 5613 | # semaphore of tenant-two must be acquired twice |
| 5614 | self.assertEqual(len(self.builds), 3) |
| 5615 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5616 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5617 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5618 | self.assertTrue('test-semaphore' in |
| 5619 | tenant_one.semaphore_handler.semaphores) |
| 5620 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5621 | 'test-semaphore', [])), 1) |
| 5622 | self.assertTrue('test-semaphore' in |
| 5623 | tenant_two.semaphore_handler.semaphores) |
| 5624 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5625 | 'test-semaphore', [])), 2) |
| 5626 | |
| 5627 | self.executor_server.release('project2-test1') |
| 5628 | self.waitUntilSettled() |
| 5629 | |
| 5630 | # one build of project1-test1 must run |
| 5631 | # one build of project2-test1 must run |
| 5632 | # semaphore of tenant-one must be acquired once |
| 5633 | # semaphore of tenant-two must be acquired once |
| 5634 | self.assertEqual(len(self.builds), 2) |
| 5635 | self.assertTrue('test-semaphore' in |
| 5636 | tenant_one.semaphore_handler.semaphores) |
| 5637 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5638 | 'test-semaphore', [])), 1) |
| 5639 | self.assertTrue('test-semaphore' in |
| 5640 | tenant_two.semaphore_handler.semaphores) |
| 5641 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5642 | 'test-semaphore', [])), 1) |
| 5643 | |
| 5644 | self.executor_server.hold_jobs_in_build = False |
| 5645 | self.executor_server.release() |
| 5646 | |
| 5647 | self.waitUntilSettled() |
| 5648 | |
| 5649 | # no build must run |
| 5650 | # semaphore of tenant-one must not be acquired |
| 5651 | # semaphore of tenant-two must not be acquired |
| 5652 | self.assertEqual(len(self.builds), 0) |
| 5653 | self.assertFalse('test-semaphore' in |
| 5654 | tenant_one.semaphore_handler.semaphores) |
| 5655 | self.assertFalse('test-semaphore' in |
| 5656 | tenant_two.semaphore_handler.semaphores) |
| 5657 | |
| 5658 | self.assertEqual(A.reported, 1) |
| 5659 | self.assertEqual(B.reported, 1) |
| 5660 | |
| 5661 | |
| 5662 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5663 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5664 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5665 | |
| 5666 | def test_semaphore_in_repo(self): |
| 5667 | "Test semaphores in repo config" |
| 5668 | |
| 5669 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5670 | # max value should not be evaluated dynamically but must be updated |
| 5671 | # after the change lands. |
| 5672 | |
| 5673 | self.waitUntilSettled() |
| 5674 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5675 | |
| 5676 | in_repo_conf = textwrap.dedent( |
| 5677 | """ |
| 5678 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5679 | name: project-test1 |
| 5680 | |
| 5681 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5682 | name: project-test2 |
| 5683 | semaphore: test-semaphore |
| 5684 | |
| 5685 | - project: |
| 5686 | name: org/project |
| 5687 | tenant-one-gate: |
| 5688 | jobs: |
| 5689 | - project-test2 |
| 5690 | |
| 5691 | # the max value in dynamic layout must be ignored |
| 5692 | - semaphore: |
| 5693 | name: test-semaphore |
| 5694 | max: 2 |
| 5695 | """) |
| 5696 | |
| 5697 | in_repo_playbook = textwrap.dedent( |
| 5698 | """ |
| 5699 | - hosts: all |
| 5700 | tasks: [] |
| 5701 | """) |
| 5702 | |
| 5703 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5704 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5705 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5706 | files=file_dict) |
| 5707 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5708 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5709 | B.setDependsOn(A, 1) |
| 5710 | C.setDependsOn(A, 1) |
| 5711 | |
| 5712 | self.executor_server.hold_jobs_in_build = True |
| 5713 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5714 | A.addApproval('Code-Review', 2) |
| 5715 | B.addApproval('Code-Review', 2) |
| 5716 | C.addApproval('Code-Review', 2) |
| 5717 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5718 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5719 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5720 | self.waitUntilSettled() |
| 5721 | |
| 5722 | # check that the layout in a queue item still has max value of 1 |
| 5723 | # for test-semaphore |
| 5724 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5725 | queue = None |
| 5726 | for queue_candidate in pipeline.queues: |
| 5727 | if queue_candidate.name == 'org/project': |
| 5728 | queue = queue_candidate |
| 5729 | break |
| 5730 | queue_item = queue.queue[0] |
James E. Blair | 29a24fd | 2017-10-02 15:04:56 -0700 | [diff] [blame] | 5731 | item_dynamic_layout = queue_item.layout |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5732 | dynamic_test_semaphore = \ |
| 5733 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5734 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5735 | |
| 5736 | # one build must be in queue, one semaphores acquired |
| 5737 | self.assertEqual(len(self.builds), 1) |
| 5738 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5739 | self.assertTrue('test-semaphore' in |
| 5740 | tenant.semaphore_handler.semaphores) |
| 5741 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5742 | 'test-semaphore', [])), 1) |
| 5743 | |
| 5744 | self.executor_server.release('project-test2') |
| 5745 | self.waitUntilSettled() |
| 5746 | |
| 5747 | # change A must be merged |
| 5748 | self.assertEqual(A.data['status'], 'MERGED') |
| 5749 | self.assertEqual(A.reported, 2) |
| 5750 | |
| 5751 | # send change-merged event as the gerrit mock doesn't send it |
| 5752 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5753 | self.waitUntilSettled() |
| 5754 | |
| 5755 | # now that change A was merged, the new semaphore max must be effective |
| 5756 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5757 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5758 | |
| 5759 | # two builds must be in queue, two semaphores acquired |
| 5760 | self.assertEqual(len(self.builds), 2) |
| 5761 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5762 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5763 | self.assertTrue('test-semaphore' in |
| 5764 | tenant.semaphore_handler.semaphores) |
| 5765 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5766 | 'test-semaphore', [])), 2) |
| 5767 | |
| 5768 | self.executor_server.release('project-test2') |
| 5769 | self.waitUntilSettled() |
| 5770 | |
| 5771 | self.assertEqual(len(self.builds), 0) |
| 5772 | self.assertFalse('test-semaphore' in |
| 5773 | tenant.semaphore_handler.semaphores) |
| 5774 | |
| 5775 | self.executor_server.hold_jobs_in_build = False |
| 5776 | self.executor_server.release() |
| 5777 | |
| 5778 | self.waitUntilSettled() |
| 5779 | self.assertEqual(len(self.builds), 0) |
| 5780 | |
| 5781 | self.assertEqual(A.reported, 2) |
| 5782 | self.assertEqual(B.reported, 2) |
| 5783 | self.assertEqual(C.reported, 2) |
David Shrewsbury | f6dc176 | 2017-10-02 13:34:37 -0400 | [diff] [blame] | 5784 | |
| 5785 | |
| 5786 | class TestSchedulerBranchMatcher(ZuulTestCase): |
| 5787 | |
| 5788 | @simple_layout('layouts/matcher-test.yaml') |
| 5789 | def test_job_branch_ignored(self): |
| 5790 | ''' |
| 5791 | Test that branch matching logic works. |
| 5792 | |
| 5793 | The 'ignore-branch' job has a branch matcher that is supposed to |
| 5794 | match every branch except for the 'featureA' branch, so it should |
| 5795 | not be run on a change to that branch. |
| 5796 | ''' |
| 5797 | self.create_branch('org/project', 'featureA') |
| 5798 | A = self.fake_gerrit.addFakeChange('org/project', 'featureA', 'A') |
| 5799 | A.addApproval('Code-Review', 2) |
| 5800 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5801 | self.waitUntilSettled() |
| 5802 | self.printHistory() |
| 5803 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5804 | 'SUCCESS') |
| 5805 | self.assertJobNotInHistory('ignore-branch') |
| 5806 | self.assertEqual(A.data['status'], 'MERGED') |
| 5807 | self.assertEqual(A.reported, 2, |
| 5808 | "A should report start and success") |
| 5809 | self.assertIn('gate', A.messages[1], |
| 5810 | "A should transit gate") |