James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 17 | import gc |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 18 | import json |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 19 | import textwrap |
| 20 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 21 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 22 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 23 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | import time |
Clint Byrum | 03454a5 | 2017-05-26 17:14:02 -0700 | [diff] [blame] | 25 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 27 | import git |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 28 | import testtools |
Monty Taylor | b934c1a | 2017-06-16 19:31:47 -0500 | [diff] [blame] | 29 | import urllib |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 31 | import zuul.change_matcher |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 32 | from zuul.driver.gerrit import gerritreporter |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 33 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 34 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 35 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 36 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | from tests.base import ( |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 38 | SSLZuulTestCase, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 39 | ZuulTestCase, |
| 40 | repack_repo, |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 41 | simple_layout, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 42 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 43 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 44 | |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 45 | class TestSchedulerSSL(SSLZuulTestCase): |
| 46 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 47 | |
| 48 | def test_jobs_executed(self): |
| 49 | "Test that jobs are executed and a change is merged" |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 50 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 51 | A.addApproval('Code-Review', 2) |
| 52 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 53 | self.waitUntilSettled() |
| 54 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 55 | 'SUCCESS') |
| 56 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 57 | 'SUCCESS') |
| 58 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 59 | 'SUCCESS') |
| 60 | self.assertEqual(A.data['status'], 'MERGED') |
| 61 | self.assertEqual(A.reported, 2) |
| 62 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 63 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 64 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 65 | 'label1') |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 66 | |
| 67 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 68 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 69 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 70 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 71 | def test_jobs_executed(self): |
| 72 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 73 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 74 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 75 | A.addApproval('Code-Review', 2) |
| 76 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 77 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 78 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 79 | 'SUCCESS') |
| 80 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 81 | 'SUCCESS') |
| 82 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 83 | 'SUCCESS') |
| 84 | self.assertEqual(A.data['status'], 'MERGED') |
| 85 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 86 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 87 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 88 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 89 | 'label1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 90 | |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 91 | for stat in self.statsd.stats: |
| 92 | k, v = stat.decode('utf-8').split(':') |
| 93 | self.log.debug('stat %s:%s', k, v) |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 94 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 95 | # Per-driver |
| 96 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 97 | # Per-driver per-connection |
| 98 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 99 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 100 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 101 | 'zuul.tenant.tenant-one.pipeline.gate.current_changes', |
| 102 | value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 103 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 104 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 105 | 'org_project.master.job.project-merge.SUCCESS', kind='ms') |
| 106 | self.assertReportedStat( |
| 107 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 108 | 'org_project.master.job.project-merge.SUCCESS', value='1|c') |
| 109 | self.assertReportedStat( |
| 110 | 'zuul.tenant.tenant-one.pipeline.gate.resident_time', kind='ms') |
| 111 | self.assertReportedStat( |
| 112 | 'zuul.tenant.tenant-one.pipeline.gate.total_changes', value='1|c') |
| 113 | self.assertReportedStat( |
| 114 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 115 | 'org_project.master.resident_time', kind='ms') |
| 116 | self.assertReportedStat( |
| 117 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 118 | 'org_project.master.total_changes', value='1|c') |
James E. Blair | faf8198 | 2017-10-10 15:42:26 -0700 | [diff] [blame] | 119 | exec_key = 'zuul.executor.%s' % self.executor_server.hostname |
| 120 | self.assertReportedStat(exec_key + '.builds', value='1|c') |
James E. Blair | 4f1731b | 2017-10-10 18:11:42 -0700 | [diff] [blame] | 121 | self.assertReportedStat('zuul.nodepool.requested', value='1|c') |
| 122 | self.assertReportedStat('zuul.nodepool.requested.label.label1', |
| 123 | value='1|c') |
| 124 | self.assertReportedStat('zuul.nodepool.fulfilled.label.label1', |
| 125 | value='1|c') |
| 126 | self.assertReportedStat('zuul.nodepool.requested.size.1', value='1|c') |
| 127 | self.assertReportedStat('zuul.nodepool.fulfilled.size.1', value='1|c') |
| 128 | self.assertReportedStat('zuul.nodepool.current_requests', value='1|g') |
James E. Blair | bdd50e6 | 2017-10-21 08:18:55 -0700 | [diff] [blame] | 129 | self.assertReportedStat('zuul.executors.online', value='1|g') |
| 130 | self.assertReportedStat('zuul.executors.accepting', value='1|g') |
| 131 | self.assertReportedStat('zuul.mergers.online', value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 132 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 133 | for build in self.history: |
| 134 | self.assertTrue(build.parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 135 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 136 | def test_initial_pipeline_gauges(self): |
| 137 | "Test that each pipeline reported its length on start" |
James E. Blair | 57bf14d | 2017-10-21 09:09:48 -0700 | [diff] [blame] | 138 | self.assertReportedStat('zuul.tenant.tenant-one.pipeline.gate.' |
| 139 | 'current_changes', |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 140 | value='0|g') |
James E. Blair | 57bf14d | 2017-10-21 09:09:48 -0700 | [diff] [blame] | 141 | self.assertReportedStat('zuul.tenant.tenant-one.pipeline.check.' |
| 142 | 'current_changes', |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 143 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 144 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 145 | def test_job_branch(self): |
| 146 | "Test the correct variant of a job runs on a branch" |
| 147 | self.create_branch('org/project', 'stable') |
| 148 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 149 | A.addApproval('Code-Review', 2) |
| 150 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 151 | self.waitUntilSettled() |
| 152 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 153 | 'SUCCESS') |
| 154 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 155 | 'SUCCESS') |
| 156 | self.assertEqual(A.data['status'], 'MERGED') |
| 157 | self.assertEqual(A.reported, 2, |
| 158 | "A should report start and success") |
| 159 | self.assertIn('gate', A.messages[1], |
| 160 | "A should transit gate") |
| 161 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 162 | 'label2') |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 163 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 164 | def test_parallel_changes(self): |
| 165 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 166 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 167 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 168 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 169 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 170 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 171 | A.addApproval('Code-Review', 2) |
| 172 | B.addApproval('Code-Review', 2) |
| 173 | C.addApproval('Code-Review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 174 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 175 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 176 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 177 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 178 | |
| 179 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 180 | self.assertEqual(len(self.builds), 1) |
| 181 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 182 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 183 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 184 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 185 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 186 | self.assertEqual(len(self.builds), 3) |
| 187 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 188 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 189 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 190 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 191 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 192 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 193 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 194 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 195 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 196 | self.assertEqual(len(self.builds), 5) |
| 197 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 198 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 199 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 200 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 201 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 202 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 203 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 204 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 205 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 206 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 207 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 208 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 209 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 210 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 211 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 212 | self.assertEqual(len(self.builds), 6) |
| 213 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 214 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 215 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 216 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 217 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 218 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 219 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 220 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 221 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 222 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 223 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 224 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 225 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 226 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 227 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 228 | self.executor_server.hold_jobs_in_build = False |
| 229 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 230 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 231 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 232 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 233 | self.assertEqual(len(self.history), 9) |
| 234 | self.assertEqual(A.data['status'], 'MERGED') |
| 235 | self.assertEqual(B.data['status'], 'MERGED') |
| 236 | self.assertEqual(C.data['status'], 'MERGED') |
| 237 | self.assertEqual(A.reported, 2) |
| 238 | self.assertEqual(B.reported, 2) |
| 239 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 240 | |
| 241 | def test_failed_changes(self): |
| 242 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 243 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 244 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 245 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 246 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 247 | A.addApproval('Code-Review', 2) |
| 248 | B.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 249 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 250 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 251 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 252 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 253 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 254 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 255 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 256 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 257 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 258 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 259 | # A/project-merge is complete |
| 260 | self.assertBuilds([ |
| 261 | dict(name='project-test1', changes='1,1'), |
| 262 | dict(name='project-test2', changes='1,1'), |
| 263 | dict(name='project-merge', changes='1,1 2,1'), |
| 264 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 265 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 266 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 267 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 268 | # A/project-merge is complete |
| 269 | # B/project-merge is complete |
| 270 | self.assertBuilds([ |
| 271 | dict(name='project-test1', changes='1,1'), |
| 272 | dict(name='project-test2', changes='1,1'), |
| 273 | dict(name='project-test1', changes='1,1 2,1'), |
| 274 | dict(name='project-test2', changes='1,1 2,1'), |
| 275 | ]) |
| 276 | |
| 277 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 278 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 279 | self.builds[0].release() |
| 280 | self.waitUntilSettled() |
| 281 | |
| 282 | self.orderedRelease() |
| 283 | self.assertHistory([ |
| 284 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 285 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 286 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 287 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 288 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 289 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 290 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 291 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 292 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 293 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 294 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 295 | self.assertEqual(A.data['status'], 'NEW') |
| 296 | self.assertEqual(B.data['status'], 'MERGED') |
| 297 | self.assertEqual(A.reported, 2) |
| 298 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 299 | |
| 300 | def test_independent_queues(self): |
| 301 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 302 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 303 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 304 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 305 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 306 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 307 | A.addApproval('Code-Review', 2) |
| 308 | B.addApproval('Code-Review', 2) |
| 309 | C.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 310 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 311 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 312 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 313 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 314 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 315 | self.waitUntilSettled() |
| 316 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 317 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 318 | self.waitUntilSettled() |
| 319 | |
| 320 | # 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] | 321 | self.assertBuilds([ |
| 322 | dict(name='project-merge', changes='1,1'), |
| 323 | dict(name='project-merge', changes='2,1'), |
| 324 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 325 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 326 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 327 | self.builds[0].release() |
| 328 | self.waitUntilSettled() |
| 329 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 330 | self.waitUntilSettled() |
| 331 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 332 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 333 | self.waitUntilSettled() |
| 334 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 335 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 336 | self.assertBuilds([ |
| 337 | dict(name='project-test1', changes='1,1'), |
| 338 | dict(name='project-test2', changes='1,1'), |
| 339 | dict(name='project-test1', changes='2,1'), |
| 340 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 341 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 342 | dict(name='project-test1', changes='2,1 3,1'), |
| 343 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 344 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 345 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 346 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 347 | self.orderedRelease() |
| 348 | self.assertHistory([ |
| 349 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 350 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 351 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 352 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 353 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 354 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 355 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 356 | dict( |
| 357 | name='project1-project2-integration', |
| 358 | result='SUCCESS', |
| 359 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 360 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 361 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 362 | dict(name='project1-project2-integration', |
| 363 | result='SUCCESS', |
| 364 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 365 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 366 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 367 | self.assertEqual(A.data['status'], 'MERGED') |
| 368 | self.assertEqual(B.data['status'], 'MERGED') |
| 369 | self.assertEqual(C.data['status'], 'MERGED') |
| 370 | self.assertEqual(A.reported, 2) |
| 371 | self.assertEqual(B.reported, 2) |
| 372 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 373 | |
| 374 | def test_failed_change_at_head(self): |
| 375 | "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] | 376 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 377 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 378 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 379 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 380 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 381 | A.addApproval('Code-Review', 2) |
| 382 | B.addApproval('Code-Review', 2) |
| 383 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 384 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 385 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 386 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 387 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 388 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 389 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 390 | |
| 391 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 392 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 393 | self.assertBuilds([ |
| 394 | dict(name='project-merge', changes='1,1'), |
| 395 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 396 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 399 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 400 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 401 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 402 | self.waitUntilSettled() |
| 403 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 404 | self.assertBuilds([ |
| 405 | dict(name='project-test1', changes='1,1'), |
| 406 | dict(name='project-test2', changes='1,1'), |
| 407 | dict(name='project-test1', changes='1,1 2,1'), |
| 408 | dict(name='project-test2', changes='1,1 2,1'), |
| 409 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 410 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 411 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 412 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 413 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 414 | self.waitUntilSettled() |
| 415 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 416 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 417 | self.assertBuilds([ |
| 418 | dict(name='project-test2', changes='1,1'), |
| 419 | dict(name='project-merge', changes='2,1'), |
| 420 | ]) |
| 421 | # Unordered history comparison because the aborts can finish |
| 422 | # in any order. |
| 423 | self.assertHistory([ |
| 424 | dict(name='project-merge', result='SUCCESS', |
| 425 | changes='1,1'), |
| 426 | dict(name='project-merge', result='SUCCESS', |
| 427 | changes='1,1 2,1'), |
| 428 | dict(name='project-merge', result='SUCCESS', |
| 429 | changes='1,1 2,1 3,1'), |
| 430 | dict(name='project-test1', result='FAILURE', |
| 431 | changes='1,1'), |
| 432 | dict(name='project-test1', result='ABORTED', |
| 433 | changes='1,1 2,1'), |
| 434 | dict(name='project-test2', result='ABORTED', |
| 435 | changes='1,1 2,1'), |
| 436 | dict(name='project-test1', result='ABORTED', |
| 437 | changes='1,1 2,1 3,1'), |
| 438 | dict(name='project-test2', result='ABORTED', |
| 439 | changes='1,1 2,1 3,1'), |
| 440 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 441 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 442 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 443 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 444 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 445 | self.waitUntilSettled() |
| 446 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 447 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 448 | self.assertBuilds([]) |
| 449 | self.assertHistory([ |
| 450 | dict(name='project-merge', result='SUCCESS', |
| 451 | changes='1,1'), |
| 452 | dict(name='project-merge', result='SUCCESS', |
| 453 | changes='1,1 2,1'), |
| 454 | dict(name='project-merge', result='SUCCESS', |
| 455 | changes='1,1 2,1 3,1'), |
| 456 | dict(name='project-test1', result='FAILURE', |
| 457 | changes='1,1'), |
| 458 | dict(name='project-test1', result='ABORTED', |
| 459 | changes='1,1 2,1'), |
| 460 | dict(name='project-test2', result='ABORTED', |
| 461 | changes='1,1 2,1'), |
| 462 | dict(name='project-test1', result='ABORTED', |
| 463 | changes='1,1 2,1 3,1'), |
| 464 | dict(name='project-test2', result='ABORTED', |
| 465 | changes='1,1 2,1 3,1'), |
| 466 | dict(name='project-merge', result='SUCCESS', |
| 467 | changes='2,1'), |
| 468 | dict(name='project-merge', result='SUCCESS', |
| 469 | changes='2,1 3,1'), |
| 470 | dict(name='project-test2', result='SUCCESS', |
| 471 | changes='1,1'), |
| 472 | dict(name='project-test1', result='SUCCESS', |
| 473 | changes='2,1'), |
| 474 | dict(name='project-test2', result='SUCCESS', |
| 475 | changes='2,1'), |
| 476 | dict(name='project-test1', result='SUCCESS', |
| 477 | changes='2,1 3,1'), |
| 478 | dict(name='project-test2', result='SUCCESS', |
| 479 | changes='2,1 3,1'), |
| 480 | ], ordered=False) |
| 481 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 482 | self.assertEqual(A.data['status'], 'NEW') |
| 483 | self.assertEqual(B.data['status'], 'MERGED') |
| 484 | self.assertEqual(C.data['status'], 'MERGED') |
| 485 | self.assertEqual(A.reported, 2) |
| 486 | self.assertEqual(B.reported, 2) |
| 487 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 488 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 489 | def test_failed_change_in_middle(self): |
| 490 | "Test a failed change in the middle of the queue" |
| 491 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 492 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 493 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 494 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 495 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 496 | A.addApproval('Code-Review', 2) |
| 497 | B.addApproval('Code-Review', 2) |
| 498 | C.addApproval('Code-Review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 499 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 500 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 501 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 502 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 503 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 504 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 505 | |
| 506 | self.waitUntilSettled() |
| 507 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 510 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 511 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 512 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 513 | self.waitUntilSettled() |
| 514 | |
| 515 | self.assertEqual(len(self.builds), 6) |
| 516 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 517 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 518 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 519 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 520 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 521 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 522 | |
| 523 | self.release(self.builds[2]) |
| 524 | self.waitUntilSettled() |
| 525 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 526 | # project-test1 and project-test2 for A |
| 527 | # project-test2 for B |
| 528 | # project-merge for C (without B) |
| 529 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 530 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 531 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 532 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 533 | self.waitUntilSettled() |
| 534 | |
| 535 | # project-test1 and project-test2 for A |
| 536 | # project-test2 for B |
| 537 | # project-test1 and project-test2 for C |
| 538 | self.assertEqual(len(self.builds), 5) |
| 539 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 540 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 541 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 542 | builds = items[0].current_build_set.getBuilds() |
| 543 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 544 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 545 | builds = items[1].current_build_set.getBuilds() |
| 546 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 547 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 548 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 549 | builds = items[2].current_build_set.getBuilds() |
| 550 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 551 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 552 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 553 | self.executor_server.hold_jobs_in_build = False |
| 554 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 555 | self.waitUntilSettled() |
| 556 | |
| 557 | self.assertEqual(len(self.builds), 0) |
| 558 | self.assertEqual(len(self.history), 12) |
| 559 | self.assertEqual(A.data['status'], 'MERGED') |
| 560 | self.assertEqual(B.data['status'], 'NEW') |
| 561 | self.assertEqual(C.data['status'], 'MERGED') |
| 562 | self.assertEqual(A.reported, 2) |
| 563 | self.assertEqual(B.reported, 2) |
| 564 | self.assertEqual(C.reported, 2) |
| 565 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 566 | def test_failed_change_at_head_with_queue(self): |
| 567 | "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] | 568 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 569 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 570 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 571 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 572 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 573 | A.addApproval('Code-Review', 2) |
| 574 | B.addApproval('Code-Review', 2) |
| 575 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 576 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 577 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 578 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 579 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 580 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 581 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 582 | |
| 583 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 584 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 585 | self.assertEqual(len(self.builds), 0) |
| 586 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 587 | self.assertEqual(queue[0].name, b'executor:execute') |
| 588 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 589 | self.assertEqual(job_args['job'], 'project-merge') |
| 590 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 591 | |
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 | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 594 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 595 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 596 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 597 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 598 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 599 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 600 | self.assertEqual(len(self.builds), 0) |
| 601 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 602 | |
| 603 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 604 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 605 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 606 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 607 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 608 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 609 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 610 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 611 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 612 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 613 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 614 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 615 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 616 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 617 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 618 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 619 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 620 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 621 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 622 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 623 | self.waitUntilSettled() |
| 624 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 625 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 626 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 627 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 628 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 629 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 630 | self.gearman_server.hold_jobs_in_queue = False |
| 631 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 632 | self.waitUntilSettled() |
| 633 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 634 | self.assertEqual(len(self.builds), 0) |
| 635 | self.assertEqual(len(self.history), 11) |
| 636 | self.assertEqual(A.data['status'], 'NEW') |
| 637 | self.assertEqual(B.data['status'], 'MERGED') |
| 638 | self.assertEqual(C.data['status'], 'MERGED') |
| 639 | self.assertEqual(A.reported, 2) |
| 640 | self.assertEqual(B.reported, 2) |
| 641 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 642 | |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 643 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 644 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 645 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 646 | A.addApproval('Code-Review', 2) |
| 647 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 648 | self.waitUntilSettled() |
| 649 | time.sleep(2) |
| 650 | |
James E. Blair | ae0f23c | 2017-09-13 10:55:15 -0600 | [diff] [blame] | 651 | data = json.loads(self.sched.formatStatusJSON('tenant-one')) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 652 | found_job = None |
| 653 | for pipeline in data['pipelines']: |
| 654 | if pipeline['name'] != 'gate': |
| 655 | continue |
| 656 | for queue in pipeline['change_queues']: |
| 657 | for head in queue['heads']: |
| 658 | for item in head: |
| 659 | for job in item['jobs']: |
| 660 | if job['name'] == 'project-merge': |
| 661 | found_job = job |
| 662 | break |
| 663 | |
| 664 | self.assertIsNotNone(found_job) |
| 665 | if iteration == 1: |
| 666 | self.assertIsNotNone(found_job['estimated_time']) |
| 667 | self.assertIsNone(found_job['remaining_time']) |
| 668 | else: |
| 669 | self.assertIsNotNone(found_job['estimated_time']) |
| 670 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 671 | self.assertIsNotNone(found_job['remaining_time']) |
| 672 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 673 | self.executor_server.hold_jobs_in_build = False |
| 674 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 675 | self.waitUntilSettled() |
| 676 | |
| 677 | def test_time_database(self): |
| 678 | "Test the time database" |
| 679 | |
| 680 | self._test_time_database(1) |
| 681 | self._test_time_database(2) |
| 682 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 683 | def test_two_failed_changes_at_head(self): |
| 684 | "Test that changes are reparented correctly if 2 fail at head" |
| 685 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 686 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 687 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 688 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 689 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 690 | A.addApproval('Code-Review', 2) |
| 691 | B.addApproval('Code-Review', 2) |
| 692 | C.addApproval('Code-Review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 693 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 694 | self.executor_server.failJob('project-test1', A) |
| 695 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 696 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 697 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 698 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 699 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 700 | self.waitUntilSettled() |
| 701 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 704 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 705 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 706 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 707 | self.waitUntilSettled() |
| 708 | |
| 709 | self.assertEqual(len(self.builds), 6) |
| 710 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 711 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 712 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 713 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 714 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 715 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 716 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 717 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 718 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 719 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 720 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 721 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 722 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 723 | |
| 724 | # Fail change B first |
| 725 | self.release(self.builds[2]) |
| 726 | self.waitUntilSettled() |
| 727 | |
| 728 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 729 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 730 | self.waitUntilSettled() |
| 731 | |
| 732 | self.assertEqual(len(self.builds), 5) |
| 733 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 734 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 735 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 736 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 737 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 738 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 739 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 740 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 741 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 742 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 743 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 744 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 745 | |
| 746 | # Finish running all passing jobs for change A |
| 747 | self.release(self.builds[1]) |
| 748 | self.waitUntilSettled() |
| 749 | # Fail and report change A |
| 750 | self.release(self.builds[0]) |
| 751 | self.waitUntilSettled() |
| 752 | |
| 753 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 754 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 755 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 756 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 757 | self.waitUntilSettled() |
| 758 | |
| 759 | self.assertEqual(len(self.builds), 4) |
| 760 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 761 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 762 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 763 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 764 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 765 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 766 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 767 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 768 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 769 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 770 | # After A failed and B and C restarted, B should be back in |
| 771 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 772 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 773 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 774 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 775 | self.executor_server.hold_jobs_in_build = False |
| 776 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 777 | self.waitUntilSettled() |
| 778 | |
| 779 | self.assertEqual(len(self.builds), 0) |
| 780 | self.assertEqual(len(self.history), 21) |
| 781 | self.assertEqual(A.data['status'], 'NEW') |
| 782 | self.assertEqual(B.data['status'], 'NEW') |
| 783 | self.assertEqual(C.data['status'], 'MERGED') |
| 784 | self.assertEqual(A.reported, 2) |
| 785 | self.assertEqual(B.reported, 2) |
| 786 | self.assertEqual(C.reported, 2) |
| 787 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 788 | def test_patch_order(self): |
| 789 | "Test that dependent patches are tested in the right order" |
| 790 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 791 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 792 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 793 | A.addApproval('Code-Review', 2) |
| 794 | B.addApproval('Code-Review', 2) |
| 795 | C.addApproval('Code-Review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 796 | |
| 797 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 798 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 799 | M2.setMerged() |
| 800 | M1.setMerged() |
| 801 | |
| 802 | # C -> B -> A -> M1 -> M2 |
| 803 | # M2 is here to make sure it is never queried. If it is, it |
| 804 | # means zuul is walking down the entire history of merged |
| 805 | # changes. |
| 806 | |
| 807 | C.setDependsOn(B, 1) |
| 808 | B.setDependsOn(A, 1) |
| 809 | A.setDependsOn(M1, 1) |
| 810 | M1.setDependsOn(M2, 1) |
| 811 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 812 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 813 | |
| 814 | self.waitUntilSettled() |
| 815 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 816 | self.assertEqual(A.data['status'], 'NEW') |
| 817 | self.assertEqual(B.data['status'], 'NEW') |
| 818 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 819 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 820 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 821 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 822 | |
| 823 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 824 | self.assertEqual(M2.queried, 0) |
| 825 | self.assertEqual(A.data['status'], 'MERGED') |
| 826 | self.assertEqual(B.data['status'], 'MERGED') |
| 827 | self.assertEqual(C.data['status'], 'MERGED') |
| 828 | self.assertEqual(A.reported, 2) |
| 829 | self.assertEqual(B.reported, 2) |
| 830 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 831 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 832 | def test_needed_changes_enqueue(self): |
| 833 | "Test that a needed change is enqueued ahead" |
| 834 | # A Given a git tree like this, if we enqueue |
| 835 | # / \ change C, we should walk up and down the tree |
| 836 | # B G and enqueue changes in the order ABCDEFG. |
| 837 | # /|\ This is also the order that you would get if |
| 838 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 839 | # / the ordering is stable across re-enqueue events. |
| 840 | # D |
| 841 | |
| 842 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 843 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 844 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 845 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 846 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 847 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 848 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 849 | B.setDependsOn(A, 1) |
| 850 | C.setDependsOn(B, 1) |
| 851 | D.setDependsOn(C, 1) |
| 852 | E.setDependsOn(B, 1) |
| 853 | F.setDependsOn(B, 1) |
| 854 | G.setDependsOn(A, 1) |
| 855 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 856 | A.addApproval('Code-Review', 2) |
| 857 | B.addApproval('Code-Review', 2) |
| 858 | C.addApproval('Code-Review', 2) |
| 859 | D.addApproval('Code-Review', 2) |
| 860 | E.addApproval('Code-Review', 2) |
| 861 | F.addApproval('Code-Review', 2) |
| 862 | G.addApproval('Code-Review', 2) |
| 863 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 864 | |
| 865 | self.waitUntilSettled() |
| 866 | |
| 867 | self.assertEqual(A.data['status'], 'NEW') |
| 868 | self.assertEqual(B.data['status'], 'NEW') |
| 869 | self.assertEqual(C.data['status'], 'NEW') |
| 870 | self.assertEqual(D.data['status'], 'NEW') |
| 871 | self.assertEqual(E.data['status'], 'NEW') |
| 872 | self.assertEqual(F.data['status'], 'NEW') |
| 873 | self.assertEqual(G.data['status'], 'NEW') |
| 874 | |
| 875 | # We're about to add approvals to changes without adding the |
| 876 | # triggering events to Zuul, so that we can be sure that it is |
| 877 | # enqueing the changes based on dependencies, not because of |
| 878 | # triggering events. Since it will have the changes cached |
| 879 | # already (without approvals), we need to clear the cache |
| 880 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 881 | for connection in self.connections.connections.values(): |
James E. Blair | b0a95ab | 2017-10-18 09:39:18 -0700 | [diff] [blame] | 882 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 883 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 884 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 885 | A.addApproval('Approved', 1) |
| 886 | B.addApproval('Approved', 1) |
| 887 | D.addApproval('Approved', 1) |
| 888 | E.addApproval('Approved', 1) |
| 889 | F.addApproval('Approved', 1) |
| 890 | G.addApproval('Approved', 1) |
| 891 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 892 | |
| 893 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 894 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 895 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 896 | self.executor_server.hold_jobs_in_build = False |
| 897 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 898 | self.waitUntilSettled() |
| 899 | |
| 900 | self.assertEqual(A.data['status'], 'MERGED') |
| 901 | self.assertEqual(B.data['status'], 'MERGED') |
| 902 | self.assertEqual(C.data['status'], 'MERGED') |
| 903 | self.assertEqual(D.data['status'], 'MERGED') |
| 904 | self.assertEqual(E.data['status'], 'MERGED') |
| 905 | self.assertEqual(F.data['status'], 'MERGED') |
| 906 | self.assertEqual(G.data['status'], 'MERGED') |
| 907 | self.assertEqual(A.reported, 2) |
| 908 | self.assertEqual(B.reported, 2) |
| 909 | self.assertEqual(C.reported, 2) |
| 910 | self.assertEqual(D.reported, 2) |
| 911 | self.assertEqual(E.reported, 2) |
| 912 | self.assertEqual(F.reported, 2) |
| 913 | self.assertEqual(G.reported, 2) |
| 914 | self.assertEqual(self.history[6].changes, |
| 915 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 916 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 917 | def test_source_cache(self): |
| 918 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 919 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 920 | |
| 921 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 922 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 923 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 924 | A.addApproval('Code-Review', 2) |
| 925 | B.addApproval('Code-Review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 926 | |
| 927 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 928 | M1.setMerged() |
| 929 | |
| 930 | B.setDependsOn(A, 1) |
| 931 | A.setDependsOn(M1, 1) |
| 932 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 933 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 934 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 935 | |
| 936 | self.waitUntilSettled() |
| 937 | |
| 938 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 939 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 940 | build.release() |
| 941 | self.waitUntilSettled() |
| 942 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 943 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 944 | build.release() |
| 945 | self.waitUntilSettled() |
| 946 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 947 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 948 | self.waitUntilSettled() |
| 949 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 950 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 951 | # there should still be changes in the cache |
James E. Blair | b0a95ab | 2017-10-18 09:39:18 -0700 | [diff] [blame] | 952 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 953 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 954 | self.executor_server.hold_jobs_in_build = False |
| 955 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 956 | self.waitUntilSettled() |
| 957 | |
| 958 | self.assertEqual(A.data['status'], 'MERGED') |
| 959 | self.assertEqual(B.data['status'], 'MERGED') |
| 960 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 961 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 962 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 963 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 964 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 965 | # TODO: move to test_gerrit (this is a unit test!) |
| 966 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 967 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 968 | (trusted, project) = tenant.getProject('org/project') |
| 969 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 970 | |
| 971 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 972 | # it easier for users to create events for testing. |
| 973 | event = zuul.model.TriggerEvent() |
| 974 | event.trigger_name = 'gerrit' |
| 975 | event.change_number = '1' |
| 976 | event.patch_number = '2' |
| 977 | |
| 978 | a = source.getChange(event) |
| 979 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 980 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 981 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 982 | A.addApproval('Code-Review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 983 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 984 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 985 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 986 | A.addApproval('Approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 987 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 988 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 989 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 990 | def test_project_merge_conflict(self): |
| 991 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 992 | |
| 993 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 994 | A = self.fake_gerrit.addFakeChange('org/project', |
| 995 | 'master', 'A', |
| 996 | files={'conflict': 'foo'}) |
| 997 | B = self.fake_gerrit.addFakeChange('org/project', |
| 998 | 'master', 'B', |
| 999 | files={'conflict': 'bar'}) |
| 1000 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1001 | 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1002 | A.addApproval('Code-Review', 2) |
| 1003 | B.addApproval('Code-Review', 2) |
| 1004 | C.addApproval('Code-Review', 2) |
| 1005 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1006 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1007 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1008 | self.waitUntilSettled() |
| 1009 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1010 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1011 | self.assertEqual(C.reported, 1) |
| 1012 | |
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() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1017 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1018 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1019 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1020 | self.gearman_server.hold_jobs_in_queue = False |
| 1021 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1022 | self.waitUntilSettled() |
| 1023 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1024 | self.assertEqual(A.data['status'], 'MERGED') |
| 1025 | self.assertEqual(B.data['status'], 'NEW') |
| 1026 | self.assertEqual(C.data['status'], 'MERGED') |
| 1027 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1028 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1029 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1030 | |
| 1031 | self.assertHistory([ |
| 1032 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1033 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1034 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1035 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1036 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1037 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1038 | ], ordered=False) |
| 1039 | |
| 1040 | def test_delayed_merge_conflict(self): |
| 1041 | "Test that delayed check merge conflicts are handled properly" |
| 1042 | |
| 1043 | # 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] | 1044 | # the executor sucesfully merges a change based on an old |
| 1045 | # repo state (frozen by the scheduler) which would otherwise |
| 1046 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1047 | self.gearman_server.hold_jobs_in_queue = True |
| 1048 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1049 | 'master', 'A', |
| 1050 | files={'conflict': 'foo'}) |
| 1051 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1052 | 'master', 'B', |
| 1053 | files={'conflict': 'bar'}) |
| 1054 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1055 | 'master', 'C') |
| 1056 | C.setDependsOn(B, 1) |
| 1057 | |
| 1058 | # A enters the gate queue; B and C enter the check queue |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1059 | A.addApproval('Code-Review', 2) |
| 1060 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1061 | self.waitUntilSettled() |
| 1062 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1063 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1064 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1065 | self.waitUntilSettled() |
| 1066 | |
| 1067 | self.assertEqual(A.reported, 1) |
| 1068 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1069 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1070 | |
| 1071 | # A merges while B and C are queued in check |
| 1072 | # Release A project-merge |
| 1073 | queue = self.gearman_server.getQueue() |
| 1074 | self.release(queue[0]) |
| 1075 | self.waitUntilSettled() |
| 1076 | |
| 1077 | # Release A project-test* |
| 1078 | # gate has higher precedence, so A's test jobs are added in |
| 1079 | # front of the merge jobs for B and C |
| 1080 | queue = self.gearman_server.getQueue() |
| 1081 | self.release(queue[0]) |
| 1082 | self.release(queue[1]) |
| 1083 | self.waitUntilSettled() |
| 1084 | |
| 1085 | self.assertEqual(A.data['status'], 'MERGED') |
| 1086 | self.assertEqual(B.data['status'], 'NEW') |
| 1087 | self.assertEqual(C.data['status'], 'NEW') |
| 1088 | self.assertEqual(A.reported, 2) |
| 1089 | self.assertEqual(B.reported, 0) |
| 1090 | self.assertEqual(C.reported, 0) |
| 1091 | self.assertHistory([ |
| 1092 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1093 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1094 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1095 | ], ordered=False) |
| 1096 | |
| 1097 | # B and C report merge conflicts |
| 1098 | # Release B project-merge |
| 1099 | queue = self.gearman_server.getQueue() |
| 1100 | self.release(queue[0]) |
| 1101 | self.waitUntilSettled() |
| 1102 | |
| 1103 | # Release C |
| 1104 | self.gearman_server.hold_jobs_in_queue = False |
| 1105 | self.gearman_server.release() |
| 1106 | self.waitUntilSettled() |
| 1107 | |
| 1108 | self.assertEqual(A.data['status'], 'MERGED') |
| 1109 | self.assertEqual(B.data['status'], 'NEW') |
| 1110 | self.assertEqual(C.data['status'], 'NEW') |
| 1111 | self.assertEqual(A.reported, 2) |
| 1112 | self.assertEqual(B.reported, 1) |
| 1113 | self.assertEqual(C.reported, 1) |
| 1114 | |
| 1115 | self.assertHistory([ |
| 1116 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1117 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1118 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1119 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1120 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1121 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1122 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1123 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1124 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1125 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1126 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1127 | def test_post(self): |
| 1128 | "Test that post jobs run" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1129 | p = "review.example.com/org/project" |
| 1130 | upstream = self.getUpstreamRepos([p]) |
| 1131 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1132 | A.setMerged() |
| 1133 | A_commit = str(upstream[p].commit('master')) |
| 1134 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1135 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1136 | e = { |
| 1137 | "type": "ref-updated", |
| 1138 | "submitter": { |
| 1139 | "name": "User Name", |
| 1140 | }, |
| 1141 | "refUpdate": { |
| 1142 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1143 | "newRev": A_commit, |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1144 | "refName": "master", |
| 1145 | "project": "org/project", |
| 1146 | } |
| 1147 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1148 | self.fake_gerrit.addEvent(e) |
| 1149 | self.waitUntilSettled() |
| 1150 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1151 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1152 | self.assertEqual(len(self.history), 1) |
| 1153 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1154 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1155 | def test_post_ignore_deletes(self): |
| 1156 | "Test that deleting refs does not trigger post jobs" |
| 1157 | |
| 1158 | e = { |
| 1159 | "type": "ref-updated", |
| 1160 | "submitter": { |
| 1161 | "name": "User Name", |
| 1162 | }, |
| 1163 | "refUpdate": { |
| 1164 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1165 | "newRev": "0000000000000000000000000000000000000000", |
| 1166 | "refName": "master", |
| 1167 | "project": "org/project", |
| 1168 | } |
| 1169 | } |
| 1170 | self.fake_gerrit.addEvent(e) |
| 1171 | self.waitUntilSettled() |
| 1172 | |
| 1173 | job_names = [x.name for x in self.history] |
| 1174 | self.assertEqual(len(self.history), 0) |
| 1175 | self.assertNotIn('project-post', job_names) |
| 1176 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1177 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1178 | def test_post_ignore_deletes_negative(self): |
| 1179 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1180 | e = { |
| 1181 | "type": "ref-updated", |
| 1182 | "submitter": { |
| 1183 | "name": "User Name", |
| 1184 | }, |
| 1185 | "refUpdate": { |
| 1186 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1187 | "newRev": "0000000000000000000000000000000000000000", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1188 | "refName": "testbranch", |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1189 | "project": "org/project", |
| 1190 | } |
| 1191 | } |
| 1192 | self.fake_gerrit.addEvent(e) |
| 1193 | self.waitUntilSettled() |
| 1194 | |
| 1195 | job_names = [x.name for x in self.history] |
| 1196 | self.assertEqual(len(self.history), 1) |
| 1197 | self.assertIn('project-post', job_names) |
| 1198 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1199 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1200 | def test_build_configuration_branch_interaction(self): |
| 1201 | "Test that switching between branches works" |
| 1202 | self.test_build_configuration() |
| 1203 | self.test_build_configuration_branch() |
| 1204 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1205 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1206 | repo = git.Repo(path) |
| 1207 | repo.heads.master.commit = repo.commit('init') |
| 1208 | self.test_build_configuration() |
| 1209 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1210 | def test_dependent_changes_rebase(self): |
| 1211 | # Test that no errors occur when we walk a dependency tree |
| 1212 | # with an unused leaf node due to a rebase. |
| 1213 | # Start by constructing: C -> B -> A |
| 1214 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1215 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1216 | B.setDependsOn(A, 1) |
| 1217 | |
| 1218 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1219 | C.setDependsOn(B, 1) |
| 1220 | |
| 1221 | # Then rebase to form: D -> C -> A |
| 1222 | C.addPatchset() # C,2 |
| 1223 | C.setDependsOn(A, 1) |
| 1224 | |
| 1225 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1226 | D.setDependsOn(C, 2) |
| 1227 | |
| 1228 | # Walk the entire tree |
| 1229 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1230 | self.waitUntilSettled() |
| 1231 | self.assertEqual(len(self.history), 3) |
| 1232 | |
| 1233 | # Verify that walking just part of the tree still works |
| 1234 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1235 | self.waitUntilSettled() |
| 1236 | self.assertEqual(len(self.history), 6) |
| 1237 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1238 | def test_dependent_changes_dequeue(self): |
| 1239 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1240 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1241 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1242 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1243 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1244 | A.addApproval('Code-Review', 2) |
| 1245 | B.addApproval('Code-Review', 2) |
| 1246 | C.addApproval('Code-Review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1247 | |
| 1248 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1249 | M1.setMerged() |
| 1250 | |
| 1251 | # C -> B -> A -> M1 |
| 1252 | |
| 1253 | C.setDependsOn(B, 1) |
| 1254 | B.setDependsOn(A, 1) |
| 1255 | A.setDependsOn(M1, 1) |
| 1256 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1257 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1258 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1259 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1260 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1261 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1262 | |
| 1263 | self.waitUntilSettled() |
| 1264 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1265 | self.assertEqual(A.data['status'], 'NEW') |
| 1266 | self.assertEqual(A.reported, 2) |
| 1267 | self.assertEqual(B.data['status'], 'NEW') |
| 1268 | self.assertEqual(B.reported, 2) |
| 1269 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1270 | self.assertIn('This change depends on a change that failed to merge.', |
| 1271 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1272 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1273 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1274 | def test_failing_dependent_changes(self): |
| 1275 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1276 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1277 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1278 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1279 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1280 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1281 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1282 | A.addApproval('Code-Review', 2) |
| 1283 | B.addApproval('Code-Review', 2) |
| 1284 | C.addApproval('Code-Review', 2) |
| 1285 | D.addApproval('Code-Review', 2) |
| 1286 | E.addApproval('Code-Review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1287 | |
| 1288 | # E, D -> C -> B, A |
| 1289 | |
| 1290 | D.setDependsOn(C, 1) |
| 1291 | C.setDependsOn(B, 1) |
| 1292 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1293 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1294 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1295 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1296 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
| 1297 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1298 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1299 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1300 | |
| 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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1310 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1311 | self.waitUntilSettled() |
| 1312 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1313 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1314 | for build in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 1315 | if build.parameters['zuul']['change'] != '1': |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1316 | build.release() |
| 1317 | self.waitUntilSettled() |
| 1318 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1319 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1320 | self.waitUntilSettled() |
| 1321 | |
| 1322 | self.assertEqual(A.data['status'], 'MERGED') |
| 1323 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1324 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1325 | self.assertEqual(B.data['status'], 'NEW') |
| 1326 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1327 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1328 | self.assertEqual(C.data['status'], 'NEW') |
| 1329 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1330 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1331 | self.assertEqual(D.data['status'], 'NEW') |
| 1332 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1333 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1334 | self.assertEqual(E.data['status'], 'MERGED') |
| 1335 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1336 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1337 | self.assertEqual(len(self.history), 18) |
| 1338 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1339 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1340 | "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] | 1341 | # If it's dequeued more than once, we should see extra |
| 1342 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1343 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1344 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1345 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1346 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1347 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1348 | A.addApproval('Code-Review', 2) |
| 1349 | B.addApproval('Code-Review', 2) |
| 1350 | C.addApproval('Code-Review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1351 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1352 | self.executor_server.failJob('project-test1', A) |
| 1353 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1354 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1355 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1356 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1357 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1358 | |
| 1359 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1360 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1361 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1362 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1363 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1364 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1369 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1370 | self.waitUntilSettled() |
| 1371 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1372 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1373 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1374 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1375 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1376 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1377 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1378 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1379 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1380 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1381 | self.waitUntilSettled() |
| 1382 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1383 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1384 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1385 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1386 | self.executor_server.hold_jobs_in_build = False |
| 1387 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1388 | self.waitUntilSettled() |
| 1389 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1390 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1391 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1392 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1393 | self.assertEqual(A.data['status'], 'NEW') |
| 1394 | self.assertEqual(B.data['status'], 'MERGED') |
| 1395 | self.assertEqual(C.data['status'], 'MERGED') |
| 1396 | self.assertEqual(A.reported, 2) |
| 1397 | self.assertEqual(B.reported, 2) |
| 1398 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1399 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1400 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1401 | def test_nonvoting_job(self): |
| 1402 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1403 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1404 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1405 | 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1406 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1407 | self.executor_server.failJob('nonvoting-project-test2', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1408 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1409 | |
| 1410 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1411 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1412 | self.assertEqual(A.data['status'], 'MERGED') |
| 1413 | self.assertEqual(A.reported, 2) |
| 1414 | self.assertEqual( |
| 1415 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1416 | 'SUCCESS') |
| 1417 | self.assertEqual( |
| 1418 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1419 | 'SUCCESS') |
| 1420 | self.assertEqual( |
| 1421 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1422 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1423 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 1424 | self.assertTrue(self.getJobFromHistory('nonvoting-project-merge'). |
| 1425 | parameters['zuul']['voting']) |
| 1426 | self.assertTrue(self.getJobFromHistory('nonvoting-project-test1'). |
| 1427 | parameters['zuul']['voting']) |
| 1428 | self.assertFalse(self.getJobFromHistory('nonvoting-project-test2'). |
| 1429 | parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1430 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1431 | def test_check_queue_success(self): |
| 1432 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1433 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1434 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1435 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1436 | |
| 1437 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1438 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1439 | self.assertEqual(A.data['status'], 'NEW') |
| 1440 | self.assertEqual(A.reported, 1) |
| 1441 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1442 | 'SUCCESS') |
| 1443 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1444 | 'SUCCESS') |
| 1445 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1446 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1447 | |
| 1448 | def test_check_queue_failure(self): |
| 1449 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1450 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1451 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1452 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1453 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1454 | |
| 1455 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1456 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1457 | self.assertEqual(A.data['status'], 'NEW') |
| 1458 | self.assertEqual(A.reported, 1) |
| 1459 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1460 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1461 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1462 | 'SUCCESS') |
| 1463 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1464 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1465 | |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1466 | @simple_layout('layouts/autohold.yaml') |
| 1467 | def test_autohold(self): |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 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 | |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1475 | # First check that successful jobs do not autohold |
| 1476 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1477 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1478 | |
| 1479 | self.waitUntilSettled() |
| 1480 | |
| 1481 | self.assertEqual(A.data['status'], 'NEW') |
| 1482 | self.assertEqual(A.reported, 1) |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1483 | # project-test2 |
| 1484 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 1485 | |
| 1486 | # Check nodepool for a held node |
| 1487 | held_node = None |
| 1488 | for node in self.fake_nodepool.getNodes(): |
| 1489 | if node['state'] == zuul.model.STATE_HOLD: |
| 1490 | held_node = node |
| 1491 | break |
| 1492 | self.assertIsNone(held_node) |
| 1493 | |
| 1494 | # Now test that failed jobs are autoheld |
| 1495 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1496 | self.executor_server.failJob('project-test2', B) |
| 1497 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1498 | |
| 1499 | self.waitUntilSettled() |
| 1500 | |
| 1501 | self.assertEqual(B.data['status'], 'NEW') |
| 1502 | self.assertEqual(B.reported, 1) |
| 1503 | # project-test2 |
| 1504 | self.assertEqual(self.history[1].result, 'FAILURE') |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1505 | |
| 1506 | # Check nodepool for a held node |
| 1507 | held_node = None |
| 1508 | for node in self.fake_nodepool.getNodes(): |
| 1509 | if node['state'] == zuul.model.STATE_HOLD: |
| 1510 | held_node = node |
| 1511 | break |
| 1512 | self.assertIsNotNone(held_node) |
| 1513 | |
| 1514 | # Validate node has recorded the failed job |
| 1515 | self.assertEqual( |
| 1516 | held_node['hold_job'], |
| 1517 | " ".join(['tenant-one', |
| 1518 | 'review.example.com/org/project', |
| 1519 | 'project-test2']) |
| 1520 | ) |
David Shrewsbury | f9af9df | 2017-08-01 15:19:26 -0400 | [diff] [blame] | 1521 | self.assertEqual(held_node['comment'], "reason text") |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1522 | |
| 1523 | # Another failed change should not hold any more nodes |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1524 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1525 | self.executor_server.failJob('project-test2', C) |
| 1526 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1527 | self.waitUntilSettled() |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1528 | self.assertEqual(C.data['status'], 'NEW') |
| 1529 | self.assertEqual(C.reported, 1) |
| 1530 | # project-test2 |
| 1531 | self.assertEqual(self.history[2].result, 'FAILURE') |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1532 | |
| 1533 | held_nodes = 0 |
| 1534 | for node in self.fake_nodepool.getNodes(): |
| 1535 | if node['state'] == zuul.model.STATE_HOLD: |
| 1536 | held_nodes += 1 |
| 1537 | self.assertEqual(held_nodes, 1) |
| 1538 | |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1539 | @simple_layout('layouts/autohold.yaml') |
Clark Boylan | aeb5a12 | 2017-10-20 14:00:11 -0700 | [diff] [blame] | 1540 | def test_autohold_ignores_aborted_jobs(self): |
| 1541 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1542 | self.gearman_server.port) |
| 1543 | self.addCleanup(client.shutdown) |
| 1544 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1545 | "reason text", 1) |
| 1546 | self.assertTrue(r) |
| 1547 | |
| 1548 | self.executor_server.hold_jobs_in_build = True |
| 1549 | |
| 1550 | # Create a change that will have its job aborted |
| 1551 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1552 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1553 | self.waitUntilSettled() |
| 1554 | |
| 1555 | # Creating new patchset on change A will abort A,1's job because |
| 1556 | # a new patchset arrived replacing A,1 with A,2. |
| 1557 | A.addPatchset() |
| 1558 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1559 | |
| 1560 | self.waitUntilSettled() |
| 1561 | self.executor_server.hold_jobs_in_build = False |
| 1562 | self.executor_server.release() |
| 1563 | self.waitUntilSettled() |
| 1564 | |
| 1565 | self.assertEqual(A.data['status'], 'NEW') |
| 1566 | # Note only the successful job for A,2 will report as we don't |
| 1567 | # report aborted builds for old patchsets. |
| 1568 | self.assertEqual(A.reported, 1) |
| 1569 | # A,1 project-test2 |
| 1570 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1571 | # A,2 project-test2 |
| 1572 | self.assertEqual(self.history[1].result, 'SUCCESS') |
| 1573 | |
| 1574 | # Check nodepool for a held node |
| 1575 | held_node = None |
| 1576 | for node in self.fake_nodepool.getNodes(): |
| 1577 | if node['state'] == zuul.model.STATE_HOLD: |
| 1578 | held_node = node |
| 1579 | break |
| 1580 | self.assertIsNone(held_node) |
| 1581 | |
| 1582 | @simple_layout('layouts/autohold.yaml') |
David Shrewsbury | c467613 | 2017-10-16 12:41:57 -0400 | [diff] [blame] | 1583 | def test_autohold_list(self): |
| 1584 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1585 | self.gearman_server.port) |
| 1586 | self.addCleanup(client.shutdown) |
| 1587 | |
| 1588 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1589 | "reason text", 1) |
| 1590 | self.assertTrue(r) |
| 1591 | |
| 1592 | autohold_requests = client.autohold_list() |
| 1593 | self.assertNotEqual({}, autohold_requests) |
| 1594 | self.assertEqual(1, len(autohold_requests.keys())) |
| 1595 | |
| 1596 | # The single dict key should be a CSV string value |
| 1597 | key = list(autohold_requests.keys())[0] |
| 1598 | tenant, project, job = key.split(',') |
| 1599 | |
| 1600 | self.assertEqual('tenant-one', tenant) |
| 1601 | self.assertIn('org/project', project) |
| 1602 | self.assertEqual('project-test2', job) |
| 1603 | |
| 1604 | # Note: the value is converted from set to list by json. |
| 1605 | self.assertEqual([1, "reason text"], autohold_requests[key]) |
| 1606 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1607 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1608 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1609 | # This particular test does a large amount of merges and needs a little |
| 1610 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1611 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1612 | "test that dependent changes behind dequeued changes work" |
| 1613 | # This complicated test is a reproduction of a real life bug |
| 1614 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1615 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1616 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1617 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1618 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1619 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1620 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1621 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1622 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1623 | D.setDependsOn(C, 1) |
| 1624 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1625 | A.addApproval('Code-Review', 2) |
| 1626 | B.addApproval('Code-Review', 2) |
| 1627 | C.addApproval('Code-Review', 2) |
| 1628 | D.addApproval('Code-Review', 2) |
| 1629 | E.addApproval('Code-Review', 2) |
| 1630 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1631 | |
| 1632 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1633 | |
| 1634 | # Change object re-use in the gerrit trigger is hidden if |
| 1635 | # changes are added in quick succession; waiting makes it more |
| 1636 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1637 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1638 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1639 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1640 | self.waitUntilSettled() |
| 1641 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1642 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1643 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1644 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1645 | self.waitUntilSettled() |
| 1646 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1647 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1648 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1649 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1650 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1651 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1652 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1653 | self.fake_gerrit.addEvent(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1654 | self.waitUntilSettled() |
| 1655 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1656 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1657 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1658 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1659 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1660 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1661 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1662 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1663 | self.waitUntilSettled() |
| 1664 | |
| 1665 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1666 | |
| 1667 | # Grab pointers to the jobs we want to release before |
| 1668 | # releasing any, because list indexes may change as |
| 1669 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1670 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1671 | a.release() |
| 1672 | b.release() |
| 1673 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1674 | self.waitUntilSettled() |
| 1675 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1676 | self.executor_server.hold_jobs_in_build = False |
| 1677 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1678 | self.waitUntilSettled() |
| 1679 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1680 | self.assertEqual(A.data['status'], 'NEW') |
| 1681 | self.assertEqual(B.data['status'], 'MERGED') |
| 1682 | self.assertEqual(C.data['status'], 'MERGED') |
| 1683 | self.assertEqual(D.data['status'], 'MERGED') |
| 1684 | self.assertEqual(E.data['status'], 'MERGED') |
| 1685 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1686 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1687 | self.assertEqual(A.reported, 2) |
| 1688 | self.assertEqual(B.reported, 2) |
| 1689 | self.assertEqual(C.reported, 2) |
| 1690 | self.assertEqual(D.reported, 2) |
| 1691 | self.assertEqual(E.reported, 2) |
| 1692 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1693 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1694 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1695 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1696 | |
| 1697 | def test_merger_repack(self): |
| 1698 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1699 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1700 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1701 | A.addApproval('Code-Review', 2) |
| 1702 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1703 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1704 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1705 | 'SUCCESS') |
| 1706 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1707 | 'SUCCESS') |
| 1708 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1709 | 'SUCCESS') |
| 1710 | self.assertEqual(A.data['status'], 'MERGED') |
| 1711 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1712 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1713 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1714 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1715 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1716 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1717 | if os.path.exists(path): |
| 1718 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1719 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1720 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1721 | if os.path.exists(path): |
| 1722 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1723 | |
| 1724 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1725 | A.addApproval('Code-Review', 2) |
| 1726 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1727 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1728 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1729 | 'SUCCESS') |
| 1730 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1731 | 'SUCCESS') |
| 1732 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1733 | 'SUCCESS') |
| 1734 | self.assertEqual(A.data['status'], 'MERGED') |
| 1735 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1736 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1737 | def test_merger_repack_large_change(self): |
| 1738 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1739 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1740 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1741 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1742 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1743 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1744 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1745 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1746 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1747 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1748 | # TODOv3(jeblair): add hostname to upstream root |
| 1749 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1750 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1751 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1752 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1753 | if os.path.exists(path): |
| 1754 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1755 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1756 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1757 | if os.path.exists(path): |
| 1758 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1759 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1760 | A.addApproval('Code-Review', 2) |
| 1761 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1762 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1763 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1764 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1765 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1766 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1767 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1768 | 'SUCCESS') |
| 1769 | self.assertEqual(A.data['status'], 'MERGED') |
| 1770 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1771 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1772 | def test_new_patchset_dequeues_old(self): |
| 1773 | "Test that a new patchset causes the old to be dequeued" |
| 1774 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1775 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1776 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1777 | M.setMerged() |
| 1778 | |
| 1779 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1780 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1781 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1782 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1783 | A.addApproval('Code-Review', 2) |
| 1784 | B.addApproval('Code-Review', 2) |
| 1785 | C.addApproval('Code-Review', 2) |
| 1786 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1787 | |
| 1788 | C.setDependsOn(B, 1) |
| 1789 | B.setDependsOn(A, 1) |
| 1790 | A.setDependsOn(M, 1) |
| 1791 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1792 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1793 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1794 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1795 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1796 | self.waitUntilSettled() |
| 1797 | |
| 1798 | B.addPatchset() |
| 1799 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1800 | self.waitUntilSettled() |
| 1801 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1802 | self.executor_server.hold_jobs_in_build = False |
| 1803 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1804 | self.waitUntilSettled() |
| 1805 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1806 | self.assertEqual(A.data['status'], 'MERGED') |
| 1807 | self.assertEqual(A.reported, 2) |
| 1808 | self.assertEqual(B.data['status'], 'NEW') |
| 1809 | self.assertEqual(B.reported, 2) |
| 1810 | self.assertEqual(C.data['status'], 'NEW') |
| 1811 | self.assertEqual(C.reported, 2) |
| 1812 | self.assertEqual(D.data['status'], 'MERGED') |
| 1813 | self.assertEqual(D.reported, 2) |
| 1814 | 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] | 1815 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1816 | def test_new_patchset_check(self): |
| 1817 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1818 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1819 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1820 | |
| 1821 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1822 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1823 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1824 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1825 | |
| 1826 | # Add two git-dependent changes |
| 1827 | B.setDependsOn(A, 1) |
| 1828 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1829 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1830 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1831 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1832 | |
| 1833 | # A live item, and a non-live/live pair |
| 1834 | items = check_pipeline.getAllItems() |
| 1835 | self.assertEqual(len(items), 3) |
| 1836 | |
| 1837 | self.assertEqual(items[0].change.number, '1') |
| 1838 | self.assertEqual(items[0].change.patchset, '1') |
| 1839 | self.assertFalse(items[0].live) |
| 1840 | |
| 1841 | self.assertEqual(items[1].change.number, '2') |
| 1842 | self.assertEqual(items[1].change.patchset, '1') |
| 1843 | self.assertTrue(items[1].live) |
| 1844 | |
| 1845 | self.assertEqual(items[2].change.number, '1') |
| 1846 | self.assertEqual(items[2].change.patchset, '1') |
| 1847 | self.assertTrue(items[2].live) |
| 1848 | |
| 1849 | # Add a new patchset to A |
| 1850 | A.addPatchset() |
| 1851 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1852 | self.waitUntilSettled() |
| 1853 | |
| 1854 | # The live copy of A,1 should be gone, but the non-live and B |
| 1855 | # should continue, and we should have a new A,2 |
| 1856 | items = check_pipeline.getAllItems() |
| 1857 | self.assertEqual(len(items), 3) |
| 1858 | |
| 1859 | self.assertEqual(items[0].change.number, '1') |
| 1860 | self.assertEqual(items[0].change.patchset, '1') |
| 1861 | self.assertFalse(items[0].live) |
| 1862 | |
| 1863 | self.assertEqual(items[1].change.number, '2') |
| 1864 | self.assertEqual(items[1].change.patchset, '1') |
| 1865 | self.assertTrue(items[1].live) |
| 1866 | |
| 1867 | self.assertEqual(items[2].change.number, '1') |
| 1868 | self.assertEqual(items[2].change.patchset, '2') |
| 1869 | self.assertTrue(items[2].live) |
| 1870 | |
| 1871 | # Add a new patchset to B |
| 1872 | B.addPatchset() |
| 1873 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1874 | self.waitUntilSettled() |
| 1875 | |
| 1876 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1877 | # but we should have a new B,2 (still based on A,1) |
| 1878 | items = check_pipeline.getAllItems() |
| 1879 | self.assertEqual(len(items), 3) |
| 1880 | |
| 1881 | self.assertEqual(items[0].change.number, '1') |
| 1882 | self.assertEqual(items[0].change.patchset, '2') |
| 1883 | self.assertTrue(items[0].live) |
| 1884 | |
| 1885 | self.assertEqual(items[1].change.number, '1') |
| 1886 | self.assertEqual(items[1].change.patchset, '1') |
| 1887 | self.assertFalse(items[1].live) |
| 1888 | |
| 1889 | self.assertEqual(items[2].change.number, '2') |
| 1890 | self.assertEqual(items[2].change.patchset, '2') |
| 1891 | self.assertTrue(items[2].live) |
| 1892 | |
| 1893 | self.builds[0].release() |
| 1894 | self.waitUntilSettled() |
| 1895 | self.builds[0].release() |
| 1896 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1897 | self.executor_server.hold_jobs_in_build = False |
| 1898 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1899 | self.waitUntilSettled() |
| 1900 | |
| 1901 | self.assertEqual(A.reported, 1) |
| 1902 | self.assertEqual(B.reported, 1) |
| 1903 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1904 | self.assertEqual(self.history[0].changes, '1,1') |
| 1905 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1906 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1907 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1908 | self.assertEqual(self.history[2].changes, '1,2') |
| 1909 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1910 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1911 | |
| 1912 | def test_abandoned_gate(self): |
| 1913 | "Test that an abandoned change is dequeued from gate" |
| 1914 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1915 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1916 | |
| 1917 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1918 | A.addApproval('Code-Review', 2) |
| 1919 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1920 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1921 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1922 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1923 | |
| 1924 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1925 | self.waitUntilSettled() |
| 1926 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1927 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1928 | self.waitUntilSettled() |
| 1929 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1930 | self.assertBuilds([]) |
| 1931 | self.assertHistory([ |
| 1932 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1933 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1934 | self.assertEqual(A.reported, 1, |
| 1935 | "Abandoned gate change should report only start") |
| 1936 | |
| 1937 | def test_abandoned_check(self): |
| 1938 | "Test that an abandoned change is dequeued from check" |
| 1939 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1940 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1941 | |
| 1942 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1943 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1944 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1945 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1946 | |
| 1947 | # Add two git-dependent changes |
| 1948 | B.setDependsOn(A, 1) |
| 1949 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1950 | self.waitUntilSettled() |
| 1951 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1952 | self.waitUntilSettled() |
| 1953 | # A live item, and a non-live/live pair |
| 1954 | items = check_pipeline.getAllItems() |
| 1955 | self.assertEqual(len(items), 3) |
| 1956 | |
| 1957 | self.assertEqual(items[0].change.number, '1') |
| 1958 | self.assertFalse(items[0].live) |
| 1959 | |
| 1960 | self.assertEqual(items[1].change.number, '2') |
| 1961 | self.assertTrue(items[1].live) |
| 1962 | |
| 1963 | self.assertEqual(items[2].change.number, '1') |
| 1964 | self.assertTrue(items[2].live) |
| 1965 | |
| 1966 | # Abandon A |
| 1967 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1968 | self.waitUntilSettled() |
| 1969 | |
| 1970 | # The live copy of A should be gone, but the non-live and B |
| 1971 | # should continue |
| 1972 | items = check_pipeline.getAllItems() |
| 1973 | self.assertEqual(len(items), 2) |
| 1974 | |
| 1975 | self.assertEqual(items[0].change.number, '1') |
| 1976 | self.assertFalse(items[0].live) |
| 1977 | |
| 1978 | self.assertEqual(items[1].change.number, '2') |
| 1979 | self.assertTrue(items[1].live) |
| 1980 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1981 | self.executor_server.hold_jobs_in_build = False |
| 1982 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1983 | self.waitUntilSettled() |
| 1984 | |
| 1985 | self.assertEqual(len(self.history), 4) |
| 1986 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1987 | 'Build should have been aborted') |
| 1988 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1989 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1990 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1991 | def test_abandoned_not_timer(self): |
| 1992 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1993 | # This test can not use simple_layout because it must start |
| 1994 | # with a configuration which does not include a |
| 1995 | # timer-triggered job so that we have an opportunity to set |
| 1996 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1997 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1998 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1999 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2000 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2001 | # The pipeline triggers every second, so we should have seen |
| 2002 | # several by now. |
| 2003 | time.sleep(5) |
| 2004 | self.waitUntilSettled() |
| 2005 | # Stop queuing timer triggered jobs so that the assertions |
| 2006 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 2007 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2008 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2009 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 2010 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2011 | # If APScheduler is in mid-event when we remove the job, we |
| 2012 | # can end up with one more event firing, so give it an extra |
| 2013 | # second to settle. |
| 2014 | time.sleep(1) |
| 2015 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2016 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2017 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2018 | |
| 2019 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2020 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2021 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2022 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2023 | |
| 2024 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2025 | self.waitUntilSettled() |
| 2026 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2027 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2028 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2029 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 2030 | self.waitUntilSettled() |
| 2031 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2032 | def test_new_patchset_dequeues_old_on_head(self): |
| 2033 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 2034 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2035 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2036 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 2037 | M.setMerged() |
| 2038 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2039 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2040 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2041 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2042 | A.addApproval('Code-Review', 2) |
| 2043 | B.addApproval('Code-Review', 2) |
| 2044 | C.addApproval('Code-Review', 2) |
| 2045 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2046 | |
| 2047 | C.setDependsOn(B, 1) |
| 2048 | B.setDependsOn(A, 1) |
| 2049 | A.setDependsOn(M, 1) |
| 2050 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2051 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2052 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2053 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2054 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2055 | self.waitUntilSettled() |
| 2056 | |
| 2057 | A.addPatchset() |
| 2058 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2059 | self.waitUntilSettled() |
| 2060 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2061 | self.executor_server.hold_jobs_in_build = False |
| 2062 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2063 | self.waitUntilSettled() |
| 2064 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2065 | self.assertEqual(A.data['status'], 'NEW') |
| 2066 | self.assertEqual(A.reported, 2) |
| 2067 | self.assertEqual(B.data['status'], 'NEW') |
| 2068 | self.assertEqual(B.reported, 2) |
| 2069 | self.assertEqual(C.data['status'], 'NEW') |
| 2070 | self.assertEqual(C.reported, 2) |
| 2071 | self.assertEqual(D.data['status'], 'MERGED') |
| 2072 | self.assertEqual(D.reported, 2) |
| 2073 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2074 | |
| 2075 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2076 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2077 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2078 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2079 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2080 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2081 | A.addApproval('Code-Review', 2) |
| 2082 | B.addApproval('Code-Review', 2) |
| 2083 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2084 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2085 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2086 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2087 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2088 | self.waitUntilSettled() |
| 2089 | |
| 2090 | B.addPatchset() |
| 2091 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2092 | self.waitUntilSettled() |
| 2093 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2094 | self.executor_server.hold_jobs_in_build = False |
| 2095 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2096 | self.waitUntilSettled() |
| 2097 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2098 | self.assertEqual(A.data['status'], 'MERGED') |
| 2099 | self.assertEqual(A.reported, 2) |
| 2100 | self.assertEqual(B.data['status'], 'NEW') |
| 2101 | self.assertEqual(B.reported, 2) |
| 2102 | self.assertEqual(C.data['status'], 'MERGED') |
| 2103 | self.assertEqual(C.reported, 2) |
| 2104 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2105 | |
| 2106 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2107 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2108 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2109 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2110 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2111 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2112 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2113 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2114 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2115 | self.waitUntilSettled() |
| 2116 | |
| 2117 | B.addPatchset() |
| 2118 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2119 | self.waitUntilSettled() |
| 2120 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2121 | self.executor_server.hold_jobs_in_build = False |
| 2122 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2123 | self.waitUntilSettled() |
| 2124 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2125 | self.assertEqual(A.data['status'], 'NEW') |
| 2126 | self.assertEqual(A.reported, 1) |
| 2127 | self.assertEqual(B.data['status'], 'NEW') |
| 2128 | self.assertEqual(B.reported, 1) |
| 2129 | self.assertEqual(C.data['status'], 'NEW') |
| 2130 | self.assertEqual(C.reported, 1) |
| 2131 | self.assertEqual(len(self.history), 10) |
| 2132 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2133 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2134 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2135 | def test_noop_job(self): |
| 2136 | "Test that the internal noop job works" |
| 2137 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2138 | A.addApproval('Code-Review', 2) |
| 2139 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2140 | self.waitUntilSettled() |
| 2141 | |
| 2142 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2143 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2144 | self.assertEqual(len(self.history), 0) |
| 2145 | self.assertEqual(A.data['status'], 'MERGED') |
| 2146 | self.assertEqual(A.reported, 2) |
| 2147 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2148 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2149 | def test_no_job_project(self): |
| 2150 | "Test that reports with no jobs don't get sent" |
| 2151 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2152 | 'master', 'A') |
| 2153 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2154 | self.waitUntilSettled() |
| 2155 | |
| 2156 | # Change wasn't reported to |
| 2157 | self.assertEqual(A.reported, False) |
| 2158 | |
| 2159 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2160 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2161 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2162 | items = check_pipeline.getAllItems() |
| 2163 | self.assertEqual(len(items), 0) |
| 2164 | |
| 2165 | self.assertEqual(len(self.history), 0) |
| 2166 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2167 | def test_zuul_refs(self): |
| 2168 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2169 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2170 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2171 | M1.setMerged() |
| 2172 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2173 | M2.setMerged() |
| 2174 | |
| 2175 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2176 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2177 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2178 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2179 | A.addApproval('Code-Review', 2) |
| 2180 | B.addApproval('Code-Review', 2) |
| 2181 | C.addApproval('Code-Review', 2) |
| 2182 | D.addApproval('Code-Review', 2) |
| 2183 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2184 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2185 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2186 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2187 | |
| 2188 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2189 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2190 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2191 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2192 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2193 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2194 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2195 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2196 | self.waitUntilSettled() |
| 2197 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2198 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2199 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2200 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2201 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2202 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2203 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2204 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2205 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2206 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2207 | d_build = x |
| 2208 | if a_build and b_build and c_build and d_build: |
| 2209 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2210 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2211 | # should have a, not b, and should not be in project2 |
| 2212 | self.assertTrue(a_build.hasChanges(A)) |
| 2213 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2214 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2215 | # should have a and b, and should not be in project2 |
| 2216 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2217 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2218 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2219 | # should have a and b in 1, c in 2 |
| 2220 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2221 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2222 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2223 | # should have a and b in 1, c and d in 2 |
| 2224 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2225 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2226 | self.executor_server.hold_jobs_in_build = False |
| 2227 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2228 | self.waitUntilSettled() |
| 2229 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2230 | self.assertEqual(A.data['status'], 'MERGED') |
| 2231 | self.assertEqual(A.reported, 2) |
| 2232 | self.assertEqual(B.data['status'], 'MERGED') |
| 2233 | self.assertEqual(B.reported, 2) |
| 2234 | self.assertEqual(C.data['status'], 'MERGED') |
| 2235 | self.assertEqual(C.reported, 2) |
| 2236 | self.assertEqual(D.data['status'], 'MERGED') |
| 2237 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2238 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2239 | def test_rerun_on_error(self): |
| 2240 | "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] | 2241 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2242 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2243 | A.addApproval('Code-Review', 2) |
| 2244 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2245 | self.waitUntilSettled() |
| 2246 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2247 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2248 | self.executor_server.hold_jobs_in_build = False |
| 2249 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2250 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2251 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2252 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2253 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2254 | def test_statsd(self): |
| 2255 | "Test each of the statsd methods used in the scheduler" |
James E. Blair | ded241e | 2017-10-10 13:22:40 -0700 | [diff] [blame] | 2256 | statsd = self.sched.statsd |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2257 | statsd.incr('test-incr') |
| 2258 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2259 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2260 | self.assertReportedStat('test-incr', '1|c') |
| 2261 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2262 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2263 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2264 | def test_stuck_job_cleanup(self): |
| 2265 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2266 | |
| 2267 | # 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] | 2268 | self.gearman_server.hold_jobs_in_queue = True |
| 2269 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2270 | A.addApproval('Code-Review', 2) |
| 2271 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2272 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2273 | # 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] | 2274 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2275 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2276 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2277 | self.sched.reconfigure(self.config) |
| 2278 | self.waitUntilSettled() |
| 2279 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2280 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2281 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2282 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2283 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2284 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2285 | |
| 2286 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2287 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2288 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2289 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2290 | def test_file_head(self): |
| 2291 | # This is a regression test for an observed bug. A change |
| 2292 | # with a file named "HEAD" in the root directory of the repo |
| 2293 | # was processed by a merger. It then was unable to reset the |
| 2294 | # repo because of: |
| 2295 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2296 | # with exit code 128 |
| 2297 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2298 | # and filename |
| 2299 | # Use '--' to separate filenames from revisions' |
| 2300 | |
| 2301 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2302 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2303 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2304 | |
| 2305 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2306 | self.waitUntilSettled() |
| 2307 | |
| 2308 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2309 | self.waitUntilSettled() |
| 2310 | |
| 2311 | self.assertIn('Build succeeded', A.messages[0]) |
| 2312 | self.assertIn('Build succeeded', B.messages[0]) |
| 2313 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2314 | def test_file_jobs(self): |
| 2315 | "Test that file jobs run only when appropriate" |
| 2316 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2317 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2318 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2319 | A.addApproval('Code-Review', 2) |
| 2320 | B.addApproval('Code-Review', 2) |
| 2321 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2322 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2323 | self.waitUntilSettled() |
| 2324 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2325 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2326 | if x.name == 'project-testfile'] |
| 2327 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2328 | self.assertEqual(len(testfile_jobs), 1) |
| 2329 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2330 | self.assertEqual(A.data['status'], 'MERGED') |
| 2331 | self.assertEqual(A.reported, 2) |
| 2332 | self.assertEqual(B.data['status'], 'MERGED') |
| 2333 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2334 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2335 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2336 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2337 | if should_skip: |
| 2338 | files = {'ignoreme': 'ignored\n'} |
| 2339 | else: |
| 2340 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2341 | |
| 2342 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2343 | 'master', |
| 2344 | 'test irrelevant-files', |
| 2345 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2346 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2347 | self.waitUntilSettled() |
| 2348 | |
| 2349 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2350 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2351 | |
| 2352 | if should_skip: |
| 2353 | self.assertEqual([], tested_change_ids) |
| 2354 | else: |
| 2355 | self.assertIn(change.data['number'], tested_change_ids) |
| 2356 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2357 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2358 | def test_irrelevant_files_match_skips_job(self): |
| 2359 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2360 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2361 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2362 | def test_irrelevant_files_no_match_runs_job(self): |
| 2363 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2364 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2365 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2366 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2367 | files = {'ignoreme': 'ignored\n'} |
| 2368 | |
| 2369 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2370 | 'master', |
| 2371 | 'test irrelevant-files', |
| 2372 | files=files) |
| 2373 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2374 | self.waitUntilSettled() |
| 2375 | |
| 2376 | run_jobs = set([build.name for build in self.history]) |
| 2377 | |
| 2378 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2379 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2380 | |
James E. Blair | af8b208 | 2017-10-03 15:38:27 -0700 | [diff] [blame] | 2381 | @simple_layout('layouts/job-vars.yaml') |
| 2382 | def test_inherited_job_variables(self): |
| 2383 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2384 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2385 | self.waitUntilSettled() |
| 2386 | self.assertHistory([ |
| 2387 | dict(name='parentjob', result='SUCCESS'), |
| 2388 | dict(name='child1', result='SUCCESS'), |
| 2389 | dict(name='child2', result='SUCCESS'), |
| 2390 | dict(name='child3', result='SUCCESS'), |
| 2391 | ], ordered=False) |
| 2392 | j = self.getJobFromHistory('parentjob') |
| 2393 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2394 | self.assertEqual(j.parameters['vars']['override'], 0) |
| 2395 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2396 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2397 | self.assertFalse('child1' in j.parameters['vars']) |
| 2398 | self.assertFalse('child2' in j.parameters['vars']) |
| 2399 | self.assertFalse('child3' in j.parameters['vars']) |
| 2400 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2401 | 'org/project0'])) |
| 2402 | j = self.getJobFromHistory('child1') |
| 2403 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2404 | self.assertEqual(j.parameters['vars']['override'], 1) |
| 2405 | self.assertEqual(j.parameters['vars']['child1override'], 1) |
| 2406 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2407 | self.assertEqual(j.parameters['vars']['child1'], 1) |
| 2408 | self.assertFalse('child2' in j.parameters['vars']) |
| 2409 | self.assertFalse('child3' in j.parameters['vars']) |
| 2410 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2411 | 'org/project1'])) |
| 2412 | j = self.getJobFromHistory('child2') |
| 2413 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2414 | self.assertEqual(j.parameters['vars']['override'], 2) |
| 2415 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2416 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2417 | self.assertFalse('child1' in j.parameters['vars']) |
| 2418 | self.assertEqual(j.parameters['vars']['child2'], 2) |
| 2419 | self.assertFalse('child3' in j.parameters['vars']) |
| 2420 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2421 | 'org/project2'])) |
| 2422 | j = self.getJobFromHistory('child3') |
| 2423 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2424 | self.assertEqual(j.parameters['vars']['override'], 3) |
| 2425 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2426 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2427 | self.assertFalse('child1' in j.parameters['vars']) |
| 2428 | self.assertFalse('child2' in j.parameters['vars']) |
| 2429 | self.assertEqual(j.parameters['vars']['child3'], 3) |
| 2430 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2431 | 'org/project3'])) |
| 2432 | |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2433 | @simple_layout('layouts/job-variants.yaml') |
| 2434 | def test_job_branch_variants(self): |
| 2435 | self.create_branch('org/project', 'stable/diablo') |
| 2436 | self.create_branch('org/project', 'stable/essex') |
| 2437 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2438 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2439 | self.waitUntilSettled() |
| 2440 | |
| 2441 | B = self.fake_gerrit.addFakeChange('org/project', 'stable/diablo', 'B') |
| 2442 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2443 | self.waitUntilSettled() |
| 2444 | |
| 2445 | C = self.fake_gerrit.addFakeChange('org/project', 'stable/essex', 'C') |
| 2446 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2447 | self.waitUntilSettled() |
| 2448 | self.assertHistory([ |
| 2449 | dict(name='python27', result='SUCCESS'), |
| 2450 | dict(name='python27', result='SUCCESS'), |
| 2451 | dict(name='python27', result='SUCCESS'), |
| 2452 | ]) |
| 2453 | |
| 2454 | p = self.history[0].parameters |
| 2455 | self.assertEqual(p['timeout'], 40) |
| 2456 | self.assertEqual(len(p['nodes']), 1) |
| 2457 | self.assertEqual(p['nodes'][0]['label'], 'new') |
| 2458 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2459 | ['base-pre', 'py27-pre']) |
| 2460 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2461 | ['py27-post-a', 'py27-post-b', 'base-post']) |
| 2462 | self.assertEqual([x['path'] for x in p['playbooks']], |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 2463 | ['playbooks/python27.yaml']) |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2464 | |
| 2465 | p = self.history[1].parameters |
| 2466 | self.assertEqual(p['timeout'], 50) |
| 2467 | self.assertEqual(len(p['nodes']), 1) |
| 2468 | self.assertEqual(p['nodes'][0]['label'], 'old') |
| 2469 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2470 | ['base-pre', 'py27-pre', 'py27-diablo-pre']) |
| 2471 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2472 | ['py27-diablo-post', 'py27-post-a', 'py27-post-b', |
| 2473 | 'base-post']) |
| 2474 | self.assertEqual([x['path'] for x in p['playbooks']], |
| 2475 | ['py27-diablo']) |
| 2476 | |
| 2477 | p = self.history[2].parameters |
| 2478 | self.assertEqual(p['timeout'], 40) |
| 2479 | self.assertEqual(len(p['nodes']), 1) |
| 2480 | self.assertEqual(p['nodes'][0]['label'], 'new') |
| 2481 | self.assertEqual([x['path'] for x in p['pre_playbooks']], |
| 2482 | ['base-pre', 'py27-pre', 'py27-essex-pre']) |
| 2483 | self.assertEqual([x['path'] for x in p['post_playbooks']], |
| 2484 | ['py27-essex-post', 'py27-post-a', 'py27-post-b', |
| 2485 | 'base-post']) |
| 2486 | self.assertEqual([x['path'] for x in p['playbooks']], |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 2487 | ['playbooks/python27.yaml']) |
James E. Blair | b09a0c5 | 2017-10-04 07:35:14 -0700 | [diff] [blame] | 2488 | |
James E. Blair | 0029267 | 2017-10-26 15:29:39 -0700 | [diff] [blame] | 2489 | @simple_layout("layouts/no-run.yaml") |
| 2490 | def test_job_without_run(self): |
| 2491 | "Test that a job without a run playbook errors" |
| 2492 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2493 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2494 | self.waitUntilSettled() |
| 2495 | self.assertIn('Job base does not specify a run playbook', |
| 2496 | A.messages[-1]) |
| 2497 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2498 | def test_queue_names(self): |
| 2499 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2500 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2501 | (trusted, project1) = tenant.getProject('org/project1') |
| 2502 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2503 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2504 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2505 | self.assertEqual(q1.name, 'integrated') |
| 2506 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2507 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2508 | def test_queue_precedence(self): |
| 2509 | "Test that queue precedence works" |
| 2510 | |
| 2511 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2512 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2513 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2514 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2515 | A.addApproval('Code-Review', 2) |
| 2516 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2517 | |
| 2518 | self.waitUntilSettled() |
| 2519 | self.gearman_server.hold_jobs_in_queue = False |
| 2520 | self.gearman_server.release() |
| 2521 | self.waitUntilSettled() |
| 2522 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2523 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2524 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2525 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2526 | self.waitUntilSettled() |
| 2527 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2528 | self.log.debug(self.history) |
| 2529 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2530 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2531 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2532 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2533 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2534 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2535 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2536 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2537 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2538 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2539 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2540 | A.addApproval('Code-Review', 2) |
| 2541 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2542 | self.waitUntilSettled() |
| 2543 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2544 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2545 | self.waitUntilSettled() |
| 2546 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2547 | port = self.webapp.server.socket.getsockname()[1] |
| 2548 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2549 | req = urllib.request.Request( |
| 2550 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2551 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2552 | headers = f.info() |
| 2553 | self.assertIn('Content-Length', headers) |
| 2554 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2555 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2556 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2557 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2558 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2559 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2560 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2561 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2562 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2563 | self.executor_server.hold_jobs_in_build = False |
| 2564 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2565 | self.waitUntilSettled() |
| 2566 | |
| 2567 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2568 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2569 | for p in data['pipelines']: |
| 2570 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2571 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2572 | self.assertEqual(q['window'], 20) |
| 2573 | else: |
| 2574 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2575 | for head in q['heads']: |
| 2576 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2577 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2578 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2579 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2580 | status_jobs.append(job) |
| 2581 | self.assertEqual('project-merge', status_jobs[0]['name']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2582 | # TODO(mordred) pull uuids from self.builds |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2583 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 2584 | 'stream.html?uuid={uuid}&logfile=console.log'.format( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2585 | uuid=status_jobs[0]['uuid']), |
| 2586 | status_jobs[0]['url']) |
| 2587 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2588 | 'finger://{hostname}/{uuid}'.format( |
| 2589 | hostname=self.executor_server.hostname, |
| 2590 | uuid=status_jobs[0]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2591 | status_jobs[0]['finger_url']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2592 | # TOOD(mordred) configure a success-url on the base job |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2593 | self.assertEqual( |
| 2594 | 'finger://{hostname}/{uuid}'.format( |
| 2595 | hostname=self.executor_server.hostname, |
| 2596 | uuid=status_jobs[0]['uuid']), |
| 2597 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2598 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2599 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 2600 | 'stream.html?uuid={uuid}&logfile=console.log'.format( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2601 | uuid=status_jobs[1]['uuid']), |
| 2602 | status_jobs[1]['url']) |
| 2603 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2604 | 'finger://{hostname}/{uuid}'.format( |
| 2605 | hostname=self.executor_server.hostname, |
| 2606 | uuid=status_jobs[1]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2607 | status_jobs[1]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2608 | self.assertEqual( |
| 2609 | 'finger://{hostname}/{uuid}'.format( |
| 2610 | hostname=self.executor_server.hostname, |
| 2611 | uuid=status_jobs[1]['uuid']), |
| 2612 | status_jobs[1]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2613 | |
| 2614 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2615 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 2616 | 'stream.html?uuid={uuid}&logfile=console.log'.format( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2617 | uuid=status_jobs[2]['uuid']), |
| 2618 | status_jobs[2]['url']) |
| 2619 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2620 | 'finger://{hostname}/{uuid}'.format( |
| 2621 | hostname=self.executor_server.hostname, |
| 2622 | uuid=status_jobs[2]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2623 | status_jobs[2]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2624 | self.assertEqual( |
| 2625 | 'finger://{hostname}/{uuid}'.format( |
| 2626 | hostname=self.executor_server.hostname, |
| 2627 | uuid=status_jobs[2]['uuid']), |
| 2628 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2629 | |
Tobias Henkel | 65639f8 | 2017-07-10 10:25:42 +0200 | [diff] [blame] | 2630 | # check job dependencies |
| 2631 | self.assertIsNotNone(status_jobs[0]['dependencies']) |
| 2632 | self.assertIsNotNone(status_jobs[1]['dependencies']) |
| 2633 | self.assertIsNotNone(status_jobs[2]['dependencies']) |
| 2634 | self.assertEqual(len(status_jobs[0]['dependencies']), 0) |
| 2635 | self.assertEqual(len(status_jobs[1]['dependencies']), 1) |
| 2636 | self.assertEqual(len(status_jobs[2]['dependencies']), 1) |
| 2637 | self.assertIn('project-merge', status_jobs[1]['dependencies']) |
| 2638 | self.assertIn('project-merge', status_jobs[2]['dependencies']) |
| 2639 | |
James E. Blair | 419a867 | 2017-10-18 14:48:25 -0700 | [diff] [blame] | 2640 | def test_reconfigure_merge(self): |
| 2641 | """Test that two reconfigure events are merged""" |
| 2642 | |
| 2643 | tenant = self.sched.abide.tenants['tenant-one'] |
| 2644 | (trusted, project) = tenant.getProject('org/project') |
| 2645 | |
| 2646 | self.sched.run_handler_lock.acquire() |
| 2647 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2648 | |
| 2649 | self.sched.reconfigureTenant(tenant, project) |
| 2650 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2651 | |
| 2652 | self.sched.reconfigureTenant(tenant, project) |
| 2653 | # The second event should have been combined with the first |
| 2654 | # so we should still only have one entry. |
| 2655 | self.assertEqual(self.sched.management_event_queue.qsize(), 1) |
| 2656 | |
| 2657 | self.sched.run_handler_lock.release() |
| 2658 | self.waitUntilSettled() |
| 2659 | |
| 2660 | self.assertEqual(self.sched.management_event_queue.qsize(), 0) |
| 2661 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2662 | def test_live_reconfiguration(self): |
| 2663 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2664 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2665 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2666 | A.addApproval('Code-Review', 2) |
| 2667 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2668 | self.waitUntilSettled() |
| 2669 | |
| 2670 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2671 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2672 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2673 | self.executor_server.hold_jobs_in_build = False |
| 2674 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2675 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2676 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2677 | 'SUCCESS') |
| 2678 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2679 | 'SUCCESS') |
| 2680 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2681 | 'SUCCESS') |
| 2682 | self.assertEqual(A.data['status'], 'MERGED') |
| 2683 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2684 | |
James E. Blair | 027ba99 | 2017-09-20 13:48:32 -0700 | [diff] [blame] | 2685 | def test_live_reconfiguration_abort(self): |
| 2686 | # Raise an exception during reconfiguration and verify we |
| 2687 | # still function. |
| 2688 | self.executor_server.hold_jobs_in_build = True |
| 2689 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2690 | A.addApproval('Code-Review', 2) |
| 2691 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2692 | self.waitUntilSettled() |
| 2693 | |
| 2694 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2695 | pipeline = tenant.layout.pipelines['gate'] |
| 2696 | change = pipeline.getAllItems()[0].change |
| 2697 | # Set this to an invalid value to cause an exception during |
| 2698 | # reconfiguration. |
| 2699 | change.branch = None |
| 2700 | |
| 2701 | self.sched.reconfigure(self.config) |
| 2702 | self.waitUntilSettled() |
| 2703 | |
| 2704 | self.executor_server.hold_jobs_in_build = False |
| 2705 | self.executor_server.release() |
| 2706 | |
| 2707 | self.waitUntilSettled() |
| 2708 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2709 | 'ABORTED') |
| 2710 | self.assertEqual(A.data['status'], 'NEW') |
| 2711 | # The final report fails because of the invalid value set above. |
| 2712 | self.assertEqual(A.reported, 1) |
| 2713 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2714 | def test_live_reconfiguration_merge_conflict(self): |
| 2715 | # A real-world bug: a change in a gate queue has a merge |
| 2716 | # conflict and a job is added to its project while it's |
| 2717 | # sitting in the queue. The job gets added to the change and |
| 2718 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2719 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2720 | |
| 2721 | # This change is fine. It's here to stop the queue long |
| 2722 | # enough for the next change to be subject to the |
| 2723 | # reconfiguration, as well as to provide a conflict for the |
| 2724 | # next change. This change will succeed and merge. |
| 2725 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2726 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2727 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2728 | |
| 2729 | # This change will be in merge conflict. During the |
| 2730 | # reconfiguration, we will add a job. We want to make sure |
| 2731 | # that doesn't cause it to get stuck. |
| 2732 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2733 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2734 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2735 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2736 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2737 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2738 | |
| 2739 | self.waitUntilSettled() |
| 2740 | |
| 2741 | # No jobs have run yet |
| 2742 | self.assertEqual(A.data['status'], 'NEW') |
| 2743 | self.assertEqual(A.reported, 1) |
| 2744 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2745 | self.assertEqual(len(self.history), 0) |
| 2746 | |
| 2747 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2748 | self.commitConfigUpdate('common-config', |
| 2749 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2750 | self.sched.reconfigure(self.config) |
| 2751 | self.waitUntilSettled() |
| 2752 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2753 | self.executor_server.hold_jobs_in_build = False |
| 2754 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2755 | self.waitUntilSettled() |
| 2756 | |
| 2757 | self.assertEqual(A.data['status'], 'MERGED') |
| 2758 | self.assertEqual(A.reported, 2) |
| 2759 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2760 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2761 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2762 | 'SUCCESS') |
| 2763 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2764 | 'SUCCESS') |
| 2765 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2766 | 'SUCCESS') |
| 2767 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2768 | 'SUCCESS') |
| 2769 | self.assertEqual(len(self.history), 4) |
| 2770 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2771 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2772 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2773 | # that tests a job added to a job tree with a failed root does |
| 2774 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2775 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2776 | |
| 2777 | # This change is fine. It's here to stop the queue long |
| 2778 | # enough for the next change to be subject to the |
| 2779 | # reconfiguration. This change will succeed and merge. |
| 2780 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2781 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2782 | A.addApproval('Code-Review', 2) |
| 2783 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2784 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2785 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2786 | self.waitUntilSettled() |
| 2787 | |
| 2788 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2789 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2790 | B.addApproval('Code-Review', 2) |
| 2791 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2792 | self.waitUntilSettled() |
| 2793 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2794 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2795 | self.waitUntilSettled() |
| 2796 | |
| 2797 | # Both -merge jobs have run, but no others. |
| 2798 | self.assertEqual(A.data['status'], 'NEW') |
| 2799 | self.assertEqual(A.reported, 1) |
| 2800 | self.assertEqual(B.data['status'], 'NEW') |
| 2801 | self.assertEqual(B.reported, 1) |
| 2802 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2803 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2804 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2805 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2806 | self.assertEqual(len(self.history), 2) |
| 2807 | |
| 2808 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2809 | self.commitConfigUpdate('common-config', |
| 2810 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2811 | self.sched.reconfigure(self.config) |
| 2812 | self.waitUntilSettled() |
| 2813 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2814 | self.executor_server.hold_jobs_in_build = False |
| 2815 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2816 | self.waitUntilSettled() |
| 2817 | |
| 2818 | self.assertEqual(A.data['status'], 'MERGED') |
| 2819 | self.assertEqual(A.reported, 2) |
| 2820 | self.assertEqual(B.data['status'], 'NEW') |
| 2821 | self.assertEqual(B.reported, 2) |
| 2822 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2823 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2824 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2825 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2826 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2827 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2828 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2829 | self.assertEqual(len(self.history), 5) |
| 2830 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2831 | def test_live_reconfiguration_failed_job(self): |
| 2832 | # Test that a change with a removed failing job does not |
| 2833 | # disrupt reconfiguration. If a change has a failed job and |
| 2834 | # that job is removed during a reconfiguration, we observed a |
| 2835 | # bug where the code to re-set build statuses would run on |
| 2836 | # that build and raise an exception because the job no longer |
| 2837 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2838 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2839 | |
| 2840 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2841 | |
| 2842 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2843 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2844 | |
| 2845 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2846 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2847 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2848 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2849 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2850 | self.waitUntilSettled() |
| 2851 | |
| 2852 | self.assertEqual(A.data['status'], 'NEW') |
| 2853 | self.assertEqual(A.reported, 0) |
| 2854 | |
| 2855 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2856 | 'SUCCESS') |
| 2857 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2858 | 'FAILURE') |
| 2859 | self.assertEqual(len(self.history), 2) |
| 2860 | |
| 2861 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2862 | self.commitConfigUpdate('common-config', |
| 2863 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2864 | self.sched.reconfigure(self.config) |
| 2865 | self.waitUntilSettled() |
| 2866 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2867 | self.executor_server.hold_jobs_in_build = False |
| 2868 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2869 | self.waitUntilSettled() |
| 2870 | |
| 2871 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2872 | 'SUCCESS') |
| 2873 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2874 | 'SUCCESS') |
| 2875 | self.assertEqual(len(self.history), 4) |
| 2876 | |
| 2877 | self.assertEqual(A.data['status'], 'NEW') |
| 2878 | self.assertEqual(A.reported, 1) |
| 2879 | self.assertIn('Build succeeded', A.messages[0]) |
| 2880 | # Ensure the removed job was not included in the report. |
| 2881 | self.assertNotIn('project-test1', A.messages[0]) |
| 2882 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2883 | def test_live_reconfiguration_shared_queue(self): |
| 2884 | # Test that a change with a failing job which was removed from |
| 2885 | # this project but otherwise still exists in the system does |
| 2886 | # not disrupt reconfiguration. |
| 2887 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2888 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2889 | |
| 2890 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2891 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2892 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2893 | |
| 2894 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2895 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2896 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2897 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2898 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2899 | self.waitUntilSettled() |
| 2900 | |
| 2901 | self.assertEqual(A.data['status'], 'NEW') |
| 2902 | self.assertEqual(A.reported, 0) |
| 2903 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2904 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2905 | 'SUCCESS') |
| 2906 | self.assertEqual(self.getJobFromHistory( |
| 2907 | 'project1-project2-integration').result, 'FAILURE') |
| 2908 | self.assertEqual(len(self.history), 2) |
| 2909 | |
| 2910 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2911 | self.commitConfigUpdate( |
| 2912 | 'common-config', |
| 2913 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2914 | self.sched.reconfigure(self.config) |
| 2915 | self.waitUntilSettled() |
| 2916 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2917 | self.executor_server.hold_jobs_in_build = False |
| 2918 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2919 | self.waitUntilSettled() |
| 2920 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2921 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2922 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2923 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2924 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2925 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2926 | 'SUCCESS') |
| 2927 | self.assertEqual(self.getJobFromHistory( |
| 2928 | 'project1-project2-integration').result, 'FAILURE') |
| 2929 | self.assertEqual(len(self.history), 4) |
| 2930 | |
| 2931 | self.assertEqual(A.data['status'], 'NEW') |
| 2932 | self.assertEqual(A.reported, 1) |
| 2933 | self.assertIn('Build succeeded', A.messages[0]) |
| 2934 | # Ensure the removed job was not included in the report. |
| 2935 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2936 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2937 | def test_double_live_reconfiguration_shared_queue(self): |
| 2938 | # This was a real-world regression. A change is added to |
| 2939 | # gate; a reconfigure happens, a second change which depends |
| 2940 | # on the first is added, and a second reconfiguration happens. |
| 2941 | # Ensure that both changes merge. |
| 2942 | |
| 2943 | # A failure may indicate incorrect caching or cleaning up of |
| 2944 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2945 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2946 | |
| 2947 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2948 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2949 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2950 | A.addApproval('Code-Review', 2) |
| 2951 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2952 | |
| 2953 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2954 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2955 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2956 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2957 | self.waitUntilSettled() |
| 2958 | |
| 2959 | # Reconfigure (with only one change in the pipeline). |
| 2960 | self.sched.reconfigure(self.config) |
| 2961 | self.waitUntilSettled() |
| 2962 | |
| 2963 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2964 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2965 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2966 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2967 | self.waitUntilSettled() |
| 2968 | |
| 2969 | # Reconfigure (with both in the pipeline). |
| 2970 | self.sched.reconfigure(self.config) |
| 2971 | self.waitUntilSettled() |
| 2972 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2973 | self.executor_server.hold_jobs_in_build = False |
| 2974 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2975 | self.waitUntilSettled() |
| 2976 | |
| 2977 | self.assertEqual(len(self.history), 8) |
| 2978 | |
| 2979 | self.assertEqual(A.data['status'], 'MERGED') |
| 2980 | self.assertEqual(A.reported, 2) |
| 2981 | self.assertEqual(B.data['status'], 'MERGED') |
| 2982 | self.assertEqual(B.reported, 2) |
| 2983 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2984 | def test_live_reconfiguration_del_project(self): |
| 2985 | # Test project deletion from layout |
| 2986 | # while changes are enqueued |
| 2987 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2988 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2989 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2990 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2991 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2992 | |
| 2993 | # A Depends-On: B |
| 2994 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2995 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2996 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2997 | |
| 2998 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2999 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 3000 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3001 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3002 | self.waitUntilSettled() |
| 3003 | self.assertEqual(len(self.builds), 5) |
| 3004 | |
| 3005 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 3006 | self.commitConfigUpdate( |
| 3007 | 'common-config', |
| 3008 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3009 | self.sched.reconfigure(self.config) |
| 3010 | self.waitUntilSettled() |
| 3011 | |
| 3012 | # Builds for C aborted, builds for A succeed, |
| 3013 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 3014 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3015 | self.assertEqual(job_c.changes, '3,1') |
| 3016 | self.assertEqual(job_c.result, 'ABORTED') |
| 3017 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3018 | self.executor_server.hold_jobs_in_build = False |
| 3019 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3020 | self.waitUntilSettled() |
| 3021 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 3022 | self.assertEqual( |
| 3023 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 3024 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3025 | |
| 3026 | self.assertEqual(A.data['status'], 'NEW') |
| 3027 | self.assertEqual(B.data['status'], 'NEW') |
| 3028 | self.assertEqual(C.data['status'], 'NEW') |
| 3029 | self.assertEqual(A.reported, 1) |
| 3030 | self.assertEqual(B.reported, 0) |
| 3031 | self.assertEqual(C.reported, 0) |
| 3032 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 3033 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3034 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3035 | self.assertIn('Build succeeded', A.messages[0]) |
| 3036 | |
James E. Blair | 872738f | 2017-10-31 16:40:36 -0700 | [diff] [blame] | 3037 | @simple_layout("layouts/reconfigure-failed-head.yaml") |
| 3038 | def test_live_reconfiguration_failed_change_at_head(self): |
| 3039 | # Test that if we reconfigure with a failed change at head, |
| 3040 | # that the change behind it isn't reparented onto it. |
| 3041 | |
| 3042 | self.executor_server.hold_jobs_in_build = True |
| 3043 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3044 | A.addApproval('Code-Review', 2) |
| 3045 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3046 | B.addApproval('Code-Review', 2) |
| 3047 | |
| 3048 | self.executor_server.failJob('job1', A) |
| 3049 | |
| 3050 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3051 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3052 | |
| 3053 | self.waitUntilSettled() |
| 3054 | |
| 3055 | self.assertBuilds([ |
| 3056 | dict(name='job1', changes='1,1'), |
| 3057 | dict(name='job2', changes='1,1'), |
| 3058 | dict(name='job1', changes='1,1 2,1'), |
| 3059 | dict(name='job2', changes='1,1 2,1'), |
| 3060 | ]) |
| 3061 | |
| 3062 | self.release(self.builds[0]) |
| 3063 | self.waitUntilSettled() |
| 3064 | |
| 3065 | self.assertBuilds([ |
| 3066 | dict(name='job2', changes='1,1'), |
| 3067 | dict(name='job1', changes='2,1'), |
| 3068 | dict(name='job2', changes='2,1'), |
| 3069 | ]) |
| 3070 | |
| 3071 | # Unordered history comparison because the aborts can finish |
| 3072 | # in any order. |
| 3073 | self.assertHistory([ |
| 3074 | dict(name='job1', result='FAILURE', changes='1,1'), |
| 3075 | dict(name='job1', result='ABORTED', changes='1,1 2,1'), |
| 3076 | dict(name='job2', result='ABORTED', changes='1,1 2,1'), |
| 3077 | ], ordered=False) |
| 3078 | |
| 3079 | self.sched.reconfigure(self.config) |
| 3080 | self.waitUntilSettled() |
| 3081 | |
| 3082 | self.executor_server.hold_jobs_in_build = False |
| 3083 | self.executor_server.release() |
| 3084 | self.waitUntilSettled() |
| 3085 | |
| 3086 | self.assertBuilds([]) |
| 3087 | |
| 3088 | self.assertHistory([ |
| 3089 | dict(name='job1', result='FAILURE', changes='1,1'), |
| 3090 | dict(name='job1', result='ABORTED', changes='1,1 2,1'), |
| 3091 | dict(name='job2', result='ABORTED', changes='1,1 2,1'), |
| 3092 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3093 | dict(name='job1', result='SUCCESS', changes='2,1'), |
| 3094 | dict(name='job2', result='SUCCESS', changes='2,1'), |
| 3095 | ], ordered=False) |
| 3096 | self.assertEqual(A.data['status'], 'NEW') |
| 3097 | self.assertEqual(B.data['status'], 'MERGED') |
| 3098 | self.assertEqual(A.reported, 2) |
| 3099 | self.assertEqual(B.reported, 2) |
| 3100 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3101 | def test_delayed_repo_init(self): |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3102 | self.init_repo("org/new-project") |
Clint Byrum | 627ba36 | 2017-08-14 13:20:40 -0700 | [diff] [blame] | 3103 | files = {'README': ''} |
| 3104 | self.addCommitToRepo("org/new-project", 'Initial commit', |
| 3105 | files=files, tag='init') |
| 3106 | self.newTenantConfig('tenants/delayed-repo-init.yaml') |
| 3107 | self.commitConfigUpdate( |
| 3108 | 'common-config', |
| 3109 | 'layouts/delayed-repo-init.yaml') |
| 3110 | self.sched.reconfigure(self.config) |
| 3111 | self.waitUntilSettled() |
| 3112 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3113 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 3114 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3115 | A.addApproval('Code-Review', 2) |
| 3116 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3117 | self.waitUntilSettled() |
| 3118 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3119 | 'SUCCESS') |
| 3120 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3121 | 'SUCCESS') |
| 3122 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3123 | 'SUCCESS') |
| 3124 | self.assertEqual(A.data['status'], 'MERGED') |
| 3125 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3126 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 3127 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3128 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3129 | self.init_repo("org/delete-project") |
| 3130 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 3131 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3132 | A.addApproval('Code-Review', 2) |
| 3133 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3134 | self.waitUntilSettled() |
| 3135 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3136 | 'SUCCESS') |
| 3137 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3138 | 'SUCCESS') |
| 3139 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3140 | 'SUCCESS') |
| 3141 | self.assertEqual(A.data['status'], 'MERGED') |
| 3142 | self.assertEqual(A.reported, 2) |
| 3143 | |
| 3144 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 3145 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 3146 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 3147 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3148 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 3149 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3150 | |
| 3151 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 3152 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3153 | B.addApproval('Code-Review', 2) |
| 3154 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3155 | self.waitUntilSettled() |
| 3156 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3157 | 'SUCCESS') |
| 3158 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3159 | 'SUCCESS') |
| 3160 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3161 | 'SUCCESS') |
| 3162 | self.assertEqual(B.data['status'], 'MERGED') |
| 3163 | self.assertEqual(B.reported, 2) |
| 3164 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 3165 | @simple_layout('layouts/untrusted-secrets.yaml') |
| 3166 | def test_untrusted_secrets(self): |
| 3167 | "Test untrusted secrets" |
| 3168 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3169 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3170 | self.waitUntilSettled() |
| 3171 | |
| 3172 | self.assertHistory([]) |
| 3173 | self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") |
James E. Blair | 8eb564a | 2017-08-10 09:21:41 -0700 | [diff] [blame] | 3174 | self.assertIn('does not allow post-review job', |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 3175 | A.messages[0]) |
| 3176 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 3177 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3178 | def test_tags(self): |
| 3179 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3180 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3181 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3182 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3183 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3184 | self.waitUntilSettled() |
| 3185 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 3186 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3187 | |
| 3188 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3189 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3190 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3191 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3192 | |
| 3193 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 3194 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 3195 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3196 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3197 | def test_timer(self): |
| 3198 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3199 | # This test can not use simple_layout because it must start |
| 3200 | # with a configuration which does not include a |
| 3201 | # timer-triggered job so that we have an opportunity to set |
| 3202 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3203 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3204 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3205 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3206 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3207 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3208 | # The pipeline triggers every second, so we should have seen |
| 3209 | # several by now. |
| 3210 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3211 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3212 | |
| 3213 | self.assertEqual(len(self.builds), 2) |
| 3214 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3215 | port = self.webapp.server.socket.getsockname()[1] |
| 3216 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 3217 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3218 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 3219 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 3220 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3221 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3222 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3223 | # Stop queuing timer triggered jobs so that the assertions |
| 3224 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3225 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3226 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3227 | self.waitUntilSettled() |
| 3228 | # If APScheduler is in mid-event when we remove the job, we |
| 3229 | # can end up with one more event firing, so give it an extra |
| 3230 | # second to settle. |
| 3231 | time.sleep(1) |
| 3232 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3233 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3234 | self.waitUntilSettled() |
| 3235 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3236 | self.assertHistory([ |
| 3237 | dict(name='project-bitrot', result='SUCCESS', |
| 3238 | ref='refs/heads/master'), |
| 3239 | dict(name='project-bitrot', result='SUCCESS', |
| 3240 | ref='refs/heads/stable'), |
| 3241 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3242 | |
| 3243 | data = json.loads(data) |
| 3244 | status_jobs = set() |
| 3245 | for p in data['pipelines']: |
| 3246 | for q in p['change_queues']: |
| 3247 | for head in q['heads']: |
| 3248 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3249 | for job in change['jobs']: |
| 3250 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3251 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3252 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3253 | def test_idle(self): |
| 3254 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3255 | # This test can not use simple_layout because it must start |
| 3256 | # with a configuration which does not include a |
| 3257 | # timer-triggered job so that we have an opportunity to set |
| 3258 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3259 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3260 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3261 | for x in range(1, 3): |
| 3262 | # Test that timer triggers periodic jobs even across |
| 3263 | # layout config reloads. |
| 3264 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3265 | self.commitConfigUpdate('common-config', |
| 3266 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3267 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3268 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3269 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3270 | # The pipeline triggers every second, so we should have seen |
| 3271 | # several by now. |
| 3272 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3273 | |
| 3274 | # Stop queuing timer triggered jobs so that the assertions |
| 3275 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3276 | self.commitConfigUpdate('common-config', |
| 3277 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3278 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3279 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3280 | # If APScheduler is in mid-event when we remove the job, |
| 3281 | # we can end up with one more event firing, so give it an |
| 3282 | # extra second to settle. |
| 3283 | time.sleep(1) |
| 3284 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3285 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3286 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3287 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3288 | self.waitUntilSettled() |
| 3289 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3290 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3291 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3292 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3293 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3294 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3295 | self.waitUntilSettled() |
| 3296 | |
| 3297 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3298 | self.waitUntilSettled() |
| 3299 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3300 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3301 | |
| 3302 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3303 | # work on the knowledge of what the first message should be as |
| 3304 | # it is only configured to go to SMTP. |
| 3305 | |
| 3306 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3307 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3308 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3309 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3310 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3311 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3312 | |
| 3313 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3314 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3315 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3316 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3317 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3318 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3319 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3320 | def test_timer_smtp(self): |
| 3321 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3322 | # This test can not use simple_layout because it must start |
| 3323 | # with a configuration which does not include a |
| 3324 | # timer-triggered job so that we have an opportunity to set |
| 3325 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3326 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3327 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3328 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3329 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3330 | # The pipeline triggers every second, so we should have seen |
| 3331 | # several by now. |
| 3332 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3333 | self.waitUntilSettled() |
| 3334 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3335 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3336 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3337 | self.waitUntilSettled() |
| 3338 | self.assertEqual(len(self.history), 2) |
| 3339 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3340 | self.assertEqual(self.getJobFromHistory( |
| 3341 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3342 | self.assertEqual(self.getJobFromHistory( |
| 3343 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3344 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3345 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3346 | |
| 3347 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3348 | # work on the knowledge of what the first message should be as |
| 3349 | # it is only configured to go to SMTP. |
| 3350 | |
| 3351 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3352 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3353 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3354 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3355 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3356 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3357 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3358 | # Stop queuing timer triggered jobs and let any that may have |
| 3359 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3360 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3361 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3362 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3363 | # If APScheduler is in mid-event when we remove the job, we |
| 3364 | # can end up with one more event firing, so give it an extra |
| 3365 | # second to settle. |
| 3366 | time.sleep(1) |
| 3367 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3368 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3369 | self.waitUntilSettled() |
| 3370 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3371 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3372 | def test_timer_sshkey(self): |
| 3373 | "Test that a periodic job can setup SSH key authentication" |
| 3374 | self.worker.hold_jobs_in_build = True |
| 3375 | self.config.set('zuul', 'layout_config', |
| 3376 | 'tests/fixtures/layout-timer.yaml') |
| 3377 | self.sched.reconfigure(self.config) |
| 3378 | self.registerJobs() |
| 3379 | |
| 3380 | # The pipeline triggers every second, so we should have seen |
| 3381 | # several by now. |
| 3382 | time.sleep(5) |
| 3383 | self.waitUntilSettled() |
| 3384 | |
| 3385 | self.assertEqual(len(self.builds), 2) |
| 3386 | |
| 3387 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3388 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3389 | with open(ssh_wrapper) as f: |
| 3390 | ssh_wrapper_content = f.read() |
| 3391 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3392 | # In the unit tests Merger runs in the same process, |
| 3393 | # so we see its' environment variables |
| 3394 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3395 | |
| 3396 | self.worker.release('.*') |
| 3397 | self.waitUntilSettled() |
| 3398 | self.assertEqual(len(self.history), 2) |
| 3399 | |
| 3400 | self.assertEqual(self.getJobFromHistory( |
| 3401 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3402 | self.assertEqual(self.getJobFromHistory( |
| 3403 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3404 | |
| 3405 | # Stop queuing timer triggered jobs and let any that may have |
| 3406 | # queued through so that end of test assertions pass. |
| 3407 | self.config.set('zuul', 'layout_config', |
| 3408 | 'tests/fixtures/layout-no-timer.yaml') |
| 3409 | self.sched.reconfigure(self.config) |
| 3410 | self.registerJobs() |
| 3411 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3412 | # If APScheduler is in mid-event when we remove the job, we |
| 3413 | # can end up with one more event firing, so give it an extra |
| 3414 | # second to settle. |
| 3415 | time.sleep(1) |
| 3416 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3417 | self.worker.release('.*') |
| 3418 | self.waitUntilSettled() |
| 3419 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3420 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3421 | "Test that the RPC client can enqueue a change" |
| 3422 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3423 | A.addApproval('Code-Review', 2) |
| 3424 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3425 | |
| 3426 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3427 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3428 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3429 | r = client.enqueue(tenant='tenant-one', |
| 3430 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3431 | project='org/project', |
| 3432 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3433 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3434 | self.waitUntilSettled() |
| 3435 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3436 | 'SUCCESS') |
| 3437 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3438 | 'SUCCESS') |
| 3439 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3440 | 'SUCCESS') |
| 3441 | self.assertEqual(A.data['status'], 'MERGED') |
| 3442 | self.assertEqual(A.reported, 2) |
| 3443 | self.assertEqual(r, True) |
| 3444 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3445 | def test_client_enqueue_ref(self): |
| 3446 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3447 | p = "review.example.com/org/project" |
| 3448 | upstream = self.getUpstreamRepos([p]) |
| 3449 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3450 | A.setMerged() |
| 3451 | A_commit = str(upstream[p].commit('master')) |
| 3452 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3453 | |
| 3454 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3455 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3456 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3457 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3458 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3459 | pipeline='post', |
| 3460 | project='org/project', |
| 3461 | trigger='gerrit', |
| 3462 | ref='master', |
| 3463 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3464 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3465 | self.waitUntilSettled() |
| 3466 | job_names = [x.name for x in self.history] |
| 3467 | self.assertEqual(len(self.history), 1) |
| 3468 | self.assertIn('project-post', job_names) |
| 3469 | self.assertEqual(r, True) |
| 3470 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3471 | def test_client_enqueue_negative(self): |
| 3472 | "Test that the RPC client returns errors" |
| 3473 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3474 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3475 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3476 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3477 | "Invalid tenant"): |
| 3478 | r = client.enqueue(tenant='tenant-foo', |
| 3479 | pipeline='gate', |
| 3480 | project='org/project', |
| 3481 | trigger='gerrit', |
| 3482 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3483 | self.assertEqual(r, False) |
| 3484 | |
| 3485 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3486 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3487 | r = client.enqueue(tenant='tenant-one', |
| 3488 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3489 | project='project-does-not-exist', |
| 3490 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3491 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3492 | self.assertEqual(r, False) |
| 3493 | |
| 3494 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3495 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3496 | r = client.enqueue(tenant='tenant-one', |
| 3497 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3498 | project='org/project', |
| 3499 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3500 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3501 | self.assertEqual(r, False) |
| 3502 | |
| 3503 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3504 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3505 | r = client.enqueue(tenant='tenant-one', |
| 3506 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3507 | project='org/project', |
| 3508 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3509 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3510 | self.assertEqual(r, False) |
| 3511 | |
| 3512 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3513 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3514 | r = client.enqueue(tenant='tenant-one', |
| 3515 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3516 | project='org/project', |
| 3517 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3518 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3519 | self.assertEqual(r, False) |
| 3520 | |
| 3521 | self.waitUntilSettled() |
| 3522 | self.assertEqual(len(self.history), 0) |
| 3523 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3524 | |
| 3525 | def test_client_promote(self): |
| 3526 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3527 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3528 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3529 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3530 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3531 | A.addApproval('Code-Review', 2) |
| 3532 | B.addApproval('Code-Review', 2) |
| 3533 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3534 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3535 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3536 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3537 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3538 | |
| 3539 | self.waitUntilSettled() |
| 3540 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3541 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3542 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3543 | enqueue_times = {} |
| 3544 | for item in items: |
| 3545 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3546 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3547 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3548 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3549 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3550 | r = client.promote(tenant='tenant-one', |
| 3551 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3552 | change_ids=['2,1', '3,1']) |
| 3553 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3554 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3555 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3556 | for item in items: |
| 3557 | self.assertEqual( |
| 3558 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3559 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3560 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3561 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3562 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3563 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3564 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3565 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3566 | self.waitUntilSettled() |
| 3567 | |
| 3568 | self.assertEqual(len(self.builds), 6) |
| 3569 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3570 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3571 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3572 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3573 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3574 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3575 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3576 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3577 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3578 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3579 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3580 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3581 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3582 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3583 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3584 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3585 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3586 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3587 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3588 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3589 | self.waitUntilSettled() |
| 3590 | |
| 3591 | self.assertEqual(A.data['status'], 'MERGED') |
| 3592 | self.assertEqual(A.reported, 2) |
| 3593 | self.assertEqual(B.data['status'], 'MERGED') |
| 3594 | self.assertEqual(B.reported, 2) |
| 3595 | self.assertEqual(C.data['status'], 'MERGED') |
| 3596 | self.assertEqual(C.reported, 2) |
| 3597 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3598 | self.assertEqual(r, True) |
| 3599 | |
| 3600 | def test_client_promote_dependent(self): |
| 3601 | "Test that the RPC client can promote a dependent change" |
| 3602 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3603 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3604 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3605 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3606 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3607 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3608 | |
| 3609 | C.setDependsOn(B, 1) |
| 3610 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3611 | A.addApproval('Code-Review', 2) |
| 3612 | B.addApproval('Code-Review', 2) |
| 3613 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3614 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3615 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3616 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3617 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3618 | |
| 3619 | self.waitUntilSettled() |
| 3620 | |
| 3621 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3622 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3623 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3624 | r = client.promote(tenant='tenant-one', |
| 3625 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3626 | change_ids=['3,1']) |
| 3627 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3628 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3629 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3630 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3631 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3632 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3633 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3634 | self.waitUntilSettled() |
| 3635 | |
| 3636 | self.assertEqual(len(self.builds), 6) |
| 3637 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3638 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3639 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3640 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3641 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3642 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3643 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3644 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3645 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3646 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3647 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3648 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3649 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3650 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3651 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3652 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3653 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3654 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3655 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3656 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3657 | self.waitUntilSettled() |
| 3658 | |
| 3659 | self.assertEqual(A.data['status'], 'MERGED') |
| 3660 | self.assertEqual(A.reported, 2) |
| 3661 | self.assertEqual(B.data['status'], 'MERGED') |
| 3662 | self.assertEqual(B.reported, 2) |
| 3663 | self.assertEqual(C.data['status'], 'MERGED') |
| 3664 | self.assertEqual(C.reported, 2) |
| 3665 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3666 | self.assertEqual(r, True) |
| 3667 | |
| 3668 | def test_client_promote_negative(self): |
| 3669 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3670 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3671 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3672 | A.addApproval('Code-Review', 2) |
| 3673 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3674 | self.waitUntilSettled() |
| 3675 | |
| 3676 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3677 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3678 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3679 | |
| 3680 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3681 | r = client.promote(tenant='tenant-one', |
| 3682 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3683 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3684 | self.assertEqual(r, False) |
| 3685 | |
| 3686 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3687 | r = client.promote(tenant='tenant-one', |
| 3688 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3689 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3690 | self.assertEqual(r, False) |
| 3691 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3692 | self.executor_server.hold_jobs_in_build = False |
| 3693 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3694 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3695 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3696 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3697 | def test_queue_rate_limiting(self): |
| 3698 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3699 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3700 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3701 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3702 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3703 | |
| 3704 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3705 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3706 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3707 | A.addApproval('Code-Review', 2) |
| 3708 | B.addApproval('Code-Review', 2) |
| 3709 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3710 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3711 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3712 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3713 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3714 | self.waitUntilSettled() |
| 3715 | |
| 3716 | # Only A and B will have their merge jobs queued because |
| 3717 | # window is 2. |
| 3718 | self.assertEqual(len(self.builds), 2) |
| 3719 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3720 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3721 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3722 | # Release the merge jobs one at a time. |
| 3723 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3724 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3725 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3726 | self.waitUntilSettled() |
| 3727 | |
| 3728 | # Only A and B will have their test jobs queued because |
| 3729 | # window is 2. |
| 3730 | self.assertEqual(len(self.builds), 4) |
| 3731 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3732 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3733 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3734 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3735 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3736 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3737 | self.waitUntilSettled() |
| 3738 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3739 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3740 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3741 | # A failed so window is reduced by 1 to 1. |
| 3742 | self.assertEqual(queue.window, 1) |
| 3743 | self.assertEqual(queue.window_floor, 1) |
| 3744 | self.assertEqual(A.data['status'], 'NEW') |
| 3745 | |
| 3746 | # Gate is reset and only B's merge job is queued because |
| 3747 | # window shrunk to 1. |
| 3748 | self.assertEqual(len(self.builds), 1) |
| 3749 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3750 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3751 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3752 | self.waitUntilSettled() |
| 3753 | |
| 3754 | # Only B's test jobs are queued because window is still 1. |
| 3755 | self.assertEqual(len(self.builds), 2) |
| 3756 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3757 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3758 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3759 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3760 | self.waitUntilSettled() |
| 3761 | |
| 3762 | # B was successfully merged so window is increased to 2. |
| 3763 | self.assertEqual(queue.window, 2) |
| 3764 | self.assertEqual(queue.window_floor, 1) |
| 3765 | self.assertEqual(B.data['status'], 'MERGED') |
| 3766 | |
| 3767 | # Only C is left and its merge job is queued. |
| 3768 | self.assertEqual(len(self.builds), 1) |
| 3769 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3770 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3771 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3772 | self.waitUntilSettled() |
| 3773 | |
| 3774 | # After successful merge job the test jobs for C are queued. |
| 3775 | self.assertEqual(len(self.builds), 2) |
| 3776 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3777 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3778 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3779 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3780 | self.waitUntilSettled() |
| 3781 | |
| 3782 | # C successfully merged so window is bumped to 3. |
| 3783 | self.assertEqual(queue.window, 3) |
| 3784 | self.assertEqual(queue.window_floor, 1) |
| 3785 | self.assertEqual(C.data['status'], 'MERGED') |
| 3786 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3787 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3788 | def test_queue_rate_limiting_dependent(self): |
| 3789 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3790 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3791 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3792 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3793 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3794 | |
| 3795 | B.setDependsOn(A, 1) |
| 3796 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3797 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3798 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3799 | A.addApproval('Code-Review', 2) |
| 3800 | B.addApproval('Code-Review', 2) |
| 3801 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3802 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3803 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3804 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3805 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3806 | self.waitUntilSettled() |
| 3807 | |
| 3808 | # Only A and B will have their merge jobs queued because |
| 3809 | # window is 2. |
| 3810 | self.assertEqual(len(self.builds), 2) |
| 3811 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3812 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3813 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3814 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3815 | |
| 3816 | # Only A and B will have their test jobs queued because |
| 3817 | # window is 2. |
| 3818 | self.assertEqual(len(self.builds), 4) |
| 3819 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3820 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3821 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3822 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3823 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3824 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3825 | self.waitUntilSettled() |
| 3826 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3827 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3828 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3829 | # A failed so window is reduced by 1 to 1. |
| 3830 | self.assertEqual(queue.window, 1) |
| 3831 | self.assertEqual(queue.window_floor, 1) |
| 3832 | self.assertEqual(A.data['status'], 'NEW') |
| 3833 | self.assertEqual(B.data['status'], 'NEW') |
| 3834 | |
| 3835 | # Gate is reset and only C's merge job is queued because |
| 3836 | # window shrunk to 1 and A and B were dequeued. |
| 3837 | self.assertEqual(len(self.builds), 1) |
| 3838 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3839 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3840 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3841 | |
| 3842 | # Only C's test jobs are queued because window is still 1. |
| 3843 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3844 | builds = self.getSortedBuilds() |
| 3845 | self.assertEqual(builds[0].name, 'project-test1') |
| 3846 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3847 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3848 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3849 | self.waitUntilSettled() |
| 3850 | |
| 3851 | # C was successfully merged so window is increased to 2. |
| 3852 | self.assertEqual(queue.window, 2) |
| 3853 | self.assertEqual(queue.window_floor, 1) |
| 3854 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3855 | |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3856 | @simple_layout('layouts/reconfigure-window.yaml') |
| 3857 | def test_reconfigure_window_shrink(self): |
| 3858 | # Test the active window shrinking during reconfiguration |
| 3859 | self.executor_server.hold_jobs_in_build = True |
| 3860 | |
| 3861 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3862 | A.addApproval('Code-Review', 2) |
| 3863 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3864 | self.waitUntilSettled() |
| 3865 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3866 | B.addApproval('Code-Review', 2) |
| 3867 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3868 | self.waitUntilSettled() |
| 3869 | |
| 3870 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3871 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3872 | self.assertEqual(queue.window, 20) |
| 3873 | self.assertTrue(len(self.builds), 4) |
| 3874 | |
| 3875 | self.executor_server.release('job1') |
| 3876 | self.waitUntilSettled() |
| 3877 | self.commitConfigUpdate('org/common-config', |
| 3878 | 'layouts/reconfigure-window2.yaml') |
| 3879 | self.sched.reconfigure(self.config) |
| 3880 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3881 | queue = tenant.layout.pipelines['gate'].queues[0] |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3882 | # Even though we have configured a smaller window, the value |
| 3883 | # on the existing shared queue should be used. |
| 3884 | self.assertEqual(queue.window, 20) |
| 3885 | self.assertTrue(len(self.builds), 4) |
| 3886 | |
| 3887 | self.sched.reconfigure(self.config) |
| 3888 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3889 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3890 | self.assertEqual(queue.window, 20) |
| 3891 | self.assertTrue(len(self.builds), 4) |
| 3892 | |
| 3893 | self.executor_server.hold_jobs_in_build = False |
| 3894 | self.executor_server.release() |
| 3895 | |
| 3896 | self.waitUntilSettled() |
| 3897 | self.assertHistory([ |
| 3898 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 3899 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 3900 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3901 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 3902 | ], ordered=False) |
| 3903 | |
| 3904 | @simple_layout('layouts/reconfigure-window-fixed.yaml') |
| 3905 | def test_reconfigure_window_fixed(self): |
| 3906 | # Test the active window shrinking during reconfiguration |
| 3907 | self.executor_server.hold_jobs_in_build = True |
| 3908 | |
| 3909 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3910 | A.addApproval('Code-Review', 2) |
| 3911 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3912 | self.waitUntilSettled() |
| 3913 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3914 | B.addApproval('Code-Review', 2) |
| 3915 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3916 | self.waitUntilSettled() |
| 3917 | |
| 3918 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3919 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3920 | self.assertEqual(queue.window, 2) |
| 3921 | self.assertTrue(len(self.builds), 4) |
| 3922 | |
| 3923 | self.executor_server.release('job1') |
| 3924 | self.waitUntilSettled() |
| 3925 | self.commitConfigUpdate('org/common-config', |
| 3926 | 'layouts/reconfigure-window-fixed2.yaml') |
| 3927 | self.sched.reconfigure(self.config) |
| 3928 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3929 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3930 | # Because we have configured a static window, it should |
| 3931 | # be allowed to shrink on reconfiguration. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3932 | self.assertEqual(queue.window, 1) |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3933 | # B is outside the window, but still marked active until the |
| 3934 | # next pass through the queue processor, so its builds haven't |
| 3935 | # been canceled. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3936 | self.assertTrue(len(self.builds), 4) |
| 3937 | |
| 3938 | self.sched.reconfigure(self.config) |
| 3939 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3940 | queue = tenant.layout.pipelines['gate'].queues[0] |
| 3941 | self.assertEqual(queue.window, 1) |
| 3942 | # B's builds have been canceled now |
| 3943 | self.assertTrue(len(self.builds), 2) |
| 3944 | |
| 3945 | self.executor_server.hold_jobs_in_build = False |
| 3946 | self.executor_server.release() |
James E. Blair | 74be381 | 2017-11-30 14:17:25 -0800 | [diff] [blame] | 3947 | |
| 3948 | # B's builds will be restarted and will show up in our history |
| 3949 | # twice. |
James E. Blair | 8fd207b | 2017-11-30 13:44:38 -0800 | [diff] [blame] | 3950 | self.waitUntilSettled() |
| 3951 | self.assertHistory([ |
| 3952 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 3953 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 3954 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3955 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 3956 | dict(name='job1', result='SUCCESS', changes='1,1 2,1'), |
| 3957 | dict(name='job2', result='SUCCESS', changes='1,1 2,1'), |
| 3958 | ], ordered=False) |
| 3959 | |
| 3960 | @simple_layout('layouts/reconfigure-remove-add.yaml') |
| 3961 | def test_reconfigure_remove_add(self): |
| 3962 | # Test removing, then adding a job while in queue |
| 3963 | self.executor_server.hold_jobs_in_build = True |
| 3964 | |
| 3965 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3966 | A.addApproval('Code-Review', 2) |
| 3967 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3968 | self.waitUntilSettled() |
| 3969 | self.assertTrue(len(self.builds), 2) |
| 3970 | self.executor_server.release('job2') |
| 3971 | self.assertTrue(len(self.builds), 1) |
| 3972 | |
| 3973 | # Remove job2 |
| 3974 | self.commitConfigUpdate('org/common-config', |
| 3975 | 'layouts/reconfigure-remove-add2.yaml') |
| 3976 | self.sched.reconfigure(self.config) |
| 3977 | self.assertTrue(len(self.builds), 1) |
| 3978 | |
| 3979 | # Add job2 back |
| 3980 | self.commitConfigUpdate('org/common-config', |
| 3981 | 'layouts/reconfigure-remove-add.yaml') |
| 3982 | self.sched.reconfigure(self.config) |
| 3983 | self.assertTrue(len(self.builds), 2) |
| 3984 | |
| 3985 | self.executor_server.hold_jobs_in_build = False |
| 3986 | self.executor_server.release() |
| 3987 | # This will run new builds for B |
| 3988 | self.waitUntilSettled() |
| 3989 | self.assertHistory([ |
| 3990 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3991 | dict(name='job1', result='SUCCESS', changes='1,1'), |
| 3992 | dict(name='job2', result='SUCCESS', changes='1,1'), |
| 3993 | ], ordered=False) |
| 3994 | |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3995 | def test_worker_update_metadata(self): |
| 3996 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3997 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3998 | |
| 3999 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4000 | A.addApproval('Code-Review', 2) |
| 4001 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4002 | self.waitUntilSettled() |
| 4003 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4004 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4005 | |
| 4006 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4007 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4008 | |
| 4009 | start = time.time() |
| 4010 | while True: |
| 4011 | if time.time() - start > 10: |
| 4012 | raise Exception("Timeout waiting for gearman server to report " |
| 4013 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4014 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4015 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4016 | break |
| 4017 | else: |
| 4018 | time.sleep(0) |
| 4019 | |
| 4020 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4021 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4022 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4023 | self.executor_server.hold_jobs_in_build = False |
| 4024 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 4025 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4026 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 4027 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4028 | def test_footer_message(self): |
| 4029 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4030 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4031 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4032 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4033 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4034 | self.waitUntilSettled() |
| 4035 | |
| 4036 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4037 | B.addApproval('Code-Review', 2) |
| 4038 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4039 | self.waitUntilSettled() |
| 4040 | |
| 4041 | self.assertEqual(2, len(self.smtp_messages)) |
| 4042 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4043 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4044 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4045 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4046 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4047 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 4048 | For CI problems and help debugging, contact ci@example.org""" |
| 4049 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 4050 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 4051 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 4052 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 4053 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4054 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 4055 | @simple_layout('layouts/unmanaged-project.yaml') |
| 4056 | def test_unmanaged_project_start_message(self): |
| 4057 | "Test start reporting is not done for unmanaged projects." |
| 4058 | self.init_repo("org/project", tag='init') |
| 4059 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4060 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4061 | self.waitUntilSettled() |
| 4062 | |
| 4063 | self.assertEqual(0, len(A.messages)) |
| 4064 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4065 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4066 | def test_merge_failure_reporters(self): |
| 4067 | """Check that the config is set up correctly""" |
| 4068 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4069 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4070 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 4071 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 4072 | "dependencies was unable to be automatically merged with the " |
| 4073 | "current state of its repository. Please rebase the change and " |
| 4074 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4075 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4076 | self.assertEqual( |
| 4077 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4078 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4079 | |
| 4080 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4081 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4082 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4083 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4084 | |
| 4085 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4086 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 4087 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4088 | |
| 4089 | self.assertTrue( |
| 4090 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4091 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4092 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4093 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 4094 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4095 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4096 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4097 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4098 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4099 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4100 | gerritreporter.GerritReporter) and |
| 4101 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 4102 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 4103 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4104 | ) |
| 4105 | ) |
| 4106 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4107 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4108 | def test_merge_failure_reports(self): |
| 4109 | """Check that when a change fails to merge the correct message is sent |
| 4110 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4111 | self.updateConfigLayout( |
| 4112 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4113 | self.sched.reconfigure(self.config) |
| 4114 | self.registerJobs() |
| 4115 | |
| 4116 | # Check a test failure isn't reported to SMTP |
| 4117 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4118 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4119 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4120 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4121 | self.waitUntilSettled() |
| 4122 | |
| 4123 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 4124 | self.assertEqual(0, len(self.smtp_messages)) |
| 4125 | |
| 4126 | # Check a merge failure is reported to SMTP |
| 4127 | # B should be merged, but C will conflict with B |
| 4128 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4129 | B.addPatchset(['conflict']) |
| 4130 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4131 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4132 | B.addApproval('Code-Review', 2) |
| 4133 | C.addApproval('Code-Review', 2) |
| 4134 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4135 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 4136 | self.waitUntilSettled() |
| 4137 | |
| 4138 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 4139 | self.assertEqual(1, len(self.smtp_messages)) |
| 4140 | self.assertEqual('The merge failed! For more information...', |
| 4141 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 4142 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4143 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 4144 | def test_default_merge_failure_reports(self): |
| 4145 | """Check that the default merge failure reports are correct.""" |
| 4146 | |
| 4147 | # A should report success, B should report merge failure. |
| 4148 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4149 | A.addPatchset(['conflict']) |
| 4150 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4151 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4152 | A.addApproval('Code-Review', 2) |
| 4153 | B.addApproval('Code-Review', 2) |
| 4154 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4155 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 4156 | self.waitUntilSettled() |
| 4157 | |
| 4158 | self.assertEqual(3, len(self.history)) # A jobs |
| 4159 | self.assertEqual(A.reported, 2) |
| 4160 | self.assertEqual(B.reported, 2) |
| 4161 | self.assertEqual(A.data['status'], 'MERGED') |
| 4162 | self.assertEqual(B.data['status'], 'NEW') |
| 4163 | self.assertIn('Build succeeded', A.messages[1]) |
| 4164 | self.assertIn('Merge Failed', B.messages[1]) |
| 4165 | self.assertIn('automatically merged', B.messages[1]) |
| 4166 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 4167 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 4168 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4169 | def test_client_get_running_jobs(self): |
| 4170 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4171 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4172 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4173 | A.addApproval('Code-Review', 2) |
| 4174 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4175 | self.waitUntilSettled() |
| 4176 | |
| 4177 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 4178 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 4179 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4180 | |
| 4181 | # Wait for gearman server to send the initial workData back to zuul |
| 4182 | start = time.time() |
| 4183 | while True: |
| 4184 | if time.time() - start > 10: |
| 4185 | raise Exception("Timeout waiting for gearman server to report " |
| 4186 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 4187 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 4188 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4189 | break |
| 4190 | else: |
| 4191 | time.sleep(0) |
| 4192 | |
| 4193 | running_items = client.get_running_jobs() |
| 4194 | |
| 4195 | self.assertEqual(1, len(running_items)) |
| 4196 | running_item = running_items[0] |
| 4197 | self.assertEqual([], running_item['failing_reasons']) |
| 4198 | self.assertEqual([], running_item['items_behind']) |
James E. Blair | 0e4c791 | 2018-01-02 14:20:17 -0800 | [diff] [blame] | 4199 | self.assertEqual('https://review.example.com/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4200 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4201 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4202 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4203 | self.assertEqual(True, running_item['active']) |
| 4204 | self.assertEqual('1,1', running_item['id']) |
| 4205 | |
| 4206 | self.assertEqual(3, len(running_item['jobs'])) |
| 4207 | for job in running_item['jobs']: |
| 4208 | if job['name'] == 'project-merge': |
| 4209 | self.assertEqual('project-merge', job['name']) |
| 4210 | self.assertEqual('gate', job['pipeline']) |
| 4211 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4212 | self.assertEqual( |
Tristan Cacqueray | a4996f1 | 2017-09-20 01:00:28 +0000 | [diff] [blame] | 4213 | 'stream.html?uuid={uuid}&logfile=console.log' |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 4214 | .format(uuid=job['uuid']), job['url']) |
| 4215 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4216 | 'finger://{hostname}/{uuid}'.format( |
| 4217 | hostname=self.executor_server.hostname, |
| 4218 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 4219 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 4220 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4221 | self.assertEqual(False, job['canceled']) |
| 4222 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 4223 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4224 | self.assertEqual('gate', job['pipeline']) |
| 4225 | break |
| 4226 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4227 | self.executor_server.hold_jobs_in_build = False |
| 4228 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 4229 | self.waitUntilSettled() |
| 4230 | |
| 4231 | running_items = client.get_running_jobs() |
| 4232 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4233 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 4234 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4235 | def test_nonvoting_pipeline(self): |
| 4236 | "Test that a nonvoting pipeline (experimental) can still report" |
| 4237 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 4238 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 4239 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4240 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4241 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 4242 | |
| 4243 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 4244 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 4245 | self.assertEqual( |
| 4246 | self.getJobFromHistory('experimental-project-test').result, |
| 4247 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 4248 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4249 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4250 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4251 | def test_disable_at(self): |
| 4252 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4253 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4254 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4255 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4256 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4257 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4258 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4259 | |
| 4260 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4261 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4262 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4263 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4264 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4265 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4266 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4267 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4268 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4269 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4270 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4271 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4272 | self.executor_server.failJob('project-test1', A) |
| 4273 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4274 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4275 | self.executor_server.failJob('project-test1', D) |
| 4276 | self.executor_server.failJob('project-test1', E) |
| 4277 | self.executor_server.failJob('project-test1', F) |
| 4278 | self.executor_server.failJob('project-test1', G) |
| 4279 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4280 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4281 | self.executor_server.failJob('project-test1', J) |
| 4282 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4283 | |
| 4284 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4285 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4286 | self.waitUntilSettled() |
| 4287 | |
| 4288 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4289 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4290 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4291 | |
| 4292 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4293 | self.waitUntilSettled() |
| 4294 | |
| 4295 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4296 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4297 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4298 | |
| 4299 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4300 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4301 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4302 | self.waitUntilSettled() |
| 4303 | |
| 4304 | # We should be disabled now |
| 4305 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4306 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4307 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4308 | |
| 4309 | # We need to wait between each of these patches to make sure the |
| 4310 | # smtp messages come back in an expected order |
| 4311 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4312 | self.waitUntilSettled() |
| 4313 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4314 | self.waitUntilSettled() |
| 4315 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4316 | self.waitUntilSettled() |
| 4317 | |
| 4318 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4319 | # leaving a message on each change |
| 4320 | self.assertEqual(1, len(A.messages)) |
| 4321 | self.assertIn('Build failed.', A.messages[0]) |
| 4322 | self.assertEqual(1, len(B.messages)) |
| 4323 | self.assertIn('Build failed.', B.messages[0]) |
| 4324 | self.assertEqual(1, len(C.messages)) |
| 4325 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4326 | self.assertEqual(1, len(D.messages)) |
| 4327 | self.assertIn('Build failed.', D.messages[0]) |
| 4328 | self.assertEqual(1, len(E.messages)) |
| 4329 | self.assertIn('Build failed.', E.messages[0]) |
| 4330 | self.assertEqual(1, len(F.messages)) |
| 4331 | self.assertIn('Build failed.', F.messages[0]) |
| 4332 | |
| 4333 | # The last 3 (GHI) would have only reported via smtp. |
| 4334 | self.assertEqual(3, len(self.smtp_messages)) |
| 4335 | self.assertEqual(0, len(G.messages)) |
| 4336 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4337 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4338 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4339 | self.assertEqual(0, len(H.messages)) |
| 4340 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4341 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4342 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4343 | self.assertEqual(0, len(I.messages)) |
| 4344 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4345 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4346 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4347 | |
| 4348 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4349 | # comes out of disabled |
| 4350 | self.sched.reconfigure(self.config) |
| 4351 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4352 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4353 | |
| 4354 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4355 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4356 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4357 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4358 | |
| 4359 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4360 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4361 | self.waitUntilSettled() |
| 4362 | |
| 4363 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4364 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4365 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4366 | |
| 4367 | # J and K went back to gerrit |
| 4368 | self.assertEqual(1, len(J.messages)) |
| 4369 | self.assertIn('Build failed.', J.messages[0]) |
| 4370 | self.assertEqual(1, len(K.messages)) |
| 4371 | self.assertIn('Build failed.', K.messages[0]) |
| 4372 | # No more messages reported via smtp |
| 4373 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4374 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4375 | @simple_layout('layouts/one-job-project.yaml') |
| 4376 | def test_one_job_project(self): |
| 4377 | "Test that queueing works with one job" |
| 4378 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4379 | 'master', 'A') |
| 4380 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4381 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4382 | A.addApproval('Code-Review', 2) |
| 4383 | B.addApproval('Code-Review', 2) |
| 4384 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4385 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4386 | self.waitUntilSettled() |
| 4387 | |
| 4388 | self.assertEqual(A.data['status'], 'MERGED') |
| 4389 | self.assertEqual(A.reported, 2) |
| 4390 | self.assertEqual(B.data['status'], 'MERGED') |
| 4391 | self.assertEqual(B.reported, 2) |
| 4392 | |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4393 | def test_job_aborted(self): |
| 4394 | "Test that if a execute server aborts a job, it is run again" |
| 4395 | self.executor_server.hold_jobs_in_build = True |
| 4396 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4397 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4398 | self.waitUntilSettled() |
| 4399 | |
| 4400 | self.executor_server.release('.*-merge') |
| 4401 | self.waitUntilSettled() |
| 4402 | |
| 4403 | self.assertEqual(len(self.builds), 2) |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4404 | |
| 4405 | # first abort |
| 4406 | self.builds[0].aborted = True |
| 4407 | self.executor_server.release('.*-test*') |
| 4408 | self.waitUntilSettled() |
| 4409 | self.assertEqual(len(self.builds), 1) |
| 4410 | |
| 4411 | # second abort |
| 4412 | self.builds[0].aborted = True |
| 4413 | self.executor_server.release('.*-test*') |
| 4414 | self.waitUntilSettled() |
| 4415 | self.assertEqual(len(self.builds), 1) |
| 4416 | |
| 4417 | # third abort |
| 4418 | self.builds[0].aborted = True |
| 4419 | self.executor_server.release('.*-test*') |
| 4420 | self.waitUntilSettled() |
| 4421 | self.assertEqual(len(self.builds), 1) |
| 4422 | |
| 4423 | # fourth abort |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4424 | self.builds[0].aborted = True |
| 4425 | self.executor_server.release('.*-test*') |
| 4426 | self.waitUntilSettled() |
| 4427 | self.assertEqual(len(self.builds), 1) |
| 4428 | |
| 4429 | self.executor_server.hold_jobs_in_build = False |
| 4430 | self.executor_server.release() |
| 4431 | self.waitUntilSettled() |
| 4432 | |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4433 | self.assertEqual(len(self.history), 7) |
| 4434 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4435 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 4436 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4437 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4438 | "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] | 4439 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4440 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4441 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4442 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4443 | self.waitUntilSettled() |
| 4444 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4445 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4446 | self.waitUntilSettled() |
| 4447 | |
| 4448 | self.assertEqual(len(self.builds), 2) |
| 4449 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4450 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4451 | self.waitUntilSettled() |
| 4452 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4453 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4454 | self.assertEqual(len(self.builds), 1, |
| 4455 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4456 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4457 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4458 | self.waitUntilSettled() |
| 4459 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4460 | self.executor_server.hold_jobs_in_build = False |
| 4461 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4462 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4463 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4464 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4465 | self.assertEqual(A.reported, 1) |
| 4466 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4467 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4468 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4469 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4470 | |
| 4471 | self.fake_nodepool.paused = True |
| 4472 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4473 | A.addApproval('Code-Review', 2) |
| 4474 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4475 | self.waitUntilSettled() |
| 4476 | |
| 4477 | self.zk.client.stop() |
| 4478 | self.zk.client.start() |
| 4479 | self.fake_nodepool.paused = False |
| 4480 | self.waitUntilSettled() |
| 4481 | |
| 4482 | self.assertEqual(A.data['status'], 'MERGED') |
| 4483 | self.assertEqual(A.reported, 2) |
| 4484 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4485 | def test_nodepool_failure(self): |
| 4486 | "Test that jobs are reported after a nodepool failure" |
| 4487 | |
| 4488 | self.fake_nodepool.paused = True |
| 4489 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4490 | A.addApproval('Code-Review', 2) |
| 4491 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4492 | self.waitUntilSettled() |
| 4493 | |
| 4494 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4495 | self.fake_nodepool.addFailRequest(req) |
| 4496 | |
| 4497 | self.fake_nodepool.paused = False |
| 4498 | self.waitUntilSettled() |
| 4499 | |
| 4500 | self.assertEqual(A.data['status'], 'NEW') |
| 4501 | self.assertEqual(A.reported, 2) |
| 4502 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4503 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4504 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4505 | |
Monty Taylor | 6dc5bc1 | 2017-09-29 15:47:31 -0500 | [diff] [blame] | 4506 | def test_nodepool_priority(self): |
| 4507 | "Test that nodes are requested at the correct priority" |
| 4508 | |
| 4509 | self.fake_nodepool.paused = True |
| 4510 | |
| 4511 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4512 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4513 | |
| 4514 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4515 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4516 | |
| 4517 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4518 | C.addApproval('Code-Review', 2) |
| 4519 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 4520 | |
| 4521 | self.waitUntilSettled() |
| 4522 | |
| 4523 | reqs = self.fake_nodepool.getNodeRequests() |
| 4524 | |
| 4525 | # The requests come back sorted by oid. Since we have three requests |
| 4526 | # for the three changes each with a different priority. |
| 4527 | # Also they get a serial number based on order they were received |
| 4528 | # so the number on the endof the oid should map to order submitted. |
| 4529 | |
| 4530 | # * gate first - high priority - change C |
| 4531 | self.assertEqual(reqs[0]['_oid'], '100-0000000002') |
| 4532 | self.assertEqual(reqs[0]['node_types'], ['label1']) |
| 4533 | # * check second - normal priority - change B |
| 4534 | self.assertEqual(reqs[1]['_oid'], '200-0000000001') |
| 4535 | self.assertEqual(reqs[1]['node_types'], ['label1']) |
| 4536 | # * post third - low priority - change A |
| 4537 | # additionally, the post job defined uses an ubuntu-xenial node, |
| 4538 | # so we include that check just as an extra verification |
| 4539 | self.assertEqual(reqs[2]['_oid'], '300-0000000000') |
| 4540 | self.assertEqual(reqs[2]['node_types'], ['ubuntu-xenial']) |
| 4541 | |
| 4542 | self.fake_nodepool.paused = False |
| 4543 | self.waitUntilSettled() |
| 4544 | |
James E. Blair | fceaf41 | 2017-09-29 13:44:57 -0700 | [diff] [blame] | 4545 | @simple_layout('layouts/multiple-templates.yaml') |
| 4546 | def test_multiple_project_templates(self): |
| 4547 | # Test that applying multiple project templates to a project |
| 4548 | # doesn't alter them when used for a second project. |
| 4549 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4550 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4551 | self.waitUntilSettled() |
| 4552 | |
| 4553 | build = self.getJobFromHistory('py27') |
| 4554 | self.assertEqual(build.parameters['zuul']['jobtags'], []) |
| 4555 | |
James E. Blair | 29c7700 | 2017-10-05 14:56:35 -0700 | [diff] [blame] | 4556 | def test_pending_merge_in_reconfig(self): |
| 4557 | # Test that if we are waiting for an outstanding merge on |
| 4558 | # reconfiguration that we continue to do so. |
| 4559 | self.gearman_server.hold_merge_jobs_in_queue = True |
| 4560 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4561 | A.setMerged() |
| 4562 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4563 | self.waitUntilSettled() |
| 4564 | # Reconfigure while we still have an outstanding merge job |
| 4565 | self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'], |
| 4566 | None) |
| 4567 | self.waitUntilSettled() |
| 4568 | # Verify the merge job is still running and that the item is |
| 4569 | # in the pipeline |
| 4570 | self.assertEqual(len(self.sched.merger.jobs), 1) |
| 4571 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4572 | pipeline = tenant.layout.pipelines['post'] |
| 4573 | self.assertEqual(len(pipeline.getAllItems()), 1) |
| 4574 | self.gearman_server.hold_merge_jobs_in_queue = False |
| 4575 | self.gearman_server.release() |
| 4576 | self.waitUntilSettled() |
| 4577 | |
James E. Blair | c32a835 | 2017-10-11 16:27:50 -0700 | [diff] [blame] | 4578 | @simple_layout('layouts/parent-matchers.yaml') |
| 4579 | def test_parent_matchers(self): |
| 4580 | "Test that if a job's parent does not match, the job does not run" |
| 4581 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4582 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4583 | self.waitUntilSettled() |
| 4584 | |
| 4585 | self.assertHistory([]) |
| 4586 | |
| 4587 | files = {'foo.txt': ''} |
| 4588 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B', |
| 4589 | files=files) |
| 4590 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4591 | self.waitUntilSettled() |
| 4592 | |
| 4593 | files = {'bar.txt': ''} |
| 4594 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C', |
| 4595 | files=files) |
| 4596 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4597 | self.waitUntilSettled() |
| 4598 | |
| 4599 | files = {'foo.txt': '', 'bar.txt': ''} |
| 4600 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D', |
| 4601 | files=files) |
| 4602 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4603 | self.waitUntilSettled() |
| 4604 | |
| 4605 | self.assertHistory([ |
| 4606 | dict(name='child-job', result='SUCCESS', changes='2,1'), |
| 4607 | dict(name='child-job', result='SUCCESS', changes='3,1'), |
| 4608 | dict(name='child-job', result='SUCCESS', changes='4,1'), |
| 4609 | ]) |
| 4610 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4611 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4612 | class TestExecutor(ZuulTestCase): |
| 4613 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4614 | |
| 4615 | def assertFinalState(self): |
| 4616 | # In this test, we expect to shut down in a non-final state, |
| 4617 | # so skip these checks. |
| 4618 | pass |
| 4619 | |
| 4620 | def assertCleanShutdown(self): |
| 4621 | self.log.debug("Assert clean shutdown") |
| 4622 | |
| 4623 | # After shutdown, make sure no jobs are running |
| 4624 | self.assertEqual({}, self.executor_server.job_workers) |
| 4625 | |
| 4626 | # Make sure that git.Repo objects have been garbage collected. |
| 4627 | repos = [] |
| 4628 | gc.collect() |
| 4629 | for obj in gc.get_objects(): |
| 4630 | if isinstance(obj, git.Repo): |
| 4631 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4632 | repos.append(obj) |
| 4633 | self.assertEqual(len(repos), 0) |
| 4634 | |
| 4635 | def test_executor_shutdown(self): |
| 4636 | "Test that the executor can shut down with jobs running" |
| 4637 | |
| 4638 | self.executor_server.hold_jobs_in_build = True |
| 4639 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4640 | A.addApproval('Code-Review', 2) |
| 4641 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4642 | self.waitUntilSettled() |
| 4643 | |
| 4644 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4645 | class TestDependencyGraph(ZuulTestCase): |
| 4646 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4647 | |
| 4648 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4649 | "Test a job in a dependency graph is queued only once" |
| 4650 | # Job dependencies, starting with A |
| 4651 | # A |
| 4652 | # / \ |
| 4653 | # B C |
| 4654 | # / \ / \ |
| 4655 | # D F E |
| 4656 | # | |
| 4657 | # G |
| 4658 | |
| 4659 | self.executor_server.hold_jobs_in_build = True |
| 4660 | change = self.fake_gerrit.addFakeChange( |
| 4661 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4662 | change.addApproval('Code-Review', 2) |
| 4663 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4664 | |
| 4665 | self.waitUntilSettled() |
| 4666 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4667 | |
| 4668 | self.executor_server.release('A') |
| 4669 | self.waitUntilSettled() |
| 4670 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4671 | |
| 4672 | self.executor_server.release('B') |
| 4673 | self.waitUntilSettled() |
| 4674 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4675 | |
| 4676 | self.executor_server.release('D') |
| 4677 | self.waitUntilSettled() |
| 4678 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4679 | |
| 4680 | self.executor_server.release('C') |
| 4681 | self.waitUntilSettled() |
| 4682 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4683 | |
| 4684 | self.executor_server.release('F') |
| 4685 | self.waitUntilSettled() |
| 4686 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4687 | |
| 4688 | self.executor_server.release('G') |
| 4689 | self.waitUntilSettled() |
| 4690 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4691 | |
| 4692 | self.executor_server.release('E') |
| 4693 | self.waitUntilSettled() |
| 4694 | self.assertEqual(len(self.builds), 0) |
| 4695 | |
| 4696 | self.executor_server.hold_jobs_in_build = False |
| 4697 | self.executor_server.release() |
| 4698 | self.waitUntilSettled() |
| 4699 | |
| 4700 | self.assertEqual(len(self.builds), 0) |
| 4701 | self.assertEqual(len(self.history), 7) |
| 4702 | |
| 4703 | self.assertEqual(change.data['status'], 'MERGED') |
| 4704 | self.assertEqual(change.reported, 2) |
| 4705 | |
| 4706 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4707 | "Test that a job waits till all dependencies are successful" |
| 4708 | # Job dependencies, starting with A |
| 4709 | # A |
| 4710 | # / \ |
| 4711 | # B C* |
| 4712 | # / \ / \ |
| 4713 | # D F E |
| 4714 | # | |
| 4715 | # G |
| 4716 | |
| 4717 | self.executor_server.hold_jobs_in_build = True |
| 4718 | change = self.fake_gerrit.addFakeChange( |
| 4719 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4720 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4721 | |
| 4722 | self.executor_server.failJob('C', change) |
| 4723 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4724 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4725 | |
| 4726 | self.waitUntilSettled() |
| 4727 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4728 | |
| 4729 | self.executor_server.release('A') |
| 4730 | self.waitUntilSettled() |
| 4731 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4732 | |
| 4733 | self.executor_server.release('B') |
| 4734 | self.waitUntilSettled() |
| 4735 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4736 | |
| 4737 | self.executor_server.release('D') |
| 4738 | self.waitUntilSettled() |
| 4739 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4740 | |
| 4741 | self.executor_server.release('C') |
| 4742 | self.waitUntilSettled() |
| 4743 | self.assertEqual(len(self.builds), 0) |
| 4744 | |
| 4745 | self.executor_server.hold_jobs_in_build = False |
| 4746 | self.executor_server.release() |
| 4747 | self.waitUntilSettled() |
| 4748 | |
| 4749 | self.assertEqual(len(self.builds), 0) |
| 4750 | self.assertEqual(len(self.history), 4) |
| 4751 | |
| 4752 | self.assertEqual(change.data['status'], 'NEW') |
| 4753 | self.assertEqual(change.reported, 2) |
| 4754 | |
| 4755 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4756 | class TestDuplicatePipeline(ZuulTestCase): |
| 4757 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4758 | |
| 4759 | def test_duplicate_pipelines(self): |
| 4760 | "Test that a change matching multiple pipelines works" |
| 4761 | |
| 4762 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4763 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4764 | self.waitUntilSettled() |
| 4765 | |
| 4766 | self.assertHistory([ |
| 4767 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4768 | pipeline='dup1'), |
| 4769 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4770 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4771 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4772 | |
| 4773 | self.assertEqual(len(A.messages), 2) |
| 4774 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4775 | if 'dup1' in A.messages[0]: |
| 4776 | self.assertIn('dup1', A.messages[0]) |
| 4777 | self.assertNotIn('dup2', A.messages[0]) |
| 4778 | self.assertIn('project-test1', A.messages[0]) |
| 4779 | self.assertIn('dup2', A.messages[1]) |
| 4780 | self.assertNotIn('dup1', A.messages[1]) |
| 4781 | self.assertIn('project-test1', A.messages[1]) |
| 4782 | else: |
| 4783 | self.assertIn('dup1', A.messages[1]) |
| 4784 | self.assertNotIn('dup2', A.messages[1]) |
| 4785 | self.assertIn('project-test1', A.messages[1]) |
| 4786 | self.assertIn('dup2', A.messages[0]) |
| 4787 | self.assertNotIn('dup1', A.messages[0]) |
| 4788 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4789 | |
| 4790 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4791 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4792 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4793 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4794 | def test_job_from_templates_executed(self): |
| 4795 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4796 | |
| 4797 | A = self.fake_gerrit.addFakeChange( |
| 4798 | 'org/templated-project', 'master', 'A') |
| 4799 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4800 | self.waitUntilSettled() |
| 4801 | |
| 4802 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4803 | 'SUCCESS') |
| 4804 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4805 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4806 | |
| 4807 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4808 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4809 | |
| 4810 | A = self.fake_gerrit.addFakeChange( |
| 4811 | 'org/layered-project', 'master', 'A') |
| 4812 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4813 | self.waitUntilSettled() |
| 4814 | |
| 4815 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4816 | 'SUCCESS') |
| 4817 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4818 | 'SUCCESS') |
| 4819 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4820 | ).result, 'SUCCESS') |
| 4821 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4822 | ).result, 'SUCCESS') |
| 4823 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4824 | ).result, 'SUCCESS') |
| 4825 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4826 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4827 | |
James E. Blair | e74f571 | 2017-09-29 15:14:31 -0700 | [diff] [blame] | 4828 | def test_unimplied_branch_matchers(self): |
| 4829 | # This tests that there are no implied branch matchers added |
| 4830 | # by project templates. |
| 4831 | self.create_branch('org/layered-project', 'stable') |
| 4832 | |
| 4833 | A = self.fake_gerrit.addFakeChange( |
| 4834 | 'org/layered-project', 'stable', 'A') |
| 4835 | |
| 4836 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4837 | self.waitUntilSettled() |
| 4838 | |
| 4839 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4840 | 'SUCCESS') |
| 4841 | print(self.getJobFromHistory('project-test1'). |
| 4842 | parameters['zuul']['_inheritance_path']) |
| 4843 | |
| 4844 | def test_implied_branch_matchers(self): |
| 4845 | # This tests that there is an implied branch matcher when a |
| 4846 | # template is used on an in-repo project pipeline definition. |
| 4847 | self.create_branch('untrusted-config', 'stable') |
| 4848 | self.fake_gerrit.addEvent( |
| 4849 | self.fake_gerrit.getFakeBranchCreatedEvent( |
| 4850 | 'untrusted-config', 'stable')) |
| 4851 | self.waitUntilSettled() |
| 4852 | |
| 4853 | A = self.fake_gerrit.addFakeChange( |
| 4854 | 'untrusted-config', 'stable', 'A') |
| 4855 | |
| 4856 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4857 | self.waitUntilSettled() |
| 4858 | |
| 4859 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4860 | 'SUCCESS') |
| 4861 | print(self.getJobFromHistory('project-test1'). |
| 4862 | parameters['zuul']['_inheritance_path']) |
| 4863 | |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4864 | |
| 4865 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4866 | tenant_config_file = 'config/success-url/main.yaml' |
| 4867 | |
| 4868 | def test_success_url(self): |
| 4869 | "Ensure bad build params are ignored" |
| 4870 | self.sched.reconfigure(self.config) |
| 4871 | self.init_repo('org/docs') |
| 4872 | |
| 4873 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4874 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4875 | self.waitUntilSettled() |
| 4876 | |
| 4877 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4878 | self.assertEqual(len(self.history), 2) |
| 4879 | |
| 4880 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4881 | for build in self.history: |
| 4882 | if build.name == 'docs-draft-test': |
| 4883 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4884 | elif build.name == 'docs-draft-test2': |
| 4885 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4886 | |
| 4887 | # Two msgs: 'Starting...' + results |
| 4888 | self.assertEqual(len(self.smtp_messages), 2) |
| 4889 | body = self.smtp_messages[1]['body'].splitlines() |
| 4890 | self.assertEqual('Build succeeded.', body[0]) |
| 4891 | |
| 4892 | self.assertIn( |
| 4893 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4894 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4895 | body[2]) |
| 4896 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4897 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4898 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4899 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 4900 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4901 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4902 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4903 | |
| 4904 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4905 | class TestSchedulerMerges(ZuulTestCase): |
| 4906 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4907 | |
| 4908 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4909 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4910 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4911 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4912 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4913 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4914 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4915 | A.addApproval('Code-Review', 2) |
| 4916 | B.addApproval('Code-Review', 2) |
| 4917 | C.addApproval('Code-Review', 2) |
| 4918 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4919 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4920 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4921 | self.waitUntilSettled() |
| 4922 | |
| 4923 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4924 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4925 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4926 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4927 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4928 | repo_messages.reverse() |
| 4929 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4930 | self.executor_server.hold_jobs_in_build = False |
| 4931 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4932 | self.waitUntilSettled() |
| 4933 | |
| 4934 | return repo_messages |
| 4935 | |
| 4936 | def _test_merge(self, mode): |
| 4937 | us_path = os.path.join( |
| 4938 | self.upstream_root, 'org/project-%s' % mode) |
| 4939 | expected_messages = [ |
| 4940 | 'initial commit', |
| 4941 | 'add content from fixture', |
| 4942 | # the intermediate commits order is nondeterministic |
| 4943 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4944 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4945 | ] |
| 4946 | result = self._test_project_merge_mode(mode) |
| 4947 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4948 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4949 | |
| 4950 | def test_project_merge_mode_merge(self): |
| 4951 | self._test_merge('merge') |
| 4952 | |
| 4953 | def test_project_merge_mode_merge_resolve(self): |
| 4954 | self._test_merge('merge-resolve') |
| 4955 | |
| 4956 | def test_project_merge_mode_cherrypick(self): |
| 4957 | expected_messages = [ |
| 4958 | 'initial commit', |
| 4959 | 'add content from fixture', |
| 4960 | 'A-1', |
| 4961 | 'B-1', |
| 4962 | 'C-1'] |
| 4963 | result = self._test_project_merge_mode('cherry-pick') |
| 4964 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4965 | |
| 4966 | def test_merge_branch(self): |
| 4967 | "Test that the right commits are on alternate branches" |
| 4968 | self.create_branch('org/project-merge-branches', 'mp') |
| 4969 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4970 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4971 | A = self.fake_gerrit.addFakeChange( |
| 4972 | 'org/project-merge-branches', 'mp', 'A') |
| 4973 | B = self.fake_gerrit.addFakeChange( |
| 4974 | 'org/project-merge-branches', 'mp', 'B') |
| 4975 | C = self.fake_gerrit.addFakeChange( |
| 4976 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4977 | A.addApproval('Code-Review', 2) |
| 4978 | B.addApproval('Code-Review', 2) |
| 4979 | C.addApproval('Code-Review', 2) |
| 4980 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4981 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4982 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4983 | self.waitUntilSettled() |
| 4984 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4985 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4986 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4987 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4988 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4989 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4990 | self.waitUntilSettled() |
| 4991 | |
| 4992 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 4993 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4994 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4995 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4996 | repo = git.Repo(path) |
| 4997 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4998 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4999 | repo_messages.reverse() |
| 5000 | correct_messages = [ |
| 5001 | 'initial commit', |
| 5002 | 'add content from fixture', |
| 5003 | 'mp commit', |
| 5004 | 'A-1', 'B-1', 'C-1'] |
| 5005 | self.assertEqual(repo_messages, correct_messages) |
| 5006 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5007 | self.executor_server.hold_jobs_in_build = False |
| 5008 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5009 | self.waitUntilSettled() |
| 5010 | |
| 5011 | def test_merge_multi_branch(self): |
| 5012 | "Test that dependent changes on multiple branches are merged" |
| 5013 | self.create_branch('org/project-merge-branches', 'mp') |
| 5014 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5015 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5016 | A = self.fake_gerrit.addFakeChange( |
| 5017 | 'org/project-merge-branches', 'master', 'A') |
| 5018 | B = self.fake_gerrit.addFakeChange( |
| 5019 | 'org/project-merge-branches', 'mp', 'B') |
| 5020 | C = self.fake_gerrit.addFakeChange( |
| 5021 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5022 | A.addApproval('Code-Review', 2) |
| 5023 | B.addApproval('Code-Review', 2) |
| 5024 | C.addApproval('Code-Review', 2) |
| 5025 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5026 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5027 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5028 | self.waitUntilSettled() |
| 5029 | |
| 5030 | job_A = None |
| 5031 | for job in self.builds: |
| 5032 | if 'project-merge' in job.name: |
| 5033 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5034 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5035 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 5036 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5037 | repo = git.Repo(path) |
| 5038 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5039 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5040 | repo_messages.reverse() |
| 5041 | correct_messages = [ |
| 5042 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5043 | self.assertEqual(repo_messages, correct_messages) |
| 5044 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5045 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5046 | self.waitUntilSettled() |
| 5047 | |
| 5048 | job_B = None |
| 5049 | for job in self.builds: |
| 5050 | if 'project-merge' in job.name: |
| 5051 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5052 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5053 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 5054 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5055 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5056 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5057 | repo_messages.reverse() |
| 5058 | correct_messages = [ |
| 5059 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5060 | self.assertEqual(repo_messages, correct_messages) |
| 5061 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5062 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5063 | self.waitUntilSettled() |
| 5064 | |
| 5065 | job_C = None |
| 5066 | for job in self.builds: |
| 5067 | if 'project-merge' in job.name: |
| 5068 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 5069 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5070 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 5071 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5072 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5073 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5074 | |
| 5075 | repo_messages.reverse() |
| 5076 | correct_messages = [ |
| 5077 | 'initial commit', 'add content from fixture', |
| 5078 | 'A-1', 'C-1'] |
| 5079 | # Ensure the right commits are in the history for this ref |
| 5080 | self.assertEqual(repo_messages, correct_messages) |
| 5081 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5082 | self.executor_server.hold_jobs_in_build = False |
| 5083 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5084 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5085 | |
| 5086 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5087 | class TestSemaphore(ZuulTestCase): |
| 5088 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5089 | |
| 5090 | def test_semaphore_one(self): |
| 5091 | "Test semaphores with max=1 (mutex)" |
| 5092 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5093 | |
| 5094 | self.executor_server.hold_jobs_in_build = True |
| 5095 | |
| 5096 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5097 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5098 | self.assertFalse('test-semaphore' in |
| 5099 | tenant.semaphore_handler.semaphores) |
| 5100 | |
| 5101 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5102 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5103 | self.waitUntilSettled() |
| 5104 | |
| 5105 | self.assertEqual(len(self.builds), 3) |
| 5106 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5107 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5108 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5109 | |
| 5110 | self.executor_server.release('semaphore-one-test1') |
| 5111 | self.waitUntilSettled() |
| 5112 | |
| 5113 | self.assertEqual(len(self.builds), 3) |
| 5114 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5115 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5116 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5117 | self.assertTrue('test-semaphore' in |
| 5118 | tenant.semaphore_handler.semaphores) |
| 5119 | |
| 5120 | self.executor_server.release('semaphore-one-test2') |
| 5121 | self.waitUntilSettled() |
| 5122 | |
| 5123 | self.assertEqual(len(self.builds), 3) |
| 5124 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5125 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5126 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5127 | self.assertTrue('test-semaphore' in |
| 5128 | tenant.semaphore_handler.semaphores) |
| 5129 | |
| 5130 | self.executor_server.release('semaphore-one-test1') |
| 5131 | self.waitUntilSettled() |
| 5132 | |
| 5133 | self.assertEqual(len(self.builds), 3) |
| 5134 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5135 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5136 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5137 | self.assertTrue('test-semaphore' in |
| 5138 | tenant.semaphore_handler.semaphores) |
| 5139 | |
| 5140 | self.executor_server.release('semaphore-one-test2') |
| 5141 | self.waitUntilSettled() |
| 5142 | |
| 5143 | self.assertEqual(len(self.builds), 2) |
| 5144 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5145 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5146 | self.assertFalse('test-semaphore' in |
| 5147 | tenant.semaphore_handler.semaphores) |
| 5148 | |
| 5149 | self.executor_server.hold_jobs_in_build = False |
| 5150 | self.executor_server.release() |
| 5151 | |
| 5152 | self.waitUntilSettled() |
| 5153 | self.assertEqual(len(self.builds), 0) |
| 5154 | |
| 5155 | self.assertEqual(A.reported, 1) |
| 5156 | self.assertEqual(B.reported, 1) |
| 5157 | self.assertFalse('test-semaphore' in |
| 5158 | tenant.semaphore_handler.semaphores) |
| 5159 | |
| 5160 | def test_semaphore_two(self): |
| 5161 | "Test semaphores with max>1" |
| 5162 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5163 | |
| 5164 | self.executor_server.hold_jobs_in_build = True |
| 5165 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5166 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5167 | self.assertFalse('test-semaphore-two' in |
| 5168 | tenant.semaphore_handler.semaphores) |
| 5169 | |
| 5170 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5171 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5172 | self.waitUntilSettled() |
| 5173 | |
| 5174 | self.assertEqual(len(self.builds), 4) |
| 5175 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5176 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5177 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5178 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5179 | self.assertTrue('test-semaphore-two' in |
| 5180 | tenant.semaphore_handler.semaphores) |
| 5181 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5182 | 'test-semaphore-two', [])), 2) |
| 5183 | |
| 5184 | self.executor_server.release('semaphore-two-test1') |
| 5185 | self.waitUntilSettled() |
| 5186 | |
| 5187 | self.assertEqual(len(self.builds), 4) |
| 5188 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5189 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5190 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5191 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5192 | self.assertTrue('test-semaphore-two' in |
| 5193 | tenant.semaphore_handler.semaphores) |
| 5194 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5195 | 'test-semaphore-two', [])), 2) |
| 5196 | |
| 5197 | self.executor_server.release('semaphore-two-test2') |
| 5198 | self.waitUntilSettled() |
| 5199 | |
| 5200 | self.assertEqual(len(self.builds), 4) |
| 5201 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5202 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5203 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5204 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5205 | self.assertTrue('test-semaphore-two' in |
| 5206 | tenant.semaphore_handler.semaphores) |
| 5207 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5208 | 'test-semaphore-two', [])), 2) |
| 5209 | |
| 5210 | self.executor_server.release('semaphore-two-test1') |
| 5211 | self.waitUntilSettled() |
| 5212 | |
| 5213 | self.assertEqual(len(self.builds), 3) |
| 5214 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5215 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5216 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5217 | self.assertTrue('test-semaphore-two' in |
| 5218 | tenant.semaphore_handler.semaphores) |
| 5219 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5220 | 'test-semaphore-two', [])), 1) |
| 5221 | |
| 5222 | self.executor_server.release('semaphore-two-test2') |
| 5223 | self.waitUntilSettled() |
| 5224 | |
| 5225 | self.assertEqual(len(self.builds), 2) |
| 5226 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5227 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5228 | self.assertFalse('test-semaphore-two' in |
| 5229 | tenant.semaphore_handler.semaphores) |
| 5230 | |
| 5231 | self.executor_server.hold_jobs_in_build = False |
| 5232 | self.executor_server.release() |
| 5233 | |
| 5234 | self.waitUntilSettled() |
| 5235 | self.assertEqual(len(self.builds), 0) |
| 5236 | |
| 5237 | self.assertEqual(A.reported, 1) |
| 5238 | self.assertEqual(B.reported, 1) |
| 5239 | |
| 5240 | def test_semaphore_abandon(self): |
| 5241 | "Test abandon with job semaphores" |
| 5242 | self.executor_server.hold_jobs_in_build = True |
| 5243 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5244 | check_pipeline = tenant.layout.pipelines['check'] |
| 5245 | |
| 5246 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5247 | self.assertFalse('test-semaphore' in |
| 5248 | tenant.semaphore_handler.semaphores) |
| 5249 | |
| 5250 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5251 | self.waitUntilSettled() |
| 5252 | |
| 5253 | self.assertTrue('test-semaphore' in |
| 5254 | tenant.semaphore_handler.semaphores) |
| 5255 | |
| 5256 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5257 | self.waitUntilSettled() |
| 5258 | |
| 5259 | # The check pipeline should be empty |
| 5260 | items = check_pipeline.getAllItems() |
| 5261 | self.assertEqual(len(items), 0) |
| 5262 | |
| 5263 | # The semaphore should be released |
| 5264 | self.assertFalse('test-semaphore' in |
| 5265 | tenant.semaphore_handler.semaphores) |
| 5266 | |
| 5267 | self.executor_server.hold_jobs_in_build = False |
| 5268 | self.executor_server.release() |
| 5269 | self.waitUntilSettled() |
| 5270 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5271 | def test_semaphore_new_patchset(self): |
| 5272 | "Test new patchset with job semaphores" |
| 5273 | self.executor_server.hold_jobs_in_build = True |
| 5274 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5275 | check_pipeline = tenant.layout.pipelines['check'] |
| 5276 | |
| 5277 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5278 | self.assertFalse('test-semaphore' in |
| 5279 | tenant.semaphore_handler.semaphores) |
| 5280 | |
| 5281 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5282 | self.waitUntilSettled() |
| 5283 | |
| 5284 | self.assertTrue('test-semaphore' in |
| 5285 | tenant.semaphore_handler.semaphores) |
| 5286 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5287 | self.assertEqual(len(semaphore), 1) |
| 5288 | |
| 5289 | A.addPatchset() |
| 5290 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5291 | self.waitUntilSettled() |
| 5292 | |
| 5293 | self.assertTrue('test-semaphore' in |
| 5294 | tenant.semaphore_handler.semaphores) |
| 5295 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5296 | self.assertEqual(len(semaphore), 1) |
| 5297 | |
| 5298 | items = check_pipeline.getAllItems() |
| 5299 | self.assertEqual(items[0].change.number, '1') |
| 5300 | self.assertEqual(items[0].change.patchset, '2') |
| 5301 | self.assertTrue(items[0].live) |
| 5302 | |
| 5303 | self.executor_server.hold_jobs_in_build = False |
| 5304 | self.executor_server.release() |
| 5305 | self.waitUntilSettled() |
| 5306 | |
| 5307 | # The semaphore should be released |
| 5308 | self.assertFalse('test-semaphore' in |
| 5309 | tenant.semaphore_handler.semaphores) |
| 5310 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5311 | def test_semaphore_reconfigure(self): |
| 5312 | "Test reconfigure with job semaphores" |
| 5313 | self.executor_server.hold_jobs_in_build = True |
| 5314 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5315 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5316 | self.assertFalse('test-semaphore' in |
| 5317 | tenant.semaphore_handler.semaphores) |
| 5318 | |
| 5319 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5320 | self.waitUntilSettled() |
| 5321 | |
| 5322 | self.assertTrue('test-semaphore' in |
| 5323 | tenant.semaphore_handler.semaphores) |
| 5324 | |
| 5325 | # reconfigure without layout change |
| 5326 | self.sched.reconfigure(self.config) |
| 5327 | self.waitUntilSettled() |
| 5328 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5329 | |
| 5330 | # semaphore still must be held |
| 5331 | self.assertTrue('test-semaphore' in |
| 5332 | tenant.semaphore_handler.semaphores) |
| 5333 | |
| 5334 | self.commitConfigUpdate( |
| 5335 | 'common-config', |
| 5336 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5337 | self.sched.reconfigure(self.config) |
| 5338 | self.waitUntilSettled() |
| 5339 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5340 | |
| 5341 | self.executor_server.release('project-test1') |
| 5342 | self.waitUntilSettled() |
| 5343 | |
| 5344 | # There should be no builds anymore |
| 5345 | self.assertEqual(len(self.builds), 0) |
| 5346 | |
| 5347 | # The semaphore should be released |
| 5348 | self.assertFalse('test-semaphore' in |
| 5349 | tenant.semaphore_handler.semaphores) |
| 5350 | |
| 5351 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5352 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5353 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5354 | |
| 5355 | def test_semaphore_tenant_isolation(self): |
| 5356 | "Test semaphores in multiple tenants" |
| 5357 | |
| 5358 | self.waitUntilSettled() |
| 5359 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5360 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5361 | |
| 5362 | self.executor_server.hold_jobs_in_build = True |
| 5363 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5364 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5365 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5366 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5367 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5368 | self.assertFalse('test-semaphore' in |
| 5369 | tenant_one.semaphore_handler.semaphores) |
| 5370 | self.assertFalse('test-semaphore' in |
| 5371 | tenant_two.semaphore_handler.semaphores) |
| 5372 | |
| 5373 | # add patches to project1 of tenant-one |
| 5374 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5375 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5376 | self.waitUntilSettled() |
| 5377 | |
| 5378 | # one build of project1-test1 must run |
| 5379 | # semaphore of tenant-one must be acquired once |
| 5380 | # semaphore of tenant-two must not be acquired |
| 5381 | self.assertEqual(len(self.builds), 1) |
| 5382 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5383 | self.assertTrue('test-semaphore' in |
| 5384 | tenant_one.semaphore_handler.semaphores) |
| 5385 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5386 | 'test-semaphore', [])), 1) |
| 5387 | self.assertFalse('test-semaphore' in |
| 5388 | tenant_two.semaphore_handler.semaphores) |
| 5389 | |
| 5390 | # add patches to project2 of tenant-two |
| 5391 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5392 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5393 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5394 | self.waitUntilSettled() |
| 5395 | |
| 5396 | # one build of project1-test1 must run |
| 5397 | # two builds of project2-test1 must run |
| 5398 | # semaphore of tenant-one must be acquired once |
| 5399 | # semaphore of tenant-two must be acquired twice |
| 5400 | self.assertEqual(len(self.builds), 3) |
| 5401 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5402 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5403 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5404 | self.assertTrue('test-semaphore' in |
| 5405 | tenant_one.semaphore_handler.semaphores) |
| 5406 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5407 | 'test-semaphore', [])), 1) |
| 5408 | self.assertTrue('test-semaphore' in |
| 5409 | tenant_two.semaphore_handler.semaphores) |
| 5410 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5411 | 'test-semaphore', [])), 2) |
| 5412 | |
| 5413 | self.executor_server.release('project1-test1') |
| 5414 | self.waitUntilSettled() |
| 5415 | |
| 5416 | # one build of project1-test1 must run |
| 5417 | # two builds of project2-test1 must run |
| 5418 | # semaphore of tenant-one must be acquired once |
| 5419 | # semaphore of tenant-two must be acquired twice |
| 5420 | self.assertEqual(len(self.builds), 3) |
| 5421 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5422 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5423 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5424 | self.assertTrue('test-semaphore' in |
| 5425 | tenant_one.semaphore_handler.semaphores) |
| 5426 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5427 | 'test-semaphore', [])), 1) |
| 5428 | self.assertTrue('test-semaphore' in |
| 5429 | tenant_two.semaphore_handler.semaphores) |
| 5430 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5431 | 'test-semaphore', [])), 2) |
| 5432 | |
| 5433 | self.executor_server.release('project2-test1') |
| 5434 | self.waitUntilSettled() |
| 5435 | |
| 5436 | # one build of project1-test1 must run |
| 5437 | # one build of project2-test1 must run |
| 5438 | # semaphore of tenant-one must be acquired once |
| 5439 | # semaphore of tenant-two must be acquired once |
| 5440 | self.assertEqual(len(self.builds), 2) |
| 5441 | self.assertTrue('test-semaphore' in |
| 5442 | tenant_one.semaphore_handler.semaphores) |
| 5443 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5444 | 'test-semaphore', [])), 1) |
| 5445 | self.assertTrue('test-semaphore' in |
| 5446 | tenant_two.semaphore_handler.semaphores) |
| 5447 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5448 | 'test-semaphore', [])), 1) |
| 5449 | |
| 5450 | self.executor_server.hold_jobs_in_build = False |
| 5451 | self.executor_server.release() |
| 5452 | |
| 5453 | self.waitUntilSettled() |
| 5454 | |
| 5455 | # no build must run |
| 5456 | # semaphore of tenant-one must not be acquired |
| 5457 | # semaphore of tenant-two must not be acquired |
| 5458 | self.assertEqual(len(self.builds), 0) |
| 5459 | self.assertFalse('test-semaphore' in |
| 5460 | tenant_one.semaphore_handler.semaphores) |
| 5461 | self.assertFalse('test-semaphore' in |
| 5462 | tenant_two.semaphore_handler.semaphores) |
| 5463 | |
| 5464 | self.assertEqual(A.reported, 1) |
| 5465 | self.assertEqual(B.reported, 1) |
| 5466 | |
| 5467 | |
Tobias Henkel | e9a2251 | 2017-12-22 08:36:12 +0100 | [diff] [blame] | 5468 | class TestImplicitProject(ZuulTestCase): |
| 5469 | tenant_config_file = 'config/implicit-project/main.yaml' |
| 5470 | |
| 5471 | def test_implicit_project(self): |
| 5472 | # config project should work with implicit project name |
| 5473 | A = self.fake_gerrit.addFakeChange('common-config', 'master', 'A') |
| 5474 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5475 | |
| 5476 | # untrusted project should work with implicit project name |
| 5477 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5478 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5479 | |
| 5480 | self.waitUntilSettled() |
| 5481 | |
| 5482 | self.assertEqual(A.data['status'], 'NEW') |
| 5483 | self.assertEqual(A.reported, 1) |
| 5484 | self.assertEqual(B.data['status'], 'NEW') |
| 5485 | self.assertEqual(B.reported, 1) |
| 5486 | self.assertHistory([ |
| 5487 | dict(name='test-common', result='SUCCESS', changes='1,1'), |
| 5488 | dict(name='test-common', result='SUCCESS', changes='2,1'), |
| 5489 | dict(name='test-project', result='SUCCESS', changes='2,1'), |
| 5490 | ], ordered=False) |
| 5491 | |
| 5492 | # now test adding a further project in repo |
| 5493 | in_repo_conf = textwrap.dedent( |
| 5494 | """ |
| 5495 | - job: |
| 5496 | name: test-project |
| 5497 | run: playbooks/test-project.yaml |
| 5498 | - job: |
| 5499 | name: test2-project |
| 5500 | run: playbooks/test-project.yaml |
| 5501 | |
| 5502 | - project: |
| 5503 | check: |
| 5504 | jobs: |
| 5505 | - test-project |
| 5506 | gate: |
| 5507 | jobs: |
| 5508 | - test-project |
| 5509 | |
| 5510 | - project: |
| 5511 | check: |
| 5512 | jobs: |
| 5513 | - test2-project |
| 5514 | gate: |
| 5515 | jobs: |
| 5516 | - test2-project |
| 5517 | |
| 5518 | """) |
| 5519 | file_dict = {'.zuul.yaml': in_repo_conf} |
| 5520 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5521 | files=file_dict) |
| 5522 | C.addApproval('Code-Review', 2) |
| 5523 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 5524 | self.waitUntilSettled() |
| 5525 | |
| 5526 | # change C must be merged |
| 5527 | self.assertEqual(C.data['status'], 'MERGED') |
| 5528 | self.assertEqual(C.reported, 2) |
| 5529 | self.assertHistory([ |
| 5530 | dict(name='test-common', result='SUCCESS', changes='1,1'), |
| 5531 | dict(name='test-common', result='SUCCESS', changes='2,1'), |
| 5532 | dict(name='test-project', result='SUCCESS', changes='2,1'), |
| 5533 | dict(name='test-common', result='SUCCESS', changes='3,1'), |
| 5534 | dict(name='test-project', result='SUCCESS', changes='3,1'), |
| 5535 | dict(name='test2-project', result='SUCCESS', changes='3,1'), |
| 5536 | ], ordered=False) |
| 5537 | |
| 5538 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5539 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5540 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5541 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5542 | |
| 5543 | def test_semaphore_in_repo(self): |
| 5544 | "Test semaphores in repo config" |
| 5545 | |
| 5546 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5547 | # max value should not be evaluated dynamically but must be updated |
| 5548 | # after the change lands. |
| 5549 | |
| 5550 | self.waitUntilSettled() |
| 5551 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5552 | |
| 5553 | in_repo_conf = textwrap.dedent( |
| 5554 | """ |
| 5555 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5556 | name: project-test1 |
| 5557 | |
| 5558 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5559 | name: project-test2 |
James E. Blair | 2f589fe | 2017-10-26 12:57:41 -0700 | [diff] [blame] | 5560 | run: playbooks/project-test2.yaml |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5561 | semaphore: test-semaphore |
| 5562 | |
| 5563 | - project: |
| 5564 | name: org/project |
| 5565 | tenant-one-gate: |
| 5566 | jobs: |
| 5567 | - project-test2 |
| 5568 | |
| 5569 | # the max value in dynamic layout must be ignored |
| 5570 | - semaphore: |
| 5571 | name: test-semaphore |
| 5572 | max: 2 |
| 5573 | """) |
| 5574 | |
| 5575 | in_repo_playbook = textwrap.dedent( |
| 5576 | """ |
| 5577 | - hosts: all |
| 5578 | tasks: [] |
| 5579 | """) |
| 5580 | |
| 5581 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5582 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5583 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5584 | files=file_dict) |
| 5585 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5586 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5587 | B.setDependsOn(A, 1) |
| 5588 | C.setDependsOn(A, 1) |
| 5589 | |
| 5590 | self.executor_server.hold_jobs_in_build = True |
| 5591 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5592 | A.addApproval('Code-Review', 2) |
| 5593 | B.addApproval('Code-Review', 2) |
| 5594 | C.addApproval('Code-Review', 2) |
| 5595 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5596 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5597 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5598 | self.waitUntilSettled() |
| 5599 | |
| 5600 | # check that the layout in a queue item still has max value of 1 |
| 5601 | # for test-semaphore |
| 5602 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5603 | queue = None |
| 5604 | for queue_candidate in pipeline.queues: |
| 5605 | if queue_candidate.name == 'org/project': |
| 5606 | queue = queue_candidate |
| 5607 | break |
| 5608 | queue_item = queue.queue[0] |
James E. Blair | 29a24fd | 2017-10-02 15:04:56 -0700 | [diff] [blame] | 5609 | item_dynamic_layout = queue_item.layout |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5610 | dynamic_test_semaphore = \ |
| 5611 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5612 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5613 | |
| 5614 | # one build must be in queue, one semaphores acquired |
| 5615 | self.assertEqual(len(self.builds), 1) |
| 5616 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5617 | self.assertTrue('test-semaphore' in |
| 5618 | tenant.semaphore_handler.semaphores) |
| 5619 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5620 | 'test-semaphore', [])), 1) |
| 5621 | |
| 5622 | self.executor_server.release('project-test2') |
| 5623 | self.waitUntilSettled() |
| 5624 | |
| 5625 | # change A must be merged |
| 5626 | self.assertEqual(A.data['status'], 'MERGED') |
| 5627 | self.assertEqual(A.reported, 2) |
| 5628 | |
| 5629 | # send change-merged event as the gerrit mock doesn't send it |
| 5630 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5631 | self.waitUntilSettled() |
| 5632 | |
| 5633 | # now that change A was merged, the new semaphore max must be effective |
| 5634 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5635 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5636 | |
| 5637 | # two builds must be in queue, two semaphores acquired |
| 5638 | self.assertEqual(len(self.builds), 2) |
| 5639 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5640 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5641 | self.assertTrue('test-semaphore' in |
| 5642 | tenant.semaphore_handler.semaphores) |
| 5643 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5644 | 'test-semaphore', [])), 2) |
| 5645 | |
| 5646 | self.executor_server.release('project-test2') |
| 5647 | self.waitUntilSettled() |
| 5648 | |
| 5649 | self.assertEqual(len(self.builds), 0) |
| 5650 | self.assertFalse('test-semaphore' in |
| 5651 | tenant.semaphore_handler.semaphores) |
| 5652 | |
| 5653 | self.executor_server.hold_jobs_in_build = False |
| 5654 | self.executor_server.release() |
| 5655 | |
| 5656 | self.waitUntilSettled() |
| 5657 | self.assertEqual(len(self.builds), 0) |
| 5658 | |
| 5659 | self.assertEqual(A.reported, 2) |
| 5660 | self.assertEqual(B.reported, 2) |
| 5661 | self.assertEqual(C.reported, 2) |
David Shrewsbury | f6dc176 | 2017-10-02 13:34:37 -0400 | [diff] [blame] | 5662 | |
| 5663 | |
| 5664 | class TestSchedulerBranchMatcher(ZuulTestCase): |
| 5665 | |
| 5666 | @simple_layout('layouts/matcher-test.yaml') |
| 5667 | def test_job_branch_ignored(self): |
| 5668 | ''' |
| 5669 | Test that branch matching logic works. |
| 5670 | |
| 5671 | The 'ignore-branch' job has a branch matcher that is supposed to |
| 5672 | match every branch except for the 'featureA' branch, so it should |
| 5673 | not be run on a change to that branch. |
| 5674 | ''' |
| 5675 | self.create_branch('org/project', 'featureA') |
| 5676 | A = self.fake_gerrit.addFakeChange('org/project', 'featureA', 'A') |
| 5677 | A.addApproval('Code-Review', 2) |
| 5678 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5679 | self.waitUntilSettled() |
| 5680 | self.printHistory() |
| 5681 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5682 | 'SUCCESS') |
| 5683 | self.assertJobNotInHistory('ignore-branch') |
| 5684 | self.assertEqual(A.data['status'], 'MERGED') |
| 5685 | self.assertEqual(A.reported, 2, |
| 5686 | "A should report start and success") |
| 5687 | self.assertIn('gate', A.messages[1], |
| 5688 | "A should transit gate") |