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 |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -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 |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 28 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 29 | import testtools |
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 |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 32 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 33 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 34 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 35 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 36 | from tests.base import ( |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | ZuulTestCase, |
| 38 | repack_repo, |
| 39 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 40 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 41 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 42 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 43 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 44 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 45 | def test_jobs_executed(self): |
| 46 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 47 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 48 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 49 | A.addApproval('code-review', 2) |
| 50 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 51 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 52 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 53 | 'SUCCESS') |
| 54 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 55 | 'SUCCESS') |
| 56 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 57 | 'SUCCESS') |
| 58 | self.assertEqual(A.data['status'], 'MERGED') |
| 59 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 60 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 61 | 'image1') |
Adam Gandelman | eace469 | 2017-02-07 15:18:36 -0800 | [diff] [blame] | 62 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 63 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 64 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 65 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 66 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 67 | value='1|g') |
| 68 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 69 | kind='ms') |
| 70 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 71 | value='1|c') |
| 72 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 73 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 74 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 75 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 76 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 77 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 78 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 79 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 80 | for build in self.builds: |
| 81 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 82 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 83 | def test_initial_pipeline_gauges(self): |
| 84 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 85 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 86 | value='0|g') |
| 87 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 88 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 89 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 90 | def test_job_branch(self): |
| 91 | "Test the correct variant of a job runs on a branch" |
| 92 | self.create_branch('org/project', 'stable') |
| 93 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 94 | A.addApproval('code-review', 2) |
| 95 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 96 | self.waitUntilSettled() |
| 97 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 98 | 'SUCCESS') |
| 99 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 100 | 'SUCCESS') |
| 101 | self.assertEqual(A.data['status'], 'MERGED') |
| 102 | self.assertEqual(A.reported, 2, |
| 103 | "A should report start and success") |
| 104 | self.assertIn('gate', A.messages[1], |
| 105 | "A should transit gate") |
| 106 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 107 | 'image2') |
| 108 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 109 | def test_parallel_changes(self): |
| 110 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 111 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 112 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 113 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 114 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 115 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 116 | A.addApproval('code-review', 2) |
| 117 | B.addApproval('code-review', 2) |
| 118 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 119 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 120 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 121 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 122 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 123 | |
| 124 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 125 | self.assertEqual(len(self.builds), 1) |
| 126 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 127 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 128 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 129 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 130 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 131 | self.assertEqual(len(self.builds), 3) |
| 132 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 133 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 134 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 135 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 136 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 137 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 138 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 139 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 140 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 141 | self.assertEqual(len(self.builds), 5) |
| 142 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 143 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 144 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 145 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 146 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 147 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 148 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 149 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 150 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 151 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 152 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 153 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 154 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 155 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 156 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 157 | self.assertEqual(len(self.builds), 6) |
| 158 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 159 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 160 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 161 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 162 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 163 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 164 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 165 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 166 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 167 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 168 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 169 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 170 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 171 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 172 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 173 | self.executor_server.hold_jobs_in_build = False |
| 174 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 175 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 176 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 177 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 178 | self.assertEqual(len(self.history), 9) |
| 179 | self.assertEqual(A.data['status'], 'MERGED') |
| 180 | self.assertEqual(B.data['status'], 'MERGED') |
| 181 | self.assertEqual(C.data['status'], 'MERGED') |
| 182 | self.assertEqual(A.reported, 2) |
| 183 | self.assertEqual(B.reported, 2) |
| 184 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 185 | |
| 186 | def test_failed_changes(self): |
| 187 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 188 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 189 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 190 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 191 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 192 | A.addApproval('code-review', 2) |
| 193 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 194 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 195 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 196 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 197 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 198 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 199 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 200 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 201 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 202 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 203 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 204 | # A/project-merge is complete |
| 205 | self.assertBuilds([ |
| 206 | dict(name='project-test1', changes='1,1'), |
| 207 | dict(name='project-test2', changes='1,1'), |
| 208 | dict(name='project-merge', changes='1,1 2,1'), |
| 209 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 210 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 211 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 212 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 213 | # A/project-merge is complete |
| 214 | # B/project-merge is complete |
| 215 | self.assertBuilds([ |
| 216 | dict(name='project-test1', changes='1,1'), |
| 217 | dict(name='project-test2', changes='1,1'), |
| 218 | dict(name='project-test1', changes='1,1 2,1'), |
| 219 | dict(name='project-test2', changes='1,1 2,1'), |
| 220 | ]) |
| 221 | |
| 222 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 223 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 224 | self.builds[0].release() |
| 225 | self.waitUntilSettled() |
| 226 | |
| 227 | self.orderedRelease() |
| 228 | self.assertHistory([ |
| 229 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 230 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 231 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 232 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 233 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 234 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 235 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 236 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 237 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 238 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 239 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 240 | self.assertEqual(A.data['status'], 'NEW') |
| 241 | self.assertEqual(B.data['status'], 'MERGED') |
| 242 | self.assertEqual(A.reported, 2) |
| 243 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 244 | |
| 245 | def test_independent_queues(self): |
| 246 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 247 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 248 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 249 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 250 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 251 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 252 | A.addApproval('code-review', 2) |
| 253 | B.addApproval('code-review', 2) |
| 254 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 255 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 256 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 257 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 258 | |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 259 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 260 | self.waitUntilSettled() |
| 261 | |
| 262 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 263 | self.waitUntilSettled() |
| 264 | |
| 265 | # 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] | 266 | self.assertBuilds([ |
| 267 | dict(name='project-merge', changes='1,1'), |
| 268 | dict(name='project-merge', changes='2,1'), |
| 269 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 270 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 271 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 272 | self.builds[0].release() |
| 273 | self.waitUntilSettled() |
| 274 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 275 | self.waitUntilSettled() |
| 276 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 277 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 278 | self.waitUntilSettled() |
| 279 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 280 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 281 | self.assertBuilds([ |
| 282 | dict(name='project-test1', changes='1,1'), |
| 283 | dict(name='project-test2', changes='1,1'), |
| 284 | dict(name='project-test1', changes='2,1'), |
| 285 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 286 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 287 | dict(name='project-test1', changes='2,1 3,1'), |
| 288 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 289 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 290 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 291 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 292 | self.orderedRelease() |
| 293 | self.assertHistory([ |
| 294 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 295 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 296 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 297 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 298 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 299 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 300 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 301 | dict( |
| 302 | name='project1-project2-integration', |
| 303 | result='SUCCESS', |
| 304 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 305 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 306 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 307 | dict(name='project1-project2-integration', |
| 308 | result='SUCCESS', |
| 309 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 310 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 311 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 312 | self.assertEqual(A.data['status'], 'MERGED') |
| 313 | self.assertEqual(B.data['status'], 'MERGED') |
| 314 | self.assertEqual(C.data['status'], 'MERGED') |
| 315 | self.assertEqual(A.reported, 2) |
| 316 | self.assertEqual(B.reported, 2) |
| 317 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 318 | |
| 319 | def test_failed_change_at_head(self): |
| 320 | "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] | 321 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 322 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 323 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 324 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 325 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 326 | A.addApproval('code-review', 2) |
| 327 | B.addApproval('code-review', 2) |
| 328 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 329 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 330 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 331 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 332 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 333 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 334 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 335 | |
| 336 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 337 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 338 | self.assertBuilds([ |
| 339 | dict(name='project-merge', changes='1,1'), |
| 340 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 341 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 342 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 343 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 344 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 345 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 346 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 347 | self.waitUntilSettled() |
| 348 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 349 | self.assertBuilds([ |
| 350 | dict(name='project-test1', changes='1,1'), |
| 351 | dict(name='project-test2', changes='1,1'), |
| 352 | dict(name='project-test1', changes='1,1 2,1'), |
| 353 | dict(name='project-test2', changes='1,1 2,1'), |
| 354 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 355 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 356 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 357 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 358 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 359 | self.waitUntilSettled() |
| 360 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 361 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 362 | self.assertBuilds([ |
| 363 | dict(name='project-test2', changes='1,1'), |
| 364 | dict(name='project-merge', changes='2,1'), |
| 365 | ]) |
| 366 | # Unordered history comparison because the aborts can finish |
| 367 | # in any order. |
| 368 | self.assertHistory([ |
| 369 | dict(name='project-merge', result='SUCCESS', |
| 370 | changes='1,1'), |
| 371 | dict(name='project-merge', result='SUCCESS', |
| 372 | changes='1,1 2,1'), |
| 373 | dict(name='project-merge', result='SUCCESS', |
| 374 | changes='1,1 2,1 3,1'), |
| 375 | dict(name='project-test1', result='FAILURE', |
| 376 | changes='1,1'), |
| 377 | dict(name='project-test1', result='ABORTED', |
| 378 | changes='1,1 2,1'), |
| 379 | dict(name='project-test2', result='ABORTED', |
| 380 | changes='1,1 2,1'), |
| 381 | dict(name='project-test1', result='ABORTED', |
| 382 | changes='1,1 2,1 3,1'), |
| 383 | dict(name='project-test2', result='ABORTED', |
| 384 | changes='1,1 2,1 3,1'), |
| 385 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 386 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 387 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 388 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 389 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 390 | self.waitUntilSettled() |
| 391 | self.orderedRelease() |
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 | self.assertHistory([ |
| 395 | dict(name='project-merge', result='SUCCESS', |
| 396 | changes='1,1'), |
| 397 | dict(name='project-merge', result='SUCCESS', |
| 398 | changes='1,1 2,1'), |
| 399 | dict(name='project-merge', result='SUCCESS', |
| 400 | changes='1,1 2,1 3,1'), |
| 401 | dict(name='project-test1', result='FAILURE', |
| 402 | changes='1,1'), |
| 403 | dict(name='project-test1', result='ABORTED', |
| 404 | changes='1,1 2,1'), |
| 405 | dict(name='project-test2', result='ABORTED', |
| 406 | changes='1,1 2,1'), |
| 407 | dict(name='project-test1', result='ABORTED', |
| 408 | changes='1,1 2,1 3,1'), |
| 409 | dict(name='project-test2', result='ABORTED', |
| 410 | changes='1,1 2,1 3,1'), |
| 411 | dict(name='project-merge', result='SUCCESS', |
| 412 | changes='2,1'), |
| 413 | dict(name='project-merge', result='SUCCESS', |
| 414 | changes='2,1 3,1'), |
| 415 | dict(name='project-test2', result='SUCCESS', |
| 416 | changes='1,1'), |
| 417 | dict(name='project-test1', result='SUCCESS', |
| 418 | changes='2,1'), |
| 419 | dict(name='project-test2', result='SUCCESS', |
| 420 | changes='2,1'), |
| 421 | dict(name='project-test1', result='SUCCESS', |
| 422 | changes='2,1 3,1'), |
| 423 | dict(name='project-test2', result='SUCCESS', |
| 424 | changes='2,1 3,1'), |
| 425 | ], ordered=False) |
| 426 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 427 | self.assertEqual(A.data['status'], 'NEW') |
| 428 | self.assertEqual(B.data['status'], 'MERGED') |
| 429 | self.assertEqual(C.data['status'], 'MERGED') |
| 430 | self.assertEqual(A.reported, 2) |
| 431 | self.assertEqual(B.reported, 2) |
| 432 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 433 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 434 | def test_failed_change_in_middle(self): |
| 435 | "Test a failed change in the middle of the queue" |
| 436 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 437 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 438 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 439 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 440 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 441 | A.addApproval('code-review', 2) |
| 442 | B.addApproval('code-review', 2) |
| 443 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 444 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 445 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 446 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 447 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 448 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 449 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 450 | |
| 451 | self.waitUntilSettled() |
| 452 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 453 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 454 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 455 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 456 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 457 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 458 | self.waitUntilSettled() |
| 459 | |
| 460 | self.assertEqual(len(self.builds), 6) |
| 461 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 462 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 463 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 464 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 465 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 466 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 467 | |
| 468 | self.release(self.builds[2]) |
| 469 | self.waitUntilSettled() |
| 470 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 471 | # project-test1 and project-test2 for A |
| 472 | # project-test2 for B |
| 473 | # project-merge for C (without B) |
| 474 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 475 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 476 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 477 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 478 | self.waitUntilSettled() |
| 479 | |
| 480 | # project-test1 and project-test2 for A |
| 481 | # project-test2 for B |
| 482 | # project-test1 and project-test2 for C |
| 483 | self.assertEqual(len(self.builds), 5) |
| 484 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 485 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 486 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 487 | builds = items[0].current_build_set.getBuilds() |
| 488 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 489 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 490 | builds = items[1].current_build_set.getBuilds() |
| 491 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 492 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 493 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 494 | builds = items[2].current_build_set.getBuilds() |
| 495 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 496 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 497 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 498 | self.executor_server.hold_jobs_in_build = False |
| 499 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 500 | self.waitUntilSettled() |
| 501 | |
| 502 | self.assertEqual(len(self.builds), 0) |
| 503 | self.assertEqual(len(self.history), 12) |
| 504 | self.assertEqual(A.data['status'], 'MERGED') |
| 505 | self.assertEqual(B.data['status'], 'NEW') |
| 506 | self.assertEqual(C.data['status'], 'MERGED') |
| 507 | self.assertEqual(A.reported, 2) |
| 508 | self.assertEqual(B.reported, 2) |
| 509 | self.assertEqual(C.reported, 2) |
| 510 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 511 | def test_failed_change_at_head_with_queue(self): |
| 512 | "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] | 513 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 514 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 515 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 516 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 517 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 518 | A.addApproval('code-review', 2) |
| 519 | B.addApproval('code-review', 2) |
| 520 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 521 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 522 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 523 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 524 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 525 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 526 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 527 | |
| 528 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 529 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 530 | self.assertEqual(len(self.builds), 0) |
| 531 | self.assertEqual(len(queue), 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 532 | self.assertEqual(queue[0].name, 'executor:execute') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 533 | job_args = json.loads(queue[0].arguments) |
| 534 | self.assertEqual(job_args['job'], 'project-merge') |
| 535 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 536 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 537 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 538 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 539 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 540 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 541 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 542 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 543 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 544 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 545 | self.assertEqual(len(self.builds), 0) |
| 546 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 547 | |
| 548 | self.assertEqual( |
| 549 | json.loads(queue[0].arguments)['job'], 'project-test1') |
| 550 | self.assertEqual( |
| 551 | json.loads(queue[1].arguments)['job'], 'project-test2') |
| 552 | self.assertEqual( |
| 553 | json.loads(queue[2].arguments)['job'], 'project-test1') |
| 554 | self.assertEqual( |
| 555 | json.loads(queue[3].arguments)['job'], 'project-test2') |
| 556 | self.assertEqual( |
| 557 | json.loads(queue[4].arguments)['job'], 'project-test1') |
| 558 | self.assertEqual( |
| 559 | json.loads(queue[5].arguments)['job'], 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 560 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 561 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 562 | self.waitUntilSettled() |
| 563 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 564 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 565 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 566 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 567 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
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 = False |
| 570 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 571 | self.waitUntilSettled() |
| 572 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 573 | self.assertEqual(len(self.builds), 0) |
| 574 | self.assertEqual(len(self.history), 11) |
| 575 | self.assertEqual(A.data['status'], 'NEW') |
| 576 | self.assertEqual(B.data['status'], 'MERGED') |
| 577 | self.assertEqual(C.data['status'], 'MERGED') |
| 578 | self.assertEqual(A.reported, 2) |
| 579 | self.assertEqual(B.reported, 2) |
| 580 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 581 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 582 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 583 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 584 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 585 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 586 | A.addApproval('code-review', 2) |
| 587 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 588 | self.waitUntilSettled() |
| 589 | time.sleep(2) |
| 590 | |
| 591 | data = json.loads(self.sched.formatStatusJSON()) |
| 592 | found_job = None |
| 593 | for pipeline in data['pipelines']: |
| 594 | if pipeline['name'] != 'gate': |
| 595 | continue |
| 596 | for queue in pipeline['change_queues']: |
| 597 | for head in queue['heads']: |
| 598 | for item in head: |
| 599 | for job in item['jobs']: |
| 600 | if job['name'] == 'project-merge': |
| 601 | found_job = job |
| 602 | break |
| 603 | |
| 604 | self.assertIsNotNone(found_job) |
| 605 | if iteration == 1: |
| 606 | self.assertIsNotNone(found_job['estimated_time']) |
| 607 | self.assertIsNone(found_job['remaining_time']) |
| 608 | else: |
| 609 | self.assertIsNotNone(found_job['estimated_time']) |
| 610 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 611 | self.assertIsNotNone(found_job['remaining_time']) |
| 612 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 613 | self.executor_server.hold_jobs_in_build = False |
| 614 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 615 | self.waitUntilSettled() |
| 616 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 617 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 618 | def test_time_database(self): |
| 619 | "Test the time database" |
| 620 | |
| 621 | self._test_time_database(1) |
| 622 | self._test_time_database(2) |
| 623 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 624 | def test_two_failed_changes_at_head(self): |
| 625 | "Test that changes are reparented correctly if 2 fail at head" |
| 626 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 627 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 628 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 629 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 630 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 631 | A.addApproval('code-review', 2) |
| 632 | B.addApproval('code-review', 2) |
| 633 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 634 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 635 | self.executor_server.failJob('project-test1', A) |
| 636 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 637 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 638 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 639 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 640 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 641 | self.waitUntilSettled() |
| 642 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 643 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 644 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 645 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 646 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 647 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 648 | self.waitUntilSettled() |
| 649 | |
| 650 | self.assertEqual(len(self.builds), 6) |
| 651 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 652 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 653 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 654 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 655 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 656 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 657 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 658 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 659 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 660 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 661 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 662 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 663 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 664 | |
| 665 | # Fail change B first |
| 666 | self.release(self.builds[2]) |
| 667 | self.waitUntilSettled() |
| 668 | |
| 669 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 670 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 671 | self.waitUntilSettled() |
| 672 | |
| 673 | self.assertEqual(len(self.builds), 5) |
| 674 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 675 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 676 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 677 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 678 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 679 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 680 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 681 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 682 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 683 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 684 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 685 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 686 | |
| 687 | # Finish running all passing jobs for change A |
| 688 | self.release(self.builds[1]) |
| 689 | self.waitUntilSettled() |
| 690 | # Fail and report change A |
| 691 | self.release(self.builds[0]) |
| 692 | self.waitUntilSettled() |
| 693 | |
| 694 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 695 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 696 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 697 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 698 | self.waitUntilSettled() |
| 699 | |
| 700 | self.assertEqual(len(self.builds), 4) |
| 701 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 702 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 703 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 704 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 705 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 706 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 707 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 708 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 709 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 710 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 711 | # After A failed and B and C restarted, B should be back in |
| 712 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 713 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 714 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 715 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 716 | self.executor_server.hold_jobs_in_build = False |
| 717 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 718 | self.waitUntilSettled() |
| 719 | |
| 720 | self.assertEqual(len(self.builds), 0) |
| 721 | self.assertEqual(len(self.history), 21) |
| 722 | self.assertEqual(A.data['status'], 'NEW') |
| 723 | self.assertEqual(B.data['status'], 'NEW') |
| 724 | self.assertEqual(C.data['status'], 'MERGED') |
| 725 | self.assertEqual(A.reported, 2) |
| 726 | self.assertEqual(B.reported, 2) |
| 727 | self.assertEqual(C.reported, 2) |
| 728 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 729 | def test_patch_order(self): |
| 730 | "Test that dependent patches are tested in the right order" |
| 731 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 732 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 733 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 734 | A.addApproval('code-review', 2) |
| 735 | B.addApproval('code-review', 2) |
| 736 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 737 | |
| 738 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 739 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 740 | M2.setMerged() |
| 741 | M1.setMerged() |
| 742 | |
| 743 | # C -> B -> A -> M1 -> M2 |
| 744 | # M2 is here to make sure it is never queried. If it is, it |
| 745 | # means zuul is walking down the entire history of merged |
| 746 | # changes. |
| 747 | |
| 748 | C.setDependsOn(B, 1) |
| 749 | B.setDependsOn(A, 1) |
| 750 | A.setDependsOn(M1, 1) |
| 751 | M1.setDependsOn(M2, 1) |
| 752 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 753 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 754 | |
| 755 | self.waitUntilSettled() |
| 756 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 757 | self.assertEqual(A.data['status'], 'NEW') |
| 758 | self.assertEqual(B.data['status'], 'NEW') |
| 759 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 760 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 761 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 762 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 763 | |
| 764 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 765 | self.assertEqual(M2.queried, 0) |
| 766 | self.assertEqual(A.data['status'], 'MERGED') |
| 767 | self.assertEqual(B.data['status'], 'MERGED') |
| 768 | self.assertEqual(C.data['status'], 'MERGED') |
| 769 | self.assertEqual(A.reported, 2) |
| 770 | self.assertEqual(B.reported, 2) |
| 771 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 772 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 773 | def test_needed_changes_enqueue(self): |
| 774 | "Test that a needed change is enqueued ahead" |
| 775 | # A Given a git tree like this, if we enqueue |
| 776 | # / \ change C, we should walk up and down the tree |
| 777 | # B G and enqueue changes in the order ABCDEFG. |
| 778 | # /|\ This is also the order that you would get if |
| 779 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 780 | # / the ordering is stable across re-enqueue events. |
| 781 | # D |
| 782 | |
| 783 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 784 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 785 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 786 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 787 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 788 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 789 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 790 | B.setDependsOn(A, 1) |
| 791 | C.setDependsOn(B, 1) |
| 792 | D.setDependsOn(C, 1) |
| 793 | E.setDependsOn(B, 1) |
| 794 | F.setDependsOn(B, 1) |
| 795 | G.setDependsOn(A, 1) |
| 796 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 797 | A.addApproval('code-review', 2) |
| 798 | B.addApproval('code-review', 2) |
| 799 | C.addApproval('code-review', 2) |
| 800 | D.addApproval('code-review', 2) |
| 801 | E.addApproval('code-review', 2) |
| 802 | F.addApproval('code-review', 2) |
| 803 | G.addApproval('code-review', 2) |
| 804 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 805 | |
| 806 | self.waitUntilSettled() |
| 807 | |
| 808 | self.assertEqual(A.data['status'], 'NEW') |
| 809 | self.assertEqual(B.data['status'], 'NEW') |
| 810 | self.assertEqual(C.data['status'], 'NEW') |
| 811 | self.assertEqual(D.data['status'], 'NEW') |
| 812 | self.assertEqual(E.data['status'], 'NEW') |
| 813 | self.assertEqual(F.data['status'], 'NEW') |
| 814 | self.assertEqual(G.data['status'], 'NEW') |
| 815 | |
| 816 | # We're about to add approvals to changes without adding the |
| 817 | # triggering events to Zuul, so that we can be sure that it is |
| 818 | # enqueing the changes based on dependencies, not because of |
| 819 | # triggering events. Since it will have the changes cached |
| 820 | # already (without approvals), we need to clear the cache |
| 821 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 822 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 823 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 824 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 825 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 826 | A.addApproval('approved', 1) |
| 827 | B.addApproval('approved', 1) |
| 828 | D.addApproval('approved', 1) |
| 829 | E.addApproval('approved', 1) |
| 830 | F.addApproval('approved', 1) |
| 831 | G.addApproval('approved', 1) |
| 832 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 833 | |
| 834 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 835 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 836 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 837 | self.executor_server.hold_jobs_in_build = False |
| 838 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 839 | self.waitUntilSettled() |
| 840 | |
| 841 | self.assertEqual(A.data['status'], 'MERGED') |
| 842 | self.assertEqual(B.data['status'], 'MERGED') |
| 843 | self.assertEqual(C.data['status'], 'MERGED') |
| 844 | self.assertEqual(D.data['status'], 'MERGED') |
| 845 | self.assertEqual(E.data['status'], 'MERGED') |
| 846 | self.assertEqual(F.data['status'], 'MERGED') |
| 847 | self.assertEqual(G.data['status'], 'MERGED') |
| 848 | self.assertEqual(A.reported, 2) |
| 849 | self.assertEqual(B.reported, 2) |
| 850 | self.assertEqual(C.reported, 2) |
| 851 | self.assertEqual(D.reported, 2) |
| 852 | self.assertEqual(E.reported, 2) |
| 853 | self.assertEqual(F.reported, 2) |
| 854 | self.assertEqual(G.reported, 2) |
| 855 | self.assertEqual(self.history[6].changes, |
| 856 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 857 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 858 | def test_source_cache(self): |
| 859 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 860 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 861 | |
| 862 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 863 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 864 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 865 | A.addApproval('code-review', 2) |
| 866 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 867 | |
| 868 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 869 | M1.setMerged() |
| 870 | |
| 871 | B.setDependsOn(A, 1) |
| 872 | A.setDependsOn(M1, 1) |
| 873 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 874 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 875 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 876 | |
| 877 | self.waitUntilSettled() |
| 878 | |
| 879 | for build in self.builds: |
| 880 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 881 | build.release() |
| 882 | self.waitUntilSettled() |
| 883 | for build in self.builds: |
| 884 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 885 | build.release() |
| 886 | self.waitUntilSettled() |
| 887 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 888 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 889 | self.waitUntilSettled() |
| 890 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 891 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 892 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 893 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 894 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 895 | self.executor_server.hold_jobs_in_build = False |
| 896 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 897 | self.waitUntilSettled() |
| 898 | |
| 899 | self.assertEqual(A.data['status'], 'MERGED') |
| 900 | self.assertEqual(B.data['status'], 'MERGED') |
| 901 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 902 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 903 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 904 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 905 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 906 | # TODO: move to test_gerrit (this is a unit test!) |
| 907 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 908 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 909 | source = tenant.layout.pipelines['gate'].source |
| 910 | |
| 911 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 912 | # it easier for users to create events for testing. |
| 913 | event = zuul.model.TriggerEvent() |
| 914 | event.trigger_name = 'gerrit' |
| 915 | event.change_number = '1' |
| 916 | event.patch_number = '2' |
| 917 | |
| 918 | a = source.getChange(event) |
| 919 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 920 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 921 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 922 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 923 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 924 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 925 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 926 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 927 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 928 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 929 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 930 | def test_project_merge_conflict(self): |
| 931 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 932 | |
| 933 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 934 | A = self.fake_gerrit.addFakeChange('org/project', |
| 935 | 'master', 'A', |
| 936 | files={'conflict': 'foo'}) |
| 937 | B = self.fake_gerrit.addFakeChange('org/project', |
| 938 | 'master', 'B', |
| 939 | files={'conflict': 'bar'}) |
| 940 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 941 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 942 | A.addApproval('code-review', 2) |
| 943 | B.addApproval('code-review', 2) |
| 944 | C.addApproval('code-review', 2) |
| 945 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 946 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 947 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 948 | self.waitUntilSettled() |
| 949 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 950 | self.assertEqual(A.reported, 1) |
| 951 | self.assertEqual(B.reported, 1) |
| 952 | self.assertEqual(C.reported, 1) |
| 953 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 954 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 955 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 956 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 957 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 958 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 959 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 960 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 961 | self.gearman_server.hold_jobs_in_queue = False |
| 962 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 963 | self.waitUntilSettled() |
| 964 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 965 | self.assertEqual(A.data['status'], 'MERGED') |
| 966 | self.assertEqual(B.data['status'], 'NEW') |
| 967 | self.assertEqual(C.data['status'], 'MERGED') |
| 968 | self.assertEqual(A.reported, 2) |
| 969 | self.assertEqual(B.reported, 2) |
| 970 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 971 | |
| 972 | self.assertHistory([ |
| 973 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 974 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 975 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 976 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 977 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 978 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 979 | ], ordered=False) |
| 980 | |
| 981 | def test_delayed_merge_conflict(self): |
| 982 | "Test that delayed check merge conflicts are handled properly" |
| 983 | |
| 984 | # Hold jobs in the gearman queue so that we can test whether |
| 985 | # the executor returns a merge failure after the scheduler has |
| 986 | # successfully merged. |
| 987 | self.gearman_server.hold_jobs_in_queue = True |
| 988 | A = self.fake_gerrit.addFakeChange('org/project', |
| 989 | 'master', 'A', |
| 990 | files={'conflict': 'foo'}) |
| 991 | B = self.fake_gerrit.addFakeChange('org/project', |
| 992 | 'master', 'B', |
| 993 | files={'conflict': 'bar'}) |
| 994 | C = self.fake_gerrit.addFakeChange('org/project', |
| 995 | 'master', 'C') |
| 996 | C.setDependsOn(B, 1) |
| 997 | |
| 998 | # A enters the gate queue; B and C enter the check queue |
| 999 | A.addApproval('code-review', 2) |
| 1000 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1001 | self.waitUntilSettled() |
| 1002 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1003 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1004 | self.waitUntilSettled() |
| 1005 | |
| 1006 | self.assertEqual(A.reported, 1) |
| 1007 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1008 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1009 | |
| 1010 | # A merges while B and C are queued in check |
| 1011 | # Release A project-merge |
| 1012 | queue = self.gearman_server.getQueue() |
| 1013 | self.release(queue[0]) |
| 1014 | self.waitUntilSettled() |
| 1015 | |
| 1016 | # Release A project-test* |
| 1017 | # gate has higher precedence, so A's test jobs are added in |
| 1018 | # front of the merge jobs for B and C |
| 1019 | queue = self.gearman_server.getQueue() |
| 1020 | self.release(queue[0]) |
| 1021 | self.release(queue[1]) |
| 1022 | self.waitUntilSettled() |
| 1023 | |
| 1024 | self.assertEqual(A.data['status'], 'MERGED') |
| 1025 | self.assertEqual(B.data['status'], 'NEW') |
| 1026 | self.assertEqual(C.data['status'], 'NEW') |
| 1027 | self.assertEqual(A.reported, 2) |
| 1028 | self.assertEqual(B.reported, 0) |
| 1029 | self.assertEqual(C.reported, 0) |
| 1030 | self.assertHistory([ |
| 1031 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1032 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1033 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1034 | ], ordered=False) |
| 1035 | |
| 1036 | # B and C report merge conflicts |
| 1037 | # Release B project-merge |
| 1038 | queue = self.gearman_server.getQueue() |
| 1039 | self.release(queue[0]) |
| 1040 | self.waitUntilSettled() |
| 1041 | |
| 1042 | # Release C |
| 1043 | self.gearman_server.hold_jobs_in_queue = False |
| 1044 | self.gearman_server.release() |
| 1045 | self.waitUntilSettled() |
| 1046 | |
| 1047 | self.assertEqual(A.data['status'], 'MERGED') |
| 1048 | self.assertEqual(B.data['status'], 'NEW') |
| 1049 | self.assertEqual(C.data['status'], 'NEW') |
| 1050 | self.assertEqual(A.reported, 2) |
| 1051 | self.assertEqual(B.reported, 1) |
| 1052 | self.assertEqual(C.reported, 1) |
| 1053 | |
| 1054 | self.assertHistory([ |
| 1055 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1056 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1057 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1058 | dict(name='project-merge', result='MERGER_FAILURE', changes='2,1'), |
| 1059 | dict(name='project-merge', result='MERGER_FAILURE', |
| 1060 | changes='2,1 3,1'), |
| 1061 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1062 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1063 | def test_post(self): |
| 1064 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1065 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1066 | e = { |
| 1067 | "type": "ref-updated", |
| 1068 | "submitter": { |
| 1069 | "name": "User Name", |
| 1070 | }, |
| 1071 | "refUpdate": { |
| 1072 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1073 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1074 | "refName": "master", |
| 1075 | "project": "org/project", |
| 1076 | } |
| 1077 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1078 | self.fake_gerrit.addEvent(e) |
| 1079 | self.waitUntilSettled() |
| 1080 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1081 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1082 | self.assertEqual(len(self.history), 1) |
| 1083 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1084 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1085 | def test_post_ignore_deletes(self): |
| 1086 | "Test that deleting refs does not trigger post jobs" |
| 1087 | |
| 1088 | e = { |
| 1089 | "type": "ref-updated", |
| 1090 | "submitter": { |
| 1091 | "name": "User Name", |
| 1092 | }, |
| 1093 | "refUpdate": { |
| 1094 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1095 | "newRev": "0000000000000000000000000000000000000000", |
| 1096 | "refName": "master", |
| 1097 | "project": "org/project", |
| 1098 | } |
| 1099 | } |
| 1100 | self.fake_gerrit.addEvent(e) |
| 1101 | self.waitUntilSettled() |
| 1102 | |
| 1103 | job_names = [x.name for x in self.history] |
| 1104 | self.assertEqual(len(self.history), 0) |
| 1105 | self.assertNotIn('project-post', job_names) |
| 1106 | |
| 1107 | def test_post_ignore_deletes_negative(self): |
| 1108 | "Test that deleting refs does trigger post jobs" |
| 1109 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1110 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1111 | self.sched.reconfigure(self.config) |
| 1112 | |
| 1113 | e = { |
| 1114 | "type": "ref-updated", |
| 1115 | "submitter": { |
| 1116 | "name": "User Name", |
| 1117 | }, |
| 1118 | "refUpdate": { |
| 1119 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1120 | "newRev": "0000000000000000000000000000000000000000", |
| 1121 | "refName": "master", |
| 1122 | "project": "org/project", |
| 1123 | } |
| 1124 | } |
| 1125 | self.fake_gerrit.addEvent(e) |
| 1126 | self.waitUntilSettled() |
| 1127 | |
| 1128 | job_names = [x.name for x in self.history] |
| 1129 | self.assertEqual(len(self.history), 1) |
| 1130 | self.assertIn('project-post', job_names) |
| 1131 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1132 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1133 | def test_build_configuration_branch_interaction(self): |
| 1134 | "Test that switching between branches works" |
| 1135 | self.test_build_configuration() |
| 1136 | self.test_build_configuration_branch() |
| 1137 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1138 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1139 | repo = git.Repo(path) |
| 1140 | repo.heads.master.commit = repo.commit('init') |
| 1141 | self.test_build_configuration() |
| 1142 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1143 | def test_dependent_changes_dequeue(self): |
| 1144 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1145 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1146 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1147 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1148 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1149 | A.addApproval('code-review', 2) |
| 1150 | B.addApproval('code-review', 2) |
| 1151 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1152 | |
| 1153 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1154 | M1.setMerged() |
| 1155 | |
| 1156 | # C -> B -> A -> M1 |
| 1157 | |
| 1158 | C.setDependsOn(B, 1) |
| 1159 | B.setDependsOn(A, 1) |
| 1160 | A.setDependsOn(M1, 1) |
| 1161 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1162 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1163 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1164 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1165 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1166 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1167 | |
| 1168 | self.waitUntilSettled() |
| 1169 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1170 | self.assertEqual(A.data['status'], 'NEW') |
| 1171 | self.assertEqual(A.reported, 2) |
| 1172 | self.assertEqual(B.data['status'], 'NEW') |
| 1173 | self.assertEqual(B.reported, 2) |
| 1174 | self.assertEqual(C.data['status'], 'NEW') |
| 1175 | self.assertEqual(C.reported, 2) |
| 1176 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1177 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1178 | def test_failing_dependent_changes(self): |
| 1179 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1180 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1181 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1182 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1183 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1184 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1185 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1186 | A.addApproval('code-review', 2) |
| 1187 | B.addApproval('code-review', 2) |
| 1188 | C.addApproval('code-review', 2) |
| 1189 | D.addApproval('code-review', 2) |
| 1190 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1191 | |
| 1192 | # E, D -> C -> B, A |
| 1193 | |
| 1194 | D.setDependsOn(C, 1) |
| 1195 | C.setDependsOn(B, 1) |
| 1196 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1197 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1198 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1199 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1200 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1201 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1202 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1203 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1204 | |
| 1205 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1206 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1207 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1208 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1209 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1210 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1211 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1212 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1213 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1214 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1215 | self.waitUntilSettled() |
| 1216 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1217 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1218 | for build in self.builds: |
| 1219 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1220 | build.release() |
| 1221 | self.waitUntilSettled() |
| 1222 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1223 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1224 | self.waitUntilSettled() |
| 1225 | |
| 1226 | self.assertEqual(A.data['status'], 'MERGED') |
| 1227 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1228 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1229 | self.assertEqual(B.data['status'], 'NEW') |
| 1230 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1231 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1232 | self.assertEqual(C.data['status'], 'NEW') |
| 1233 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1234 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1235 | self.assertEqual(D.data['status'], 'NEW') |
| 1236 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1237 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1238 | self.assertEqual(E.data['status'], 'MERGED') |
| 1239 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1240 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1241 | self.assertEqual(len(self.history), 18) |
| 1242 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1243 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1244 | "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] | 1245 | # If it's dequeued more than once, we should see extra |
| 1246 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1247 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1248 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1249 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1250 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1251 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1252 | A.addApproval('code-review', 2) |
| 1253 | B.addApproval('code-review', 2) |
| 1254 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1255 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1256 | self.executor_server.failJob('project-test1', A) |
| 1257 | self.executor_server.failJob('project-test2', A) |
| 1258 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1259 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1260 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1261 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1262 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1263 | |
| 1264 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1265 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1266 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1267 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1268 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1269 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1270 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1271 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1272 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1273 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1274 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1275 | self.waitUntilSettled() |
| 1276 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1277 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1278 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1279 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1280 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1281 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1282 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1283 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1284 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1285 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1286 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1287 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1288 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1289 | self.waitUntilSettled() |
| 1290 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1291 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1292 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1293 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1294 | self.executor_server.hold_jobs_in_build = False |
| 1295 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1296 | self.waitUntilSettled() |
| 1297 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1298 | self.assertEqual(len(self.builds), 0) |
| 1299 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1300 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1301 | self.assertEqual(A.data['status'], 'NEW') |
| 1302 | self.assertEqual(B.data['status'], 'MERGED') |
| 1303 | self.assertEqual(C.data['status'], 'MERGED') |
| 1304 | self.assertEqual(A.reported, 2) |
| 1305 | self.assertEqual(B.reported, 2) |
| 1306 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1307 | |
| 1308 | def test_nonvoting_job(self): |
| 1309 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1310 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1311 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1312 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1313 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1314 | self.executor_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1315 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1316 | |
| 1317 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1318 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1319 | self.assertEqual(A.data['status'], 'MERGED') |
| 1320 | self.assertEqual(A.reported, 2) |
| 1321 | self.assertEqual( |
| 1322 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1323 | 'SUCCESS') |
| 1324 | self.assertEqual( |
| 1325 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1326 | 'SUCCESS') |
| 1327 | self.assertEqual( |
| 1328 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1329 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1330 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1331 | for build in self.builds: |
| 1332 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1333 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1334 | def test_check_queue_success(self): |
| 1335 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1336 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1337 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1338 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1339 | |
| 1340 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1341 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1342 | self.assertEqual(A.data['status'], 'NEW') |
| 1343 | self.assertEqual(A.reported, 1) |
| 1344 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1345 | 'SUCCESS') |
| 1346 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1347 | 'SUCCESS') |
| 1348 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1349 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1350 | |
| 1351 | def test_check_queue_failure(self): |
| 1352 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1353 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1354 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1355 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1356 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1357 | |
| 1358 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1359 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1360 | self.assertEqual(A.data['status'], 'NEW') |
| 1361 | self.assertEqual(A.reported, 1) |
| 1362 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1363 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1364 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1365 | 'SUCCESS') |
| 1366 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1367 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1368 | |
| 1369 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1370 | # This particular test does a large amount of merges and needs a little |
| 1371 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1372 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1373 | "test that dependent changes behind dequeued changes work" |
| 1374 | # This complicated test is a reproduction of a real life bug |
| 1375 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1376 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1377 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1378 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1379 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1380 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1381 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1382 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1383 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1384 | D.setDependsOn(C, 1) |
| 1385 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1386 | A.addApproval('code-review', 2) |
| 1387 | B.addApproval('code-review', 2) |
| 1388 | C.addApproval('code-review', 2) |
| 1389 | D.addApproval('code-review', 2) |
| 1390 | E.addApproval('code-review', 2) |
| 1391 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1392 | |
| 1393 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1394 | |
| 1395 | # Change object re-use in the gerrit trigger is hidden if |
| 1396 | # changes are added in quick succession; waiting makes it more |
| 1397 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1398 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1399 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1400 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1401 | self.waitUntilSettled() |
| 1402 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1403 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1404 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1405 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1406 | self.waitUntilSettled() |
| 1407 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1408 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1409 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1410 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1411 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1412 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1413 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1414 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1415 | self.waitUntilSettled() |
| 1416 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1417 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1418 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1419 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1420 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1421 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1422 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1423 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1424 | self.waitUntilSettled() |
| 1425 | |
| 1426 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1427 | |
| 1428 | # Grab pointers to the jobs we want to release before |
| 1429 | # releasing any, because list indexes may change as |
| 1430 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1431 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1432 | a.release() |
| 1433 | b.release() |
| 1434 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1435 | self.waitUntilSettled() |
| 1436 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1437 | self.executor_server.hold_jobs_in_build = False |
| 1438 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1439 | self.waitUntilSettled() |
| 1440 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1441 | self.assertEqual(A.data['status'], 'NEW') |
| 1442 | self.assertEqual(B.data['status'], 'MERGED') |
| 1443 | self.assertEqual(C.data['status'], 'MERGED') |
| 1444 | self.assertEqual(D.data['status'], 'MERGED') |
| 1445 | self.assertEqual(E.data['status'], 'MERGED') |
| 1446 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1447 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1448 | self.assertEqual(A.reported, 2) |
| 1449 | self.assertEqual(B.reported, 2) |
| 1450 | self.assertEqual(C.reported, 2) |
| 1451 | self.assertEqual(D.reported, 2) |
| 1452 | self.assertEqual(E.reported, 2) |
| 1453 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1454 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1455 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1456 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1457 | |
| 1458 | def test_merger_repack(self): |
| 1459 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1460 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1461 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1462 | A.addApproval('code-review', 2) |
| 1463 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1464 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1465 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1466 | 'SUCCESS') |
| 1467 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1468 | 'SUCCESS') |
| 1469 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1470 | 'SUCCESS') |
| 1471 | self.assertEqual(A.data['status'], 'MERGED') |
| 1472 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1473 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1474 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1475 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1476 | path = os.path.join(self.merger_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1477 | if os.path.exists(path): |
| 1478 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1479 | path = os.path.join(self.executor_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1480 | if os.path.exists(path): |
| 1481 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1482 | |
| 1483 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1484 | A.addApproval('code-review', 2) |
| 1485 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1486 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1487 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1488 | 'SUCCESS') |
| 1489 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1490 | 'SUCCESS') |
| 1491 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1492 | 'SUCCESS') |
| 1493 | self.assertEqual(A.data['status'], 'MERGED') |
| 1494 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1495 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1496 | def test_merger_repack_large_change(self): |
| 1497 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1498 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1499 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1500 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1501 | trusted, project = tenant.getProject('org/project1') |
| 1502 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1503 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1504 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1505 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1506 | path = os.path.join(self.upstream_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1507 | repack_repo(path) |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1508 | path = os.path.join(self.merger_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1509 | if os.path.exists(path): |
| 1510 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1511 | path = os.path.join(self.executor_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1512 | if os.path.exists(path): |
| 1513 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1514 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1515 | A.addApproval('code-review', 2) |
| 1516 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1517 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1518 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1519 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1520 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1521 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1522 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1523 | 'SUCCESS') |
| 1524 | self.assertEqual(A.data['status'], 'MERGED') |
| 1525 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1526 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1527 | def test_new_patchset_dequeues_old(self): |
| 1528 | "Test that a new patchset causes the old to be dequeued" |
| 1529 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1530 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1531 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1532 | M.setMerged() |
| 1533 | |
| 1534 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1535 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1536 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1537 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1538 | A.addApproval('code-review', 2) |
| 1539 | B.addApproval('code-review', 2) |
| 1540 | C.addApproval('code-review', 2) |
| 1541 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1542 | |
| 1543 | C.setDependsOn(B, 1) |
| 1544 | B.setDependsOn(A, 1) |
| 1545 | A.setDependsOn(M, 1) |
| 1546 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1547 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1548 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1549 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1550 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1551 | self.waitUntilSettled() |
| 1552 | |
| 1553 | B.addPatchset() |
| 1554 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1555 | self.waitUntilSettled() |
| 1556 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1557 | self.executor_server.hold_jobs_in_build = False |
| 1558 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1559 | self.waitUntilSettled() |
| 1560 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1561 | self.assertEqual(A.data['status'], 'MERGED') |
| 1562 | self.assertEqual(A.reported, 2) |
| 1563 | self.assertEqual(B.data['status'], 'NEW') |
| 1564 | self.assertEqual(B.reported, 2) |
| 1565 | self.assertEqual(C.data['status'], 'NEW') |
| 1566 | self.assertEqual(C.reported, 2) |
| 1567 | self.assertEqual(D.data['status'], 'MERGED') |
| 1568 | self.assertEqual(D.reported, 2) |
| 1569 | 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] | 1570 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1571 | def test_new_patchset_check(self): |
| 1572 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1573 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1574 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1575 | |
| 1576 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1577 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1578 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1579 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1580 | |
| 1581 | # Add two git-dependent changes |
| 1582 | B.setDependsOn(A, 1) |
| 1583 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1584 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1585 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1586 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1587 | |
| 1588 | # A live item, and a non-live/live pair |
| 1589 | items = check_pipeline.getAllItems() |
| 1590 | self.assertEqual(len(items), 3) |
| 1591 | |
| 1592 | self.assertEqual(items[0].change.number, '1') |
| 1593 | self.assertEqual(items[0].change.patchset, '1') |
| 1594 | self.assertFalse(items[0].live) |
| 1595 | |
| 1596 | self.assertEqual(items[1].change.number, '2') |
| 1597 | self.assertEqual(items[1].change.patchset, '1') |
| 1598 | self.assertTrue(items[1].live) |
| 1599 | |
| 1600 | self.assertEqual(items[2].change.number, '1') |
| 1601 | self.assertEqual(items[2].change.patchset, '1') |
| 1602 | self.assertTrue(items[2].live) |
| 1603 | |
| 1604 | # Add a new patchset to A |
| 1605 | A.addPatchset() |
| 1606 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1607 | self.waitUntilSettled() |
| 1608 | |
| 1609 | # The live copy of A,1 should be gone, but the non-live and B |
| 1610 | # should continue, and we should have a new A,2 |
| 1611 | items = check_pipeline.getAllItems() |
| 1612 | self.assertEqual(len(items), 3) |
| 1613 | |
| 1614 | self.assertEqual(items[0].change.number, '1') |
| 1615 | self.assertEqual(items[0].change.patchset, '1') |
| 1616 | self.assertFalse(items[0].live) |
| 1617 | |
| 1618 | self.assertEqual(items[1].change.number, '2') |
| 1619 | self.assertEqual(items[1].change.patchset, '1') |
| 1620 | self.assertTrue(items[1].live) |
| 1621 | |
| 1622 | self.assertEqual(items[2].change.number, '1') |
| 1623 | self.assertEqual(items[2].change.patchset, '2') |
| 1624 | self.assertTrue(items[2].live) |
| 1625 | |
| 1626 | # Add a new patchset to B |
| 1627 | B.addPatchset() |
| 1628 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1629 | self.waitUntilSettled() |
| 1630 | |
| 1631 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1632 | # but we should have a new B,2 (still based on A,1) |
| 1633 | items = check_pipeline.getAllItems() |
| 1634 | self.assertEqual(len(items), 3) |
| 1635 | |
| 1636 | self.assertEqual(items[0].change.number, '1') |
| 1637 | self.assertEqual(items[0].change.patchset, '2') |
| 1638 | self.assertTrue(items[0].live) |
| 1639 | |
| 1640 | self.assertEqual(items[1].change.number, '1') |
| 1641 | self.assertEqual(items[1].change.patchset, '1') |
| 1642 | self.assertFalse(items[1].live) |
| 1643 | |
| 1644 | self.assertEqual(items[2].change.number, '2') |
| 1645 | self.assertEqual(items[2].change.patchset, '2') |
| 1646 | self.assertTrue(items[2].live) |
| 1647 | |
| 1648 | self.builds[0].release() |
| 1649 | self.waitUntilSettled() |
| 1650 | self.builds[0].release() |
| 1651 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1652 | self.executor_server.hold_jobs_in_build = False |
| 1653 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1654 | self.waitUntilSettled() |
| 1655 | |
| 1656 | self.assertEqual(A.reported, 1) |
| 1657 | self.assertEqual(B.reported, 1) |
| 1658 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1659 | self.assertEqual(self.history[0].changes, '1,1') |
| 1660 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1661 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1662 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1663 | self.assertEqual(self.history[2].changes, '1,2') |
| 1664 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1665 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1666 | |
| 1667 | def test_abandoned_gate(self): |
| 1668 | "Test that an abandoned change is dequeued from gate" |
| 1669 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1670 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1671 | |
| 1672 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1673 | A.addApproval('code-review', 2) |
| 1674 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1675 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1676 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1677 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1678 | |
| 1679 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1680 | self.waitUntilSettled() |
| 1681 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1682 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1683 | self.waitUntilSettled() |
| 1684 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1685 | self.assertBuilds([]) |
| 1686 | self.assertHistory([ |
| 1687 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1688 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1689 | self.assertEqual(A.reported, 1, |
| 1690 | "Abandoned gate change should report only start") |
| 1691 | |
| 1692 | def test_abandoned_check(self): |
| 1693 | "Test that an abandoned change is dequeued from check" |
| 1694 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1695 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1696 | |
| 1697 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1698 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1699 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1700 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1701 | |
| 1702 | # Add two git-dependent changes |
| 1703 | B.setDependsOn(A, 1) |
| 1704 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1705 | self.waitUntilSettled() |
| 1706 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1707 | self.waitUntilSettled() |
| 1708 | # A live item, and a non-live/live pair |
| 1709 | items = check_pipeline.getAllItems() |
| 1710 | self.assertEqual(len(items), 3) |
| 1711 | |
| 1712 | self.assertEqual(items[0].change.number, '1') |
| 1713 | self.assertFalse(items[0].live) |
| 1714 | |
| 1715 | self.assertEqual(items[1].change.number, '2') |
| 1716 | self.assertTrue(items[1].live) |
| 1717 | |
| 1718 | self.assertEqual(items[2].change.number, '1') |
| 1719 | self.assertTrue(items[2].live) |
| 1720 | |
| 1721 | # Abandon A |
| 1722 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1723 | self.waitUntilSettled() |
| 1724 | |
| 1725 | # The live copy of A should be gone, but the non-live and B |
| 1726 | # should continue |
| 1727 | items = check_pipeline.getAllItems() |
| 1728 | self.assertEqual(len(items), 2) |
| 1729 | |
| 1730 | self.assertEqual(items[0].change.number, '1') |
| 1731 | self.assertFalse(items[0].live) |
| 1732 | |
| 1733 | self.assertEqual(items[1].change.number, '2') |
| 1734 | self.assertTrue(items[1].live) |
| 1735 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1736 | self.executor_server.hold_jobs_in_build = False |
| 1737 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1738 | self.waitUntilSettled() |
| 1739 | |
| 1740 | self.assertEqual(len(self.history), 4) |
| 1741 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1742 | 'Build should have been aborted') |
| 1743 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1744 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1745 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1746 | def test_abandoned_not_timer(self): |
| 1747 | "Test that an abandoned change does not cancel timer jobs" |
| 1748 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1749 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1750 | |
| 1751 | # Start timer trigger - also org/project |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1752 | self.updateConfigLayout('layout-idle') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1753 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1754 | # The pipeline triggers every second, so we should have seen |
| 1755 | # several by now. |
| 1756 | time.sleep(5) |
| 1757 | self.waitUntilSettled() |
| 1758 | # Stop queuing timer triggered jobs so that the assertions |
| 1759 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1760 | # Must be in same repo, so overwrite config with another one |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 1761 | self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1762 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1763 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1764 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1765 | |
| 1766 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1767 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1768 | self.waitUntilSettled() |
| 1769 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1770 | |
| 1771 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1772 | self.waitUntilSettled() |
| 1773 | |
| 1774 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1775 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1776 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1777 | self.waitUntilSettled() |
| 1778 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1779 | def test_zuul_url_return(self): |
| 1780 | "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf" |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1781 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1782 | self.executor_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1783 | |
| 1784 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1785 | A.addApproval('code-review', 2) |
| 1786 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1787 | self.waitUntilSettled() |
| 1788 | |
| 1789 | self.assertEqual(len(self.builds), 1) |
| 1790 | for build in self.builds: |
| 1791 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1792 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1793 | self.executor_server.hold_jobs_in_build = False |
| 1794 | self.executor_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1795 | self.waitUntilSettled() |
| 1796 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1797 | def test_new_patchset_dequeues_old_on_head(self): |
| 1798 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1799 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1800 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1801 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1802 | M.setMerged() |
| 1803 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1804 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1805 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1806 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1807 | A.addApproval('code-review', 2) |
| 1808 | B.addApproval('code-review', 2) |
| 1809 | C.addApproval('code-review', 2) |
| 1810 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1811 | |
| 1812 | C.setDependsOn(B, 1) |
| 1813 | B.setDependsOn(A, 1) |
| 1814 | A.setDependsOn(M, 1) |
| 1815 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1816 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1817 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1818 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1819 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1820 | self.waitUntilSettled() |
| 1821 | |
| 1822 | A.addPatchset() |
| 1823 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1824 | self.waitUntilSettled() |
| 1825 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1826 | self.executor_server.hold_jobs_in_build = False |
| 1827 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1828 | self.waitUntilSettled() |
| 1829 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1830 | self.assertEqual(A.data['status'], 'NEW') |
| 1831 | self.assertEqual(A.reported, 2) |
| 1832 | self.assertEqual(B.data['status'], 'NEW') |
| 1833 | self.assertEqual(B.reported, 2) |
| 1834 | self.assertEqual(C.data['status'], 'NEW') |
| 1835 | self.assertEqual(C.reported, 2) |
| 1836 | self.assertEqual(D.data['status'], 'MERGED') |
| 1837 | self.assertEqual(D.reported, 2) |
| 1838 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1839 | |
| 1840 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1841 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1842 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1843 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1844 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1845 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1846 | A.addApproval('code-review', 2) |
| 1847 | B.addApproval('code-review', 2) |
| 1848 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1849 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1850 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1851 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1852 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1853 | self.waitUntilSettled() |
| 1854 | |
| 1855 | B.addPatchset() |
| 1856 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1857 | self.waitUntilSettled() |
| 1858 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1859 | self.executor_server.hold_jobs_in_build = False |
| 1860 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1861 | self.waitUntilSettled() |
| 1862 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1863 | self.assertEqual(A.data['status'], 'MERGED') |
| 1864 | self.assertEqual(A.reported, 2) |
| 1865 | self.assertEqual(B.data['status'], 'NEW') |
| 1866 | self.assertEqual(B.reported, 2) |
| 1867 | self.assertEqual(C.data['status'], 'MERGED') |
| 1868 | self.assertEqual(C.reported, 2) |
| 1869 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1870 | |
| 1871 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1872 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1873 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1874 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1875 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1876 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1877 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1878 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1879 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1880 | self.waitUntilSettled() |
| 1881 | |
| 1882 | B.addPatchset() |
| 1883 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1884 | self.waitUntilSettled() |
| 1885 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1886 | self.executor_server.hold_jobs_in_build = False |
| 1887 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1888 | self.waitUntilSettled() |
| 1889 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1890 | self.assertEqual(A.data['status'], 'NEW') |
| 1891 | self.assertEqual(A.reported, 1) |
| 1892 | self.assertEqual(B.data['status'], 'NEW') |
| 1893 | self.assertEqual(B.reported, 1) |
| 1894 | self.assertEqual(C.data['status'], 'NEW') |
| 1895 | self.assertEqual(C.reported, 1) |
| 1896 | self.assertEqual(len(self.history), 10) |
| 1897 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1898 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1899 | def test_noop_job(self): |
| 1900 | "Test that the internal noop job works" |
| 1901 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1902 | A.addApproval('code-review', 2) |
| 1903 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1904 | self.waitUntilSettled() |
| 1905 | |
| 1906 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1907 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1908 | self.assertEqual(len(self.history), 0) |
| 1909 | self.assertEqual(A.data['status'], 'MERGED') |
| 1910 | self.assertEqual(A.reported, 2) |
| 1911 | |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1912 | def test_no_job_project(self): |
| 1913 | "Test that reports with no jobs don't get sent" |
| 1914 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1915 | 'master', 'A') |
| 1916 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1917 | self.waitUntilSettled() |
| 1918 | |
| 1919 | # Change wasn't reported to |
| 1920 | self.assertEqual(A.reported, False) |
| 1921 | |
| 1922 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1923 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1924 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1925 | items = check_pipeline.getAllItems() |
| 1926 | self.assertEqual(len(items), 0) |
| 1927 | |
| 1928 | self.assertEqual(len(self.history), 0) |
| 1929 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1930 | def test_zuul_refs(self): |
| 1931 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1932 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1933 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1934 | M1.setMerged() |
| 1935 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1936 | M2.setMerged() |
| 1937 | |
| 1938 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1939 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1940 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1941 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1942 | A.addApproval('code-review', 2) |
| 1943 | B.addApproval('code-review', 2) |
| 1944 | C.addApproval('code-review', 2) |
| 1945 | D.addApproval('code-review', 2) |
| 1946 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1947 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1948 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1949 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1950 | |
| 1951 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1952 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1953 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1954 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1955 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1956 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1957 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1958 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1959 | self.waitUntilSettled() |
| 1960 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1961 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1962 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1963 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1964 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1965 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1966 | a_build = x |
| 1967 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1968 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1969 | b_build = x |
| 1970 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1971 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1972 | c_build = x |
| 1973 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1974 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1975 | d_build = x |
| 1976 | if a_build and b_build and c_build and d_build: |
| 1977 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1978 | |
| 1979 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1980 | self.assertIsNotNone(a_zref) |
| 1981 | self.assertIsNotNone(b_zref) |
| 1982 | self.assertIsNotNone(c_zref) |
| 1983 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1984 | |
| 1985 | # And they should all be different |
| 1986 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1987 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1988 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1989 | # should have a, not b, and should not be in project2 |
| 1990 | self.assertTrue(a_build.hasChanges(A)) |
| 1991 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1992 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1993 | # should have a and b, and should not be in project2 |
| 1994 | self.assertTrue(b_build.hasChanges(A, B)) |
| 1995 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1996 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1997 | # should have a and b in 1, c in 2 |
| 1998 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 1999 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2000 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2001 | # should have a and b in 1, c and d in 2 |
| 2002 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2003 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2004 | self.executor_server.hold_jobs_in_build = False |
| 2005 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2006 | self.waitUntilSettled() |
| 2007 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2008 | self.assertEqual(A.data['status'], 'MERGED') |
| 2009 | self.assertEqual(A.reported, 2) |
| 2010 | self.assertEqual(B.data['status'], 'MERGED') |
| 2011 | self.assertEqual(B.reported, 2) |
| 2012 | self.assertEqual(C.data['status'], 'MERGED') |
| 2013 | self.assertEqual(C.reported, 2) |
| 2014 | self.assertEqual(D.data['status'], 'MERGED') |
| 2015 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2016 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2017 | def test_rerun_on_error(self): |
| 2018 | "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] | 2019 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2020 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2021 | A.addApproval('code-review', 2) |
| 2022 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2023 | self.waitUntilSettled() |
| 2024 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2025 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2026 | self.executor_server.hold_jobs_in_build = False |
| 2027 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2028 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2029 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2030 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2031 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2032 | def test_statsd(self): |
| 2033 | "Test each of the statsd methods used in the scheduler" |
| 2034 | import extras |
| 2035 | statsd = extras.try_import('statsd.statsd') |
| 2036 | statsd.incr('test-incr') |
| 2037 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2038 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2039 | self.assertReportedStat('test-incr', '1|c') |
| 2040 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2041 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2042 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2043 | def test_stuck_job_cleanup(self): |
| 2044 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2045 | |
| 2046 | # 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] | 2047 | self.gearman_server.hold_jobs_in_queue = True |
| 2048 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2049 | A.addApproval('code-review', 2) |
| 2050 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2051 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2052 | # 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] | 2053 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2054 | |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2055 | self.commitLayoutUpdate('common-config', 'layout-no-jobs') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2056 | self.sched.reconfigure(self.config) |
| 2057 | self.waitUntilSettled() |
| 2058 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2059 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2060 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2061 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2062 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2063 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2064 | |
| 2065 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2066 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2067 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2068 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2069 | def test_file_head(self): |
| 2070 | # This is a regression test for an observed bug. A change |
| 2071 | # with a file named "HEAD" in the root directory of the repo |
| 2072 | # was processed by a merger. It then was unable to reset the |
| 2073 | # repo because of: |
| 2074 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2075 | # with exit code 128 |
| 2076 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2077 | # and filename |
| 2078 | # Use '--' to separate filenames from revisions' |
| 2079 | |
| 2080 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2081 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2082 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2083 | |
| 2084 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2085 | self.waitUntilSettled() |
| 2086 | |
| 2087 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2088 | self.waitUntilSettled() |
| 2089 | |
| 2090 | self.assertIn('Build succeeded', A.messages[0]) |
| 2091 | self.assertIn('Build succeeded', B.messages[0]) |
| 2092 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2093 | def test_file_jobs(self): |
| 2094 | "Test that file jobs run only when appropriate" |
| 2095 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2096 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2097 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2098 | A.addApproval('code-review', 2) |
| 2099 | B.addApproval('code-review', 2) |
| 2100 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2101 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2102 | self.waitUntilSettled() |
| 2103 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2104 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2105 | if x.name == 'project-testfile'] |
| 2106 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2107 | self.assertEqual(len(testfile_jobs), 1) |
| 2108 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2109 | self.assertEqual(A.data['status'], 'MERGED') |
| 2110 | self.assertEqual(A.reported, 2) |
| 2111 | self.assertEqual(B.data['status'], 'MERGED') |
| 2112 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2113 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2114 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2115 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2116 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2117 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2118 | |
| 2119 | if should_skip: |
| 2120 | files = {'ignoreme': 'ignored\n'} |
| 2121 | else: |
| 2122 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2123 | |
| 2124 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2125 | 'master', |
| 2126 | 'test irrelevant-files', |
| 2127 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2128 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2129 | self.waitUntilSettled() |
| 2130 | |
| 2131 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2132 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2133 | |
| 2134 | if should_skip: |
| 2135 | self.assertEqual([], tested_change_ids) |
| 2136 | else: |
| 2137 | self.assertIn(change.data['number'], tested_change_ids) |
| 2138 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2139 | def test_irrelevant_files_match_skips_job(self): |
| 2140 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2141 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2142 | def test_irrelevant_files_no_match_runs_job(self): |
| 2143 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2144 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2145 | def test_inherited_jobs_keep_matchers(self): |
| 2146 | self.updateConfigLayout('layout-inheritance') |
| 2147 | self.sched.reconfigure(self.config) |
| 2148 | |
| 2149 | files = {'ignoreme': 'ignored\n'} |
| 2150 | |
| 2151 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2152 | 'master', |
| 2153 | 'test irrelevant-files', |
| 2154 | files=files) |
| 2155 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2156 | self.waitUntilSettled() |
| 2157 | |
| 2158 | run_jobs = set([build.name for build in self.history]) |
| 2159 | |
| 2160 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2161 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2162 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2163 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2164 | def test_test_config(self): |
| 2165 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2166 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2167 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2168 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2169 | def test_queue_names(self): |
| 2170 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2171 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2172 | source = tenant.layout.pipelines['gate'].source |
| 2173 | project1 = source.getProject('org/project1') |
| 2174 | project2 = source.getProject('org/project2') |
| 2175 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2176 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2177 | self.assertEqual(q1.name, 'integrated') |
| 2178 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2179 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2180 | def test_queue_precedence(self): |
| 2181 | "Test that queue precedence works" |
| 2182 | |
| 2183 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2184 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2185 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2186 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2187 | A.addApproval('code-review', 2) |
| 2188 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2189 | |
| 2190 | self.waitUntilSettled() |
| 2191 | self.gearman_server.hold_jobs_in_queue = False |
| 2192 | self.gearman_server.release() |
| 2193 | self.waitUntilSettled() |
| 2194 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2195 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2196 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2197 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2198 | self.waitUntilSettled() |
| 2199 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2200 | self.log.debug(self.history) |
| 2201 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2202 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2203 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2204 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2205 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2206 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2207 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2208 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2209 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2210 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2211 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2212 | A.addApproval('code-review', 2) |
| 2213 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2214 | self.waitUntilSettled() |
| 2215 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2216 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2217 | self.waitUntilSettled() |
| 2218 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2219 | port = self.webapp.server.socket.getsockname()[1] |
| 2220 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2221 | req = urllib.request.Request( |
| 2222 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2223 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2224 | headers = f.info() |
| 2225 | self.assertIn('Content-Length', headers) |
| 2226 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2227 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2228 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2229 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2230 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2231 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2232 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2233 | data = f.read() |
| 2234 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2235 | self.executor_server.hold_jobs_in_build = False |
| 2236 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2237 | self.waitUntilSettled() |
| 2238 | |
| 2239 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2240 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2241 | for p in data['pipelines']: |
| 2242 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2243 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2244 | self.assertEqual(q['window'], 20) |
| 2245 | else: |
| 2246 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2247 | for head in q['heads']: |
| 2248 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2249 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2250 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2251 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2252 | status_jobs.append(job) |
| 2253 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2254 | self.assertEqual('https://server/job/project-merge/0/', |
| 2255 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2256 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2257 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2258 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2259 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2260 | status_jobs[1]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2261 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2262 | status_jobs[1]['report_url']) |
| 2263 | |
| 2264 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2265 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2266 | status_jobs[2]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2267 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2268 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2269 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2270 | def test_semaphore_one(self): |
| 2271 | "Test semaphores with max=1 (mutex)" |
| 2272 | self.updateConfigLayout('layout-semaphore') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2273 | self.sched.reconfigure(self.config) |
| 2274 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2275 | self.waitUntilSettled() |
| 2276 | tenant = self.sched.abide.tenants.get('openstack') |
| 2277 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2278 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2279 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2280 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2281 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2282 | self.assertFalse('test-semaphore' in |
| 2283 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2284 | |
| 2285 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2286 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2287 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2288 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2289 | self.assertEqual(len(self.builds), 3) |
| 2290 | self.assertEqual(self.builds[0].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2291 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2292 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2293 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2294 | self.executor_server.release('semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2295 | self.waitUntilSettled() |
| 2296 | |
| 2297 | self.assertEqual(len(self.builds), 3) |
| 2298 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2299 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2300 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 2301 | self.assertTrue('test-semaphore' in |
| 2302 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2303 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2304 | self.executor_server.release('semaphore-one-test2') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2305 | self.waitUntilSettled() |
| 2306 | |
| 2307 | self.assertEqual(len(self.builds), 3) |
| 2308 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2309 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2310 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 2311 | self.assertTrue('test-semaphore' in |
| 2312 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2313 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2314 | self.executor_server.release('semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2315 | self.waitUntilSettled() |
| 2316 | |
| 2317 | self.assertEqual(len(self.builds), 3) |
| 2318 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2319 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2320 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 2321 | self.assertTrue('test-semaphore' in |
| 2322 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2323 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2324 | self.executor_server.release('semaphore-one-test2') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2325 | self.waitUntilSettled() |
| 2326 | |
| 2327 | self.assertEqual(len(self.builds), 2) |
| 2328 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2329 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2330 | self.assertFalse('test-semaphore' in |
| 2331 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2332 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2333 | self.executor_server.hold_jobs_in_build = False |
| 2334 | self.executor_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2335 | |
| 2336 | self.waitUntilSettled() |
| 2337 | self.assertEqual(len(self.builds), 0) |
| 2338 | |
| 2339 | self.assertEqual(A.reported, 1) |
| 2340 | self.assertEqual(B.reported, 1) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2341 | self.assertFalse('test-semaphore' in |
| 2342 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2343 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2344 | def test_semaphore_two(self): |
| 2345 | "Test semaphores with max>1" |
| 2346 | self.updateConfigLayout('layout-semaphore') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2347 | self.sched.reconfigure(self.config) |
| 2348 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2349 | self.waitUntilSettled() |
| 2350 | tenant = self.sched.abide.tenants.get('openstack') |
| 2351 | |
| 2352 | self.executor_server.hold_jobs_in_build = True |
| 2353 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2354 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2355 | self.assertFalse('test-semaphore-two' in |
| 2356 | tenant.semaphore_handler.semaphores) |
| 2357 | |
| 2358 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2359 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2360 | self.waitUntilSettled() |
| 2361 | |
| 2362 | self.assertEqual(len(self.builds), 4) |
| 2363 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2364 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 2365 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 2366 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 2367 | self.assertTrue('test-semaphore-two' in |
| 2368 | tenant.semaphore_handler.semaphores) |
| 2369 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2370 | 'test-semaphore-two', [])), 2) |
| 2371 | |
| 2372 | self.executor_server.release('semaphore-two-test1') |
| 2373 | self.waitUntilSettled() |
| 2374 | |
| 2375 | self.assertEqual(len(self.builds), 4) |
| 2376 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2377 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 2378 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2379 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 2380 | self.assertTrue('test-semaphore-two' in |
| 2381 | tenant.semaphore_handler.semaphores) |
| 2382 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2383 | 'test-semaphore-two', [])), 2) |
| 2384 | |
| 2385 | self.executor_server.release('semaphore-two-test2') |
| 2386 | self.waitUntilSettled() |
| 2387 | |
| 2388 | self.assertEqual(len(self.builds), 4) |
| 2389 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2390 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2391 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 2392 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 2393 | self.assertTrue('test-semaphore-two' in |
| 2394 | tenant.semaphore_handler.semaphores) |
| 2395 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2396 | 'test-semaphore-two', [])), 2) |
| 2397 | |
| 2398 | self.executor_server.release('semaphore-two-test1') |
| 2399 | self.waitUntilSettled() |
| 2400 | |
| 2401 | self.assertEqual(len(self.builds), 3) |
| 2402 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2403 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2404 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 2405 | self.assertTrue('test-semaphore-two' in |
| 2406 | tenant.semaphore_handler.semaphores) |
| 2407 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2408 | 'test-semaphore-two', [])), 1) |
| 2409 | |
| 2410 | self.executor_server.release('semaphore-two-test2') |
| 2411 | self.waitUntilSettled() |
| 2412 | |
| 2413 | self.assertEqual(len(self.builds), 2) |
| 2414 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2415 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2416 | self.assertFalse('test-semaphore-two' in |
| 2417 | tenant.semaphore_handler.semaphores) |
| 2418 | |
| 2419 | self.executor_server.hold_jobs_in_build = False |
| 2420 | self.executor_server.release() |
| 2421 | |
| 2422 | self.waitUntilSettled() |
| 2423 | self.assertEqual(len(self.builds), 0) |
| 2424 | |
| 2425 | self.assertEqual(A.reported, 1) |
| 2426 | self.assertEqual(B.reported, 1) |
| 2427 | |
| 2428 | def test_semaphore_abandon(self): |
| 2429 | "Test abandon with job semaphores" |
| 2430 | self.updateConfigLayout('layout-semaphore') |
| 2431 | self.sched.reconfigure(self.config) |
| 2432 | |
| 2433 | self.waitUntilSettled() |
| 2434 | tenant = self.sched.abide.tenants.get('openstack') |
| 2435 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2436 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2437 | |
| 2438 | tenant = self.sched.abide.tenants.get('openstack') |
| 2439 | check_pipeline = tenant.layout.pipelines['check'] |
| 2440 | |
| 2441 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2442 | self.assertFalse('test-semaphore' in |
| 2443 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2444 | |
| 2445 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2446 | self.waitUntilSettled() |
| 2447 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2448 | self.assertTrue('test-semaphore' in |
| 2449 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2450 | |
| 2451 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2452 | self.waitUntilSettled() |
| 2453 | |
| 2454 | # The check pipeline should be empty |
| 2455 | items = check_pipeline.getAllItems() |
| 2456 | self.assertEqual(len(items), 0) |
| 2457 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2458 | # The semaphore should be released |
| 2459 | self.assertFalse('test-semaphore' in |
| 2460 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2461 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2462 | self.executor_server.hold_jobs_in_build = False |
| 2463 | self.executor_server.release() |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2464 | self.waitUntilSettled() |
| 2465 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2466 | def test_semaphore_reconfigure(self): |
| 2467 | "Test reconfigure with job semaphores" |
| 2468 | self.updateConfigLayout('layout-semaphore') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2469 | self.sched.reconfigure(self.config) |
| 2470 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2471 | self.waitUntilSettled() |
| 2472 | tenant = self.sched.abide.tenants.get('openstack') |
| 2473 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2474 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2475 | |
| 2476 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2477 | self.assertFalse('test-semaphore' in |
| 2478 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2479 | |
| 2480 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2481 | self.waitUntilSettled() |
| 2482 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2483 | self.assertTrue('test-semaphore' in |
| 2484 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2485 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2486 | # reconfigure without layout change |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2487 | self.sched.reconfigure(self.config) |
| 2488 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2489 | tenant = self.sched.abide.tenants.get('openstack') |
| 2490 | |
| 2491 | # semaphore still must be held |
| 2492 | self.assertTrue('test-semaphore' in |
| 2493 | tenant.semaphore_handler.semaphores) |
| 2494 | |
| 2495 | self.updateConfigLayout('layout-semaphore-reconfiguration') |
| 2496 | self.sched.reconfigure(self.config) |
| 2497 | self.waitUntilSettled() |
| 2498 | tenant = self.sched.abide.tenants.get('openstack') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2499 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2500 | self.executor_server.release('project-test1') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2501 | self.waitUntilSettled() |
| 2502 | |
| 2503 | # There should be no builds anymore |
| 2504 | self.assertEqual(len(self.builds), 0) |
| 2505 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2506 | # The semaphore should be released |
| 2507 | self.assertFalse('test-semaphore' in |
| 2508 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2509 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2510 | def test_live_reconfiguration(self): |
| 2511 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2512 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2513 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2514 | A.addApproval('code-review', 2) |
| 2515 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2516 | self.waitUntilSettled() |
| 2517 | |
| 2518 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2519 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2520 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2521 | self.executor_server.hold_jobs_in_build = False |
| 2522 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2523 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2524 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2525 | 'SUCCESS') |
| 2526 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2527 | 'SUCCESS') |
| 2528 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2529 | 'SUCCESS') |
| 2530 | self.assertEqual(A.data['status'], 'MERGED') |
| 2531 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2532 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2533 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2534 | def test_live_reconfiguration_merge_conflict(self): |
| 2535 | # A real-world bug: a change in a gate queue has a merge |
| 2536 | # conflict and a job is added to its project while it's |
| 2537 | # sitting in the queue. The job gets added to the change and |
| 2538 | # enqueued and the change gets stuck. |
| 2539 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2540 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2541 | |
| 2542 | # This change is fine. It's here to stop the queue long |
| 2543 | # enough for the next change to be subject to the |
| 2544 | # reconfiguration, as well as to provide a conflict for the |
| 2545 | # next change. This change will succeed and merge. |
| 2546 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2547 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2548 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2549 | |
| 2550 | # This change will be in merge conflict. During the |
| 2551 | # reconfiguration, we will add a job. We want to make sure |
| 2552 | # that doesn't cause it to get stuck. |
| 2553 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2554 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2555 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2556 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2557 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2558 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2559 | |
| 2560 | self.waitUntilSettled() |
| 2561 | |
| 2562 | # No jobs have run yet |
| 2563 | self.assertEqual(A.data['status'], 'NEW') |
| 2564 | self.assertEqual(A.reported, 1) |
| 2565 | self.assertEqual(B.data['status'], 'NEW') |
| 2566 | self.assertEqual(B.reported, 1) |
| 2567 | self.assertEqual(len(self.history), 0) |
| 2568 | |
| 2569 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2570 | self.updateConfigLayout( |
| 2571 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2572 | self.sched.reconfigure(self.config) |
| 2573 | self.waitUntilSettled() |
| 2574 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2575 | self.executor_server.hold_jobs_in_build = False |
| 2576 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2577 | self.waitUntilSettled() |
| 2578 | |
| 2579 | self.assertEqual(A.data['status'], 'MERGED') |
| 2580 | self.assertEqual(A.reported, 2) |
| 2581 | self.assertEqual(B.data['status'], 'NEW') |
| 2582 | self.assertEqual(B.reported, 2) |
| 2583 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2584 | 'SUCCESS') |
| 2585 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2586 | 'SUCCESS') |
| 2587 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2588 | 'SUCCESS') |
| 2589 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2590 | 'SUCCESS') |
| 2591 | self.assertEqual(len(self.history), 4) |
| 2592 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2593 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2594 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2595 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2596 | # that tests a job added to a job tree with a failed root does |
| 2597 | # not run. |
| 2598 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2599 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2600 | |
| 2601 | # This change is fine. It's here to stop the queue long |
| 2602 | # enough for the next change to be subject to the |
| 2603 | # reconfiguration. This change will succeed and merge. |
| 2604 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2605 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2606 | A.addApproval('code-review', 2) |
| 2607 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2608 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2609 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2610 | self.waitUntilSettled() |
| 2611 | |
| 2612 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2613 | self.executor_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2614 | B.addApproval('code-review', 2) |
| 2615 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2616 | self.waitUntilSettled() |
| 2617 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2618 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2619 | self.waitUntilSettled() |
| 2620 | |
| 2621 | # Both -merge jobs have run, but no others. |
| 2622 | self.assertEqual(A.data['status'], 'NEW') |
| 2623 | self.assertEqual(A.reported, 1) |
| 2624 | self.assertEqual(B.data['status'], 'NEW') |
| 2625 | self.assertEqual(B.reported, 1) |
| 2626 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2627 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2628 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2629 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2630 | self.assertEqual(len(self.history), 2) |
| 2631 | |
| 2632 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2633 | self.updateConfigLayout( |
| 2634 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2635 | self.sched.reconfigure(self.config) |
| 2636 | self.waitUntilSettled() |
| 2637 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2638 | self.executor_server.hold_jobs_in_build = False |
| 2639 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2640 | self.waitUntilSettled() |
| 2641 | |
| 2642 | self.assertEqual(A.data['status'], 'MERGED') |
| 2643 | self.assertEqual(A.reported, 2) |
| 2644 | self.assertEqual(B.data['status'], 'NEW') |
| 2645 | self.assertEqual(B.reported, 2) |
| 2646 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2647 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2648 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2649 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2650 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2651 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2652 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2653 | self.assertEqual(len(self.history), 5) |
| 2654 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2655 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2656 | def test_live_reconfiguration_failed_job(self): |
| 2657 | # Test that a change with a removed failing job does not |
| 2658 | # disrupt reconfiguration. If a change has a failed job and |
| 2659 | # that job is removed during a reconfiguration, we observed a |
| 2660 | # bug where the code to re-set build statuses would run on |
| 2661 | # that build and raise an exception because the job no longer |
| 2662 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2663 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2664 | |
| 2665 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2666 | |
| 2667 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2668 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2669 | |
| 2670 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2671 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2672 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2673 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2674 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2675 | self.waitUntilSettled() |
| 2676 | |
| 2677 | self.assertEqual(A.data['status'], 'NEW') |
| 2678 | self.assertEqual(A.reported, 0) |
| 2679 | |
| 2680 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2681 | 'SUCCESS') |
| 2682 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2683 | 'FAILURE') |
| 2684 | self.assertEqual(len(self.history), 2) |
| 2685 | |
| 2686 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2687 | self.updateConfigLayout( |
| 2688 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2689 | self.sched.reconfigure(self.config) |
| 2690 | self.waitUntilSettled() |
| 2691 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2692 | self.executor_server.hold_jobs_in_build = False |
| 2693 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2694 | self.waitUntilSettled() |
| 2695 | |
| 2696 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2697 | 'SUCCESS') |
| 2698 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2699 | 'SUCCESS') |
| 2700 | self.assertEqual(len(self.history), 4) |
| 2701 | |
| 2702 | self.assertEqual(A.data['status'], 'NEW') |
| 2703 | self.assertEqual(A.reported, 1) |
| 2704 | self.assertIn('Build succeeded', A.messages[0]) |
| 2705 | # Ensure the removed job was not included in the report. |
| 2706 | self.assertNotIn('project-test1', A.messages[0]) |
| 2707 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2708 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2709 | def test_live_reconfiguration_shared_queue(self): |
| 2710 | # Test that a change with a failing job which was removed from |
| 2711 | # this project but otherwise still exists in the system does |
| 2712 | # not disrupt reconfiguration. |
| 2713 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2714 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2715 | |
| 2716 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2717 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2718 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2719 | |
| 2720 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2721 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2722 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2723 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2724 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2725 | self.waitUntilSettled() |
| 2726 | |
| 2727 | self.assertEqual(A.data['status'], 'NEW') |
| 2728 | self.assertEqual(A.reported, 0) |
| 2729 | |
| 2730 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2731 | 'SUCCESS') |
| 2732 | self.assertEqual(self.getJobFromHistory( |
| 2733 | 'project1-project2-integration').result, 'FAILURE') |
| 2734 | self.assertEqual(len(self.history), 2) |
| 2735 | |
| 2736 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2737 | self.updateConfigLayout( |
| 2738 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2739 | self.sched.reconfigure(self.config) |
| 2740 | self.waitUntilSettled() |
| 2741 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2742 | self.executor_server.hold_jobs_in_build = False |
| 2743 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2744 | self.waitUntilSettled() |
| 2745 | |
| 2746 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2747 | 'SUCCESS') |
| 2748 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2749 | 'SUCCESS') |
| 2750 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2751 | 'SUCCESS') |
| 2752 | self.assertEqual(self.getJobFromHistory( |
| 2753 | 'project1-project2-integration').result, 'FAILURE') |
| 2754 | self.assertEqual(len(self.history), 4) |
| 2755 | |
| 2756 | self.assertEqual(A.data['status'], 'NEW') |
| 2757 | self.assertEqual(A.reported, 1) |
| 2758 | self.assertIn('Build succeeded', A.messages[0]) |
| 2759 | # Ensure the removed job was not included in the report. |
| 2760 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2761 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2762 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2763 | def test_double_live_reconfiguration_shared_queue(self): |
| 2764 | # This was a real-world regression. A change is added to |
| 2765 | # gate; a reconfigure happens, a second change which depends |
| 2766 | # on the first is added, and a second reconfiguration happens. |
| 2767 | # Ensure that both changes merge. |
| 2768 | |
| 2769 | # A failure may indicate incorrect caching or cleaning up of |
| 2770 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2771 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2772 | |
| 2773 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2774 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2775 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2776 | A.addApproval('code-review', 2) |
| 2777 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2778 | |
| 2779 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2780 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2781 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2782 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2783 | self.waitUntilSettled() |
| 2784 | |
| 2785 | # Reconfigure (with only one change in the pipeline). |
| 2786 | self.sched.reconfigure(self.config) |
| 2787 | self.waitUntilSettled() |
| 2788 | |
| 2789 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2790 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2791 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2792 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2793 | self.waitUntilSettled() |
| 2794 | |
| 2795 | # Reconfigure (with both in the pipeline). |
| 2796 | self.sched.reconfigure(self.config) |
| 2797 | self.waitUntilSettled() |
| 2798 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2799 | self.executor_server.hold_jobs_in_build = False |
| 2800 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2801 | self.waitUntilSettled() |
| 2802 | |
| 2803 | self.assertEqual(len(self.history), 8) |
| 2804 | |
| 2805 | self.assertEqual(A.data['status'], 'MERGED') |
| 2806 | self.assertEqual(A.reported, 2) |
| 2807 | self.assertEqual(B.data['status'], 'MERGED') |
| 2808 | self.assertEqual(B.reported, 2) |
| 2809 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2810 | def test_live_reconfiguration_del_project(self): |
| 2811 | # Test project deletion from layout |
| 2812 | # while changes are enqueued |
| 2813 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2814 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2815 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2816 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2817 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2818 | |
| 2819 | # A Depends-On: B |
| 2820 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2821 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2822 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2823 | |
| 2824 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2825 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2826 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2827 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2828 | self.waitUntilSettled() |
| 2829 | self.assertEqual(len(self.builds), 5) |
| 2830 | |
| 2831 | # This layout defines only org/project, not org/project1 |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2832 | self.commitLayoutUpdate('common-config', |
| 2833 | 'layout-live-reconfiguration-del-project') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2834 | self.sched.reconfigure(self.config) |
| 2835 | self.waitUntilSettled() |
| 2836 | |
| 2837 | # Builds for C aborted, builds for A succeed, |
| 2838 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2839 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2840 | self.assertEqual(job_c.changes, '3,1') |
| 2841 | self.assertEqual(job_c.result, 'ABORTED') |
| 2842 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2843 | self.executor_server.hold_jobs_in_build = False |
| 2844 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2845 | self.waitUntilSettled() |
| 2846 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2847 | self.assertEqual( |
| 2848 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2849 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2850 | |
| 2851 | self.assertEqual(A.data['status'], 'NEW') |
| 2852 | self.assertEqual(B.data['status'], 'NEW') |
| 2853 | self.assertEqual(C.data['status'], 'NEW') |
| 2854 | self.assertEqual(A.reported, 1) |
| 2855 | self.assertEqual(B.reported, 0) |
| 2856 | self.assertEqual(C.reported, 0) |
| 2857 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2858 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2859 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2860 | self.assertIn('Build succeeded', A.messages[0]) |
| 2861 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2862 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2863 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2864 | self.updateConfigLayout( |
| 2865 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2866 | self.sched.reconfigure(self.config) |
| 2867 | |
| 2868 | self.init_repo("org/new-project") |
| 2869 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2870 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2871 | A.addApproval('code-review', 2) |
| 2872 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2873 | self.waitUntilSettled() |
| 2874 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2875 | 'SUCCESS') |
| 2876 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2877 | 'SUCCESS') |
| 2878 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2879 | 'SUCCESS') |
| 2880 | self.assertEqual(A.data['status'], 'MERGED') |
| 2881 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2882 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2883 | def test_repo_deleted(self): |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 2884 | self.updateConfigLayout('layout-repo-deleted', ['org/delete-project']) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2885 | self.sched.reconfigure(self.config) |
| 2886 | |
| 2887 | self.init_repo("org/delete-project") |
| 2888 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2889 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2890 | A.addApproval('code-review', 2) |
| 2891 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2892 | self.waitUntilSettled() |
| 2893 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2894 | 'SUCCESS') |
| 2895 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2896 | 'SUCCESS') |
| 2897 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2898 | 'SUCCESS') |
| 2899 | self.assertEqual(A.data['status'], 'MERGED') |
| 2900 | self.assertEqual(A.reported, 2) |
| 2901 | |
| 2902 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2903 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2904 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2905 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2906 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2907 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2908 | |
| 2909 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2910 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2911 | B.addApproval('code-review', 2) |
| 2912 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2913 | self.waitUntilSettled() |
| 2914 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2915 | 'SUCCESS') |
| 2916 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2917 | 'SUCCESS') |
| 2918 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2919 | 'SUCCESS') |
| 2920 | self.assertEqual(B.data['status'], 'MERGED') |
| 2921 | self.assertEqual(B.reported, 2) |
| 2922 | |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2923 | def test_tags(self): |
| 2924 | "Test job tags" |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2925 | self.updateConfigLayout('layout-tags') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2926 | self.sched.reconfigure(self.config) |
| 2927 | |
| 2928 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2929 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2930 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2931 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2932 | self.waitUntilSettled() |
| 2933 | |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2934 | self.assertEqual(len(self.history), 8) |
| 2935 | |
| 2936 | results = {self.getJobFromHistory('merge', |
| 2937 | project='org/project1').uuid: 'extratag merge', |
| 2938 | self.getJobFromHistory('merge', |
| 2939 | project='org/project2').uuid: 'merge'} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2940 | |
| 2941 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2942 | self.assertEqual(results.get(build.uuid, ''), |
| 2943 | build.parameters['vars']['zuul'].get('tags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2944 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2945 | def test_timer(self): |
| 2946 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2947 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2948 | self.updateConfigLayout('layout-timer') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2949 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2950 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2951 | # The pipeline triggers every second, so we should have seen |
| 2952 | # several by now. |
| 2953 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2954 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2955 | |
| 2956 | self.assertEqual(len(self.builds), 2) |
| 2957 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2958 | port = self.webapp.server.socket.getsockname()[1] |
| 2959 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2960 | req = urllib.request.Request( |
| 2961 | "http://localhost:%s/openstack/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2962 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2963 | data = f.read() |
| 2964 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2965 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2966 | # Stop queuing timer triggered jobs so that the assertions |
| 2967 | # below don't race against more jobs being queued. |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2968 | self.commitLayoutUpdate('layout-timer', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2969 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2970 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2971 | self.waitUntilSettled() |
| 2972 | |
| 2973 | self.assertEqual(self.getJobFromHistory( |
| 2974 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2975 | self.assertEqual(self.getJobFromHistory( |
| 2976 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2977 | |
| 2978 | data = json.loads(data) |
| 2979 | status_jobs = set() |
| 2980 | for p in data['pipelines']: |
| 2981 | for q in p['change_queues']: |
| 2982 | for head in q['heads']: |
| 2983 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2984 | for job in change['jobs']: |
| 2985 | status_jobs.add(job['name']) |
| 2986 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2987 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2988 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2989 | def test_idle(self): |
| 2990 | "Test that frequent periodic jobs work" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2991 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2992 | self.updateConfigLayout('layout-idle') |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2993 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2994 | for x in range(1, 3): |
| 2995 | # Test that timer triggers periodic jobs even across |
| 2996 | # layout config reloads. |
| 2997 | # Start timer trigger |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2998 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2999 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3000 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3001 | # The pipeline triggers every second, so we should have seen |
| 3002 | # several by now. |
| 3003 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3004 | |
| 3005 | # Stop queuing timer triggered jobs so that the assertions |
| 3006 | # below don't race against more jobs being queued. |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3007 | before = self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3008 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3009 | self.waitUntilSettled() |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3010 | self.assertEqual(len(self.builds), 2, |
| 3011 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3012 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3013 | self.waitUntilSettled() |
| 3014 | self.assertEqual(len(self.builds), 0) |
| 3015 | self.assertEqual(len(self.history), x * 2) |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3016 | # Revert back to layout-idle |
| 3017 | repo = git.Repo(os.path.join(self.test_root, |
| 3018 | 'upstream', |
| 3019 | 'layout-idle')) |
| 3020 | repo.git.reset('--hard', before) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3021 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3022 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 3023 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3024 | self.sched.reconfigure(self.config) |
| 3025 | |
| 3026 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3027 | self.waitUntilSettled() |
| 3028 | |
| 3029 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3030 | self.waitUntilSettled() |
| 3031 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3032 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3033 | |
| 3034 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3035 | # work on the knowledge of what the first message should be as |
| 3036 | # it is only configured to go to SMTP. |
| 3037 | |
| 3038 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3039 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3040 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3041 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3042 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3043 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3044 | |
| 3045 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3046 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3047 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3048 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3049 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3050 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3051 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3052 | def test_timer_smtp(self): |
| 3053 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3054 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 3055 | self.updateConfigLayout('layout-timer-smtp') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3056 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3057 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3058 | # The pipeline triggers every second, so we should have seen |
| 3059 | # several by now. |
| 3060 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3061 | self.waitUntilSettled() |
| 3062 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3063 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3064 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3065 | self.waitUntilSettled() |
| 3066 | self.assertEqual(len(self.history), 2) |
| 3067 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3068 | self.assertEqual(self.getJobFromHistory( |
| 3069 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3070 | self.assertEqual(self.getJobFromHistory( |
| 3071 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3072 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3073 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3074 | |
| 3075 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3076 | # work on the knowledge of what the first message should be as |
| 3077 | # it is only configured to go to SMTP. |
| 3078 | |
| 3079 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3080 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3081 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3082 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3083 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3084 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3085 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3086 | # Stop queuing timer triggered jobs and let any that may have |
| 3087 | # queued through so that end of test assertions pass. |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 3088 | self.commitLayoutUpdate('layout-timer-smtp', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3089 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3090 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3091 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3092 | self.waitUntilSettled() |
| 3093 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3094 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3095 | def test_timer_sshkey(self): |
| 3096 | "Test that a periodic job can setup SSH key authentication" |
| 3097 | self.worker.hold_jobs_in_build = True |
| 3098 | self.config.set('zuul', 'layout_config', |
| 3099 | 'tests/fixtures/layout-timer.yaml') |
| 3100 | self.sched.reconfigure(self.config) |
| 3101 | self.registerJobs() |
| 3102 | |
| 3103 | # The pipeline triggers every second, so we should have seen |
| 3104 | # several by now. |
| 3105 | time.sleep(5) |
| 3106 | self.waitUntilSettled() |
| 3107 | |
| 3108 | self.assertEqual(len(self.builds), 2) |
| 3109 | |
| 3110 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3111 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3112 | with open(ssh_wrapper) as f: |
| 3113 | ssh_wrapper_content = f.read() |
| 3114 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3115 | # In the unit tests Merger runs in the same process, |
| 3116 | # so we see its' environment variables |
| 3117 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3118 | |
| 3119 | self.worker.release('.*') |
| 3120 | self.waitUntilSettled() |
| 3121 | self.assertEqual(len(self.history), 2) |
| 3122 | |
| 3123 | self.assertEqual(self.getJobFromHistory( |
| 3124 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3125 | self.assertEqual(self.getJobFromHistory( |
| 3126 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3127 | |
| 3128 | # Stop queuing timer triggered jobs and let any that may have |
| 3129 | # queued through so that end of test assertions pass. |
| 3130 | self.config.set('zuul', 'layout_config', |
| 3131 | 'tests/fixtures/layout-no-timer.yaml') |
| 3132 | self.sched.reconfigure(self.config) |
| 3133 | self.registerJobs() |
| 3134 | self.waitUntilSettled() |
| 3135 | self.worker.release('.*') |
| 3136 | self.waitUntilSettled() |
| 3137 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3138 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3139 | "Test that the RPC client can enqueue a change" |
| 3140 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3141 | A.addApproval('code-review', 2) |
| 3142 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3143 | |
| 3144 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3145 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3146 | r = client.enqueue(tenant='tenant-one', |
| 3147 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3148 | project='org/project', |
| 3149 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3150 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3151 | self.waitUntilSettled() |
| 3152 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3153 | 'SUCCESS') |
| 3154 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3155 | 'SUCCESS') |
| 3156 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3157 | 'SUCCESS') |
| 3158 | self.assertEqual(A.data['status'], 'MERGED') |
| 3159 | self.assertEqual(A.reported, 2) |
| 3160 | self.assertEqual(r, True) |
| 3161 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3162 | def test_client_enqueue_ref(self): |
| 3163 | "Test that the RPC client can enqueue a ref" |
| 3164 | |
| 3165 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3166 | self.gearman_server.port) |
| 3167 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3168 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3169 | pipeline='post', |
| 3170 | project='org/project', |
| 3171 | trigger='gerrit', |
| 3172 | ref='master', |
| 3173 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3174 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3175 | self.waitUntilSettled() |
| 3176 | job_names = [x.name for x in self.history] |
| 3177 | self.assertEqual(len(self.history), 1) |
| 3178 | self.assertIn('project-post', job_names) |
| 3179 | self.assertEqual(r, True) |
| 3180 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3181 | def test_client_enqueue_negative(self): |
| 3182 | "Test that the RPC client returns errors" |
| 3183 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3184 | self.gearman_server.port) |
| 3185 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3186 | "Invalid tenant"): |
| 3187 | r = client.enqueue(tenant='tenant-foo', |
| 3188 | pipeline='gate', |
| 3189 | project='org/project', |
| 3190 | trigger='gerrit', |
| 3191 | change='1,1') |
| 3192 | client.shutdown() |
| 3193 | self.assertEqual(r, False) |
| 3194 | |
| 3195 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3196 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3197 | r = client.enqueue(tenant='tenant-one', |
| 3198 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3199 | project='project-does-not-exist', |
| 3200 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3201 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3202 | client.shutdown() |
| 3203 | self.assertEqual(r, False) |
| 3204 | |
| 3205 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3206 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3207 | r = client.enqueue(tenant='tenant-one', |
| 3208 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3209 | project='org/project', |
| 3210 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3211 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3212 | client.shutdown() |
| 3213 | self.assertEqual(r, False) |
| 3214 | |
| 3215 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3216 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3217 | r = client.enqueue(tenant='tenant-one', |
| 3218 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3219 | project='org/project', |
| 3220 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3221 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3222 | client.shutdown() |
| 3223 | self.assertEqual(r, False) |
| 3224 | |
| 3225 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3226 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3227 | r = client.enqueue(tenant='tenant-one', |
| 3228 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3229 | project='org/project', |
| 3230 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3231 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3232 | client.shutdown() |
| 3233 | self.assertEqual(r, False) |
| 3234 | |
| 3235 | self.waitUntilSettled() |
| 3236 | self.assertEqual(len(self.history), 0) |
| 3237 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3238 | |
| 3239 | def test_client_promote(self): |
| 3240 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3241 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3242 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3243 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3244 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3245 | A.addApproval('code-review', 2) |
| 3246 | B.addApproval('code-review', 2) |
| 3247 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3248 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3249 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3250 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3251 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3252 | |
| 3253 | self.waitUntilSettled() |
| 3254 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3255 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3256 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3257 | enqueue_times = {} |
| 3258 | for item in items: |
| 3259 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3260 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3261 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3262 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3263 | r = client.promote(tenant='tenant-one', |
| 3264 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3265 | change_ids=['2,1', '3,1']) |
| 3266 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3267 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3268 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3269 | for item in items: |
| 3270 | self.assertEqual( |
| 3271 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3272 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3273 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3274 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3275 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3276 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3277 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3278 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3279 | self.waitUntilSettled() |
| 3280 | |
| 3281 | self.assertEqual(len(self.builds), 6) |
| 3282 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3283 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3284 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3285 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3286 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3287 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3288 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3289 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3290 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3291 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3292 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3293 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3294 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3295 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3296 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3297 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3298 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3299 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3300 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3301 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3302 | self.waitUntilSettled() |
| 3303 | |
| 3304 | self.assertEqual(A.data['status'], 'MERGED') |
| 3305 | self.assertEqual(A.reported, 2) |
| 3306 | self.assertEqual(B.data['status'], 'MERGED') |
| 3307 | self.assertEqual(B.reported, 2) |
| 3308 | self.assertEqual(C.data['status'], 'MERGED') |
| 3309 | self.assertEqual(C.reported, 2) |
| 3310 | |
| 3311 | client.shutdown() |
| 3312 | self.assertEqual(r, True) |
| 3313 | |
| 3314 | def test_client_promote_dependent(self): |
| 3315 | "Test that the RPC client can promote a dependent change" |
| 3316 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3317 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3318 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3319 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3320 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3321 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3322 | |
| 3323 | C.setDependsOn(B, 1) |
| 3324 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3325 | A.addApproval('code-review', 2) |
| 3326 | B.addApproval('code-review', 2) |
| 3327 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3328 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3329 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3330 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3331 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3332 | |
| 3333 | self.waitUntilSettled() |
| 3334 | |
| 3335 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3336 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3337 | r = client.promote(tenant='tenant-one', |
| 3338 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3339 | change_ids=['3,1']) |
| 3340 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3341 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3342 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3343 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3344 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3345 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3346 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3347 | self.waitUntilSettled() |
| 3348 | |
| 3349 | self.assertEqual(len(self.builds), 6) |
| 3350 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3351 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3352 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3353 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3354 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3355 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3356 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3357 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3358 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3359 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3360 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3361 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3362 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3363 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3364 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3365 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3366 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3367 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3368 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3369 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3370 | self.waitUntilSettled() |
| 3371 | |
| 3372 | self.assertEqual(A.data['status'], 'MERGED') |
| 3373 | self.assertEqual(A.reported, 2) |
| 3374 | self.assertEqual(B.data['status'], 'MERGED') |
| 3375 | self.assertEqual(B.reported, 2) |
| 3376 | self.assertEqual(C.data['status'], 'MERGED') |
| 3377 | self.assertEqual(C.reported, 2) |
| 3378 | |
| 3379 | client.shutdown() |
| 3380 | self.assertEqual(r, True) |
| 3381 | |
| 3382 | def test_client_promote_negative(self): |
| 3383 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3384 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3385 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3386 | A.addApproval('code-review', 2) |
| 3387 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3388 | self.waitUntilSettled() |
| 3389 | |
| 3390 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3391 | self.gearman_server.port) |
| 3392 | |
| 3393 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3394 | r = client.promote(tenant='tenant-one', |
| 3395 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3396 | change_ids=['2,1', '3,1']) |
| 3397 | client.shutdown() |
| 3398 | self.assertEqual(r, False) |
| 3399 | |
| 3400 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3401 | r = client.promote(tenant='tenant-one', |
| 3402 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3403 | change_ids=['4,1']) |
| 3404 | client.shutdown() |
| 3405 | self.assertEqual(r, False) |
| 3406 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3407 | self.executor_server.hold_jobs_in_build = False |
| 3408 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3409 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3410 | |
| 3411 | def test_queue_rate_limiting(self): |
| 3412 | "Test that DependentPipelines are rate limited with dep across window" |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3413 | self.updateConfigLayout('layout-rate-limit') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3414 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3415 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3416 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3417 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3418 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3419 | |
| 3420 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3421 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3422 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3423 | A.addApproval('code-review', 2) |
| 3424 | B.addApproval('code-review', 2) |
| 3425 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3426 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3427 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3428 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3429 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3430 | self.waitUntilSettled() |
| 3431 | |
| 3432 | # Only A and B will have their merge jobs queued because |
| 3433 | # window is 2. |
| 3434 | self.assertEqual(len(self.builds), 2) |
| 3435 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3436 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3437 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3438 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3439 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3440 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3441 | self.waitUntilSettled() |
| 3442 | |
| 3443 | # Only A and B will have their test jobs queued because |
| 3444 | # window is 2. |
| 3445 | self.assertEqual(len(self.builds), 4) |
| 3446 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3447 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3448 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3449 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3450 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3451 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3452 | self.waitUntilSettled() |
| 3453 | |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3454 | tenant = self.sched.abide.tenants.get('openstack') |
| 3455 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3456 | # A failed so window is reduced by 1 to 1. |
| 3457 | self.assertEqual(queue.window, 1) |
| 3458 | self.assertEqual(queue.window_floor, 1) |
| 3459 | self.assertEqual(A.data['status'], 'NEW') |
| 3460 | |
| 3461 | # Gate is reset and only B's merge job is queued because |
| 3462 | # window shrunk to 1. |
| 3463 | self.assertEqual(len(self.builds), 1) |
| 3464 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3465 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3466 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3467 | self.waitUntilSettled() |
| 3468 | |
| 3469 | # Only B's test jobs are queued because window is still 1. |
| 3470 | self.assertEqual(len(self.builds), 2) |
| 3471 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3472 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3473 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3474 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3475 | self.waitUntilSettled() |
| 3476 | |
| 3477 | # B was successfully merged so window is increased to 2. |
| 3478 | self.assertEqual(queue.window, 2) |
| 3479 | self.assertEqual(queue.window_floor, 1) |
| 3480 | self.assertEqual(B.data['status'], 'MERGED') |
| 3481 | |
| 3482 | # Only C is left and its merge job is queued. |
| 3483 | self.assertEqual(len(self.builds), 1) |
| 3484 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3485 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3486 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3487 | self.waitUntilSettled() |
| 3488 | |
| 3489 | # After successful merge job the test jobs for C are queued. |
| 3490 | self.assertEqual(len(self.builds), 2) |
| 3491 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3492 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3493 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3494 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3495 | self.waitUntilSettled() |
| 3496 | |
| 3497 | # C successfully merged so window is bumped to 3. |
| 3498 | self.assertEqual(queue.window, 3) |
| 3499 | self.assertEqual(queue.window_floor, 1) |
| 3500 | self.assertEqual(C.data['status'], 'MERGED') |
| 3501 | |
| 3502 | def test_queue_rate_limiting_dependent(self): |
| 3503 | "Test that DependentPipelines are rate limited with dep in window" |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3504 | self.updateConfigLayout('layout-rate-limit') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3505 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3506 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3507 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3508 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3509 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3510 | |
| 3511 | B.setDependsOn(A, 1) |
| 3512 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3513 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3514 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3515 | A.addApproval('code-review', 2) |
| 3516 | B.addApproval('code-review', 2) |
| 3517 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3518 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3519 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3520 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3521 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3522 | self.waitUntilSettled() |
| 3523 | |
| 3524 | # Only A and B will have their merge jobs queued because |
| 3525 | # window is 2. |
| 3526 | self.assertEqual(len(self.builds), 2) |
| 3527 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3528 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3529 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3530 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3531 | |
| 3532 | # Only A and B will have their test jobs queued because |
| 3533 | # window is 2. |
| 3534 | self.assertEqual(len(self.builds), 4) |
| 3535 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3536 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3537 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3538 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3539 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3540 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3541 | self.waitUntilSettled() |
| 3542 | |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3543 | tenant = self.sched.abide.tenants.get('openstack') |
| 3544 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3545 | # A failed so window is reduced by 1 to 1. |
| 3546 | self.assertEqual(queue.window, 1) |
| 3547 | self.assertEqual(queue.window_floor, 1) |
| 3548 | self.assertEqual(A.data['status'], 'NEW') |
| 3549 | self.assertEqual(B.data['status'], 'NEW') |
| 3550 | |
| 3551 | # Gate is reset and only C's merge job is queued because |
| 3552 | # window shrunk to 1 and A and B were dequeued. |
| 3553 | self.assertEqual(len(self.builds), 1) |
| 3554 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3555 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3556 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3557 | |
| 3558 | # Only C's test jobs are queued because window is still 1. |
| 3559 | self.assertEqual(len(self.builds), 2) |
| 3560 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3561 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3562 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3563 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3564 | self.waitUntilSettled() |
| 3565 | |
| 3566 | # C was successfully merged so window is increased to 2. |
| 3567 | self.assertEqual(queue.window, 2) |
| 3568 | self.assertEqual(queue.window_floor, 1) |
| 3569 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3570 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3571 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3572 | def test_worker_update_metadata(self): |
| 3573 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3574 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3575 | |
| 3576 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3577 | A.addApproval('code-review', 2) |
| 3578 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3579 | self.waitUntilSettled() |
| 3580 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3581 | self.assertEqual(len(self.executor.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3582 | |
| 3583 | self.log.debug('Current builds:') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3584 | self.log.debug(self.executor.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3585 | |
| 3586 | start = time.time() |
| 3587 | while True: |
| 3588 | if time.time() - start > 10: |
| 3589 | raise Exception("Timeout waiting for gearman server to report " |
| 3590 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3591 | build = self.executor.builds.values()[0] |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3592 | if build.worker.name == "My Worker": |
| 3593 | break |
| 3594 | else: |
| 3595 | time.sleep(0) |
| 3596 | |
| 3597 | self.log.debug(build) |
| 3598 | self.assertEqual("My Worker", build.worker.name) |
| 3599 | self.assertEqual("localhost", build.worker.hostname) |
| 3600 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3601 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3602 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3603 | self.assertEqual("v1.1", build.worker.version) |
| 3604 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3605 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3606 | self.executor_server.hold_jobs_in_build = False |
| 3607 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3608 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3609 | |
| 3610 | def test_footer_message(self): |
| 3611 | "Test a pipeline's footer message is correctly added to the report." |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3612 | self.updateConfigLayout('layout-footer-message') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3613 | self.sched.reconfigure(self.config) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3614 | |
| 3615 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3616 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3617 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3618 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3619 | self.waitUntilSettled() |
| 3620 | |
| 3621 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3622 | B.addApproval('code-review', 2) |
| 3623 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3624 | self.waitUntilSettled() |
| 3625 | |
| 3626 | self.assertEqual(2, len(self.smtp_messages)) |
| 3627 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3628 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3629 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3630 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3631 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3632 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3633 | For CI problems and help debugging, contact ci@example.org""" |
| 3634 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3635 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3636 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3637 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3638 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3639 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3640 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3641 | def test_merge_failure_reporters(self): |
| 3642 | """Check that the config is set up correctly""" |
| 3643 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3644 | self.updateConfigLayout( |
| 3645 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3646 | self.sched.reconfigure(self.config) |
| 3647 | self.registerJobs() |
| 3648 | |
| 3649 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3650 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3651 | "dependencies was unable to be automatically merged with the " |
| 3652 | "current state of its repository. Please rebase the change and " |
| 3653 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3654 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3655 | self.assertEqual( |
| 3656 | "The merge failed! For more information...", |
| 3657 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3658 | |
| 3659 | self.assertEqual( |
| 3660 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3661 | self.assertEqual( |
| 3662 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3663 | |
| 3664 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3665 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3666 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3667 | |
| 3668 | self.assertTrue( |
| 3669 | ( |
| 3670 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3671 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3672 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3673 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3674 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3675 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3676 | ) or ( |
| 3677 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3678 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3679 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3680 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3681 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3682 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3683 | ) |
| 3684 | ) |
| 3685 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3686 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3687 | def test_merge_failure_reports(self): |
| 3688 | """Check that when a change fails to merge the correct message is sent |
| 3689 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3690 | self.updateConfigLayout( |
| 3691 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3692 | self.sched.reconfigure(self.config) |
| 3693 | self.registerJobs() |
| 3694 | |
| 3695 | # Check a test failure isn't reported to SMTP |
| 3696 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3697 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3698 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3699 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3700 | self.waitUntilSettled() |
| 3701 | |
| 3702 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3703 | self.assertEqual(0, len(self.smtp_messages)) |
| 3704 | |
| 3705 | # Check a merge failure is reported to SMTP |
| 3706 | # B should be merged, but C will conflict with B |
| 3707 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3708 | B.addPatchset(['conflict']) |
| 3709 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3710 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3711 | B.addApproval('code-review', 2) |
| 3712 | C.addApproval('code-review', 2) |
| 3713 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3714 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3715 | self.waitUntilSettled() |
| 3716 | |
| 3717 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3718 | self.assertEqual(1, len(self.smtp_messages)) |
| 3719 | self.assertEqual('The merge failed! For more information...', |
| 3720 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3721 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3722 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3723 | def test_default_merge_failure_reports(self): |
| 3724 | """Check that the default merge failure reports are correct.""" |
| 3725 | |
| 3726 | # A should report success, B should report merge failure. |
| 3727 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3728 | A.addPatchset(['conflict']) |
| 3729 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3730 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3731 | A.addApproval('code-review', 2) |
| 3732 | B.addApproval('code-review', 2) |
| 3733 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3734 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3735 | self.waitUntilSettled() |
| 3736 | |
| 3737 | self.assertEqual(3, len(self.history)) # A jobs |
| 3738 | self.assertEqual(A.reported, 2) |
| 3739 | self.assertEqual(B.reported, 2) |
| 3740 | self.assertEqual(A.data['status'], 'MERGED') |
| 3741 | self.assertEqual(B.data['status'], 'NEW') |
| 3742 | self.assertIn('Build succeeded', A.messages[1]) |
| 3743 | self.assertIn('Merge Failed', B.messages[1]) |
| 3744 | self.assertIn('automatically merged', B.messages[1]) |
| 3745 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3746 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3747 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3748 | def test_client_get_running_jobs(self): |
| 3749 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3750 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3751 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3752 | A.addApproval('code-review', 2) |
| 3753 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3754 | self.waitUntilSettled() |
| 3755 | |
| 3756 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3757 | self.gearman_server.port) |
| 3758 | |
| 3759 | # Wait for gearman server to send the initial workData back to zuul |
| 3760 | start = time.time() |
| 3761 | while True: |
| 3762 | if time.time() - start > 10: |
| 3763 | raise Exception("Timeout waiting for gearman server to report " |
| 3764 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3765 | build = self.executor_client.builds.values()[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3766 | if build.worker.name == "My Worker": |
| 3767 | break |
| 3768 | else: |
| 3769 | time.sleep(0) |
| 3770 | |
| 3771 | running_items = client.get_running_jobs() |
| 3772 | |
| 3773 | self.assertEqual(1, len(running_items)) |
| 3774 | running_item = running_items[0] |
| 3775 | self.assertEqual([], running_item['failing_reasons']) |
| 3776 | self.assertEqual([], running_item['items_behind']) |
| 3777 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3778 | self.assertEqual(None, running_item['item_ahead']) |
| 3779 | self.assertEqual('org/project', running_item['project']) |
| 3780 | self.assertEqual(None, running_item['remaining_time']) |
| 3781 | self.assertEqual(True, running_item['active']) |
| 3782 | self.assertEqual('1,1', running_item['id']) |
| 3783 | |
| 3784 | self.assertEqual(3, len(running_item['jobs'])) |
| 3785 | for job in running_item['jobs']: |
| 3786 | if job['name'] == 'project-merge': |
| 3787 | self.assertEqual('project-merge', job['name']) |
| 3788 | self.assertEqual('gate', job['pipeline']) |
| 3789 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3790 | self.assertEqual('https://server/job/project-merge/0/', |
| 3791 | job['url']) |
| 3792 | self.assertEqual(7, len(job['worker'])) |
| 3793 | self.assertEqual(False, job['canceled']) |
| 3794 | self.assertEqual(True, job['voting']) |
| 3795 | self.assertEqual(None, job['result']) |
| 3796 | self.assertEqual('gate', job['pipeline']) |
| 3797 | break |
| 3798 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3799 | self.executor_server.hold_jobs_in_build = False |
| 3800 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3801 | self.waitUntilSettled() |
| 3802 | |
| 3803 | running_items = client.get_running_jobs() |
| 3804 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3805 | |
| 3806 | def test_nonvoting_pipeline(self): |
| 3807 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3808 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3809 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3810 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3811 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3812 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3813 | |
| 3814 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3815 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3816 | self.assertEqual( |
| 3817 | self.getJobFromHistory('experimental-project-test').result, |
| 3818 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3819 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3820 | |
| 3821 | def test_crd_gate(self): |
| 3822 | "Test cross-repo dependencies" |
| 3823 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3824 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3825 | A.addApproval('code-review', 2) |
| 3826 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3827 | |
| 3828 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3829 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3830 | AM2.setMerged() |
| 3831 | AM1.setMerged() |
| 3832 | |
| 3833 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3834 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3835 | BM2.setMerged() |
| 3836 | BM1.setMerged() |
| 3837 | |
| 3838 | # A -> AM1 -> AM2 |
| 3839 | # B -> BM1 -> BM2 |
| 3840 | # A Depends-On: B |
| 3841 | # M2 is here to make sure it is never queried. If it is, it |
| 3842 | # means zuul is walking down the entire history of merged |
| 3843 | # changes. |
| 3844 | |
| 3845 | B.setDependsOn(BM1, 1) |
| 3846 | BM1.setDependsOn(BM2, 1) |
| 3847 | |
| 3848 | A.setDependsOn(AM1, 1) |
| 3849 | AM1.setDependsOn(AM2, 1) |
| 3850 | |
| 3851 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3852 | A.subject, B.data['id']) |
| 3853 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3854 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3855 | self.waitUntilSettled() |
| 3856 | |
| 3857 | self.assertEqual(A.data['status'], 'NEW') |
| 3858 | self.assertEqual(B.data['status'], 'NEW') |
| 3859 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3860 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3861 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3862 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3863 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3864 | B.addApproval('approved', 1) |
| 3865 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3866 | self.waitUntilSettled() |
| 3867 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3868 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3869 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3870 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3871 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3872 | self.executor_server.hold_jobs_in_build = False |
| 3873 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3874 | self.waitUntilSettled() |
| 3875 | |
| 3876 | self.assertEqual(AM2.queried, 0) |
| 3877 | self.assertEqual(BM2.queried, 0) |
| 3878 | self.assertEqual(A.data['status'], 'MERGED') |
| 3879 | self.assertEqual(B.data['status'], 'MERGED') |
| 3880 | self.assertEqual(A.reported, 2) |
| 3881 | self.assertEqual(B.reported, 2) |
| 3882 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3883 | changes = self.getJobFromHistory( |
| 3884 | 'project-merge', 'org/project1').changes |
| 3885 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3886 | |
| 3887 | def test_crd_branch(self): |
| 3888 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3889 | |
| 3890 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3891 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3892 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3893 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3894 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3895 | A.addApproval('code-review', 2) |
| 3896 | B.addApproval('code-review', 2) |
| 3897 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3898 | |
| 3899 | # A Depends-On: B+C |
| 3900 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3901 | A.subject, B.data['id']) |
| 3902 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3903 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3904 | B.addApproval('approved', 1) |
| 3905 | C.addApproval('approved', 1) |
| 3906 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3907 | self.waitUntilSettled() |
| 3908 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3909 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3910 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3911 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3912 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3913 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3914 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3915 | self.executor_server.hold_jobs_in_build = False |
| 3916 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3917 | self.waitUntilSettled() |
| 3918 | |
| 3919 | self.assertEqual(A.data['status'], 'MERGED') |
| 3920 | self.assertEqual(B.data['status'], 'MERGED') |
| 3921 | self.assertEqual(C.data['status'], 'MERGED') |
| 3922 | self.assertEqual(A.reported, 2) |
| 3923 | self.assertEqual(B.reported, 2) |
| 3924 | self.assertEqual(C.reported, 2) |
| 3925 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3926 | changes = self.getJobFromHistory( |
| 3927 | 'project-merge', 'org/project1').changes |
| 3928 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3929 | |
| 3930 | def test_crd_multiline(self): |
| 3931 | "Test multiple depends-on lines in commit" |
| 3932 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3933 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3934 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3935 | A.addApproval('code-review', 2) |
| 3936 | B.addApproval('code-review', 2) |
| 3937 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3938 | |
| 3939 | # A Depends-On: B+C |
| 3940 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3941 | A.subject, B.data['id'], C.data['id']) |
| 3942 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3943 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3944 | B.addApproval('approved', 1) |
| 3945 | C.addApproval('approved', 1) |
| 3946 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3947 | self.waitUntilSettled() |
| 3948 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3949 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3950 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3951 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3952 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3953 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3954 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3955 | self.executor_server.hold_jobs_in_build = False |
| 3956 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3957 | self.waitUntilSettled() |
| 3958 | |
| 3959 | self.assertEqual(A.data['status'], 'MERGED') |
| 3960 | self.assertEqual(B.data['status'], 'MERGED') |
| 3961 | self.assertEqual(C.data['status'], 'MERGED') |
| 3962 | self.assertEqual(A.reported, 2) |
| 3963 | self.assertEqual(B.reported, 2) |
| 3964 | self.assertEqual(C.reported, 2) |
| 3965 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3966 | changes = self.getJobFromHistory( |
| 3967 | 'project-merge', 'org/project1').changes |
| 3968 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3969 | |
| 3970 | def test_crd_unshared_gate(self): |
| 3971 | "Test cross-repo dependencies in unshared gate queues" |
| 3972 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3973 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3974 | A.addApproval('code-review', 2) |
| 3975 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3976 | |
| 3977 | # A Depends-On: B |
| 3978 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3979 | A.subject, B.data['id']) |
| 3980 | |
| 3981 | # A and B do not share a queue, make sure that A is unable to |
| 3982 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3983 | B.addApproval('approved', 1) |
| 3984 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3985 | self.waitUntilSettled() |
| 3986 | |
| 3987 | self.assertEqual(A.data['status'], 'NEW') |
| 3988 | self.assertEqual(B.data['status'], 'NEW') |
| 3989 | self.assertEqual(A.reported, 0) |
| 3990 | self.assertEqual(B.reported, 0) |
| 3991 | self.assertEqual(len(self.history), 0) |
| 3992 | |
| 3993 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3994 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3995 | self.waitUntilSettled() |
| 3996 | |
| 3997 | self.assertEqual(B.data['status'], 'MERGED') |
| 3998 | self.assertEqual(B.reported, 2) |
| 3999 | |
| 4000 | # Now that B is merged, A should be able to be enqueued and |
| 4001 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4002 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4003 | self.waitUntilSettled() |
| 4004 | |
| 4005 | self.assertEqual(A.data['status'], 'MERGED') |
| 4006 | self.assertEqual(A.reported, 2) |
| 4007 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4008 | def test_crd_gate_reverse(self): |
| 4009 | "Test reverse cross-repo dependencies" |
| 4010 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4011 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4012 | A.addApproval('code-review', 2) |
| 4013 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4014 | |
| 4015 | # A Depends-On: B |
| 4016 | |
| 4017 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4018 | A.subject, B.data['id']) |
| 4019 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4020 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4021 | self.waitUntilSettled() |
| 4022 | |
| 4023 | self.assertEqual(A.data['status'], 'NEW') |
| 4024 | self.assertEqual(B.data['status'], 'NEW') |
| 4025 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4026 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4027 | A.addApproval('approved', 1) |
| 4028 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4029 | self.waitUntilSettled() |
| 4030 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4031 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4032 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4033 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4034 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4035 | self.executor_server.hold_jobs_in_build = False |
| 4036 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4037 | self.waitUntilSettled() |
| 4038 | |
| 4039 | self.assertEqual(A.data['status'], 'MERGED') |
| 4040 | self.assertEqual(B.data['status'], 'MERGED') |
| 4041 | self.assertEqual(A.reported, 2) |
| 4042 | self.assertEqual(B.reported, 2) |
| 4043 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4044 | changes = self.getJobFromHistory( |
| 4045 | 'project-merge', 'org/project1').changes |
| 4046 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4047 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4048 | def test_crd_cycle(self): |
| 4049 | "Test cross-repo dependency cycles" |
| 4050 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4051 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4052 | A.addApproval('code-review', 2) |
| 4053 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4054 | |
| 4055 | # A -> B -> A (via commit-depends) |
| 4056 | |
| 4057 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4058 | A.subject, B.data['id']) |
| 4059 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4060 | B.subject, A.data['id']) |
| 4061 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4062 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4063 | self.waitUntilSettled() |
| 4064 | |
| 4065 | self.assertEqual(A.reported, 0) |
| 4066 | self.assertEqual(B.reported, 0) |
| 4067 | self.assertEqual(A.data['status'], 'NEW') |
| 4068 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4069 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4070 | def test_crd_gate_unknown(self): |
| 4071 | "Test unknown projects in dependent pipeline" |
| 4072 | self.init_repo("org/unknown") |
| 4073 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4074 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4075 | A.addApproval('code-review', 2) |
| 4076 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4077 | |
| 4078 | # A Depends-On: B |
| 4079 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4080 | A.subject, B.data['id']) |
| 4081 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4082 | B.addApproval('approved', 1) |
| 4083 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4084 | self.waitUntilSettled() |
| 4085 | |
| 4086 | # Unknown projects cannot share a queue with any other |
| 4087 | # since they don't have common jobs with any other (they have no jobs). |
| 4088 | # Changes which depend on unknown project changes |
| 4089 | # should not be processed in dependent pipeline |
| 4090 | self.assertEqual(A.data['status'], 'NEW') |
| 4091 | self.assertEqual(B.data['status'], 'NEW') |
| 4092 | self.assertEqual(A.reported, 0) |
| 4093 | self.assertEqual(B.reported, 0) |
| 4094 | self.assertEqual(len(self.history), 0) |
| 4095 | |
| 4096 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4097 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4098 | B.setMerged() |
| 4099 | self.waitUntilSettled() |
| 4100 | self.assertEqual(len(self.history), 0) |
| 4101 | |
| 4102 | # Now that B is merged, A should be able to be enqueued and |
| 4103 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4104 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4105 | self.waitUntilSettled() |
| 4106 | |
| 4107 | self.assertEqual(A.data['status'], 'MERGED') |
| 4108 | self.assertEqual(A.reported, 2) |
| 4109 | self.assertEqual(B.data['status'], 'MERGED') |
| 4110 | self.assertEqual(B.reported, 0) |
| 4111 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4112 | def test_crd_check(self): |
| 4113 | "Test cross-repo dependencies in independent pipelines" |
| 4114 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4115 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4116 | self.gearman_server.hold_jobs_in_queue = True |
| 4117 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4118 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4119 | |
| 4120 | # A Depends-On: B |
| 4121 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4122 | A.subject, B.data['id']) |
| 4123 | |
| 4124 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4125 | self.waitUntilSettled() |
| 4126 | |
| 4127 | queue = self.gearman_server.getQueue() |
| 4128 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 4129 | self.gearman_server.hold_jobs_in_queue = False |
| 4130 | self.gearman_server.release() |
| 4131 | self.waitUntilSettled() |
| 4132 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4133 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4134 | self.waitUntilSettled() |
| 4135 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4136 | path = os.path.join(self.builds[0].jobdir.src_root, "org/project1") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4137 | repo = git.Repo(path) |
| 4138 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4139 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4140 | correct_messages = [ |
| 4141 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4142 | self.assertEqual(repo_messages, correct_messages) |
| 4143 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4144 | path = os.path.join(self.builds[0].jobdir.src_root, "org/project2") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4145 | repo = git.Repo(path) |
| 4146 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4147 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4148 | correct_messages = [ |
| 4149 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4150 | self.assertEqual(repo_messages, correct_messages) |
| 4151 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4152 | self.executor_server.hold_jobs_in_build = False |
| 4153 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4154 | self.waitUntilSettled() |
| 4155 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4156 | self.assertEqual(A.data['status'], 'NEW') |
| 4157 | self.assertEqual(B.data['status'], 'NEW') |
| 4158 | self.assertEqual(A.reported, 1) |
| 4159 | self.assertEqual(B.reported, 0) |
| 4160 | |
| 4161 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4162 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4163 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4164 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4165 | def test_crd_check_git_depends(self): |
| 4166 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4167 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4168 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4169 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4170 | |
| 4171 | # Add two git-dependent changes and make sure they both report |
| 4172 | # success. |
| 4173 | B.setDependsOn(A, 1) |
| 4174 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4175 | self.waitUntilSettled() |
| 4176 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4177 | self.waitUntilSettled() |
| 4178 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4179 | self.orderedRelease() |
| 4180 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4181 | self.waitUntilSettled() |
| 4182 | |
| 4183 | self.assertEqual(A.data['status'], 'NEW') |
| 4184 | self.assertEqual(B.data['status'], 'NEW') |
| 4185 | self.assertEqual(A.reported, 1) |
| 4186 | self.assertEqual(B.reported, 1) |
| 4187 | |
| 4188 | self.assertEqual(self.history[0].changes, '1,1') |
| 4189 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4190 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4191 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4192 | |
| 4193 | self.assertIn('Build succeeded', A.messages[0]) |
| 4194 | self.assertIn('Build succeeded', B.messages[0]) |
| 4195 | |
| 4196 | def test_crd_check_duplicate(self): |
| 4197 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4198 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4199 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4200 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4201 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4202 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4203 | |
| 4204 | # Add two git-dependent changes... |
| 4205 | B.setDependsOn(A, 1) |
| 4206 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4207 | self.waitUntilSettled() |
| 4208 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4209 | |
| 4210 | # ...make sure the live one is not duplicated... |
| 4211 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4212 | self.waitUntilSettled() |
| 4213 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4214 | |
| 4215 | # ...but the non-live one is able to be. |
| 4216 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4217 | self.waitUntilSettled() |
| 4218 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4219 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4220 | # Release jobs in order to avoid races with change A jobs |
| 4221 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4222 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4223 | self.executor_server.hold_jobs_in_build = False |
| 4224 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4225 | self.waitUntilSettled() |
| 4226 | |
| 4227 | self.assertEqual(A.data['status'], 'NEW') |
| 4228 | self.assertEqual(B.data['status'], 'NEW') |
| 4229 | self.assertEqual(A.reported, 1) |
| 4230 | self.assertEqual(B.reported, 1) |
| 4231 | |
| 4232 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4233 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4234 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4235 | |
| 4236 | self.assertIn('Build succeeded', A.messages[0]) |
| 4237 | self.assertIn('Build succeeded', B.messages[0]) |
| 4238 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4239 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4240 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4241 | |
| 4242 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4243 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4244 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4245 | |
| 4246 | # A Depends-On: B |
| 4247 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4248 | A.subject, B.data['id']) |
| 4249 | |
| 4250 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4251 | self.waitUntilSettled() |
| 4252 | |
| 4253 | self.sched.reconfigure(self.config) |
| 4254 | |
| 4255 | # Make sure the items still share a change queue, and the |
| 4256 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4257 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4258 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4259 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4260 | first_item = queue.queue[0] |
| 4261 | for item in queue.queue: |
| 4262 | self.assertEqual(item.queue, first_item.queue) |
| 4263 | self.assertFalse(first_item.live) |
| 4264 | self.assertTrue(queue.queue[1].live) |
| 4265 | |
| 4266 | self.gearman_server.hold_jobs_in_queue = False |
| 4267 | self.gearman_server.release() |
| 4268 | self.waitUntilSettled() |
| 4269 | |
| 4270 | self.assertEqual(A.data['status'], 'NEW') |
| 4271 | self.assertEqual(B.data['status'], 'NEW') |
| 4272 | self.assertEqual(A.reported, 1) |
| 4273 | self.assertEqual(B.reported, 0) |
| 4274 | |
| 4275 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4276 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4277 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4278 | def test_crd_check_reconfiguration(self): |
| 4279 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4280 | |
| 4281 | def test_crd_undefined_project(self): |
| 4282 | """Test that undefined projects in dependencies are handled for |
| 4283 | independent pipelines""" |
| 4284 | # It's a hack for fake gerrit, |
| 4285 | # as it implies repo creation upon the creation of any change |
| 4286 | self.init_repo("org/unknown") |
| 4287 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4288 | |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4289 | def test_crd_check_ignore_dependencies(self): |
| 4290 | "Test cross-repo dependencies can be ignored" |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4291 | self.updateConfigLayout('layout-ignore-dependencies') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4292 | self.sched.reconfigure(self.config) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4293 | |
| 4294 | self.gearman_server.hold_jobs_in_queue = True |
| 4295 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4296 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4297 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4298 | |
| 4299 | # A Depends-On: B |
| 4300 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4301 | A.subject, B.data['id']) |
| 4302 | # C git-depends on B |
| 4303 | C.setDependsOn(B, 1) |
| 4304 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4305 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4306 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4307 | self.waitUntilSettled() |
| 4308 | |
| 4309 | # Make sure none of the items share a change queue, and all |
| 4310 | # are live. |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4311 | tenant = self.sched.abide.tenants.get('openstack') |
| 4312 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4313 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4314 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4315 | for item in check_pipeline.getAllItems(): |
| 4316 | self.assertTrue(item.live) |
| 4317 | |
| 4318 | self.gearman_server.hold_jobs_in_queue = False |
| 4319 | self.gearman_server.release() |
| 4320 | self.waitUntilSettled() |
| 4321 | |
| 4322 | self.assertEqual(A.data['status'], 'NEW') |
| 4323 | self.assertEqual(B.data['status'], 'NEW') |
| 4324 | self.assertEqual(C.data['status'], 'NEW') |
| 4325 | self.assertEqual(A.reported, 1) |
| 4326 | self.assertEqual(B.reported, 1) |
| 4327 | self.assertEqual(C.reported, 1) |
| 4328 | |
| 4329 | # Each job should have tested exactly one change |
| 4330 | for job in self.history: |
| 4331 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4332 | |
| 4333 | def test_crd_check_transitive(self): |
| 4334 | "Test transitive cross-repo dependencies" |
| 4335 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4336 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4337 | # and C,2 (not C,1 which would indicate stale data in the |
| 4338 | # cache for B). |
| 4339 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4340 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4341 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4342 | |
| 4343 | # A Depends-On: B |
| 4344 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4345 | A.subject, B.data['id']) |
| 4346 | |
| 4347 | # B Depends-On: C |
| 4348 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4349 | B.subject, C.data['id']) |
| 4350 | |
| 4351 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4352 | self.waitUntilSettled() |
| 4353 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4354 | |
| 4355 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4356 | self.waitUntilSettled() |
| 4357 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4358 | |
| 4359 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4360 | self.waitUntilSettled() |
| 4361 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4362 | |
| 4363 | C.addPatchset() |
| 4364 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4365 | self.waitUntilSettled() |
| 4366 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4367 | |
| 4368 | A.addPatchset() |
| 4369 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4370 | self.waitUntilSettled() |
| 4371 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4372 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4373 | def test_crd_check_unknown(self): |
| 4374 | "Test unknown projects in independent pipeline" |
| 4375 | self.init_repo("org/unknown") |
| 4376 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4377 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4378 | # A Depends-On: B |
| 4379 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4380 | A.subject, B.data['id']) |
| 4381 | |
| 4382 | # Make sure zuul has seen an event on B. |
| 4383 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4384 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4385 | self.waitUntilSettled() |
| 4386 | |
| 4387 | self.assertEqual(A.data['status'], 'NEW') |
| 4388 | self.assertEqual(A.reported, 1) |
| 4389 | self.assertEqual(B.data['status'], 'NEW') |
| 4390 | self.assertEqual(B.reported, 0) |
| 4391 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4392 | def test_crd_cycle_join(self): |
| 4393 | "Test an updated change creates a cycle" |
| 4394 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4395 | |
| 4396 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4397 | self.waitUntilSettled() |
| 4398 | |
| 4399 | # Create B->A |
| 4400 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4401 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4402 | B.subject, A.data['id']) |
| 4403 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4404 | self.waitUntilSettled() |
| 4405 | |
| 4406 | # Update A to add A->B (a cycle). |
| 4407 | A.addPatchset() |
| 4408 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4409 | A.subject, B.data['id']) |
| 4410 | # Normally we would submit the patchset-created event for |
| 4411 | # processing here, however, we have no way of noting whether |
| 4412 | # the dependency cycle detection correctly raised an |
| 4413 | # exception, so instead, we reach into the source driver and |
| 4414 | # call the method that would ultimately be called by the event |
| 4415 | # processing. |
| 4416 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4417 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4418 | source = tenant.layout.pipelines['gate'].source |
| 4419 | |
| 4420 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4421 | # it easier for users to create events for testing. |
| 4422 | event = zuul.model.TriggerEvent() |
| 4423 | event.trigger_name = 'gerrit' |
| 4424 | event.change_number = '1' |
| 4425 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4426 | with testtools.ExpectedException( |
| 4427 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4428 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4429 | self.log.debug("Got expected dependency cycle exception") |
| 4430 | |
| 4431 | # Now if we update B to remove the depends-on, everything |
| 4432 | # should be okay. B; A->B |
| 4433 | |
| 4434 | B.addPatchset() |
| 4435 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4436 | |
| 4437 | source.getChange(event, True) |
| 4438 | event.change_number = '2' |
| 4439 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4440 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4441 | def test_disable_at(self): |
| 4442 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4443 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4444 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4445 | self.sched.reconfigure(self.config) |
| 4446 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4447 | tenant = self.sched.abide.tenants.get('openstack') |
| 4448 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4449 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4450 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4451 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4452 | |
| 4453 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4454 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4455 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4456 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4457 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4458 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4459 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4460 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4461 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4462 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4463 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4464 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4465 | self.executor_server.failJob('project-test1', A) |
| 4466 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4467 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4468 | self.executor_server.failJob('project-test1', D) |
| 4469 | self.executor_server.failJob('project-test1', E) |
| 4470 | self.executor_server.failJob('project-test1', F) |
| 4471 | self.executor_server.failJob('project-test1', G) |
| 4472 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4473 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4474 | self.executor_server.failJob('project-test1', J) |
| 4475 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4476 | |
| 4477 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4478 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4479 | self.waitUntilSettled() |
| 4480 | |
| 4481 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4482 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4483 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4484 | |
| 4485 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4486 | self.waitUntilSettled() |
| 4487 | |
| 4488 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4489 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4490 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4491 | |
| 4492 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4493 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4494 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4495 | self.waitUntilSettled() |
| 4496 | |
| 4497 | # We should be disabled now |
| 4498 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4499 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4500 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4501 | |
| 4502 | # We need to wait between each of these patches to make sure the |
| 4503 | # smtp messages come back in an expected order |
| 4504 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4505 | self.waitUntilSettled() |
| 4506 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4507 | self.waitUntilSettled() |
| 4508 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4509 | self.waitUntilSettled() |
| 4510 | |
| 4511 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4512 | # leaving a message on each change |
| 4513 | self.assertEqual(1, len(A.messages)) |
| 4514 | self.assertIn('Build failed.', A.messages[0]) |
| 4515 | self.assertEqual(1, len(B.messages)) |
| 4516 | self.assertIn('Build failed.', B.messages[0]) |
| 4517 | self.assertEqual(1, len(C.messages)) |
| 4518 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4519 | self.assertEqual(1, len(D.messages)) |
| 4520 | self.assertIn('Build failed.', D.messages[0]) |
| 4521 | self.assertEqual(1, len(E.messages)) |
| 4522 | self.assertIn('Build failed.', E.messages[0]) |
| 4523 | self.assertEqual(1, len(F.messages)) |
| 4524 | self.assertIn('Build failed.', F.messages[0]) |
| 4525 | |
| 4526 | # The last 3 (GHI) would have only reported via smtp. |
| 4527 | self.assertEqual(3, len(self.smtp_messages)) |
| 4528 | self.assertEqual(0, len(G.messages)) |
| 4529 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4530 | self.assertIn( |
| 4531 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4532 | self.assertEqual(0, len(H.messages)) |
| 4533 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4534 | self.assertIn( |
| 4535 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4536 | self.assertEqual(0, len(I.messages)) |
| 4537 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4538 | self.assertIn( |
| 4539 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4540 | |
| 4541 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4542 | # comes out of disabled |
| 4543 | self.sched.reconfigure(self.config) |
| 4544 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4545 | tenant = self.sched.abide.tenants.get('openstack') |
| 4546 | |
| 4547 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4548 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4549 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4550 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4551 | |
| 4552 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4553 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4554 | self.waitUntilSettled() |
| 4555 | |
| 4556 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4557 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4558 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4559 | |
| 4560 | # J and K went back to gerrit |
| 4561 | self.assertEqual(1, len(J.messages)) |
| 4562 | self.assertIn('Build failed.', J.messages[0]) |
| 4563 | self.assertEqual(1, len(K.messages)) |
| 4564 | self.assertIn('Build failed.', K.messages[0]) |
| 4565 | # No more messages reported via smtp |
| 4566 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4567 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4568 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4569 | "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] | 4570 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4571 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4572 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4573 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4574 | self.waitUntilSettled() |
| 4575 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4576 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4577 | self.waitUntilSettled() |
| 4578 | |
| 4579 | self.assertEqual(len(self.builds), 2) |
| 4580 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4581 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4582 | self.waitUntilSettled() |
| 4583 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4584 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4585 | self.assertEqual(len(self.builds), 1, |
| 4586 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4587 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4588 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4589 | self.waitUntilSettled() |
| 4590 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4591 | self.executor_server.hold_jobs_in_build = False |
| 4592 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4593 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4594 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4595 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4596 | self.assertEqual(A.reported, 1) |
| 4597 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4598 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4599 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4600 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4601 | |
| 4602 | self.fake_nodepool.paused = True |
| 4603 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4604 | A.addApproval('code-review', 2) |
| 4605 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4606 | self.waitUntilSettled() |
| 4607 | |
| 4608 | self.zk.client.stop() |
| 4609 | self.zk.client.start() |
| 4610 | self.fake_nodepool.paused = False |
| 4611 | self.waitUntilSettled() |
| 4612 | |
| 4613 | self.assertEqual(A.data['status'], 'MERGED') |
| 4614 | self.assertEqual(A.reported, 2) |
| 4615 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4616 | def test_nodepool_failure(self): |
| 4617 | "Test that jobs are reported after a nodepool failure" |
| 4618 | |
| 4619 | self.fake_nodepool.paused = True |
| 4620 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4621 | A.addApproval('code-review', 2) |
| 4622 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4623 | self.waitUntilSettled() |
| 4624 | |
| 4625 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4626 | self.fake_nodepool.addFailRequest(req) |
| 4627 | |
| 4628 | self.fake_nodepool.paused = False |
| 4629 | self.waitUntilSettled() |
| 4630 | |
| 4631 | self.assertEqual(A.data['status'], 'NEW') |
| 4632 | self.assertEqual(A.reported, 2) |
| 4633 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4634 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4635 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4636 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4637 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4638 | class TestExecutor(ZuulTestCase): |
| 4639 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4640 | |
| 4641 | def assertFinalState(self): |
| 4642 | # In this test, we expect to shut down in a non-final state, |
| 4643 | # so skip these checks. |
| 4644 | pass |
| 4645 | |
| 4646 | def assertCleanShutdown(self): |
| 4647 | self.log.debug("Assert clean shutdown") |
| 4648 | |
| 4649 | # After shutdown, make sure no jobs are running |
| 4650 | self.assertEqual({}, self.executor_server.job_workers) |
| 4651 | |
| 4652 | # Make sure that git.Repo objects have been garbage collected. |
| 4653 | repos = [] |
| 4654 | gc.collect() |
| 4655 | for obj in gc.get_objects(): |
| 4656 | if isinstance(obj, git.Repo): |
| 4657 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4658 | repos.append(obj) |
| 4659 | self.assertEqual(len(repos), 0) |
| 4660 | |
| 4661 | def test_executor_shutdown(self): |
| 4662 | "Test that the executor can shut down with jobs running" |
| 4663 | |
| 4664 | self.executor_server.hold_jobs_in_build = True |
| 4665 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4666 | A.addApproval('code-review', 2) |
| 4667 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4668 | self.waitUntilSettled() |
| 4669 | |
| 4670 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4671 | class TestDependencyGraph(ZuulTestCase): |
| 4672 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4673 | |
| 4674 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4675 | "Test a job in a dependency graph is queued only once" |
| 4676 | # Job dependencies, starting with A |
| 4677 | # A |
| 4678 | # / \ |
| 4679 | # B C |
| 4680 | # / \ / \ |
| 4681 | # D F E |
| 4682 | # | |
| 4683 | # G |
| 4684 | |
| 4685 | self.executor_server.hold_jobs_in_build = True |
| 4686 | change = self.fake_gerrit.addFakeChange( |
| 4687 | 'org/project', 'master', 'change') |
| 4688 | change.addApproval('code-review', 2) |
| 4689 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4690 | |
| 4691 | self.waitUntilSettled() |
| 4692 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4693 | |
| 4694 | self.executor_server.release('A') |
| 4695 | self.waitUntilSettled() |
| 4696 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4697 | |
| 4698 | self.executor_server.release('B') |
| 4699 | self.waitUntilSettled() |
| 4700 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4701 | |
| 4702 | self.executor_server.release('D') |
| 4703 | self.waitUntilSettled() |
| 4704 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4705 | |
| 4706 | self.executor_server.release('C') |
| 4707 | self.waitUntilSettled() |
| 4708 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4709 | |
| 4710 | self.executor_server.release('F') |
| 4711 | self.waitUntilSettled() |
| 4712 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4713 | |
| 4714 | self.executor_server.release('G') |
| 4715 | self.waitUntilSettled() |
| 4716 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4717 | |
| 4718 | self.executor_server.release('E') |
| 4719 | self.waitUntilSettled() |
| 4720 | self.assertEqual(len(self.builds), 0) |
| 4721 | |
| 4722 | self.executor_server.hold_jobs_in_build = False |
| 4723 | self.executor_server.release() |
| 4724 | self.waitUntilSettled() |
| 4725 | |
| 4726 | self.assertEqual(len(self.builds), 0) |
| 4727 | self.assertEqual(len(self.history), 7) |
| 4728 | |
| 4729 | self.assertEqual(change.data['status'], 'MERGED') |
| 4730 | self.assertEqual(change.reported, 2) |
| 4731 | |
| 4732 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4733 | "Test that a job waits till all dependencies are successful" |
| 4734 | # Job dependencies, starting with A |
| 4735 | # A |
| 4736 | # / \ |
| 4737 | # B C* |
| 4738 | # / \ / \ |
| 4739 | # D F E |
| 4740 | # | |
| 4741 | # G |
| 4742 | |
| 4743 | self.executor_server.hold_jobs_in_build = True |
| 4744 | change = self.fake_gerrit.addFakeChange( |
| 4745 | 'org/project', 'master', 'change') |
| 4746 | change.addApproval('code-review', 2) |
| 4747 | |
| 4748 | self.executor_server.failJob('C', change) |
| 4749 | |
| 4750 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4751 | |
| 4752 | self.waitUntilSettled() |
| 4753 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4754 | |
| 4755 | self.executor_server.release('A') |
| 4756 | self.waitUntilSettled() |
| 4757 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4758 | |
| 4759 | self.executor_server.release('B') |
| 4760 | self.waitUntilSettled() |
| 4761 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4762 | |
| 4763 | self.executor_server.release('D') |
| 4764 | self.waitUntilSettled() |
| 4765 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4766 | |
| 4767 | self.executor_server.release('C') |
| 4768 | self.waitUntilSettled() |
| 4769 | self.assertEqual(len(self.builds), 0) |
| 4770 | |
| 4771 | self.executor_server.hold_jobs_in_build = False |
| 4772 | self.executor_server.release() |
| 4773 | self.waitUntilSettled() |
| 4774 | |
| 4775 | self.assertEqual(len(self.builds), 0) |
| 4776 | self.assertEqual(len(self.history), 4) |
| 4777 | |
| 4778 | self.assertEqual(change.data['status'], 'NEW') |
| 4779 | self.assertEqual(change.reported, 2) |
| 4780 | |
| 4781 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4782 | class TestDuplicatePipeline(ZuulTestCase): |
| 4783 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4784 | |
| 4785 | def test_duplicate_pipelines(self): |
| 4786 | "Test that a change matching multiple pipelines works" |
| 4787 | |
| 4788 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4789 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4790 | self.waitUntilSettled() |
| 4791 | |
| 4792 | self.assertHistory([ |
| 4793 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4794 | pipeline='dup1'), |
| 4795 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4796 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4797 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4798 | |
| 4799 | self.assertEqual(len(A.messages), 2) |
| 4800 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4801 | if 'dup1' in A.messages[0]: |
| 4802 | self.assertIn('dup1', A.messages[0]) |
| 4803 | self.assertNotIn('dup2', A.messages[0]) |
| 4804 | self.assertIn('project-test1', A.messages[0]) |
| 4805 | self.assertIn('dup2', A.messages[1]) |
| 4806 | self.assertNotIn('dup1', A.messages[1]) |
| 4807 | self.assertIn('project-test1', A.messages[1]) |
| 4808 | else: |
| 4809 | self.assertIn('dup1', A.messages[1]) |
| 4810 | self.assertNotIn('dup2', A.messages[1]) |
| 4811 | self.assertIn('project-test1', A.messages[1]) |
| 4812 | self.assertIn('dup2', A.messages[0]) |
| 4813 | self.assertNotIn('dup1', A.messages[0]) |
| 4814 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4815 | |
| 4816 | |
| 4817 | class TestSchedulerOneJobProject(ZuulTestCase): |
| 4818 | tenant_config_file = 'config/one-job-project/main.yaml' |
| 4819 | |
| 4820 | def test_one_job_project(self): |
| 4821 | "Test that queueing works with one job" |
| 4822 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4823 | 'master', 'A') |
| 4824 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4825 | 'master', 'B') |
| 4826 | A.addApproval('code-review', 2) |
| 4827 | B.addApproval('code-review', 2) |
| 4828 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4829 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4830 | self.waitUntilSettled() |
| 4831 | |
| 4832 | self.assertEqual(A.data['status'], 'MERGED') |
| 4833 | self.assertEqual(A.reported, 2) |
| 4834 | self.assertEqual(B.data['status'], 'MERGED') |
| 4835 | self.assertEqual(B.reported, 2) |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4836 | |
| 4837 | |
| 4838 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4839 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4840 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4841 | def test_job_from_templates_executed(self): |
| 4842 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4843 | |
| 4844 | A = self.fake_gerrit.addFakeChange( |
| 4845 | 'org/templated-project', 'master', 'A') |
| 4846 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4847 | self.waitUntilSettled() |
| 4848 | |
| 4849 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4850 | 'SUCCESS') |
| 4851 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4852 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4853 | |
| 4854 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4855 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4856 | |
| 4857 | A = self.fake_gerrit.addFakeChange( |
| 4858 | 'org/layered-project', 'master', 'A') |
| 4859 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4860 | self.waitUntilSettled() |
| 4861 | |
| 4862 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4863 | 'SUCCESS') |
| 4864 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4865 | 'SUCCESS') |
| 4866 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4867 | ).result, 'SUCCESS') |
| 4868 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4869 | ).result, 'SUCCESS') |
| 4870 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4871 | ).result, 'SUCCESS') |
| 4872 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4873 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4874 | |
| 4875 | |
| 4876 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4877 | tenant_config_file = 'config/success-url/main.yaml' |
| 4878 | |
| 4879 | def test_success_url(self): |
| 4880 | "Ensure bad build params are ignored" |
| 4881 | self.sched.reconfigure(self.config) |
| 4882 | self.init_repo('org/docs') |
| 4883 | |
| 4884 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4885 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4886 | self.waitUntilSettled() |
| 4887 | |
| 4888 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4889 | self.assertEqual(len(self.history), 2) |
| 4890 | |
| 4891 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4892 | for build in self.history: |
| 4893 | if build.name == 'docs-draft-test': |
| 4894 | uuid = build.uuid[:7] |
| 4895 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4896 | |
| 4897 | # Two msgs: 'Starting...' + results |
| 4898 | self.assertEqual(len(self.smtp_messages), 2) |
| 4899 | body = self.smtp_messages[1]['body'].splitlines() |
| 4900 | self.assertEqual('Build succeeded.', body[0]) |
| 4901 | |
| 4902 | self.assertIn( |
| 4903 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4904 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4905 | body[2]) |
| 4906 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4907 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4908 | self.assertIn( |
| 4909 | '- docs-draft-test2 https://server/job', |
| 4910 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4911 | |
| 4912 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4913 | class TestSchedulerMerges(ZuulTestCase): |
| 4914 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4915 | |
| 4916 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4917 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4918 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4919 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4920 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4921 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4922 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4923 | A.addApproval('code-review', 2) |
| 4924 | B.addApproval('code-review', 2) |
| 4925 | C.addApproval('code-review', 2) |
| 4926 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4927 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4928 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4929 | self.waitUntilSettled() |
| 4930 | |
| 4931 | build = self.builds[-1] |
| 4932 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4933 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4934 | path = os.path.join(build.jobdir.src_root, project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4935 | repo = git.Repo(path) |
| 4936 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4937 | repo_messages.reverse() |
| 4938 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4939 | self.executor_server.hold_jobs_in_build = False |
| 4940 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4941 | self.waitUntilSettled() |
| 4942 | |
| 4943 | return repo_messages |
| 4944 | |
| 4945 | def _test_merge(self, mode): |
| 4946 | us_path = os.path.join( |
| 4947 | self.upstream_root, 'org/project-%s' % mode) |
| 4948 | expected_messages = [ |
| 4949 | 'initial commit', |
| 4950 | 'add content from fixture', |
| 4951 | # the intermediate commits order is nondeterministic |
| 4952 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4953 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4954 | ] |
| 4955 | result = self._test_project_merge_mode(mode) |
| 4956 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4957 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4958 | |
| 4959 | def test_project_merge_mode_merge(self): |
| 4960 | self._test_merge('merge') |
| 4961 | |
| 4962 | def test_project_merge_mode_merge_resolve(self): |
| 4963 | self._test_merge('merge-resolve') |
| 4964 | |
| 4965 | def test_project_merge_mode_cherrypick(self): |
| 4966 | expected_messages = [ |
| 4967 | 'initial commit', |
| 4968 | 'add content from fixture', |
| 4969 | 'A-1', |
| 4970 | 'B-1', |
| 4971 | 'C-1'] |
| 4972 | result = self._test_project_merge_mode('cherry-pick') |
| 4973 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4974 | |
| 4975 | def test_merge_branch(self): |
| 4976 | "Test that the right commits are on alternate branches" |
| 4977 | self.create_branch('org/project-merge-branches', 'mp') |
| 4978 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4979 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4980 | A = self.fake_gerrit.addFakeChange( |
| 4981 | 'org/project-merge-branches', 'mp', 'A') |
| 4982 | B = self.fake_gerrit.addFakeChange( |
| 4983 | 'org/project-merge-branches', 'mp', 'B') |
| 4984 | C = self.fake_gerrit.addFakeChange( |
| 4985 | 'org/project-merge-branches', 'mp', 'C') |
| 4986 | A.addApproval('code-review', 2) |
| 4987 | B.addApproval('code-review', 2) |
| 4988 | C.addApproval('code-review', 2) |
| 4989 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4990 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4991 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4992 | self.waitUntilSettled() |
| 4993 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4994 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4995 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4996 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4997 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4998 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4999 | self.waitUntilSettled() |
| 5000 | |
| 5001 | build = self.builds[-1] |
| 5002 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 5003 | ref = self.getParameter(build, 'ZUUL_REF') |
| 5004 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5005 | build.jobdir.src_root, 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5006 | repo = git.Repo(path) |
| 5007 | |
| 5008 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 5009 | repo_messages.reverse() |
| 5010 | correct_messages = [ |
| 5011 | 'initial commit', |
| 5012 | 'add content from fixture', |
| 5013 | 'mp commit', |
| 5014 | 'A-1', 'B-1', 'C-1'] |
| 5015 | self.assertEqual(repo_messages, correct_messages) |
| 5016 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5017 | self.executor_server.hold_jobs_in_build = False |
| 5018 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5019 | self.waitUntilSettled() |
| 5020 | |
| 5021 | def test_merge_multi_branch(self): |
| 5022 | "Test that dependent changes on multiple branches are merged" |
| 5023 | self.create_branch('org/project-merge-branches', 'mp') |
| 5024 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5025 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5026 | A = self.fake_gerrit.addFakeChange( |
| 5027 | 'org/project-merge-branches', 'master', 'A') |
| 5028 | B = self.fake_gerrit.addFakeChange( |
| 5029 | 'org/project-merge-branches', 'mp', 'B') |
| 5030 | C = self.fake_gerrit.addFakeChange( |
| 5031 | 'org/project-merge-branches', 'master', 'C') |
| 5032 | A.addApproval('code-review', 2) |
| 5033 | B.addApproval('code-review', 2) |
| 5034 | C.addApproval('code-review', 2) |
| 5035 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5036 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5037 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5038 | self.waitUntilSettled() |
| 5039 | |
| 5040 | job_A = None |
| 5041 | for job in self.builds: |
| 5042 | if 'project-merge' in job.name: |
| 5043 | job_A = job |
| 5044 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 5045 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 5046 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 5047 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 5048 | |
| 5049 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5050 | job_A.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5051 | repo = git.Repo(path) |
| 5052 | repo_messages = [c.message.strip() |
| 5053 | for c in repo.iter_commits(ref_A)] |
| 5054 | repo_messages.reverse() |
| 5055 | correct_messages = [ |
| 5056 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5057 | self.assertEqual(repo_messages, correct_messages) |
| 5058 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5059 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5060 | self.waitUntilSettled() |
| 5061 | |
| 5062 | job_B = None |
| 5063 | for job in self.builds: |
| 5064 | if 'project-merge' in job.name: |
| 5065 | job_B = job |
| 5066 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 5067 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 5068 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 5069 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 5070 | |
| 5071 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5072 | job_B.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5073 | repo = git.Repo(path) |
| 5074 | repo_messages = [c.message.strip() |
| 5075 | for c in repo.iter_commits(ref_B)] |
| 5076 | repo_messages.reverse() |
| 5077 | correct_messages = [ |
| 5078 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5079 | self.assertEqual(repo_messages, correct_messages) |
| 5080 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5081 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5082 | self.waitUntilSettled() |
| 5083 | |
| 5084 | job_C = None |
| 5085 | for job in self.builds: |
| 5086 | if 'project-merge' in job.name: |
| 5087 | job_C = job |
| 5088 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 5089 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 5090 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 5091 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
| 5092 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5093 | job_C.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5094 | repo = git.Repo(path) |
| 5095 | repo_messages = [c.message.strip() |
| 5096 | for c in repo.iter_commits(ref_C)] |
| 5097 | |
| 5098 | repo_messages.reverse() |
| 5099 | correct_messages = [ |
| 5100 | 'initial commit', 'add content from fixture', |
| 5101 | 'A-1', 'C-1'] |
| 5102 | # Ensure the right commits are in the history for this ref |
| 5103 | self.assertEqual(repo_messages, correct_messages) |
| 5104 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5105 | self.executor_server.hold_jobs_in_build = False |
| 5106 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5107 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5108 | |
| 5109 | |
| 5110 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5111 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5112 | |
| 5113 | def test_semaphore_tenant_isolation(self): |
| 5114 | "Test semaphores in multiple tenants" |
| 5115 | |
| 5116 | self.waitUntilSettled() |
| 5117 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5118 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5119 | |
| 5120 | self.executor_server.hold_jobs_in_build = True |
| 5121 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5122 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5123 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5124 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5125 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5126 | self.assertFalse('test-semaphore' in |
| 5127 | tenant_one.semaphore_handler.semaphores) |
| 5128 | self.assertFalse('test-semaphore' in |
| 5129 | tenant_two.semaphore_handler.semaphores) |
| 5130 | |
| 5131 | # add patches to project1 of tenant-one |
| 5132 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5133 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5134 | self.waitUntilSettled() |
| 5135 | |
| 5136 | # one build of project1-test1 must run |
| 5137 | # semaphore of tenant-one must be acquired once |
| 5138 | # semaphore of tenant-two must not be acquired |
| 5139 | self.assertEqual(len(self.builds), 1) |
| 5140 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5141 | self.assertTrue('test-semaphore' in |
| 5142 | tenant_one.semaphore_handler.semaphores) |
| 5143 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5144 | 'test-semaphore', [])), 1) |
| 5145 | self.assertFalse('test-semaphore' in |
| 5146 | tenant_two.semaphore_handler.semaphores) |
| 5147 | |
| 5148 | # add patches to project2 of tenant-two |
| 5149 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5150 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5151 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5152 | self.waitUntilSettled() |
| 5153 | |
| 5154 | # one build of project1-test1 must run |
| 5155 | # two builds of project2-test1 must run |
| 5156 | # semaphore of tenant-one must be acquired once |
| 5157 | # semaphore of tenant-two must be acquired twice |
| 5158 | self.assertEqual(len(self.builds), 3) |
| 5159 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5160 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5161 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5162 | self.assertTrue('test-semaphore' in |
| 5163 | tenant_one.semaphore_handler.semaphores) |
| 5164 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5165 | 'test-semaphore', [])), 1) |
| 5166 | self.assertTrue('test-semaphore' in |
| 5167 | tenant_two.semaphore_handler.semaphores) |
| 5168 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5169 | 'test-semaphore', [])), 2) |
| 5170 | |
| 5171 | self.executor_server.release('project1-test1') |
| 5172 | self.waitUntilSettled() |
| 5173 | |
| 5174 | # one build of project1-test1 must run |
| 5175 | # two builds of project2-test1 must run |
| 5176 | # semaphore of tenant-one must be acquired once |
| 5177 | # semaphore of tenant-two must be acquired twice |
| 5178 | self.assertEqual(len(self.builds), 3) |
| 5179 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5180 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5181 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5182 | self.assertTrue('test-semaphore' in |
| 5183 | tenant_one.semaphore_handler.semaphores) |
| 5184 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5185 | 'test-semaphore', [])), 1) |
| 5186 | self.assertTrue('test-semaphore' in |
| 5187 | tenant_two.semaphore_handler.semaphores) |
| 5188 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5189 | 'test-semaphore', [])), 2) |
| 5190 | |
| 5191 | self.executor_server.release('project2-test1') |
| 5192 | self.waitUntilSettled() |
| 5193 | |
| 5194 | # one build of project1-test1 must run |
| 5195 | # one build of project2-test1 must run |
| 5196 | # semaphore of tenant-one must be acquired once |
| 5197 | # semaphore of tenant-two must be acquired once |
| 5198 | self.assertEqual(len(self.builds), 2) |
| 5199 | self.assertTrue('test-semaphore' in |
| 5200 | tenant_one.semaphore_handler.semaphores) |
| 5201 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5202 | 'test-semaphore', [])), 1) |
| 5203 | self.assertTrue('test-semaphore' in |
| 5204 | tenant_two.semaphore_handler.semaphores) |
| 5205 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5206 | 'test-semaphore', [])), 1) |
| 5207 | |
| 5208 | self.executor_server.hold_jobs_in_build = False |
| 5209 | self.executor_server.release() |
| 5210 | |
| 5211 | self.waitUntilSettled() |
| 5212 | |
| 5213 | # no build must run |
| 5214 | # semaphore of tenant-one must not be acquired |
| 5215 | # semaphore of tenant-two must not be acquired |
| 5216 | self.assertEqual(len(self.builds), 0) |
| 5217 | self.assertFalse('test-semaphore' in |
| 5218 | tenant_one.semaphore_handler.semaphores) |
| 5219 | self.assertFalse('test-semaphore' in |
| 5220 | tenant_two.semaphore_handler.semaphores) |
| 5221 | |
| 5222 | self.assertEqual(A.reported, 1) |
| 5223 | self.assertEqual(B.reported, 1) |
| 5224 | |
| 5225 | |
| 5226 | class TestSemaphoreInRepo(ZuulTestCase): |
| 5227 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5228 | |
| 5229 | def test_semaphore_in_repo(self): |
| 5230 | "Test semaphores in repo config" |
| 5231 | |
| 5232 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5233 | # max value should not be evaluated dynamically but must be updated |
| 5234 | # after the change lands. |
| 5235 | |
| 5236 | self.waitUntilSettled() |
| 5237 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5238 | |
| 5239 | in_repo_conf = textwrap.dedent( |
| 5240 | """ |
| 5241 | - job: |
| 5242 | name: project-test2 |
| 5243 | semaphore: test-semaphore |
| 5244 | |
| 5245 | - project: |
| 5246 | name: org/project |
| 5247 | tenant-one-gate: |
| 5248 | jobs: |
| 5249 | - project-test2 |
| 5250 | |
| 5251 | # the max value in dynamic layout must be ignored |
| 5252 | - semaphore: |
| 5253 | name: test-semaphore |
| 5254 | max: 2 |
| 5255 | """) |
| 5256 | |
| 5257 | in_repo_playbook = textwrap.dedent( |
| 5258 | """ |
| 5259 | - hosts: all |
| 5260 | tasks: [] |
| 5261 | """) |
| 5262 | |
| 5263 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5264 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5265 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5266 | files=file_dict) |
| 5267 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5268 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5269 | B.setDependsOn(A, 1) |
| 5270 | C.setDependsOn(A, 1) |
| 5271 | |
| 5272 | self.executor_server.hold_jobs_in_build = True |
| 5273 | |
| 5274 | A.addApproval('code-review', 2) |
| 5275 | B.addApproval('code-review', 2) |
| 5276 | C.addApproval('code-review', 2) |
| 5277 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5278 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5279 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5280 | self.waitUntilSettled() |
| 5281 | |
| 5282 | # check that the layout in a queue item still has max value of 1 |
| 5283 | # for test-semaphore |
| 5284 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5285 | queue = None |
| 5286 | for queue_candidate in pipeline.queues: |
| 5287 | if queue_candidate.name == 'org/project': |
| 5288 | queue = queue_candidate |
| 5289 | break |
| 5290 | queue_item = queue.queue[0] |
| 5291 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5292 | dynamic_test_semaphore = \ |
| 5293 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5294 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5295 | |
| 5296 | # one build must be in queue, one semaphores acquired |
| 5297 | self.assertEqual(len(self.builds), 1) |
| 5298 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5299 | self.assertTrue('test-semaphore' in |
| 5300 | tenant.semaphore_handler.semaphores) |
| 5301 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5302 | 'test-semaphore', [])), 1) |
| 5303 | |
| 5304 | self.executor_server.release('project-test2') |
| 5305 | self.waitUntilSettled() |
| 5306 | |
| 5307 | # change A must be merged |
| 5308 | self.assertEqual(A.data['status'], 'MERGED') |
| 5309 | self.assertEqual(A.reported, 2) |
| 5310 | |
| 5311 | # send change-merged event as the gerrit mock doesn't send it |
| 5312 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5313 | self.waitUntilSettled() |
| 5314 | |
| 5315 | # now that change A was merged, the new semaphore max must be effective |
| 5316 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5317 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5318 | |
| 5319 | # two builds must be in queue, two semaphores acquired |
| 5320 | self.assertEqual(len(self.builds), 2) |
| 5321 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5322 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5323 | self.assertTrue('test-semaphore' in |
| 5324 | tenant.semaphore_handler.semaphores) |
| 5325 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5326 | 'test-semaphore', [])), 2) |
| 5327 | |
| 5328 | self.executor_server.release('project-test2') |
| 5329 | self.waitUntilSettled() |
| 5330 | |
| 5331 | self.assertEqual(len(self.builds), 0) |
| 5332 | self.assertFalse('test-semaphore' in |
| 5333 | tenant.semaphore_handler.semaphores) |
| 5334 | |
| 5335 | self.executor_server.hold_jobs_in_build = False |
| 5336 | self.executor_server.release() |
| 5337 | |
| 5338 | self.waitUntilSettled() |
| 5339 | self.assertEqual(len(self.builds), 0) |
| 5340 | |
| 5341 | self.assertEqual(A.reported, 2) |
| 5342 | self.assertEqual(B.reported, 2) |
| 5343 | self.assertEqual(C.reported, 2) |