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 | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 17 | import json |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 18 | import textwrap |
| 19 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 20 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 21 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 22 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 23 | import time |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 24 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 25 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 26 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 27 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 28 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 29 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 30 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 31 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 32 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 33 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 34 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 35 | from tests.base import ( |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 36 | ZuulTestCase, |
| 37 | repack_repo, |
| 38 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 39 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 40 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 41 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 42 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 43 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 44 | def test_jobs_executed(self): |
| 45 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 46 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 47 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 48 | A.addApproval('code-review', 2) |
| 49 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 50 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 51 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 52 | 'SUCCESS') |
| 53 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 54 | 'SUCCESS') |
| 55 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 56 | 'SUCCESS') |
| 57 | self.assertEqual(A.data['status'], 'MERGED') |
| 58 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 59 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 60 | 'image1') |
Adam Gandelman | eace469 | 2017-02-07 15:18:36 -0800 | [diff] [blame] | 61 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 62 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 63 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 64 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 65 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 66 | value='1|g') |
| 67 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 68 | kind='ms') |
| 69 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 70 | value='1|c') |
| 71 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 72 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 73 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 74 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 75 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 76 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 77 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 78 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 79 | for build in self.builds: |
| 80 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 81 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 82 | def test_initial_pipeline_gauges(self): |
| 83 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 84 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 85 | value='0|g') |
| 86 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 87 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 88 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 89 | def test_job_branch(self): |
| 90 | "Test the correct variant of a job runs on a branch" |
| 91 | self.create_branch('org/project', 'stable') |
| 92 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 93 | A.addApproval('code-review', 2) |
| 94 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 95 | self.waitUntilSettled() |
| 96 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 97 | 'SUCCESS') |
| 98 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 99 | 'SUCCESS') |
| 100 | self.assertEqual(A.data['status'], 'MERGED') |
| 101 | self.assertEqual(A.reported, 2, |
| 102 | "A should report start and success") |
| 103 | self.assertIn('gate', A.messages[1], |
| 104 | "A should transit gate") |
| 105 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 106 | 'image2') |
| 107 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 108 | def test_parallel_changes(self): |
| 109 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 110 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 111 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 112 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 113 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 114 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 115 | A.addApproval('code-review', 2) |
| 116 | B.addApproval('code-review', 2) |
| 117 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 118 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 119 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 120 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 121 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 122 | |
| 123 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 124 | self.assertEqual(len(self.builds), 1) |
| 125 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 126 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 127 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 128 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 129 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 130 | self.assertEqual(len(self.builds), 3) |
| 131 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 132 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 133 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 134 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 135 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 136 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 137 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 138 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 139 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 140 | self.assertEqual(len(self.builds), 5) |
| 141 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 142 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 143 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 144 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 145 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 146 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 147 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 148 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 149 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 150 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 151 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 152 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 153 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 154 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 155 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 156 | self.assertEqual(len(self.builds), 6) |
| 157 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 158 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 159 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 160 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 161 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 162 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 163 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 164 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 165 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 166 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 167 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 168 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 169 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 170 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 171 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 172 | self.executor_server.hold_jobs_in_build = False |
| 173 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 174 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 175 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 176 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 177 | self.assertEqual(len(self.history), 9) |
| 178 | self.assertEqual(A.data['status'], 'MERGED') |
| 179 | self.assertEqual(B.data['status'], 'MERGED') |
| 180 | self.assertEqual(C.data['status'], 'MERGED') |
| 181 | self.assertEqual(A.reported, 2) |
| 182 | self.assertEqual(B.reported, 2) |
| 183 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 184 | |
| 185 | def test_failed_changes(self): |
| 186 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 187 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 188 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 189 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 190 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 191 | A.addApproval('code-review', 2) |
| 192 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 193 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 194 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 195 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 196 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 197 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 198 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 199 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 200 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 201 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 202 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 203 | # A/project-merge is complete |
| 204 | self.assertBuilds([ |
| 205 | dict(name='project-test1', changes='1,1'), |
| 206 | dict(name='project-test2', changes='1,1'), |
| 207 | dict(name='project-merge', changes='1,1 2,1'), |
| 208 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 209 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 210 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 211 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 212 | # A/project-merge is complete |
| 213 | # B/project-merge is complete |
| 214 | self.assertBuilds([ |
| 215 | dict(name='project-test1', changes='1,1'), |
| 216 | dict(name='project-test2', changes='1,1'), |
| 217 | dict(name='project-test1', changes='1,1 2,1'), |
| 218 | dict(name='project-test2', changes='1,1 2,1'), |
| 219 | ]) |
| 220 | |
| 221 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 222 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 223 | self.builds[0].release() |
| 224 | self.waitUntilSettled() |
| 225 | |
| 226 | self.orderedRelease() |
| 227 | self.assertHistory([ |
| 228 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 229 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 230 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 231 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 232 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 233 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 234 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 235 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 236 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 237 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 238 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 239 | self.assertEqual(A.data['status'], 'NEW') |
| 240 | self.assertEqual(B.data['status'], 'MERGED') |
| 241 | self.assertEqual(A.reported, 2) |
| 242 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 243 | |
| 244 | def test_independent_queues(self): |
| 245 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 246 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 247 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 248 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 249 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 250 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 251 | A.addApproval('code-review', 2) |
| 252 | B.addApproval('code-review', 2) |
| 253 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 254 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 255 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 256 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 257 | |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 258 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 259 | self.waitUntilSettled() |
| 260 | |
| 261 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 262 | self.waitUntilSettled() |
| 263 | |
| 264 | # 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] | 265 | self.assertBuilds([ |
| 266 | dict(name='project-merge', changes='1,1'), |
| 267 | dict(name='project-merge', changes='2,1'), |
| 268 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 269 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 270 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 271 | self.builds[0].release() |
| 272 | self.waitUntilSettled() |
| 273 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 274 | self.waitUntilSettled() |
| 275 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 276 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 277 | self.waitUntilSettled() |
| 278 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 279 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 280 | self.assertBuilds([ |
| 281 | dict(name='project-test1', changes='1,1'), |
| 282 | dict(name='project-test2', changes='1,1'), |
| 283 | dict(name='project-test1', changes='2,1'), |
| 284 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 285 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 286 | dict(name='project-test1', changes='2,1 3,1'), |
| 287 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 288 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 289 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 290 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 291 | self.orderedRelease() |
| 292 | self.assertHistory([ |
| 293 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 294 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 295 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 296 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 297 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 298 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 299 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 300 | dict( |
| 301 | name='project1-project2-integration', |
| 302 | result='SUCCESS', |
| 303 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 304 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 305 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 306 | dict(name='project1-project2-integration', |
| 307 | result='SUCCESS', |
| 308 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 309 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 310 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 311 | self.assertEqual(A.data['status'], 'MERGED') |
| 312 | self.assertEqual(B.data['status'], 'MERGED') |
| 313 | self.assertEqual(C.data['status'], 'MERGED') |
| 314 | self.assertEqual(A.reported, 2) |
| 315 | self.assertEqual(B.reported, 2) |
| 316 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 317 | |
| 318 | def test_failed_change_at_head(self): |
| 319 | "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] | 320 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 321 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 322 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 323 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 324 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 325 | A.addApproval('code-review', 2) |
| 326 | B.addApproval('code-review', 2) |
| 327 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 328 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 329 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 330 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 331 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 332 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 333 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 334 | |
| 335 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 336 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 337 | self.assertBuilds([ |
| 338 | dict(name='project-merge', changes='1,1'), |
| 339 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 340 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 341 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 342 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 343 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 344 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 345 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 346 | self.waitUntilSettled() |
| 347 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 348 | self.assertBuilds([ |
| 349 | dict(name='project-test1', changes='1,1'), |
| 350 | dict(name='project-test2', changes='1,1'), |
| 351 | dict(name='project-test1', changes='1,1 2,1'), |
| 352 | dict(name='project-test2', changes='1,1 2,1'), |
| 353 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 354 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 355 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 356 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 357 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 358 | self.waitUntilSettled() |
| 359 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 360 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 361 | self.assertBuilds([ |
| 362 | dict(name='project-test2', changes='1,1'), |
| 363 | dict(name='project-merge', changes='2,1'), |
| 364 | ]) |
| 365 | # Unordered history comparison because the aborts can finish |
| 366 | # in any order. |
| 367 | self.assertHistory([ |
| 368 | dict(name='project-merge', result='SUCCESS', |
| 369 | changes='1,1'), |
| 370 | dict(name='project-merge', result='SUCCESS', |
| 371 | changes='1,1 2,1'), |
| 372 | dict(name='project-merge', result='SUCCESS', |
| 373 | changes='1,1 2,1 3,1'), |
| 374 | dict(name='project-test1', result='FAILURE', |
| 375 | changes='1,1'), |
| 376 | dict(name='project-test1', result='ABORTED', |
| 377 | changes='1,1 2,1'), |
| 378 | dict(name='project-test2', result='ABORTED', |
| 379 | changes='1,1 2,1'), |
| 380 | dict(name='project-test1', result='ABORTED', |
| 381 | changes='1,1 2,1 3,1'), |
| 382 | dict(name='project-test2', result='ABORTED', |
| 383 | changes='1,1 2,1 3,1'), |
| 384 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 385 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 386 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 387 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 388 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 389 | self.waitUntilSettled() |
| 390 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 391 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 392 | self.assertBuilds([]) |
| 393 | self.assertHistory([ |
| 394 | dict(name='project-merge', result='SUCCESS', |
| 395 | changes='1,1'), |
| 396 | dict(name='project-merge', result='SUCCESS', |
| 397 | changes='1,1 2,1'), |
| 398 | dict(name='project-merge', result='SUCCESS', |
| 399 | changes='1,1 2,1 3,1'), |
| 400 | dict(name='project-test1', result='FAILURE', |
| 401 | changes='1,1'), |
| 402 | dict(name='project-test1', result='ABORTED', |
| 403 | changes='1,1 2,1'), |
| 404 | dict(name='project-test2', result='ABORTED', |
| 405 | changes='1,1 2,1'), |
| 406 | dict(name='project-test1', result='ABORTED', |
| 407 | changes='1,1 2,1 3,1'), |
| 408 | dict(name='project-test2', result='ABORTED', |
| 409 | changes='1,1 2,1 3,1'), |
| 410 | dict(name='project-merge', result='SUCCESS', |
| 411 | changes='2,1'), |
| 412 | dict(name='project-merge', result='SUCCESS', |
| 413 | changes='2,1 3,1'), |
| 414 | dict(name='project-test2', result='SUCCESS', |
| 415 | changes='1,1'), |
| 416 | dict(name='project-test1', result='SUCCESS', |
| 417 | changes='2,1'), |
| 418 | dict(name='project-test2', result='SUCCESS', |
| 419 | changes='2,1'), |
| 420 | dict(name='project-test1', result='SUCCESS', |
| 421 | changes='2,1 3,1'), |
| 422 | dict(name='project-test2', result='SUCCESS', |
| 423 | changes='2,1 3,1'), |
| 424 | ], ordered=False) |
| 425 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 426 | self.assertEqual(A.data['status'], 'NEW') |
| 427 | self.assertEqual(B.data['status'], 'MERGED') |
| 428 | self.assertEqual(C.data['status'], 'MERGED') |
| 429 | self.assertEqual(A.reported, 2) |
| 430 | self.assertEqual(B.reported, 2) |
| 431 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 432 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 433 | def test_failed_change_in_middle(self): |
| 434 | "Test a failed change in the middle of the queue" |
| 435 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 436 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 437 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 438 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 439 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 440 | A.addApproval('code-review', 2) |
| 441 | B.addApproval('code-review', 2) |
| 442 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 443 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 444 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 445 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 446 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 447 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 448 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 449 | |
| 450 | self.waitUntilSettled() |
| 451 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 452 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 453 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 454 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 455 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 456 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 457 | self.waitUntilSettled() |
| 458 | |
| 459 | self.assertEqual(len(self.builds), 6) |
| 460 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 461 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 462 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 463 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 464 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 465 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 466 | |
| 467 | self.release(self.builds[2]) |
| 468 | self.waitUntilSettled() |
| 469 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 470 | # project-test1 and project-test2 for A |
| 471 | # project-test2 for B |
| 472 | # project-merge for C (without B) |
| 473 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 474 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 475 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 476 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 477 | self.waitUntilSettled() |
| 478 | |
| 479 | # project-test1 and project-test2 for A |
| 480 | # project-test2 for B |
| 481 | # project-test1 and project-test2 for C |
| 482 | self.assertEqual(len(self.builds), 5) |
| 483 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 484 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 485 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 486 | builds = items[0].current_build_set.getBuilds() |
| 487 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 488 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 489 | builds = items[1].current_build_set.getBuilds() |
| 490 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 491 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 492 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 493 | builds = items[2].current_build_set.getBuilds() |
| 494 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 495 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 496 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 497 | self.executor_server.hold_jobs_in_build = False |
| 498 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 499 | self.waitUntilSettled() |
| 500 | |
| 501 | self.assertEqual(len(self.builds), 0) |
| 502 | self.assertEqual(len(self.history), 12) |
| 503 | self.assertEqual(A.data['status'], 'MERGED') |
| 504 | self.assertEqual(B.data['status'], 'NEW') |
| 505 | self.assertEqual(C.data['status'], 'MERGED') |
| 506 | self.assertEqual(A.reported, 2) |
| 507 | self.assertEqual(B.reported, 2) |
| 508 | self.assertEqual(C.reported, 2) |
| 509 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 510 | def test_failed_change_at_head_with_queue(self): |
| 511 | "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] | 512 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 513 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 514 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 515 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 516 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 517 | A.addApproval('code-review', 2) |
| 518 | B.addApproval('code-review', 2) |
| 519 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 520 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 521 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 522 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 523 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 524 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 525 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 526 | |
| 527 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 528 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 529 | self.assertEqual(len(self.builds), 0) |
| 530 | self.assertEqual(len(queue), 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 531 | self.assertEqual(queue[0].name, 'executor:execute') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 532 | job_args = json.loads(queue[0].arguments) |
| 533 | self.assertEqual(job_args['job'], 'project-merge') |
| 534 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 535 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 536 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 537 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 538 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 539 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 540 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 541 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 542 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 543 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 544 | self.assertEqual(len(self.builds), 0) |
| 545 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 546 | |
| 547 | self.assertEqual( |
| 548 | json.loads(queue[0].arguments)['job'], 'project-test1') |
| 549 | self.assertEqual( |
| 550 | json.loads(queue[1].arguments)['job'], 'project-test2') |
| 551 | self.assertEqual( |
| 552 | json.loads(queue[2].arguments)['job'], 'project-test1') |
| 553 | self.assertEqual( |
| 554 | json.loads(queue[3].arguments)['job'], 'project-test2') |
| 555 | self.assertEqual( |
| 556 | json.loads(queue[4].arguments)['job'], 'project-test1') |
| 557 | self.assertEqual( |
| 558 | json.loads(queue[5].arguments)['job'], 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 559 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 560 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 561 | self.waitUntilSettled() |
| 562 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 563 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 564 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 565 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 566 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 567 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 568 | self.gearman_server.hold_jobs_in_queue = False |
| 569 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 570 | self.waitUntilSettled() |
| 571 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 572 | self.assertEqual(len(self.builds), 0) |
| 573 | self.assertEqual(len(self.history), 11) |
| 574 | self.assertEqual(A.data['status'], 'NEW') |
| 575 | self.assertEqual(B.data['status'], 'MERGED') |
| 576 | self.assertEqual(C.data['status'], 'MERGED') |
| 577 | self.assertEqual(A.reported, 2) |
| 578 | self.assertEqual(B.reported, 2) |
| 579 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 580 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 581 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 582 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 583 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 584 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 585 | A.addApproval('code-review', 2) |
| 586 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 587 | self.waitUntilSettled() |
| 588 | time.sleep(2) |
| 589 | |
| 590 | data = json.loads(self.sched.formatStatusJSON()) |
| 591 | found_job = None |
| 592 | for pipeline in data['pipelines']: |
| 593 | if pipeline['name'] != 'gate': |
| 594 | continue |
| 595 | for queue in pipeline['change_queues']: |
| 596 | for head in queue['heads']: |
| 597 | for item in head: |
| 598 | for job in item['jobs']: |
| 599 | if job['name'] == 'project-merge': |
| 600 | found_job = job |
| 601 | break |
| 602 | |
| 603 | self.assertIsNotNone(found_job) |
| 604 | if iteration == 1: |
| 605 | self.assertIsNotNone(found_job['estimated_time']) |
| 606 | self.assertIsNone(found_job['remaining_time']) |
| 607 | else: |
| 608 | self.assertIsNotNone(found_job['estimated_time']) |
| 609 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 610 | self.assertIsNotNone(found_job['remaining_time']) |
| 611 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 612 | self.executor_server.hold_jobs_in_build = False |
| 613 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 614 | self.waitUntilSettled() |
| 615 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 616 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 617 | def test_time_database(self): |
| 618 | "Test the time database" |
| 619 | |
| 620 | self._test_time_database(1) |
| 621 | self._test_time_database(2) |
| 622 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 623 | def test_two_failed_changes_at_head(self): |
| 624 | "Test that changes are reparented correctly if 2 fail at head" |
| 625 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 626 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 627 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 628 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 629 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 630 | A.addApproval('code-review', 2) |
| 631 | B.addApproval('code-review', 2) |
| 632 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 633 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 634 | self.executor_server.failJob('project-test1', A) |
| 635 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 636 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 637 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 638 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 639 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 640 | self.waitUntilSettled() |
| 641 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 642 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 643 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 644 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 645 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 646 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 647 | self.waitUntilSettled() |
| 648 | |
| 649 | self.assertEqual(len(self.builds), 6) |
| 650 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 651 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 652 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 653 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 654 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 655 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 656 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 657 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 658 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 659 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 660 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 661 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 662 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 663 | |
| 664 | # Fail change B first |
| 665 | self.release(self.builds[2]) |
| 666 | self.waitUntilSettled() |
| 667 | |
| 668 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 669 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 670 | self.waitUntilSettled() |
| 671 | |
| 672 | self.assertEqual(len(self.builds), 5) |
| 673 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 674 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 675 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 676 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 677 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 678 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 679 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 680 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 681 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 682 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 683 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 684 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 685 | |
| 686 | # Finish running all passing jobs for change A |
| 687 | self.release(self.builds[1]) |
| 688 | self.waitUntilSettled() |
| 689 | # Fail and report change A |
| 690 | self.release(self.builds[0]) |
| 691 | self.waitUntilSettled() |
| 692 | |
| 693 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 694 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 695 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 696 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 697 | self.waitUntilSettled() |
| 698 | |
| 699 | self.assertEqual(len(self.builds), 4) |
| 700 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 701 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 702 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 703 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 704 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 705 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 706 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 707 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 708 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 709 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 710 | # After A failed and B and C restarted, B should be back in |
| 711 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 712 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 713 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 714 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 715 | self.executor_server.hold_jobs_in_build = False |
| 716 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 717 | self.waitUntilSettled() |
| 718 | |
| 719 | self.assertEqual(len(self.builds), 0) |
| 720 | self.assertEqual(len(self.history), 21) |
| 721 | self.assertEqual(A.data['status'], 'NEW') |
| 722 | self.assertEqual(B.data['status'], 'NEW') |
| 723 | self.assertEqual(C.data['status'], 'MERGED') |
| 724 | self.assertEqual(A.reported, 2) |
| 725 | self.assertEqual(B.reported, 2) |
| 726 | self.assertEqual(C.reported, 2) |
| 727 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 728 | def test_patch_order(self): |
| 729 | "Test that dependent patches are tested in the right order" |
| 730 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 731 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 732 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 733 | A.addApproval('code-review', 2) |
| 734 | B.addApproval('code-review', 2) |
| 735 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 736 | |
| 737 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 738 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 739 | M2.setMerged() |
| 740 | M1.setMerged() |
| 741 | |
| 742 | # C -> B -> A -> M1 -> M2 |
| 743 | # M2 is here to make sure it is never queried. If it is, it |
| 744 | # means zuul is walking down the entire history of merged |
| 745 | # changes. |
| 746 | |
| 747 | C.setDependsOn(B, 1) |
| 748 | B.setDependsOn(A, 1) |
| 749 | A.setDependsOn(M1, 1) |
| 750 | M1.setDependsOn(M2, 1) |
| 751 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 752 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 753 | |
| 754 | self.waitUntilSettled() |
| 755 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 756 | self.assertEqual(A.data['status'], 'NEW') |
| 757 | self.assertEqual(B.data['status'], 'NEW') |
| 758 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 759 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 760 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 761 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 762 | |
| 763 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 764 | self.assertEqual(M2.queried, 0) |
| 765 | self.assertEqual(A.data['status'], 'MERGED') |
| 766 | self.assertEqual(B.data['status'], 'MERGED') |
| 767 | self.assertEqual(C.data['status'], 'MERGED') |
| 768 | self.assertEqual(A.reported, 2) |
| 769 | self.assertEqual(B.reported, 2) |
| 770 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 771 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 772 | def test_needed_changes_enqueue(self): |
| 773 | "Test that a needed change is enqueued ahead" |
| 774 | # A Given a git tree like this, if we enqueue |
| 775 | # / \ change C, we should walk up and down the tree |
| 776 | # B G and enqueue changes in the order ABCDEFG. |
| 777 | # /|\ This is also the order that you would get if |
| 778 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 779 | # / the ordering is stable across re-enqueue events. |
| 780 | # D |
| 781 | |
| 782 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 783 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 784 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 785 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 786 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 787 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 788 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 789 | B.setDependsOn(A, 1) |
| 790 | C.setDependsOn(B, 1) |
| 791 | D.setDependsOn(C, 1) |
| 792 | E.setDependsOn(B, 1) |
| 793 | F.setDependsOn(B, 1) |
| 794 | G.setDependsOn(A, 1) |
| 795 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 796 | A.addApproval('code-review', 2) |
| 797 | B.addApproval('code-review', 2) |
| 798 | C.addApproval('code-review', 2) |
| 799 | D.addApproval('code-review', 2) |
| 800 | E.addApproval('code-review', 2) |
| 801 | F.addApproval('code-review', 2) |
| 802 | G.addApproval('code-review', 2) |
| 803 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 804 | |
| 805 | self.waitUntilSettled() |
| 806 | |
| 807 | self.assertEqual(A.data['status'], 'NEW') |
| 808 | self.assertEqual(B.data['status'], 'NEW') |
| 809 | self.assertEqual(C.data['status'], 'NEW') |
| 810 | self.assertEqual(D.data['status'], 'NEW') |
| 811 | self.assertEqual(E.data['status'], 'NEW') |
| 812 | self.assertEqual(F.data['status'], 'NEW') |
| 813 | self.assertEqual(G.data['status'], 'NEW') |
| 814 | |
| 815 | # We're about to add approvals to changes without adding the |
| 816 | # triggering events to Zuul, so that we can be sure that it is |
| 817 | # enqueing the changes based on dependencies, not because of |
| 818 | # triggering events. Since it will have the changes cached |
| 819 | # already (without approvals), we need to clear the cache |
| 820 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 821 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 822 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 823 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 824 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 825 | A.addApproval('approved', 1) |
| 826 | B.addApproval('approved', 1) |
| 827 | D.addApproval('approved', 1) |
| 828 | E.addApproval('approved', 1) |
| 829 | F.addApproval('approved', 1) |
| 830 | G.addApproval('approved', 1) |
| 831 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 832 | |
| 833 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 834 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 835 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 836 | self.executor_server.hold_jobs_in_build = False |
| 837 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 838 | self.waitUntilSettled() |
| 839 | |
| 840 | self.assertEqual(A.data['status'], 'MERGED') |
| 841 | self.assertEqual(B.data['status'], 'MERGED') |
| 842 | self.assertEqual(C.data['status'], 'MERGED') |
| 843 | self.assertEqual(D.data['status'], 'MERGED') |
| 844 | self.assertEqual(E.data['status'], 'MERGED') |
| 845 | self.assertEqual(F.data['status'], 'MERGED') |
| 846 | self.assertEqual(G.data['status'], 'MERGED') |
| 847 | self.assertEqual(A.reported, 2) |
| 848 | self.assertEqual(B.reported, 2) |
| 849 | self.assertEqual(C.reported, 2) |
| 850 | self.assertEqual(D.reported, 2) |
| 851 | self.assertEqual(E.reported, 2) |
| 852 | self.assertEqual(F.reported, 2) |
| 853 | self.assertEqual(G.reported, 2) |
| 854 | self.assertEqual(self.history[6].changes, |
| 855 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 856 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 857 | def test_source_cache(self): |
| 858 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 859 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 860 | |
| 861 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 862 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 863 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 864 | A.addApproval('code-review', 2) |
| 865 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 866 | |
| 867 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 868 | M1.setMerged() |
| 869 | |
| 870 | B.setDependsOn(A, 1) |
| 871 | A.setDependsOn(M1, 1) |
| 872 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 873 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 874 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 875 | |
| 876 | self.waitUntilSettled() |
| 877 | |
| 878 | for build in self.builds: |
| 879 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 880 | build.release() |
| 881 | self.waitUntilSettled() |
| 882 | for build in self.builds: |
| 883 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 884 | build.release() |
| 885 | self.waitUntilSettled() |
| 886 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 887 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 888 | self.waitUntilSettled() |
| 889 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 890 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 891 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 892 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 893 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 894 | self.executor_server.hold_jobs_in_build = False |
| 895 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 896 | self.waitUntilSettled() |
| 897 | |
| 898 | self.assertEqual(A.data['status'], 'MERGED') |
| 899 | self.assertEqual(B.data['status'], 'MERGED') |
| 900 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 901 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 902 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 903 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 904 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 905 | # TODO: move to test_gerrit (this is a unit test!) |
| 906 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 907 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 908 | source = tenant.layout.pipelines['gate'].source |
| 909 | |
| 910 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 911 | # it easier for users to create events for testing. |
| 912 | event = zuul.model.TriggerEvent() |
| 913 | event.trigger_name = 'gerrit' |
| 914 | event.change_number = '1' |
| 915 | event.patch_number = '2' |
| 916 | |
| 917 | a = source.getChange(event) |
| 918 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 919 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 920 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 921 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 922 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 923 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 924 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 925 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 926 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 927 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 928 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 929 | def test_project_merge_conflict(self): |
| 930 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 931 | |
| 932 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 933 | A = self.fake_gerrit.addFakeChange('org/project', |
| 934 | 'master', 'A', |
| 935 | files={'conflict': 'foo'}) |
| 936 | B = self.fake_gerrit.addFakeChange('org/project', |
| 937 | 'master', 'B', |
| 938 | files={'conflict': 'bar'}) |
| 939 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 940 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 941 | A.addApproval('code-review', 2) |
| 942 | B.addApproval('code-review', 2) |
| 943 | C.addApproval('code-review', 2) |
| 944 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 945 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 946 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 947 | self.waitUntilSettled() |
| 948 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 949 | self.assertEqual(A.reported, 1) |
| 950 | self.assertEqual(B.reported, 1) |
| 951 | self.assertEqual(C.reported, 1) |
| 952 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 953 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 954 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 955 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 956 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 957 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 958 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 959 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 960 | self.gearman_server.hold_jobs_in_queue = False |
| 961 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 962 | self.waitUntilSettled() |
| 963 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 964 | self.assertEqual(A.data['status'], 'MERGED') |
| 965 | self.assertEqual(B.data['status'], 'NEW') |
| 966 | self.assertEqual(C.data['status'], 'MERGED') |
| 967 | self.assertEqual(A.reported, 2) |
| 968 | self.assertEqual(B.reported, 2) |
| 969 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 970 | |
| 971 | self.assertHistory([ |
| 972 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 973 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 974 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 975 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 976 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 977 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 978 | ], ordered=False) |
| 979 | |
| 980 | def test_delayed_merge_conflict(self): |
| 981 | "Test that delayed check merge conflicts are handled properly" |
| 982 | |
| 983 | # Hold jobs in the gearman queue so that we can test whether |
| 984 | # the executor returns a merge failure after the scheduler has |
| 985 | # successfully merged. |
| 986 | self.gearman_server.hold_jobs_in_queue = True |
| 987 | A = self.fake_gerrit.addFakeChange('org/project', |
| 988 | 'master', 'A', |
| 989 | files={'conflict': 'foo'}) |
| 990 | B = self.fake_gerrit.addFakeChange('org/project', |
| 991 | 'master', 'B', |
| 992 | files={'conflict': 'bar'}) |
| 993 | C = self.fake_gerrit.addFakeChange('org/project', |
| 994 | 'master', 'C') |
| 995 | C.setDependsOn(B, 1) |
| 996 | |
| 997 | # A enters the gate queue; B and C enter the check queue |
| 998 | A.addApproval('code-review', 2) |
| 999 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1000 | self.waitUntilSettled() |
| 1001 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1002 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1003 | self.waitUntilSettled() |
| 1004 | |
| 1005 | self.assertEqual(A.reported, 1) |
| 1006 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1007 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1008 | |
| 1009 | # A merges while B and C are queued in check |
| 1010 | # Release A project-merge |
| 1011 | queue = self.gearman_server.getQueue() |
| 1012 | self.release(queue[0]) |
| 1013 | self.waitUntilSettled() |
| 1014 | |
| 1015 | # Release A project-test* |
| 1016 | # gate has higher precedence, so A's test jobs are added in |
| 1017 | # front of the merge jobs for B and C |
| 1018 | queue = self.gearman_server.getQueue() |
| 1019 | self.release(queue[0]) |
| 1020 | self.release(queue[1]) |
| 1021 | self.waitUntilSettled() |
| 1022 | |
| 1023 | self.assertEqual(A.data['status'], 'MERGED') |
| 1024 | self.assertEqual(B.data['status'], 'NEW') |
| 1025 | self.assertEqual(C.data['status'], 'NEW') |
| 1026 | self.assertEqual(A.reported, 2) |
| 1027 | self.assertEqual(B.reported, 0) |
| 1028 | self.assertEqual(C.reported, 0) |
| 1029 | self.assertHistory([ |
| 1030 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1031 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1032 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1033 | ], ordered=False) |
| 1034 | |
| 1035 | # B and C report merge conflicts |
| 1036 | # Release B project-merge |
| 1037 | queue = self.gearman_server.getQueue() |
| 1038 | self.release(queue[0]) |
| 1039 | self.waitUntilSettled() |
| 1040 | |
| 1041 | # Release C |
| 1042 | self.gearman_server.hold_jobs_in_queue = False |
| 1043 | self.gearman_server.release() |
| 1044 | self.waitUntilSettled() |
| 1045 | |
| 1046 | self.assertEqual(A.data['status'], 'MERGED') |
| 1047 | self.assertEqual(B.data['status'], 'NEW') |
| 1048 | self.assertEqual(C.data['status'], 'NEW') |
| 1049 | self.assertEqual(A.reported, 2) |
| 1050 | self.assertEqual(B.reported, 1) |
| 1051 | self.assertEqual(C.reported, 1) |
| 1052 | |
| 1053 | self.assertHistory([ |
| 1054 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1055 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1056 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1057 | dict(name='project-merge', result='MERGER_FAILURE', changes='2,1'), |
| 1058 | dict(name='project-merge', result='MERGER_FAILURE', |
| 1059 | changes='2,1 3,1'), |
| 1060 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1061 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1062 | def test_post(self): |
| 1063 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1064 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1065 | e = { |
| 1066 | "type": "ref-updated", |
| 1067 | "submitter": { |
| 1068 | "name": "User Name", |
| 1069 | }, |
| 1070 | "refUpdate": { |
| 1071 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1072 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1073 | "refName": "master", |
| 1074 | "project": "org/project", |
| 1075 | } |
| 1076 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1077 | self.fake_gerrit.addEvent(e) |
| 1078 | self.waitUntilSettled() |
| 1079 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1080 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1081 | self.assertEqual(len(self.history), 1) |
| 1082 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1083 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1084 | def test_post_ignore_deletes(self): |
| 1085 | "Test that deleting refs does not trigger post jobs" |
| 1086 | |
| 1087 | e = { |
| 1088 | "type": "ref-updated", |
| 1089 | "submitter": { |
| 1090 | "name": "User Name", |
| 1091 | }, |
| 1092 | "refUpdate": { |
| 1093 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1094 | "newRev": "0000000000000000000000000000000000000000", |
| 1095 | "refName": "master", |
| 1096 | "project": "org/project", |
| 1097 | } |
| 1098 | } |
| 1099 | self.fake_gerrit.addEvent(e) |
| 1100 | self.waitUntilSettled() |
| 1101 | |
| 1102 | job_names = [x.name for x in self.history] |
| 1103 | self.assertEqual(len(self.history), 0) |
| 1104 | self.assertNotIn('project-post', job_names) |
| 1105 | |
| 1106 | def test_post_ignore_deletes_negative(self): |
| 1107 | "Test that deleting refs does trigger post jobs" |
| 1108 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1109 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1110 | self.sched.reconfigure(self.config) |
| 1111 | |
| 1112 | e = { |
| 1113 | "type": "ref-updated", |
| 1114 | "submitter": { |
| 1115 | "name": "User Name", |
| 1116 | }, |
| 1117 | "refUpdate": { |
| 1118 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1119 | "newRev": "0000000000000000000000000000000000000000", |
| 1120 | "refName": "master", |
| 1121 | "project": "org/project", |
| 1122 | } |
| 1123 | } |
| 1124 | self.fake_gerrit.addEvent(e) |
| 1125 | self.waitUntilSettled() |
| 1126 | |
| 1127 | job_names = [x.name for x in self.history] |
| 1128 | self.assertEqual(len(self.history), 1) |
| 1129 | self.assertIn('project-post', job_names) |
| 1130 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1131 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1132 | def test_build_configuration_branch_interaction(self): |
| 1133 | "Test that switching between branches works" |
| 1134 | self.test_build_configuration() |
| 1135 | self.test_build_configuration_branch() |
| 1136 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1137 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1138 | repo = git.Repo(path) |
| 1139 | repo.heads.master.commit = repo.commit('init') |
| 1140 | self.test_build_configuration() |
| 1141 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1142 | def test_dependent_changes_dequeue(self): |
| 1143 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1144 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1145 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1146 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1147 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1148 | A.addApproval('code-review', 2) |
| 1149 | B.addApproval('code-review', 2) |
| 1150 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1151 | |
| 1152 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1153 | M1.setMerged() |
| 1154 | |
| 1155 | # C -> B -> A -> M1 |
| 1156 | |
| 1157 | C.setDependsOn(B, 1) |
| 1158 | B.setDependsOn(A, 1) |
| 1159 | A.setDependsOn(M1, 1) |
| 1160 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1161 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1162 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1163 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1164 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1165 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1166 | |
| 1167 | self.waitUntilSettled() |
| 1168 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1169 | self.assertEqual(A.data['status'], 'NEW') |
| 1170 | self.assertEqual(A.reported, 2) |
| 1171 | self.assertEqual(B.data['status'], 'NEW') |
| 1172 | self.assertEqual(B.reported, 2) |
| 1173 | self.assertEqual(C.data['status'], 'NEW') |
| 1174 | self.assertEqual(C.reported, 2) |
| 1175 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1176 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1177 | def test_failing_dependent_changes(self): |
| 1178 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1179 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1180 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1181 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1182 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1183 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1184 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1185 | A.addApproval('code-review', 2) |
| 1186 | B.addApproval('code-review', 2) |
| 1187 | C.addApproval('code-review', 2) |
| 1188 | D.addApproval('code-review', 2) |
| 1189 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1190 | |
| 1191 | # E, D -> C -> B, A |
| 1192 | |
| 1193 | D.setDependsOn(C, 1) |
| 1194 | C.setDependsOn(B, 1) |
| 1195 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1196 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1197 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1198 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1199 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1200 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1201 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1202 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1203 | |
| 1204 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1205 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1206 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1207 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1208 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1209 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1210 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1211 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1212 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1213 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1214 | self.waitUntilSettled() |
| 1215 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1216 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1217 | for build in self.builds: |
| 1218 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1219 | build.release() |
| 1220 | self.waitUntilSettled() |
| 1221 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1222 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1223 | self.waitUntilSettled() |
| 1224 | |
| 1225 | self.assertEqual(A.data['status'], 'MERGED') |
| 1226 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1227 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1228 | self.assertEqual(B.data['status'], 'NEW') |
| 1229 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1230 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1231 | self.assertEqual(C.data['status'], 'NEW') |
| 1232 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1233 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1234 | self.assertEqual(D.data['status'], 'NEW') |
| 1235 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1236 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1237 | self.assertEqual(E.data['status'], 'MERGED') |
| 1238 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1239 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1240 | self.assertEqual(len(self.history), 18) |
| 1241 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1242 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1243 | "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] | 1244 | # If it's dequeued more than once, we should see extra |
| 1245 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1246 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1247 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1248 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1249 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1250 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1251 | A.addApproval('code-review', 2) |
| 1252 | B.addApproval('code-review', 2) |
| 1253 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1254 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1255 | self.executor_server.failJob('project-test1', A) |
| 1256 | self.executor_server.failJob('project-test2', A) |
| 1257 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1258 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1259 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1260 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1261 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1262 | |
| 1263 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1264 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1265 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1266 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1267 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1268 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1269 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1270 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1271 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1272 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1273 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1274 | self.waitUntilSettled() |
| 1275 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1276 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1277 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1278 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1279 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1280 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1281 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1282 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1283 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1284 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1285 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1286 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1287 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1288 | self.waitUntilSettled() |
| 1289 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1290 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1291 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1292 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1293 | self.executor_server.hold_jobs_in_build = False |
| 1294 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1295 | self.waitUntilSettled() |
| 1296 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1297 | self.assertEqual(len(self.builds), 0) |
| 1298 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1299 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1300 | self.assertEqual(A.data['status'], 'NEW') |
| 1301 | self.assertEqual(B.data['status'], 'MERGED') |
| 1302 | self.assertEqual(C.data['status'], 'MERGED') |
| 1303 | self.assertEqual(A.reported, 2) |
| 1304 | self.assertEqual(B.reported, 2) |
| 1305 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1306 | |
| 1307 | def test_nonvoting_job(self): |
| 1308 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1309 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1310 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1311 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1312 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1313 | self.executor_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1314 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1315 | |
| 1316 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1317 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1318 | self.assertEqual(A.data['status'], 'MERGED') |
| 1319 | self.assertEqual(A.reported, 2) |
| 1320 | self.assertEqual( |
| 1321 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1322 | 'SUCCESS') |
| 1323 | self.assertEqual( |
| 1324 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1325 | 'SUCCESS') |
| 1326 | self.assertEqual( |
| 1327 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1328 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1329 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1330 | for build in self.builds: |
| 1331 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1332 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1333 | def test_check_queue_success(self): |
| 1334 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1335 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1336 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1337 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1338 | |
| 1339 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1340 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1341 | self.assertEqual(A.data['status'], 'NEW') |
| 1342 | self.assertEqual(A.reported, 1) |
| 1343 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1344 | 'SUCCESS') |
| 1345 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1346 | 'SUCCESS') |
| 1347 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1348 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1349 | |
| 1350 | def test_check_queue_failure(self): |
| 1351 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1352 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1353 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1354 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1355 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1356 | |
| 1357 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1358 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1359 | self.assertEqual(A.data['status'], 'NEW') |
| 1360 | self.assertEqual(A.reported, 1) |
| 1361 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1362 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1363 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1364 | 'SUCCESS') |
| 1365 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1366 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1367 | |
| 1368 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1369 | # This particular test does a large amount of merges and needs a little |
| 1370 | # more time to complete |
| 1371 | self.wait_timeout = 90 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1372 | "test that dependent changes behind dequeued changes work" |
| 1373 | # This complicated test is a reproduction of a real life bug |
| 1374 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1375 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1376 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1377 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1378 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1379 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1380 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1381 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1382 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1383 | D.setDependsOn(C, 1) |
| 1384 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1385 | A.addApproval('code-review', 2) |
| 1386 | B.addApproval('code-review', 2) |
| 1387 | C.addApproval('code-review', 2) |
| 1388 | D.addApproval('code-review', 2) |
| 1389 | E.addApproval('code-review', 2) |
| 1390 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1391 | |
| 1392 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1393 | |
| 1394 | # Change object re-use in the gerrit trigger is hidden if |
| 1395 | # changes are added in quick succession; waiting makes it more |
| 1396 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1397 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1398 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1399 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1400 | self.waitUntilSettled() |
| 1401 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1402 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1403 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1404 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1405 | self.waitUntilSettled() |
| 1406 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1407 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1408 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1409 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1410 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1411 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1412 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1413 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1414 | self.waitUntilSettled() |
| 1415 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1416 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1417 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1418 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1419 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1420 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1421 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1422 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1423 | self.waitUntilSettled() |
| 1424 | |
| 1425 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1426 | |
| 1427 | # Grab pointers to the jobs we want to release before |
| 1428 | # releasing any, because list indexes may change as |
| 1429 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1430 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1431 | a.release() |
| 1432 | b.release() |
| 1433 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1434 | self.waitUntilSettled() |
| 1435 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1436 | self.executor_server.hold_jobs_in_build = False |
| 1437 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1438 | self.waitUntilSettled() |
| 1439 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1440 | self.assertEqual(A.data['status'], 'NEW') |
| 1441 | self.assertEqual(B.data['status'], 'MERGED') |
| 1442 | self.assertEqual(C.data['status'], 'MERGED') |
| 1443 | self.assertEqual(D.data['status'], 'MERGED') |
| 1444 | self.assertEqual(E.data['status'], 'MERGED') |
| 1445 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1446 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1447 | self.assertEqual(A.reported, 2) |
| 1448 | self.assertEqual(B.reported, 2) |
| 1449 | self.assertEqual(C.reported, 2) |
| 1450 | self.assertEqual(D.reported, 2) |
| 1451 | self.assertEqual(E.reported, 2) |
| 1452 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1453 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1454 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1455 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1456 | |
| 1457 | def test_merger_repack(self): |
| 1458 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1459 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1460 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1461 | A.addApproval('code-review', 2) |
| 1462 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1463 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1464 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1465 | 'SUCCESS') |
| 1466 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1467 | 'SUCCESS') |
| 1468 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1469 | 'SUCCESS') |
| 1470 | self.assertEqual(A.data['status'], 'MERGED') |
| 1471 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1472 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1473 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1474 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1475 | path = os.path.join(self.merger_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1476 | if os.path.exists(path): |
| 1477 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1478 | path = os.path.join(self.executor_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1479 | if os.path.exists(path): |
| 1480 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1481 | |
| 1482 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1483 | A.addApproval('code-review', 2) |
| 1484 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1485 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1486 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1487 | 'SUCCESS') |
| 1488 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1489 | 'SUCCESS') |
| 1490 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1491 | 'SUCCESS') |
| 1492 | self.assertEqual(A.data['status'], 'MERGED') |
| 1493 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1494 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1495 | def test_merger_repack_large_change(self): |
| 1496 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1497 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1498 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1499 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1500 | url = self.fake_gerrit.getGitUrl( |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1501 | tenant.layout.project_configs.get('org/project1')) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1502 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1503 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1504 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1505 | path = os.path.join(self.upstream_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1506 | repack_repo(path) |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1507 | path = os.path.join(self.merger_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1508 | if os.path.exists(path): |
| 1509 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1510 | path = os.path.join(self.executor_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1511 | if os.path.exists(path): |
| 1512 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1513 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1514 | A.addApproval('code-review', 2) |
| 1515 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1516 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1517 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1518 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1519 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1520 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1521 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1522 | 'SUCCESS') |
| 1523 | self.assertEqual(A.data['status'], 'MERGED') |
| 1524 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1525 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1526 | def test_new_patchset_dequeues_old(self): |
| 1527 | "Test that a new patchset causes the old to be dequeued" |
| 1528 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1529 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1530 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1531 | M.setMerged() |
| 1532 | |
| 1533 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1534 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1535 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1536 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1537 | A.addApproval('code-review', 2) |
| 1538 | B.addApproval('code-review', 2) |
| 1539 | C.addApproval('code-review', 2) |
| 1540 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1541 | |
| 1542 | C.setDependsOn(B, 1) |
| 1543 | B.setDependsOn(A, 1) |
| 1544 | A.setDependsOn(M, 1) |
| 1545 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1546 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1547 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1548 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1549 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1550 | self.waitUntilSettled() |
| 1551 | |
| 1552 | B.addPatchset() |
| 1553 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1554 | self.waitUntilSettled() |
| 1555 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1556 | self.executor_server.hold_jobs_in_build = False |
| 1557 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1558 | self.waitUntilSettled() |
| 1559 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1560 | self.assertEqual(A.data['status'], 'MERGED') |
| 1561 | self.assertEqual(A.reported, 2) |
| 1562 | self.assertEqual(B.data['status'], 'NEW') |
| 1563 | self.assertEqual(B.reported, 2) |
| 1564 | self.assertEqual(C.data['status'], 'NEW') |
| 1565 | self.assertEqual(C.reported, 2) |
| 1566 | self.assertEqual(D.data['status'], 'MERGED') |
| 1567 | self.assertEqual(D.reported, 2) |
| 1568 | 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] | 1569 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1570 | def test_new_patchset_check(self): |
| 1571 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1572 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1573 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1574 | |
| 1575 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1576 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1577 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1578 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1579 | |
| 1580 | # Add two git-dependent changes |
| 1581 | B.setDependsOn(A, 1) |
| 1582 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1583 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1584 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1585 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1586 | |
| 1587 | # A live item, and a non-live/live pair |
| 1588 | items = check_pipeline.getAllItems() |
| 1589 | self.assertEqual(len(items), 3) |
| 1590 | |
| 1591 | self.assertEqual(items[0].change.number, '1') |
| 1592 | self.assertEqual(items[0].change.patchset, '1') |
| 1593 | self.assertFalse(items[0].live) |
| 1594 | |
| 1595 | self.assertEqual(items[1].change.number, '2') |
| 1596 | self.assertEqual(items[1].change.patchset, '1') |
| 1597 | self.assertTrue(items[1].live) |
| 1598 | |
| 1599 | self.assertEqual(items[2].change.number, '1') |
| 1600 | self.assertEqual(items[2].change.patchset, '1') |
| 1601 | self.assertTrue(items[2].live) |
| 1602 | |
| 1603 | # Add a new patchset to A |
| 1604 | A.addPatchset() |
| 1605 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1606 | self.waitUntilSettled() |
| 1607 | |
| 1608 | # The live copy of A,1 should be gone, but the non-live and B |
| 1609 | # should continue, and we should have a new A,2 |
| 1610 | items = check_pipeline.getAllItems() |
| 1611 | self.assertEqual(len(items), 3) |
| 1612 | |
| 1613 | self.assertEqual(items[0].change.number, '1') |
| 1614 | self.assertEqual(items[0].change.patchset, '1') |
| 1615 | self.assertFalse(items[0].live) |
| 1616 | |
| 1617 | self.assertEqual(items[1].change.number, '2') |
| 1618 | self.assertEqual(items[1].change.patchset, '1') |
| 1619 | self.assertTrue(items[1].live) |
| 1620 | |
| 1621 | self.assertEqual(items[2].change.number, '1') |
| 1622 | self.assertEqual(items[2].change.patchset, '2') |
| 1623 | self.assertTrue(items[2].live) |
| 1624 | |
| 1625 | # Add a new patchset to B |
| 1626 | B.addPatchset() |
| 1627 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1628 | self.waitUntilSettled() |
| 1629 | |
| 1630 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1631 | # but we should have a new B,2 (still based on A,1) |
| 1632 | items = check_pipeline.getAllItems() |
| 1633 | self.assertEqual(len(items), 3) |
| 1634 | |
| 1635 | self.assertEqual(items[0].change.number, '1') |
| 1636 | self.assertEqual(items[0].change.patchset, '2') |
| 1637 | self.assertTrue(items[0].live) |
| 1638 | |
| 1639 | self.assertEqual(items[1].change.number, '1') |
| 1640 | self.assertEqual(items[1].change.patchset, '1') |
| 1641 | self.assertFalse(items[1].live) |
| 1642 | |
| 1643 | self.assertEqual(items[2].change.number, '2') |
| 1644 | self.assertEqual(items[2].change.patchset, '2') |
| 1645 | self.assertTrue(items[2].live) |
| 1646 | |
| 1647 | self.builds[0].release() |
| 1648 | self.waitUntilSettled() |
| 1649 | self.builds[0].release() |
| 1650 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1651 | self.executor_server.hold_jobs_in_build = False |
| 1652 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1653 | self.waitUntilSettled() |
| 1654 | |
| 1655 | self.assertEqual(A.reported, 1) |
| 1656 | self.assertEqual(B.reported, 1) |
| 1657 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1658 | self.assertEqual(self.history[0].changes, '1,1') |
| 1659 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1660 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1661 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1662 | self.assertEqual(self.history[2].changes, '1,2') |
| 1663 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1664 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1665 | |
| 1666 | def test_abandoned_gate(self): |
| 1667 | "Test that an abandoned change is dequeued from gate" |
| 1668 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1669 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1670 | |
| 1671 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1672 | A.addApproval('code-review', 2) |
| 1673 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1674 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1675 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1676 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1677 | |
| 1678 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1679 | self.waitUntilSettled() |
| 1680 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1681 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1682 | self.waitUntilSettled() |
| 1683 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1684 | self.assertBuilds([]) |
| 1685 | self.assertHistory([ |
| 1686 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1687 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1688 | self.assertEqual(A.reported, 1, |
| 1689 | "Abandoned gate change should report only start") |
| 1690 | |
| 1691 | def test_abandoned_check(self): |
| 1692 | "Test that an abandoned change is dequeued from check" |
| 1693 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1694 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1695 | |
| 1696 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1697 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1698 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1699 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1700 | |
| 1701 | # Add two git-dependent changes |
| 1702 | B.setDependsOn(A, 1) |
| 1703 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1704 | self.waitUntilSettled() |
| 1705 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1706 | self.waitUntilSettled() |
| 1707 | # A live item, and a non-live/live pair |
| 1708 | items = check_pipeline.getAllItems() |
| 1709 | self.assertEqual(len(items), 3) |
| 1710 | |
| 1711 | self.assertEqual(items[0].change.number, '1') |
| 1712 | self.assertFalse(items[0].live) |
| 1713 | |
| 1714 | self.assertEqual(items[1].change.number, '2') |
| 1715 | self.assertTrue(items[1].live) |
| 1716 | |
| 1717 | self.assertEqual(items[2].change.number, '1') |
| 1718 | self.assertTrue(items[2].live) |
| 1719 | |
| 1720 | # Abandon A |
| 1721 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1722 | self.waitUntilSettled() |
| 1723 | |
| 1724 | # The live copy of A should be gone, but the non-live and B |
| 1725 | # should continue |
| 1726 | items = check_pipeline.getAllItems() |
| 1727 | self.assertEqual(len(items), 2) |
| 1728 | |
| 1729 | self.assertEqual(items[0].change.number, '1') |
| 1730 | self.assertFalse(items[0].live) |
| 1731 | |
| 1732 | self.assertEqual(items[1].change.number, '2') |
| 1733 | self.assertTrue(items[1].live) |
| 1734 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1735 | self.executor_server.hold_jobs_in_build = False |
| 1736 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1737 | self.waitUntilSettled() |
| 1738 | |
| 1739 | self.assertEqual(len(self.history), 4) |
| 1740 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1741 | 'Build should have been aborted') |
| 1742 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1743 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1744 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1745 | def test_abandoned_not_timer(self): |
| 1746 | "Test that an abandoned change does not cancel timer jobs" |
| 1747 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1748 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1749 | |
| 1750 | # Start timer trigger - also org/project |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1751 | self.updateConfigLayout('layout-idle') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1752 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1753 | # The pipeline triggers every second, so we should have seen |
| 1754 | # several by now. |
| 1755 | time.sleep(5) |
| 1756 | self.waitUntilSettled() |
| 1757 | # Stop queuing timer triggered jobs so that the assertions |
| 1758 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1759 | # Must be in same repo, so overwrite config with another one |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 1760 | self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1761 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1762 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1763 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1764 | |
| 1765 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1766 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1767 | self.waitUntilSettled() |
| 1768 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1769 | |
| 1770 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1771 | self.waitUntilSettled() |
| 1772 | |
| 1773 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1774 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1775 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1776 | self.waitUntilSettled() |
| 1777 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1778 | def test_zuul_url_return(self): |
| 1779 | "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] | 1780 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1781 | self.executor_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1782 | |
| 1783 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1784 | A.addApproval('code-review', 2) |
| 1785 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1786 | self.waitUntilSettled() |
| 1787 | |
| 1788 | self.assertEqual(len(self.builds), 1) |
| 1789 | for build in self.builds: |
| 1790 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1791 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1792 | self.executor_server.hold_jobs_in_build = False |
| 1793 | self.executor_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1794 | self.waitUntilSettled() |
| 1795 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1796 | def test_new_patchset_dequeues_old_on_head(self): |
| 1797 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1798 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1799 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1800 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1801 | M.setMerged() |
| 1802 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1803 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1804 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1805 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1806 | A.addApproval('code-review', 2) |
| 1807 | B.addApproval('code-review', 2) |
| 1808 | C.addApproval('code-review', 2) |
| 1809 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1810 | |
| 1811 | C.setDependsOn(B, 1) |
| 1812 | B.setDependsOn(A, 1) |
| 1813 | A.setDependsOn(M, 1) |
| 1814 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1815 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1816 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1817 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1818 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1819 | self.waitUntilSettled() |
| 1820 | |
| 1821 | A.addPatchset() |
| 1822 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1823 | self.waitUntilSettled() |
| 1824 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1825 | self.executor_server.hold_jobs_in_build = False |
| 1826 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1827 | self.waitUntilSettled() |
| 1828 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1829 | self.assertEqual(A.data['status'], 'NEW') |
| 1830 | self.assertEqual(A.reported, 2) |
| 1831 | self.assertEqual(B.data['status'], 'NEW') |
| 1832 | self.assertEqual(B.reported, 2) |
| 1833 | self.assertEqual(C.data['status'], 'NEW') |
| 1834 | self.assertEqual(C.reported, 2) |
| 1835 | self.assertEqual(D.data['status'], 'MERGED') |
| 1836 | self.assertEqual(D.reported, 2) |
| 1837 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1838 | |
| 1839 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1840 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1841 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1842 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1843 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1844 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1845 | A.addApproval('code-review', 2) |
| 1846 | B.addApproval('code-review', 2) |
| 1847 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1848 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1849 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1850 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1851 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1852 | self.waitUntilSettled() |
| 1853 | |
| 1854 | B.addPatchset() |
| 1855 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1856 | self.waitUntilSettled() |
| 1857 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1858 | self.executor_server.hold_jobs_in_build = False |
| 1859 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1860 | self.waitUntilSettled() |
| 1861 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1862 | self.assertEqual(A.data['status'], 'MERGED') |
| 1863 | self.assertEqual(A.reported, 2) |
| 1864 | self.assertEqual(B.data['status'], 'NEW') |
| 1865 | self.assertEqual(B.reported, 2) |
| 1866 | self.assertEqual(C.data['status'], 'MERGED') |
| 1867 | self.assertEqual(C.reported, 2) |
| 1868 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1869 | |
| 1870 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1871 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1872 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1873 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1874 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1875 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1876 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1877 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1878 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1879 | self.waitUntilSettled() |
| 1880 | |
| 1881 | B.addPatchset() |
| 1882 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1883 | self.waitUntilSettled() |
| 1884 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1885 | self.executor_server.hold_jobs_in_build = False |
| 1886 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1887 | self.waitUntilSettled() |
| 1888 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1889 | self.assertEqual(A.data['status'], 'NEW') |
| 1890 | self.assertEqual(A.reported, 1) |
| 1891 | self.assertEqual(B.data['status'], 'NEW') |
| 1892 | self.assertEqual(B.reported, 1) |
| 1893 | self.assertEqual(C.data['status'], 'NEW') |
| 1894 | self.assertEqual(C.reported, 1) |
| 1895 | self.assertEqual(len(self.history), 10) |
| 1896 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1897 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1898 | def test_noop_job(self): |
| 1899 | "Test that the internal noop job works" |
| 1900 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1901 | A.addApproval('code-review', 2) |
| 1902 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1903 | self.waitUntilSettled() |
| 1904 | |
| 1905 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1906 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1907 | self.assertEqual(len(self.history), 0) |
| 1908 | self.assertEqual(A.data['status'], 'MERGED') |
| 1909 | self.assertEqual(A.reported, 2) |
| 1910 | |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1911 | def test_no_job_project(self): |
| 1912 | "Test that reports with no jobs don't get sent" |
| 1913 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1914 | 'master', 'A') |
| 1915 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1916 | self.waitUntilSettled() |
| 1917 | |
| 1918 | # Change wasn't reported to |
| 1919 | self.assertEqual(A.reported, False) |
| 1920 | |
| 1921 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1922 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1923 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1924 | items = check_pipeline.getAllItems() |
| 1925 | self.assertEqual(len(items), 0) |
| 1926 | |
| 1927 | self.assertEqual(len(self.history), 0) |
| 1928 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1929 | def test_zuul_refs(self): |
| 1930 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1931 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1932 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1933 | M1.setMerged() |
| 1934 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1935 | M2.setMerged() |
| 1936 | |
| 1937 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1938 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1939 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1940 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1941 | A.addApproval('code-review', 2) |
| 1942 | B.addApproval('code-review', 2) |
| 1943 | C.addApproval('code-review', 2) |
| 1944 | D.addApproval('code-review', 2) |
| 1945 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1946 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1947 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1948 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1949 | |
| 1950 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1951 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1952 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1953 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1954 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1955 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1956 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1957 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1958 | self.waitUntilSettled() |
| 1959 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1960 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1961 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1962 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1963 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1964 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1965 | a_build = x |
| 1966 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1967 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1968 | b_build = x |
| 1969 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1970 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1971 | c_build = x |
| 1972 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1973 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1974 | d_build = x |
| 1975 | if a_build and b_build and c_build and d_build: |
| 1976 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1977 | |
| 1978 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1979 | self.assertIsNotNone(a_zref) |
| 1980 | self.assertIsNotNone(b_zref) |
| 1981 | self.assertIsNotNone(c_zref) |
| 1982 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1983 | |
| 1984 | # And they should all be different |
| 1985 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1986 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1987 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1988 | # should have a, not b, and should not be in project2 |
| 1989 | self.assertTrue(a_build.hasChanges(A)) |
| 1990 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1991 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1992 | # should have a and b, and should not be in project2 |
| 1993 | self.assertTrue(b_build.hasChanges(A, B)) |
| 1994 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1995 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1996 | # should have a and b in 1, c in 2 |
| 1997 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 1998 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1999 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2000 | # should have a and b in 1, c and d in 2 |
| 2001 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2002 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2003 | self.executor_server.hold_jobs_in_build = False |
| 2004 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2005 | self.waitUntilSettled() |
| 2006 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2007 | self.assertEqual(A.data['status'], 'MERGED') |
| 2008 | self.assertEqual(A.reported, 2) |
| 2009 | self.assertEqual(B.data['status'], 'MERGED') |
| 2010 | self.assertEqual(B.reported, 2) |
| 2011 | self.assertEqual(C.data['status'], 'MERGED') |
| 2012 | self.assertEqual(C.reported, 2) |
| 2013 | self.assertEqual(D.data['status'], 'MERGED') |
| 2014 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2015 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2016 | def test_rerun_on_error(self): |
| 2017 | "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] | 2018 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2019 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2020 | A.addApproval('code-review', 2) |
| 2021 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2022 | self.waitUntilSettled() |
| 2023 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2024 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2025 | self.executor_server.hold_jobs_in_build = False |
| 2026 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2027 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2028 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2029 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2030 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2031 | def test_statsd(self): |
| 2032 | "Test each of the statsd methods used in the scheduler" |
| 2033 | import extras |
| 2034 | statsd = extras.try_import('statsd.statsd') |
| 2035 | statsd.incr('test-incr') |
| 2036 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2037 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2038 | self.assertReportedStat('test-incr', '1|c') |
| 2039 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2040 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2041 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2042 | def test_stuck_job_cleanup(self): |
| 2043 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2044 | |
| 2045 | # 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] | 2046 | self.gearman_server.hold_jobs_in_queue = True |
| 2047 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2048 | A.addApproval('code-review', 2) |
| 2049 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2050 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2051 | # 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] | 2052 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2053 | |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2054 | self.commitLayoutUpdate('common-config', 'layout-no-jobs') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2055 | self.sched.reconfigure(self.config) |
| 2056 | self.waitUntilSettled() |
| 2057 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2058 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2059 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2060 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2061 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2062 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2063 | |
| 2064 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2065 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2066 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2067 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2068 | def test_file_head(self): |
| 2069 | # This is a regression test for an observed bug. A change |
| 2070 | # with a file named "HEAD" in the root directory of the repo |
| 2071 | # was processed by a merger. It then was unable to reset the |
| 2072 | # repo because of: |
| 2073 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2074 | # with exit code 128 |
| 2075 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2076 | # and filename |
| 2077 | # Use '--' to separate filenames from revisions' |
| 2078 | |
| 2079 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2080 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2081 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2082 | |
| 2083 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2084 | self.waitUntilSettled() |
| 2085 | |
| 2086 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2087 | self.waitUntilSettled() |
| 2088 | |
| 2089 | self.assertIn('Build succeeded', A.messages[0]) |
| 2090 | self.assertIn('Build succeeded', B.messages[0]) |
| 2091 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2092 | def test_file_jobs(self): |
| 2093 | "Test that file jobs run only when appropriate" |
| 2094 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2095 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2096 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2097 | A.addApproval('code-review', 2) |
| 2098 | B.addApproval('code-review', 2) |
| 2099 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2100 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2101 | self.waitUntilSettled() |
| 2102 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2103 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2104 | if x.name == 'project-testfile'] |
| 2105 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2106 | self.assertEqual(len(testfile_jobs), 1) |
| 2107 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2108 | self.assertEqual(A.data['status'], 'MERGED') |
| 2109 | self.assertEqual(A.reported, 2) |
| 2110 | self.assertEqual(B.data['status'], 'MERGED') |
| 2111 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2112 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2113 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2114 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2115 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2116 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2117 | |
| 2118 | if should_skip: |
| 2119 | files = {'ignoreme': 'ignored\n'} |
| 2120 | else: |
| 2121 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2122 | |
| 2123 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2124 | 'master', |
| 2125 | 'test irrelevant-files', |
| 2126 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2127 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2128 | self.waitUntilSettled() |
| 2129 | |
| 2130 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2131 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2132 | |
| 2133 | if should_skip: |
| 2134 | self.assertEqual([], tested_change_ids) |
| 2135 | else: |
| 2136 | self.assertIn(change.data['number'], tested_change_ids) |
| 2137 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2138 | def test_irrelevant_files_match_skips_job(self): |
| 2139 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2140 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2141 | def test_irrelevant_files_no_match_runs_job(self): |
| 2142 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2143 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2144 | def test_inherited_jobs_keep_matchers(self): |
| 2145 | self.updateConfigLayout('layout-inheritance') |
| 2146 | self.sched.reconfigure(self.config) |
| 2147 | |
| 2148 | files = {'ignoreme': 'ignored\n'} |
| 2149 | |
| 2150 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2151 | 'master', |
| 2152 | 'test irrelevant-files', |
| 2153 | files=files) |
| 2154 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2155 | self.waitUntilSettled() |
| 2156 | |
| 2157 | run_jobs = set([build.name for build in self.history]) |
| 2158 | |
| 2159 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2160 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2161 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2162 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2163 | def test_test_config(self): |
| 2164 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2165 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2166 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2167 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2168 | def test_queue_names(self): |
| 2169 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2170 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2171 | source = tenant.layout.pipelines['gate'].source |
| 2172 | project1 = source.getProject('org/project1') |
| 2173 | project2 = source.getProject('org/project2') |
| 2174 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2175 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2176 | self.assertEqual(q1.name, 'integrated') |
| 2177 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2178 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2179 | def test_queue_precedence(self): |
| 2180 | "Test that queue precedence works" |
| 2181 | |
| 2182 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2183 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2184 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2185 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2186 | A.addApproval('code-review', 2) |
| 2187 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2188 | |
| 2189 | self.waitUntilSettled() |
| 2190 | self.gearman_server.hold_jobs_in_queue = False |
| 2191 | self.gearman_server.release() |
| 2192 | self.waitUntilSettled() |
| 2193 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2194 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2195 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2196 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2197 | self.waitUntilSettled() |
| 2198 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2199 | self.log.debug(self.history) |
| 2200 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2201 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2202 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2203 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2204 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2205 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2206 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2207 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2208 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2209 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2210 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2211 | A.addApproval('code-review', 2) |
| 2212 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2213 | self.waitUntilSettled() |
| 2214 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2215 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2216 | self.waitUntilSettled() |
| 2217 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2218 | port = self.webapp.server.socket.getsockname()[1] |
| 2219 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2220 | req = urllib.request.Request( |
| 2221 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2222 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2223 | headers = f.info() |
| 2224 | self.assertIn('Content-Length', headers) |
| 2225 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2226 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2227 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2228 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2229 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2230 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2231 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2232 | data = f.read() |
| 2233 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2234 | self.executor_server.hold_jobs_in_build = False |
| 2235 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2236 | self.waitUntilSettled() |
| 2237 | |
| 2238 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2239 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2240 | for p in data['pipelines']: |
| 2241 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2242 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2243 | self.assertEqual(q['window'], 20) |
| 2244 | else: |
| 2245 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2246 | for head in q['heads']: |
| 2247 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2248 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2249 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2250 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2251 | status_jobs.append(job) |
| 2252 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2253 | self.assertEqual('https://server/job/project-merge/0/', |
| 2254 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2255 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2256 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2257 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2258 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2259 | status_jobs[1]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2260 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2261 | status_jobs[1]['report_url']) |
| 2262 | |
| 2263 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2264 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2265 | status_jobs[2]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2266 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2267 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2268 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2269 | def test_semaphore_one(self): |
| 2270 | "Test semaphores with max=1 (mutex)" |
| 2271 | self.updateConfigLayout('layout-semaphore') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2272 | self.sched.reconfigure(self.config) |
| 2273 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2274 | self.waitUntilSettled() |
| 2275 | tenant = self.sched.abide.tenants.get('openstack') |
| 2276 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2277 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2278 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2279 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2280 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2281 | self.assertFalse('test-semaphore' in |
| 2282 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2283 | |
| 2284 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2285 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2286 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2287 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2288 | self.assertEqual(len(self.builds), 3) |
| 2289 | self.assertEqual(self.builds[0].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2290 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2291 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2292 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2293 | self.executor_server.release('semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2294 | self.waitUntilSettled() |
| 2295 | |
| 2296 | self.assertEqual(len(self.builds), 3) |
| 2297 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2298 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2299 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 2300 | self.assertTrue('test-semaphore' in |
| 2301 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2302 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2303 | self.executor_server.release('semaphore-one-test2') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2304 | self.waitUntilSettled() |
| 2305 | |
| 2306 | self.assertEqual(len(self.builds), 3) |
| 2307 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2308 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2309 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 2310 | self.assertTrue('test-semaphore' in |
| 2311 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2312 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2313 | self.executor_server.release('semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2314 | self.waitUntilSettled() |
| 2315 | |
| 2316 | self.assertEqual(len(self.builds), 3) |
| 2317 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2318 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2319 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 2320 | self.assertTrue('test-semaphore' in |
| 2321 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2322 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2323 | self.executor_server.release('semaphore-one-test2') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2324 | self.waitUntilSettled() |
| 2325 | |
| 2326 | self.assertEqual(len(self.builds), 2) |
| 2327 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2328 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2329 | self.assertFalse('test-semaphore' in |
| 2330 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2331 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2332 | self.executor_server.hold_jobs_in_build = False |
| 2333 | self.executor_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2334 | |
| 2335 | self.waitUntilSettled() |
| 2336 | self.assertEqual(len(self.builds), 0) |
| 2337 | |
| 2338 | self.assertEqual(A.reported, 1) |
| 2339 | self.assertEqual(B.reported, 1) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2340 | self.assertFalse('test-semaphore' in |
| 2341 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2342 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2343 | def test_semaphore_two(self): |
| 2344 | "Test semaphores with max>1" |
| 2345 | self.updateConfigLayout('layout-semaphore') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2346 | self.sched.reconfigure(self.config) |
| 2347 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2348 | self.waitUntilSettled() |
| 2349 | tenant = self.sched.abide.tenants.get('openstack') |
| 2350 | |
| 2351 | self.executor_server.hold_jobs_in_build = True |
| 2352 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2353 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2354 | self.assertFalse('test-semaphore-two' in |
| 2355 | tenant.semaphore_handler.semaphores) |
| 2356 | |
| 2357 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2358 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2359 | self.waitUntilSettled() |
| 2360 | |
| 2361 | self.assertEqual(len(self.builds), 4) |
| 2362 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2363 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 2364 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 2365 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 2366 | self.assertTrue('test-semaphore-two' in |
| 2367 | tenant.semaphore_handler.semaphores) |
| 2368 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2369 | 'test-semaphore-two', [])), 2) |
| 2370 | |
| 2371 | self.executor_server.release('semaphore-two-test1') |
| 2372 | self.waitUntilSettled() |
| 2373 | |
| 2374 | self.assertEqual(len(self.builds), 4) |
| 2375 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2376 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 2377 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2378 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 2379 | self.assertTrue('test-semaphore-two' in |
| 2380 | tenant.semaphore_handler.semaphores) |
| 2381 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2382 | 'test-semaphore-two', [])), 2) |
| 2383 | |
| 2384 | self.executor_server.release('semaphore-two-test2') |
| 2385 | self.waitUntilSettled() |
| 2386 | |
| 2387 | self.assertEqual(len(self.builds), 4) |
| 2388 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2389 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2390 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 2391 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 2392 | self.assertTrue('test-semaphore-two' in |
| 2393 | tenant.semaphore_handler.semaphores) |
| 2394 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2395 | 'test-semaphore-two', [])), 2) |
| 2396 | |
| 2397 | self.executor_server.release('semaphore-two-test1') |
| 2398 | self.waitUntilSettled() |
| 2399 | |
| 2400 | self.assertEqual(len(self.builds), 3) |
| 2401 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2402 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2403 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 2404 | self.assertTrue('test-semaphore-two' in |
| 2405 | tenant.semaphore_handler.semaphores) |
| 2406 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2407 | 'test-semaphore-two', [])), 1) |
| 2408 | |
| 2409 | self.executor_server.release('semaphore-two-test2') |
| 2410 | self.waitUntilSettled() |
| 2411 | |
| 2412 | self.assertEqual(len(self.builds), 2) |
| 2413 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2414 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2415 | self.assertFalse('test-semaphore-two' in |
| 2416 | tenant.semaphore_handler.semaphores) |
| 2417 | |
| 2418 | self.executor_server.hold_jobs_in_build = False |
| 2419 | self.executor_server.release() |
| 2420 | |
| 2421 | self.waitUntilSettled() |
| 2422 | self.assertEqual(len(self.builds), 0) |
| 2423 | |
| 2424 | self.assertEqual(A.reported, 1) |
| 2425 | self.assertEqual(B.reported, 1) |
| 2426 | |
| 2427 | def test_semaphore_abandon(self): |
| 2428 | "Test abandon with job semaphores" |
| 2429 | self.updateConfigLayout('layout-semaphore') |
| 2430 | self.sched.reconfigure(self.config) |
| 2431 | |
| 2432 | self.waitUntilSettled() |
| 2433 | tenant = self.sched.abide.tenants.get('openstack') |
| 2434 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2435 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2436 | |
| 2437 | tenant = self.sched.abide.tenants.get('openstack') |
| 2438 | check_pipeline = tenant.layout.pipelines['check'] |
| 2439 | |
| 2440 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2441 | self.assertFalse('test-semaphore' in |
| 2442 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2443 | |
| 2444 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2445 | self.waitUntilSettled() |
| 2446 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2447 | self.assertTrue('test-semaphore' in |
| 2448 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2449 | |
| 2450 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2451 | self.waitUntilSettled() |
| 2452 | |
| 2453 | # The check pipeline should be empty |
| 2454 | items = check_pipeline.getAllItems() |
| 2455 | self.assertEqual(len(items), 0) |
| 2456 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2457 | # The semaphore should be released |
| 2458 | self.assertFalse('test-semaphore' in |
| 2459 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2460 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2461 | self.executor_server.hold_jobs_in_build = False |
| 2462 | self.executor_server.release() |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2463 | self.waitUntilSettled() |
| 2464 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2465 | def test_semaphore_reconfigure(self): |
| 2466 | "Test reconfigure with job semaphores" |
| 2467 | self.updateConfigLayout('layout-semaphore') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2468 | self.sched.reconfigure(self.config) |
| 2469 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2470 | self.waitUntilSettled() |
| 2471 | tenant = self.sched.abide.tenants.get('openstack') |
| 2472 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2473 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2474 | |
| 2475 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2476 | self.assertFalse('test-semaphore' in |
| 2477 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2478 | |
| 2479 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2480 | self.waitUntilSettled() |
| 2481 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2482 | self.assertTrue('test-semaphore' in |
| 2483 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2484 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2485 | # reconfigure without layout change |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2486 | self.sched.reconfigure(self.config) |
| 2487 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2488 | tenant = self.sched.abide.tenants.get('openstack') |
| 2489 | |
| 2490 | # semaphore still must be held |
| 2491 | self.assertTrue('test-semaphore' in |
| 2492 | tenant.semaphore_handler.semaphores) |
| 2493 | |
| 2494 | self.updateConfigLayout('layout-semaphore-reconfiguration') |
| 2495 | self.sched.reconfigure(self.config) |
| 2496 | self.waitUntilSettled() |
| 2497 | tenant = self.sched.abide.tenants.get('openstack') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2498 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2499 | self.executor_server.release('project-test1') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2500 | self.waitUntilSettled() |
| 2501 | |
| 2502 | # There should be no builds anymore |
| 2503 | self.assertEqual(len(self.builds), 0) |
| 2504 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2505 | # The semaphore should be released |
| 2506 | self.assertFalse('test-semaphore' in |
| 2507 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2508 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2509 | def test_live_reconfiguration(self): |
| 2510 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2511 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2512 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2513 | A.addApproval('code-review', 2) |
| 2514 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2515 | self.waitUntilSettled() |
| 2516 | |
| 2517 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2518 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2519 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2520 | self.executor_server.hold_jobs_in_build = False |
| 2521 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2522 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2523 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2524 | 'SUCCESS') |
| 2525 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2526 | 'SUCCESS') |
| 2527 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2528 | 'SUCCESS') |
| 2529 | self.assertEqual(A.data['status'], 'MERGED') |
| 2530 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2531 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2532 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2533 | def test_live_reconfiguration_merge_conflict(self): |
| 2534 | # A real-world bug: a change in a gate queue has a merge |
| 2535 | # conflict and a job is added to its project while it's |
| 2536 | # sitting in the queue. The job gets added to the change and |
| 2537 | # enqueued and the change gets stuck. |
| 2538 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2539 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2540 | |
| 2541 | # This change is fine. It's here to stop the queue long |
| 2542 | # enough for the next change to be subject to the |
| 2543 | # reconfiguration, as well as to provide a conflict for the |
| 2544 | # next change. This change will succeed and merge. |
| 2545 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2546 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2547 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2548 | |
| 2549 | # This change will be in merge conflict. During the |
| 2550 | # reconfiguration, we will add a job. We want to make sure |
| 2551 | # that doesn't cause it to get stuck. |
| 2552 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2553 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2554 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2555 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2556 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2557 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2558 | |
| 2559 | self.waitUntilSettled() |
| 2560 | |
| 2561 | # No jobs have run yet |
| 2562 | self.assertEqual(A.data['status'], 'NEW') |
| 2563 | self.assertEqual(A.reported, 1) |
| 2564 | self.assertEqual(B.data['status'], 'NEW') |
| 2565 | self.assertEqual(B.reported, 1) |
| 2566 | self.assertEqual(len(self.history), 0) |
| 2567 | |
| 2568 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2569 | self.updateConfigLayout( |
| 2570 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2571 | self.sched.reconfigure(self.config) |
| 2572 | self.waitUntilSettled() |
| 2573 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2574 | self.executor_server.hold_jobs_in_build = False |
| 2575 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2576 | self.waitUntilSettled() |
| 2577 | |
| 2578 | self.assertEqual(A.data['status'], 'MERGED') |
| 2579 | self.assertEqual(A.reported, 2) |
| 2580 | self.assertEqual(B.data['status'], 'NEW') |
| 2581 | self.assertEqual(B.reported, 2) |
| 2582 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2583 | 'SUCCESS') |
| 2584 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2585 | 'SUCCESS') |
| 2586 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2587 | 'SUCCESS') |
| 2588 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2589 | 'SUCCESS') |
| 2590 | self.assertEqual(len(self.history), 4) |
| 2591 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2592 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2593 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2594 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2595 | # that tests a job added to a job tree with a failed root does |
| 2596 | # not run. |
| 2597 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2598 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2599 | |
| 2600 | # This change is fine. It's here to stop the queue long |
| 2601 | # enough for the next change to be subject to the |
| 2602 | # reconfiguration. This change will succeed and merge. |
| 2603 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2604 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2605 | A.addApproval('code-review', 2) |
| 2606 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2607 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2608 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2609 | self.waitUntilSettled() |
| 2610 | |
| 2611 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2612 | self.executor_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2613 | B.addApproval('code-review', 2) |
| 2614 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2615 | self.waitUntilSettled() |
| 2616 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2617 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2618 | self.waitUntilSettled() |
| 2619 | |
| 2620 | # Both -merge jobs have run, but no others. |
| 2621 | self.assertEqual(A.data['status'], 'NEW') |
| 2622 | self.assertEqual(A.reported, 1) |
| 2623 | self.assertEqual(B.data['status'], 'NEW') |
| 2624 | self.assertEqual(B.reported, 1) |
| 2625 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2626 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2627 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2628 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2629 | self.assertEqual(len(self.history), 2) |
| 2630 | |
| 2631 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2632 | self.updateConfigLayout( |
| 2633 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2634 | self.sched.reconfigure(self.config) |
| 2635 | self.waitUntilSettled() |
| 2636 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2637 | self.executor_server.hold_jobs_in_build = False |
| 2638 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2639 | self.waitUntilSettled() |
| 2640 | |
| 2641 | self.assertEqual(A.data['status'], 'MERGED') |
| 2642 | self.assertEqual(A.reported, 2) |
| 2643 | self.assertEqual(B.data['status'], 'NEW') |
| 2644 | self.assertEqual(B.reported, 2) |
| 2645 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2646 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2647 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2648 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2649 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2650 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2651 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2652 | self.assertEqual(len(self.history), 5) |
| 2653 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2654 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2655 | def test_live_reconfiguration_failed_job(self): |
| 2656 | # Test that a change with a removed failing job does not |
| 2657 | # disrupt reconfiguration. If a change has a failed job and |
| 2658 | # that job is removed during a reconfiguration, we observed a |
| 2659 | # bug where the code to re-set build statuses would run on |
| 2660 | # that build and raise an exception because the job no longer |
| 2661 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2662 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2663 | |
| 2664 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2665 | |
| 2666 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2667 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2668 | |
| 2669 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2670 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2671 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2672 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2673 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2674 | self.waitUntilSettled() |
| 2675 | |
| 2676 | self.assertEqual(A.data['status'], 'NEW') |
| 2677 | self.assertEqual(A.reported, 0) |
| 2678 | |
| 2679 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2680 | 'SUCCESS') |
| 2681 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2682 | 'FAILURE') |
| 2683 | self.assertEqual(len(self.history), 2) |
| 2684 | |
| 2685 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2686 | self.updateConfigLayout( |
| 2687 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2688 | self.sched.reconfigure(self.config) |
| 2689 | self.waitUntilSettled() |
| 2690 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2691 | self.executor_server.hold_jobs_in_build = False |
| 2692 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2693 | self.waitUntilSettled() |
| 2694 | |
| 2695 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2696 | 'SUCCESS') |
| 2697 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2698 | 'SUCCESS') |
| 2699 | self.assertEqual(len(self.history), 4) |
| 2700 | |
| 2701 | self.assertEqual(A.data['status'], 'NEW') |
| 2702 | self.assertEqual(A.reported, 1) |
| 2703 | self.assertIn('Build succeeded', A.messages[0]) |
| 2704 | # Ensure the removed job was not included in the report. |
| 2705 | self.assertNotIn('project-test1', A.messages[0]) |
| 2706 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2707 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2708 | def test_live_reconfiguration_shared_queue(self): |
| 2709 | # Test that a change with a failing job which was removed from |
| 2710 | # this project but otherwise still exists in the system does |
| 2711 | # not disrupt reconfiguration. |
| 2712 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2713 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2714 | |
| 2715 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2716 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2717 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2718 | |
| 2719 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2720 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2721 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2722 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2723 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2724 | self.waitUntilSettled() |
| 2725 | |
| 2726 | self.assertEqual(A.data['status'], 'NEW') |
| 2727 | self.assertEqual(A.reported, 0) |
| 2728 | |
| 2729 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2730 | 'SUCCESS') |
| 2731 | self.assertEqual(self.getJobFromHistory( |
| 2732 | 'project1-project2-integration').result, 'FAILURE') |
| 2733 | self.assertEqual(len(self.history), 2) |
| 2734 | |
| 2735 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2736 | self.updateConfigLayout( |
| 2737 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2738 | self.sched.reconfigure(self.config) |
| 2739 | self.waitUntilSettled() |
| 2740 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2741 | self.executor_server.hold_jobs_in_build = False |
| 2742 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2743 | self.waitUntilSettled() |
| 2744 | |
| 2745 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2746 | 'SUCCESS') |
| 2747 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2748 | 'SUCCESS') |
| 2749 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2750 | 'SUCCESS') |
| 2751 | self.assertEqual(self.getJobFromHistory( |
| 2752 | 'project1-project2-integration').result, 'FAILURE') |
| 2753 | self.assertEqual(len(self.history), 4) |
| 2754 | |
| 2755 | self.assertEqual(A.data['status'], 'NEW') |
| 2756 | self.assertEqual(A.reported, 1) |
| 2757 | self.assertIn('Build succeeded', A.messages[0]) |
| 2758 | # Ensure the removed job was not included in the report. |
| 2759 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2760 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2761 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2762 | def test_double_live_reconfiguration_shared_queue(self): |
| 2763 | # This was a real-world regression. A change is added to |
| 2764 | # gate; a reconfigure happens, a second change which depends |
| 2765 | # on the first is added, and a second reconfiguration happens. |
| 2766 | # Ensure that both changes merge. |
| 2767 | |
| 2768 | # A failure may indicate incorrect caching or cleaning up of |
| 2769 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2770 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2771 | |
| 2772 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2773 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2774 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2775 | A.addApproval('code-review', 2) |
| 2776 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2777 | |
| 2778 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2779 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2780 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2781 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2782 | self.waitUntilSettled() |
| 2783 | |
| 2784 | # Reconfigure (with only one change in the pipeline). |
| 2785 | self.sched.reconfigure(self.config) |
| 2786 | self.waitUntilSettled() |
| 2787 | |
| 2788 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2789 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2790 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2791 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2792 | self.waitUntilSettled() |
| 2793 | |
| 2794 | # Reconfigure (with both in the pipeline). |
| 2795 | self.sched.reconfigure(self.config) |
| 2796 | self.waitUntilSettled() |
| 2797 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2798 | self.executor_server.hold_jobs_in_build = False |
| 2799 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2800 | self.waitUntilSettled() |
| 2801 | |
| 2802 | self.assertEqual(len(self.history), 8) |
| 2803 | |
| 2804 | self.assertEqual(A.data['status'], 'MERGED') |
| 2805 | self.assertEqual(A.reported, 2) |
| 2806 | self.assertEqual(B.data['status'], 'MERGED') |
| 2807 | self.assertEqual(B.reported, 2) |
| 2808 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2809 | def test_live_reconfiguration_del_project(self): |
| 2810 | # Test project deletion from layout |
| 2811 | # while changes are enqueued |
| 2812 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2813 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2814 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2815 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2816 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2817 | |
| 2818 | # A Depends-On: B |
| 2819 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2820 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2821 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2822 | |
| 2823 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2824 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2825 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2826 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2827 | self.waitUntilSettled() |
| 2828 | self.assertEqual(len(self.builds), 5) |
| 2829 | |
| 2830 | # This layout defines only org/project, not org/project1 |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2831 | self.commitLayoutUpdate('common-config', |
| 2832 | 'layout-live-reconfiguration-del-project') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2833 | self.sched.reconfigure(self.config) |
| 2834 | self.waitUntilSettled() |
| 2835 | |
| 2836 | # Builds for C aborted, builds for A succeed, |
| 2837 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2838 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2839 | self.assertEqual(job_c.changes, '3,1') |
| 2840 | self.assertEqual(job_c.result, 'ABORTED') |
| 2841 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2842 | self.executor_server.hold_jobs_in_build = False |
| 2843 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2844 | self.waitUntilSettled() |
| 2845 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2846 | self.assertEqual( |
| 2847 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2848 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2849 | |
| 2850 | self.assertEqual(A.data['status'], 'NEW') |
| 2851 | self.assertEqual(B.data['status'], 'NEW') |
| 2852 | self.assertEqual(C.data['status'], 'NEW') |
| 2853 | self.assertEqual(A.reported, 1) |
| 2854 | self.assertEqual(B.reported, 0) |
| 2855 | self.assertEqual(C.reported, 0) |
| 2856 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2857 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2858 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2859 | self.assertIn('Build succeeded', A.messages[0]) |
| 2860 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2861 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2862 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2863 | self.updateConfigLayout( |
| 2864 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2865 | self.sched.reconfigure(self.config) |
| 2866 | |
| 2867 | self.init_repo("org/new-project") |
| 2868 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2869 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2870 | A.addApproval('code-review', 2) |
| 2871 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2872 | self.waitUntilSettled() |
| 2873 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2874 | 'SUCCESS') |
| 2875 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2876 | 'SUCCESS') |
| 2877 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2878 | 'SUCCESS') |
| 2879 | self.assertEqual(A.data['status'], 'MERGED') |
| 2880 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2881 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2882 | def test_repo_deleted(self): |
Paul Belanger | 66e9596 | 2016-11-11 12:11:06 -0500 | [diff] [blame] | 2883 | self.updateConfigLayout('layout-repo-deleted') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2884 | self.sched.reconfigure(self.config) |
| 2885 | |
| 2886 | self.init_repo("org/delete-project") |
| 2887 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2888 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2889 | A.addApproval('code-review', 2) |
| 2890 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2891 | self.waitUntilSettled() |
| 2892 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2893 | 'SUCCESS') |
| 2894 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2895 | 'SUCCESS') |
| 2896 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2897 | 'SUCCESS') |
| 2898 | self.assertEqual(A.data['status'], 'MERGED') |
| 2899 | self.assertEqual(A.reported, 2) |
| 2900 | |
| 2901 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2902 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2903 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2904 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2905 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2906 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2907 | |
| 2908 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2909 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2910 | B.addApproval('code-review', 2) |
| 2911 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2912 | self.waitUntilSettled() |
| 2913 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2914 | 'SUCCESS') |
| 2915 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2916 | 'SUCCESS') |
| 2917 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2918 | 'SUCCESS') |
| 2919 | self.assertEqual(B.data['status'], 'MERGED') |
| 2920 | self.assertEqual(B.reported, 2) |
| 2921 | |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2922 | def test_tags(self): |
| 2923 | "Test job tags" |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2924 | self.updateConfigLayout('layout-tags') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2925 | self.sched.reconfigure(self.config) |
| 2926 | |
| 2927 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2928 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2929 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2930 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2931 | self.waitUntilSettled() |
| 2932 | |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2933 | self.assertEqual(len(self.history), 8) |
| 2934 | |
| 2935 | results = {self.getJobFromHistory('merge', |
| 2936 | project='org/project1').uuid: 'extratag merge', |
| 2937 | self.getJobFromHistory('merge', |
| 2938 | project='org/project2').uuid: 'merge'} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2939 | |
| 2940 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2941 | self.assertEqual(results.get(build.uuid, ''), |
| 2942 | build.parameters['vars']['zuul'].get('tags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2943 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2944 | def test_timer(self): |
| 2945 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2946 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2947 | self.updateConfigLayout('layout-timer') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2948 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2949 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2950 | # The pipeline triggers every second, so we should have seen |
| 2951 | # several by now. |
| 2952 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2953 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2954 | |
| 2955 | self.assertEqual(len(self.builds), 2) |
| 2956 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2957 | port = self.webapp.server.socket.getsockname()[1] |
| 2958 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2959 | req = urllib.request.Request( |
| 2960 | "http://localhost:%s/openstack/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2961 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2962 | data = f.read() |
| 2963 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2964 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2965 | # Stop queuing timer triggered jobs so that the assertions |
| 2966 | # below don't race against more jobs being queued. |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2967 | self.commitLayoutUpdate('layout-timer', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2968 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2969 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2970 | self.waitUntilSettled() |
| 2971 | |
| 2972 | self.assertEqual(self.getJobFromHistory( |
| 2973 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2974 | self.assertEqual(self.getJobFromHistory( |
| 2975 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2976 | |
| 2977 | data = json.loads(data) |
| 2978 | status_jobs = set() |
| 2979 | for p in data['pipelines']: |
| 2980 | for q in p['change_queues']: |
| 2981 | for head in q['heads']: |
| 2982 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2983 | for job in change['jobs']: |
| 2984 | status_jobs.add(job['name']) |
| 2985 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2986 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2987 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2988 | def test_idle(self): |
| 2989 | "Test that frequent periodic jobs work" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2990 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2991 | self.updateConfigLayout('layout-idle') |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2992 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2993 | for x in range(1, 3): |
| 2994 | # Test that timer triggers periodic jobs even across |
| 2995 | # layout config reloads. |
| 2996 | # Start timer trigger |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2997 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2998 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2999 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3000 | # The pipeline triggers every second, so we should have seen |
| 3001 | # several by now. |
| 3002 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3003 | |
| 3004 | # Stop queuing timer triggered jobs so that the assertions |
| 3005 | # below don't race against more jobs being queued. |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3006 | before = self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3007 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3008 | self.waitUntilSettled() |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3009 | self.assertEqual(len(self.builds), 2, |
| 3010 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3011 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3012 | self.waitUntilSettled() |
| 3013 | self.assertEqual(len(self.builds), 0) |
| 3014 | self.assertEqual(len(self.history), x * 2) |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3015 | # Revert back to layout-idle |
| 3016 | repo = git.Repo(os.path.join(self.test_root, |
| 3017 | 'upstream', |
| 3018 | 'layout-idle')) |
| 3019 | repo.git.reset('--hard', before) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3020 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3021 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 3022 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3023 | self.sched.reconfigure(self.config) |
| 3024 | |
| 3025 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3026 | self.waitUntilSettled() |
| 3027 | |
| 3028 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3029 | self.waitUntilSettled() |
| 3030 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3031 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3032 | |
| 3033 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3034 | # work on the knowledge of what the first message should be as |
| 3035 | # it is only configured to go to SMTP. |
| 3036 | |
| 3037 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3038 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3039 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3040 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3041 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3042 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3043 | |
| 3044 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3045 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3046 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3047 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3048 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3049 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3050 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3051 | def test_timer_smtp(self): |
| 3052 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3053 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 3054 | self.updateConfigLayout('layout-timer-smtp') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3055 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3056 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3057 | # The pipeline triggers every second, so we should have seen |
| 3058 | # several by now. |
| 3059 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3060 | self.waitUntilSettled() |
| 3061 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3062 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3063 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3064 | self.waitUntilSettled() |
| 3065 | self.assertEqual(len(self.history), 2) |
| 3066 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3067 | self.assertEqual(self.getJobFromHistory( |
| 3068 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3069 | self.assertEqual(self.getJobFromHistory( |
| 3070 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3071 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3072 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3073 | |
| 3074 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3075 | # work on the knowledge of what the first message should be as |
| 3076 | # it is only configured to go to SMTP. |
| 3077 | |
| 3078 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3079 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3080 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3081 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3082 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3083 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3084 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3085 | # Stop queuing timer triggered jobs and let any that may have |
| 3086 | # queued through so that end of test assertions pass. |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 3087 | self.commitLayoutUpdate('layout-timer-smtp', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3088 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3089 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3090 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3091 | self.waitUntilSettled() |
| 3092 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3093 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3094 | def test_timer_sshkey(self): |
| 3095 | "Test that a periodic job can setup SSH key authentication" |
| 3096 | self.worker.hold_jobs_in_build = True |
| 3097 | self.config.set('zuul', 'layout_config', |
| 3098 | 'tests/fixtures/layout-timer.yaml') |
| 3099 | self.sched.reconfigure(self.config) |
| 3100 | self.registerJobs() |
| 3101 | |
| 3102 | # The pipeline triggers every second, so we should have seen |
| 3103 | # several by now. |
| 3104 | time.sleep(5) |
| 3105 | self.waitUntilSettled() |
| 3106 | |
| 3107 | self.assertEqual(len(self.builds), 2) |
| 3108 | |
| 3109 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3110 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3111 | with open(ssh_wrapper) as f: |
| 3112 | ssh_wrapper_content = f.read() |
| 3113 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3114 | # In the unit tests Merger runs in the same process, |
| 3115 | # so we see its' environment variables |
| 3116 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3117 | |
| 3118 | self.worker.release('.*') |
| 3119 | self.waitUntilSettled() |
| 3120 | self.assertEqual(len(self.history), 2) |
| 3121 | |
| 3122 | self.assertEqual(self.getJobFromHistory( |
| 3123 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3124 | self.assertEqual(self.getJobFromHistory( |
| 3125 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3126 | |
| 3127 | # Stop queuing timer triggered jobs and let any that may have |
| 3128 | # queued through so that end of test assertions pass. |
| 3129 | self.config.set('zuul', 'layout_config', |
| 3130 | 'tests/fixtures/layout-no-timer.yaml') |
| 3131 | self.sched.reconfigure(self.config) |
| 3132 | self.registerJobs() |
| 3133 | self.waitUntilSettled() |
| 3134 | self.worker.release('.*') |
| 3135 | self.waitUntilSettled() |
| 3136 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3137 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3138 | "Test that the RPC client can enqueue a change" |
| 3139 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3140 | A.addApproval('code-review', 2) |
| 3141 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3142 | |
| 3143 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3144 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3145 | r = client.enqueue(tenant='tenant-one', |
| 3146 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3147 | project='org/project', |
| 3148 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3149 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3150 | self.waitUntilSettled() |
| 3151 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3152 | 'SUCCESS') |
| 3153 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3154 | 'SUCCESS') |
| 3155 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3156 | 'SUCCESS') |
| 3157 | self.assertEqual(A.data['status'], 'MERGED') |
| 3158 | self.assertEqual(A.reported, 2) |
| 3159 | self.assertEqual(r, True) |
| 3160 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3161 | def test_client_enqueue_ref(self): |
| 3162 | "Test that the RPC client can enqueue a ref" |
| 3163 | |
| 3164 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3165 | self.gearman_server.port) |
| 3166 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3167 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3168 | pipeline='post', |
| 3169 | project='org/project', |
| 3170 | trigger='gerrit', |
| 3171 | ref='master', |
| 3172 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3173 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3174 | self.waitUntilSettled() |
| 3175 | job_names = [x.name for x in self.history] |
| 3176 | self.assertEqual(len(self.history), 1) |
| 3177 | self.assertIn('project-post', job_names) |
| 3178 | self.assertEqual(r, True) |
| 3179 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3180 | def test_client_enqueue_negative(self): |
| 3181 | "Test that the RPC client returns errors" |
| 3182 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3183 | self.gearman_server.port) |
| 3184 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3185 | "Invalid tenant"): |
| 3186 | r = client.enqueue(tenant='tenant-foo', |
| 3187 | pipeline='gate', |
| 3188 | project='org/project', |
| 3189 | trigger='gerrit', |
| 3190 | change='1,1') |
| 3191 | client.shutdown() |
| 3192 | self.assertEqual(r, False) |
| 3193 | |
| 3194 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3195 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3196 | r = client.enqueue(tenant='tenant-one', |
| 3197 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3198 | project='project-does-not-exist', |
| 3199 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3200 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3201 | client.shutdown() |
| 3202 | self.assertEqual(r, False) |
| 3203 | |
| 3204 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3205 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3206 | r = client.enqueue(tenant='tenant-one', |
| 3207 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3208 | project='org/project', |
| 3209 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3210 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3211 | client.shutdown() |
| 3212 | self.assertEqual(r, False) |
| 3213 | |
| 3214 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3215 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3216 | r = client.enqueue(tenant='tenant-one', |
| 3217 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3218 | project='org/project', |
| 3219 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3220 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3221 | client.shutdown() |
| 3222 | self.assertEqual(r, False) |
| 3223 | |
| 3224 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3225 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3226 | r = client.enqueue(tenant='tenant-one', |
| 3227 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3228 | project='org/project', |
| 3229 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3230 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3231 | client.shutdown() |
| 3232 | self.assertEqual(r, False) |
| 3233 | |
| 3234 | self.waitUntilSettled() |
| 3235 | self.assertEqual(len(self.history), 0) |
| 3236 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3237 | |
| 3238 | def test_client_promote(self): |
| 3239 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3240 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3241 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3242 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3243 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3244 | A.addApproval('code-review', 2) |
| 3245 | B.addApproval('code-review', 2) |
| 3246 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3247 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3248 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3249 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3250 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3251 | |
| 3252 | self.waitUntilSettled() |
| 3253 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3254 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3255 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3256 | enqueue_times = {} |
| 3257 | for item in items: |
| 3258 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3259 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3260 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3261 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3262 | r = client.promote(tenant='tenant-one', |
| 3263 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3264 | change_ids=['2,1', '3,1']) |
| 3265 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3266 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3267 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3268 | for item in items: |
| 3269 | self.assertEqual( |
| 3270 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3271 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3272 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3273 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3274 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3275 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3276 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3277 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3278 | self.waitUntilSettled() |
| 3279 | |
| 3280 | self.assertEqual(len(self.builds), 6) |
| 3281 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3282 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3283 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3284 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3285 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3286 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3287 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3288 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3289 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3290 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3291 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3292 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3293 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3294 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3295 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3296 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3297 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3298 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3299 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3300 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3301 | self.waitUntilSettled() |
| 3302 | |
| 3303 | self.assertEqual(A.data['status'], 'MERGED') |
| 3304 | self.assertEqual(A.reported, 2) |
| 3305 | self.assertEqual(B.data['status'], 'MERGED') |
| 3306 | self.assertEqual(B.reported, 2) |
| 3307 | self.assertEqual(C.data['status'], 'MERGED') |
| 3308 | self.assertEqual(C.reported, 2) |
| 3309 | |
| 3310 | client.shutdown() |
| 3311 | self.assertEqual(r, True) |
| 3312 | |
| 3313 | def test_client_promote_dependent(self): |
| 3314 | "Test that the RPC client can promote a dependent change" |
| 3315 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3316 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3317 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3318 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3319 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3320 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3321 | |
| 3322 | C.setDependsOn(B, 1) |
| 3323 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3324 | A.addApproval('code-review', 2) |
| 3325 | B.addApproval('code-review', 2) |
| 3326 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3327 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3328 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3329 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3330 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3331 | |
| 3332 | self.waitUntilSettled() |
| 3333 | |
| 3334 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3335 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3336 | r = client.promote(tenant='tenant-one', |
| 3337 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3338 | change_ids=['3,1']) |
| 3339 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3340 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3341 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3342 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3343 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3344 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3345 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3346 | self.waitUntilSettled() |
| 3347 | |
| 3348 | self.assertEqual(len(self.builds), 6) |
| 3349 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3350 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3351 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3352 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3353 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3354 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3355 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3356 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3357 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3358 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3359 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3360 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3361 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3362 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3363 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3364 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3365 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3366 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3367 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3368 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3369 | self.waitUntilSettled() |
| 3370 | |
| 3371 | self.assertEqual(A.data['status'], 'MERGED') |
| 3372 | self.assertEqual(A.reported, 2) |
| 3373 | self.assertEqual(B.data['status'], 'MERGED') |
| 3374 | self.assertEqual(B.reported, 2) |
| 3375 | self.assertEqual(C.data['status'], 'MERGED') |
| 3376 | self.assertEqual(C.reported, 2) |
| 3377 | |
| 3378 | client.shutdown() |
| 3379 | self.assertEqual(r, True) |
| 3380 | |
| 3381 | def test_client_promote_negative(self): |
| 3382 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3383 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3384 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3385 | A.addApproval('code-review', 2) |
| 3386 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3387 | self.waitUntilSettled() |
| 3388 | |
| 3389 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3390 | self.gearman_server.port) |
| 3391 | |
| 3392 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3393 | r = client.promote(tenant='tenant-one', |
| 3394 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3395 | change_ids=['2,1', '3,1']) |
| 3396 | client.shutdown() |
| 3397 | self.assertEqual(r, False) |
| 3398 | |
| 3399 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3400 | r = client.promote(tenant='tenant-one', |
| 3401 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3402 | change_ids=['4,1']) |
| 3403 | client.shutdown() |
| 3404 | self.assertEqual(r, False) |
| 3405 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3406 | self.executor_server.hold_jobs_in_build = False |
| 3407 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3408 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3409 | |
| 3410 | def test_queue_rate_limiting(self): |
| 3411 | "Test that DependentPipelines are rate limited with dep across window" |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3412 | self.updateConfigLayout('layout-rate-limit') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3413 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3414 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3415 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3416 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3417 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3418 | |
| 3419 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3420 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3421 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3422 | A.addApproval('code-review', 2) |
| 3423 | B.addApproval('code-review', 2) |
| 3424 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3425 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3426 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3427 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3428 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3429 | self.waitUntilSettled() |
| 3430 | |
| 3431 | # Only A and B will have their merge jobs queued because |
| 3432 | # window is 2. |
| 3433 | self.assertEqual(len(self.builds), 2) |
| 3434 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3435 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3436 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3437 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3438 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3439 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3440 | self.waitUntilSettled() |
| 3441 | |
| 3442 | # Only A and B will have their test jobs queued because |
| 3443 | # window is 2. |
| 3444 | self.assertEqual(len(self.builds), 4) |
| 3445 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3446 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3447 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3448 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3449 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3450 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3451 | self.waitUntilSettled() |
| 3452 | |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3453 | tenant = self.sched.abide.tenants.get('openstack') |
| 3454 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3455 | # A failed so window is reduced by 1 to 1. |
| 3456 | self.assertEqual(queue.window, 1) |
| 3457 | self.assertEqual(queue.window_floor, 1) |
| 3458 | self.assertEqual(A.data['status'], 'NEW') |
| 3459 | |
| 3460 | # Gate is reset and only B's merge job is queued because |
| 3461 | # window shrunk to 1. |
| 3462 | self.assertEqual(len(self.builds), 1) |
| 3463 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3464 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3465 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3466 | self.waitUntilSettled() |
| 3467 | |
| 3468 | # Only B's test jobs are queued because window is still 1. |
| 3469 | self.assertEqual(len(self.builds), 2) |
| 3470 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3471 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3472 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3473 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3474 | self.waitUntilSettled() |
| 3475 | |
| 3476 | # B was successfully merged so window is increased to 2. |
| 3477 | self.assertEqual(queue.window, 2) |
| 3478 | self.assertEqual(queue.window_floor, 1) |
| 3479 | self.assertEqual(B.data['status'], 'MERGED') |
| 3480 | |
| 3481 | # Only C is left and its merge job is queued. |
| 3482 | self.assertEqual(len(self.builds), 1) |
| 3483 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3484 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3485 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3486 | self.waitUntilSettled() |
| 3487 | |
| 3488 | # After successful merge job the test jobs for C are queued. |
| 3489 | self.assertEqual(len(self.builds), 2) |
| 3490 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3491 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3492 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3493 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3494 | self.waitUntilSettled() |
| 3495 | |
| 3496 | # C successfully merged so window is bumped to 3. |
| 3497 | self.assertEqual(queue.window, 3) |
| 3498 | self.assertEqual(queue.window_floor, 1) |
| 3499 | self.assertEqual(C.data['status'], 'MERGED') |
| 3500 | |
| 3501 | def test_queue_rate_limiting_dependent(self): |
| 3502 | "Test that DependentPipelines are rate limited with dep in window" |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3503 | self.updateConfigLayout('layout-rate-limit') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3504 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3505 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3506 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3507 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3508 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3509 | |
| 3510 | B.setDependsOn(A, 1) |
| 3511 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3512 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3513 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3514 | A.addApproval('code-review', 2) |
| 3515 | B.addApproval('code-review', 2) |
| 3516 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3517 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3518 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3519 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3520 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3521 | self.waitUntilSettled() |
| 3522 | |
| 3523 | # Only A and B will have their merge jobs queued because |
| 3524 | # window is 2. |
| 3525 | self.assertEqual(len(self.builds), 2) |
| 3526 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3527 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3528 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3529 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3530 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3531 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3532 | self.waitUntilSettled() |
| 3533 | |
| 3534 | # Only A and B will have their test jobs queued because |
| 3535 | # window is 2. |
| 3536 | self.assertEqual(len(self.builds), 4) |
| 3537 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3538 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3539 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3540 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3541 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3542 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3543 | self.waitUntilSettled() |
| 3544 | |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3545 | tenant = self.sched.abide.tenants.get('openstack') |
| 3546 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3547 | # A failed so window is reduced by 1 to 1. |
| 3548 | self.assertEqual(queue.window, 1) |
| 3549 | self.assertEqual(queue.window_floor, 1) |
| 3550 | self.assertEqual(A.data['status'], 'NEW') |
| 3551 | self.assertEqual(B.data['status'], 'NEW') |
| 3552 | |
| 3553 | # Gate is reset and only C's merge job is queued because |
| 3554 | # window shrunk to 1 and A and B were dequeued. |
| 3555 | self.assertEqual(len(self.builds), 1) |
| 3556 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3557 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3558 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3559 | self.waitUntilSettled() |
| 3560 | |
| 3561 | # Only C's test jobs are queued because window is still 1. |
| 3562 | self.assertEqual(len(self.builds), 2) |
| 3563 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3564 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3565 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3566 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3567 | self.waitUntilSettled() |
| 3568 | |
| 3569 | # C was successfully merged so window is increased to 2. |
| 3570 | self.assertEqual(queue.window, 2) |
| 3571 | self.assertEqual(queue.window_floor, 1) |
| 3572 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3573 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3574 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3575 | def test_worker_update_metadata(self): |
| 3576 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3577 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3578 | |
| 3579 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3580 | A.addApproval('code-review', 2) |
| 3581 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3582 | self.waitUntilSettled() |
| 3583 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3584 | self.assertEqual(len(self.executor.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3585 | |
| 3586 | self.log.debug('Current builds:') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3587 | self.log.debug(self.executor.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3588 | |
| 3589 | start = time.time() |
| 3590 | while True: |
| 3591 | if time.time() - start > 10: |
| 3592 | raise Exception("Timeout waiting for gearman server to report " |
| 3593 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3594 | build = self.executor.builds.values()[0] |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3595 | if build.worker.name == "My Worker": |
| 3596 | break |
| 3597 | else: |
| 3598 | time.sleep(0) |
| 3599 | |
| 3600 | self.log.debug(build) |
| 3601 | self.assertEqual("My Worker", build.worker.name) |
| 3602 | self.assertEqual("localhost", build.worker.hostname) |
| 3603 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3604 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3605 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3606 | self.assertEqual("v1.1", build.worker.version) |
| 3607 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3608 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3609 | self.executor_server.hold_jobs_in_build = False |
| 3610 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3611 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3612 | |
| 3613 | def test_footer_message(self): |
| 3614 | "Test a pipeline's footer message is correctly added to the report." |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3615 | self.updateConfigLayout('layout-footer-message') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3616 | self.sched.reconfigure(self.config) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3617 | |
| 3618 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3619 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3620 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3621 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3622 | self.waitUntilSettled() |
| 3623 | |
| 3624 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3625 | B.addApproval('code-review', 2) |
| 3626 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3627 | self.waitUntilSettled() |
| 3628 | |
| 3629 | self.assertEqual(2, len(self.smtp_messages)) |
| 3630 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3631 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3632 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3633 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3634 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3635 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3636 | For CI problems and help debugging, contact ci@example.org""" |
| 3637 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3638 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3639 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3640 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3641 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3642 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3643 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3644 | def test_merge_failure_reporters(self): |
| 3645 | """Check that the config is set up correctly""" |
| 3646 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3647 | self.updateConfigLayout( |
| 3648 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3649 | self.sched.reconfigure(self.config) |
| 3650 | self.registerJobs() |
| 3651 | |
| 3652 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3653 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3654 | "dependencies was unable to be automatically merged with the " |
| 3655 | "current state of its repository. Please rebase the change and " |
| 3656 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3657 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3658 | self.assertEqual( |
| 3659 | "The merge failed! For more information...", |
| 3660 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3661 | |
| 3662 | self.assertEqual( |
| 3663 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3664 | self.assertEqual( |
| 3665 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3666 | |
| 3667 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3668 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3669 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3670 | |
| 3671 | self.assertTrue( |
| 3672 | ( |
| 3673 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3674 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3675 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3676 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3677 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3678 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3679 | ) or ( |
| 3680 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3681 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3682 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3683 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3684 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3685 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3686 | ) |
| 3687 | ) |
| 3688 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3689 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3690 | def test_merge_failure_reports(self): |
| 3691 | """Check that when a change fails to merge the correct message is sent |
| 3692 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3693 | self.updateConfigLayout( |
| 3694 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3695 | self.sched.reconfigure(self.config) |
| 3696 | self.registerJobs() |
| 3697 | |
| 3698 | # Check a test failure isn't reported to SMTP |
| 3699 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3700 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3701 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3702 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3703 | self.waitUntilSettled() |
| 3704 | |
| 3705 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3706 | self.assertEqual(0, len(self.smtp_messages)) |
| 3707 | |
| 3708 | # Check a merge failure is reported to SMTP |
| 3709 | # B should be merged, but C will conflict with B |
| 3710 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3711 | B.addPatchset(['conflict']) |
| 3712 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3713 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3714 | B.addApproval('code-review', 2) |
| 3715 | C.addApproval('code-review', 2) |
| 3716 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3717 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3718 | self.waitUntilSettled() |
| 3719 | |
| 3720 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3721 | self.assertEqual(1, len(self.smtp_messages)) |
| 3722 | self.assertEqual('The merge failed! For more information...', |
| 3723 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3724 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3725 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3726 | def test_default_merge_failure_reports(self): |
| 3727 | """Check that the default merge failure reports are correct.""" |
| 3728 | |
| 3729 | # A should report success, B should report merge failure. |
| 3730 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3731 | A.addPatchset(['conflict']) |
| 3732 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3733 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3734 | A.addApproval('code-review', 2) |
| 3735 | B.addApproval('code-review', 2) |
| 3736 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3737 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3738 | self.waitUntilSettled() |
| 3739 | |
| 3740 | self.assertEqual(3, len(self.history)) # A jobs |
| 3741 | self.assertEqual(A.reported, 2) |
| 3742 | self.assertEqual(B.reported, 2) |
| 3743 | self.assertEqual(A.data['status'], 'MERGED') |
| 3744 | self.assertEqual(B.data['status'], 'NEW') |
| 3745 | self.assertIn('Build succeeded', A.messages[1]) |
| 3746 | self.assertIn('Merge Failed', B.messages[1]) |
| 3747 | self.assertIn('automatically merged', B.messages[1]) |
| 3748 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3749 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3750 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3751 | def test_client_get_running_jobs(self): |
| 3752 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3753 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3754 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3755 | A.addApproval('code-review', 2) |
| 3756 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3757 | self.waitUntilSettled() |
| 3758 | |
| 3759 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3760 | self.gearman_server.port) |
| 3761 | |
| 3762 | # Wait for gearman server to send the initial workData back to zuul |
| 3763 | start = time.time() |
| 3764 | while True: |
| 3765 | if time.time() - start > 10: |
| 3766 | raise Exception("Timeout waiting for gearman server to report " |
| 3767 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3768 | build = self.executor_client.builds.values()[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3769 | if build.worker.name == "My Worker": |
| 3770 | break |
| 3771 | else: |
| 3772 | time.sleep(0) |
| 3773 | |
| 3774 | running_items = client.get_running_jobs() |
| 3775 | |
| 3776 | self.assertEqual(1, len(running_items)) |
| 3777 | running_item = running_items[0] |
| 3778 | self.assertEqual([], running_item['failing_reasons']) |
| 3779 | self.assertEqual([], running_item['items_behind']) |
| 3780 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3781 | self.assertEqual(None, running_item['item_ahead']) |
| 3782 | self.assertEqual('org/project', running_item['project']) |
| 3783 | self.assertEqual(None, running_item['remaining_time']) |
| 3784 | self.assertEqual(True, running_item['active']) |
| 3785 | self.assertEqual('1,1', running_item['id']) |
| 3786 | |
| 3787 | self.assertEqual(3, len(running_item['jobs'])) |
| 3788 | for job in running_item['jobs']: |
| 3789 | if job['name'] == 'project-merge': |
| 3790 | self.assertEqual('project-merge', job['name']) |
| 3791 | self.assertEqual('gate', job['pipeline']) |
| 3792 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3793 | self.assertEqual('https://server/job/project-merge/0/', |
| 3794 | job['url']) |
| 3795 | self.assertEqual(7, len(job['worker'])) |
| 3796 | self.assertEqual(False, job['canceled']) |
| 3797 | self.assertEqual(True, job['voting']) |
| 3798 | self.assertEqual(None, job['result']) |
| 3799 | self.assertEqual('gate', job['pipeline']) |
| 3800 | break |
| 3801 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3802 | self.executor_server.hold_jobs_in_build = False |
| 3803 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3804 | self.waitUntilSettled() |
| 3805 | |
| 3806 | running_items = client.get_running_jobs() |
| 3807 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3808 | |
| 3809 | def test_nonvoting_pipeline(self): |
| 3810 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3811 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3812 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3813 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3814 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3815 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3816 | |
| 3817 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3818 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3819 | self.assertEqual( |
| 3820 | self.getJobFromHistory('experimental-project-test').result, |
| 3821 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3822 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3823 | |
| 3824 | def test_crd_gate(self): |
| 3825 | "Test cross-repo dependencies" |
| 3826 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3827 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3828 | A.addApproval('code-review', 2) |
| 3829 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3830 | |
| 3831 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3832 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3833 | AM2.setMerged() |
| 3834 | AM1.setMerged() |
| 3835 | |
| 3836 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3837 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3838 | BM2.setMerged() |
| 3839 | BM1.setMerged() |
| 3840 | |
| 3841 | # A -> AM1 -> AM2 |
| 3842 | # B -> BM1 -> BM2 |
| 3843 | # A Depends-On: B |
| 3844 | # M2 is here to make sure it is never queried. If it is, it |
| 3845 | # means zuul is walking down the entire history of merged |
| 3846 | # changes. |
| 3847 | |
| 3848 | B.setDependsOn(BM1, 1) |
| 3849 | BM1.setDependsOn(BM2, 1) |
| 3850 | |
| 3851 | A.setDependsOn(AM1, 1) |
| 3852 | AM1.setDependsOn(AM2, 1) |
| 3853 | |
| 3854 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3855 | A.subject, B.data['id']) |
| 3856 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3857 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3858 | self.waitUntilSettled() |
| 3859 | |
| 3860 | self.assertEqual(A.data['status'], 'NEW') |
| 3861 | self.assertEqual(B.data['status'], 'NEW') |
| 3862 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3863 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3864 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3865 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3866 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3867 | B.addApproval('approved', 1) |
| 3868 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3869 | self.waitUntilSettled() |
| 3870 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3871 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3872 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3873 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3874 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3875 | self.executor_server.hold_jobs_in_build = False |
| 3876 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3877 | self.waitUntilSettled() |
| 3878 | |
| 3879 | self.assertEqual(AM2.queried, 0) |
| 3880 | self.assertEqual(BM2.queried, 0) |
| 3881 | self.assertEqual(A.data['status'], 'MERGED') |
| 3882 | self.assertEqual(B.data['status'], 'MERGED') |
| 3883 | self.assertEqual(A.reported, 2) |
| 3884 | self.assertEqual(B.reported, 2) |
| 3885 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3886 | changes = self.getJobFromHistory( |
| 3887 | 'project-merge', 'org/project1').changes |
| 3888 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3889 | |
| 3890 | def test_crd_branch(self): |
| 3891 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3892 | |
| 3893 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3894 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3895 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3896 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3897 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3898 | A.addApproval('code-review', 2) |
| 3899 | B.addApproval('code-review', 2) |
| 3900 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3901 | |
| 3902 | # A Depends-On: B+C |
| 3903 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3904 | A.subject, B.data['id']) |
| 3905 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3906 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3907 | B.addApproval('approved', 1) |
| 3908 | C.addApproval('approved', 1) |
| 3909 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3910 | self.waitUntilSettled() |
| 3911 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3912 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3913 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3914 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3915 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3916 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3917 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3918 | self.executor_server.hold_jobs_in_build = False |
| 3919 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3920 | self.waitUntilSettled() |
| 3921 | |
| 3922 | self.assertEqual(A.data['status'], 'MERGED') |
| 3923 | self.assertEqual(B.data['status'], 'MERGED') |
| 3924 | self.assertEqual(C.data['status'], 'MERGED') |
| 3925 | self.assertEqual(A.reported, 2) |
| 3926 | self.assertEqual(B.reported, 2) |
| 3927 | self.assertEqual(C.reported, 2) |
| 3928 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3929 | changes = self.getJobFromHistory( |
| 3930 | 'project-merge', 'org/project1').changes |
| 3931 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3932 | |
| 3933 | def test_crd_multiline(self): |
| 3934 | "Test multiple depends-on lines in commit" |
| 3935 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3936 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3937 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3938 | A.addApproval('code-review', 2) |
| 3939 | B.addApproval('code-review', 2) |
| 3940 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3941 | |
| 3942 | # A Depends-On: B+C |
| 3943 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3944 | A.subject, B.data['id'], C.data['id']) |
| 3945 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3946 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3947 | B.addApproval('approved', 1) |
| 3948 | C.addApproval('approved', 1) |
| 3949 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3950 | self.waitUntilSettled() |
| 3951 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3952 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3953 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3954 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3955 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3956 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3957 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3958 | self.executor_server.hold_jobs_in_build = False |
| 3959 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3960 | self.waitUntilSettled() |
| 3961 | |
| 3962 | self.assertEqual(A.data['status'], 'MERGED') |
| 3963 | self.assertEqual(B.data['status'], 'MERGED') |
| 3964 | self.assertEqual(C.data['status'], 'MERGED') |
| 3965 | self.assertEqual(A.reported, 2) |
| 3966 | self.assertEqual(B.reported, 2) |
| 3967 | self.assertEqual(C.reported, 2) |
| 3968 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3969 | changes = self.getJobFromHistory( |
| 3970 | 'project-merge', 'org/project1').changes |
| 3971 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3972 | |
| 3973 | def test_crd_unshared_gate(self): |
| 3974 | "Test cross-repo dependencies in unshared gate queues" |
| 3975 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3976 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3977 | A.addApproval('code-review', 2) |
| 3978 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3979 | |
| 3980 | # A Depends-On: B |
| 3981 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3982 | A.subject, B.data['id']) |
| 3983 | |
| 3984 | # A and B do not share a queue, make sure that A is unable to |
| 3985 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3986 | B.addApproval('approved', 1) |
| 3987 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3988 | self.waitUntilSettled() |
| 3989 | |
| 3990 | self.assertEqual(A.data['status'], 'NEW') |
| 3991 | self.assertEqual(B.data['status'], 'NEW') |
| 3992 | self.assertEqual(A.reported, 0) |
| 3993 | self.assertEqual(B.reported, 0) |
| 3994 | self.assertEqual(len(self.history), 0) |
| 3995 | |
| 3996 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3997 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3998 | self.waitUntilSettled() |
| 3999 | |
| 4000 | self.assertEqual(B.data['status'], 'MERGED') |
| 4001 | self.assertEqual(B.reported, 2) |
| 4002 | |
| 4003 | # Now that B is merged, A should be able to be enqueued and |
| 4004 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4005 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4006 | self.waitUntilSettled() |
| 4007 | |
| 4008 | self.assertEqual(A.data['status'], 'MERGED') |
| 4009 | self.assertEqual(A.reported, 2) |
| 4010 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4011 | def test_crd_gate_reverse(self): |
| 4012 | "Test reverse cross-repo dependencies" |
| 4013 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4014 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4015 | A.addApproval('code-review', 2) |
| 4016 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4017 | |
| 4018 | # A Depends-On: B |
| 4019 | |
| 4020 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4021 | A.subject, B.data['id']) |
| 4022 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4023 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4024 | self.waitUntilSettled() |
| 4025 | |
| 4026 | self.assertEqual(A.data['status'], 'NEW') |
| 4027 | self.assertEqual(B.data['status'], 'NEW') |
| 4028 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4029 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4030 | A.addApproval('approved', 1) |
| 4031 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4032 | self.waitUntilSettled() |
| 4033 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4034 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4035 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4036 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4037 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4038 | self.executor_server.hold_jobs_in_build = False |
| 4039 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4040 | self.waitUntilSettled() |
| 4041 | |
| 4042 | self.assertEqual(A.data['status'], 'MERGED') |
| 4043 | self.assertEqual(B.data['status'], 'MERGED') |
| 4044 | self.assertEqual(A.reported, 2) |
| 4045 | self.assertEqual(B.reported, 2) |
| 4046 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4047 | changes = self.getJobFromHistory( |
| 4048 | 'project-merge', 'org/project1').changes |
| 4049 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4050 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4051 | def test_crd_cycle(self): |
| 4052 | "Test cross-repo dependency cycles" |
| 4053 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4054 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4055 | A.addApproval('code-review', 2) |
| 4056 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4057 | |
| 4058 | # A -> B -> A (via commit-depends) |
| 4059 | |
| 4060 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4061 | A.subject, B.data['id']) |
| 4062 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4063 | B.subject, A.data['id']) |
| 4064 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4065 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4066 | self.waitUntilSettled() |
| 4067 | |
| 4068 | self.assertEqual(A.reported, 0) |
| 4069 | self.assertEqual(B.reported, 0) |
| 4070 | self.assertEqual(A.data['status'], 'NEW') |
| 4071 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4072 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4073 | def test_crd_gate_unknown(self): |
| 4074 | "Test unknown projects in dependent pipeline" |
| 4075 | self.init_repo("org/unknown") |
| 4076 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4077 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4078 | A.addApproval('code-review', 2) |
| 4079 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4080 | |
| 4081 | # A Depends-On: B |
| 4082 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4083 | A.subject, B.data['id']) |
| 4084 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4085 | B.addApproval('approved', 1) |
| 4086 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4087 | self.waitUntilSettled() |
| 4088 | |
| 4089 | # Unknown projects cannot share a queue with any other |
| 4090 | # since they don't have common jobs with any other (they have no jobs). |
| 4091 | # Changes which depend on unknown project changes |
| 4092 | # should not be processed in dependent pipeline |
| 4093 | self.assertEqual(A.data['status'], 'NEW') |
| 4094 | self.assertEqual(B.data['status'], 'NEW') |
| 4095 | self.assertEqual(A.reported, 0) |
| 4096 | self.assertEqual(B.reported, 0) |
| 4097 | self.assertEqual(len(self.history), 0) |
| 4098 | |
| 4099 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4100 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4101 | B.setMerged() |
| 4102 | self.waitUntilSettled() |
| 4103 | self.assertEqual(len(self.history), 0) |
| 4104 | |
| 4105 | # Now that B is merged, A should be able to be enqueued and |
| 4106 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4107 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4108 | self.waitUntilSettled() |
| 4109 | |
| 4110 | self.assertEqual(A.data['status'], 'MERGED') |
| 4111 | self.assertEqual(A.reported, 2) |
| 4112 | self.assertEqual(B.data['status'], 'MERGED') |
| 4113 | self.assertEqual(B.reported, 0) |
| 4114 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4115 | def test_crd_check(self): |
| 4116 | "Test cross-repo dependencies in independent pipelines" |
| 4117 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4118 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4119 | self.gearman_server.hold_jobs_in_queue = True |
| 4120 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4121 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4122 | |
| 4123 | # A Depends-On: B |
| 4124 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4125 | A.subject, B.data['id']) |
| 4126 | |
| 4127 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4128 | self.waitUntilSettled() |
| 4129 | |
| 4130 | queue = self.gearman_server.getQueue() |
| 4131 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 4132 | self.gearman_server.hold_jobs_in_queue = False |
| 4133 | self.gearman_server.release() |
| 4134 | self.waitUntilSettled() |
| 4135 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4136 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4137 | self.waitUntilSettled() |
| 4138 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4139 | 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] | 4140 | repo = git.Repo(path) |
| 4141 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4142 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4143 | correct_messages = [ |
| 4144 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4145 | self.assertEqual(repo_messages, correct_messages) |
| 4146 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4147 | 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] | 4148 | repo = git.Repo(path) |
| 4149 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4150 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4151 | correct_messages = [ |
| 4152 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4153 | self.assertEqual(repo_messages, correct_messages) |
| 4154 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4155 | self.executor_server.hold_jobs_in_build = False |
| 4156 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4157 | self.waitUntilSettled() |
| 4158 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4159 | self.assertEqual(A.data['status'], 'NEW') |
| 4160 | self.assertEqual(B.data['status'], 'NEW') |
| 4161 | self.assertEqual(A.reported, 1) |
| 4162 | self.assertEqual(B.reported, 0) |
| 4163 | |
| 4164 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4165 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4166 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4167 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4168 | def test_crd_check_git_depends(self): |
| 4169 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4170 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4171 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4172 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4173 | |
| 4174 | # Add two git-dependent changes and make sure they both report |
| 4175 | # success. |
| 4176 | B.setDependsOn(A, 1) |
| 4177 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4178 | self.waitUntilSettled() |
| 4179 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4180 | self.waitUntilSettled() |
| 4181 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4182 | self.orderedRelease() |
| 4183 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4184 | self.waitUntilSettled() |
| 4185 | |
| 4186 | self.assertEqual(A.data['status'], 'NEW') |
| 4187 | self.assertEqual(B.data['status'], 'NEW') |
| 4188 | self.assertEqual(A.reported, 1) |
| 4189 | self.assertEqual(B.reported, 1) |
| 4190 | |
| 4191 | self.assertEqual(self.history[0].changes, '1,1') |
| 4192 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4193 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4194 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4195 | |
| 4196 | self.assertIn('Build succeeded', A.messages[0]) |
| 4197 | self.assertIn('Build succeeded', B.messages[0]) |
| 4198 | |
| 4199 | def test_crd_check_duplicate(self): |
| 4200 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4201 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4202 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4203 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4204 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4205 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4206 | |
| 4207 | # Add two git-dependent changes... |
| 4208 | B.setDependsOn(A, 1) |
| 4209 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4210 | self.waitUntilSettled() |
| 4211 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4212 | |
| 4213 | # ...make sure the live one is not duplicated... |
| 4214 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4215 | self.waitUntilSettled() |
| 4216 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4217 | |
| 4218 | # ...but the non-live one is able to be. |
| 4219 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4220 | self.waitUntilSettled() |
| 4221 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4222 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4223 | # Release jobs in order to avoid races with change A jobs |
| 4224 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4225 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4226 | self.executor_server.hold_jobs_in_build = False |
| 4227 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4228 | self.waitUntilSettled() |
| 4229 | |
| 4230 | self.assertEqual(A.data['status'], 'NEW') |
| 4231 | self.assertEqual(B.data['status'], 'NEW') |
| 4232 | self.assertEqual(A.reported, 1) |
| 4233 | self.assertEqual(B.reported, 1) |
| 4234 | |
| 4235 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4236 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4237 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4238 | |
| 4239 | self.assertIn('Build succeeded', A.messages[0]) |
| 4240 | self.assertIn('Build succeeded', B.messages[0]) |
| 4241 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4242 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4243 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4244 | |
| 4245 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4246 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4247 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4248 | |
| 4249 | # A Depends-On: B |
| 4250 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4251 | A.subject, B.data['id']) |
| 4252 | |
| 4253 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4254 | self.waitUntilSettled() |
| 4255 | |
| 4256 | self.sched.reconfigure(self.config) |
| 4257 | |
| 4258 | # Make sure the items still share a change queue, and the |
| 4259 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4260 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4261 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4262 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4263 | first_item = queue.queue[0] |
| 4264 | for item in queue.queue: |
| 4265 | self.assertEqual(item.queue, first_item.queue) |
| 4266 | self.assertFalse(first_item.live) |
| 4267 | self.assertTrue(queue.queue[1].live) |
| 4268 | |
| 4269 | self.gearman_server.hold_jobs_in_queue = False |
| 4270 | self.gearman_server.release() |
| 4271 | self.waitUntilSettled() |
| 4272 | |
| 4273 | self.assertEqual(A.data['status'], 'NEW') |
| 4274 | self.assertEqual(B.data['status'], 'NEW') |
| 4275 | self.assertEqual(A.reported, 1) |
| 4276 | self.assertEqual(B.reported, 0) |
| 4277 | |
| 4278 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4279 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4280 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4281 | def test_crd_check_reconfiguration(self): |
| 4282 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4283 | |
| 4284 | def test_crd_undefined_project(self): |
| 4285 | """Test that undefined projects in dependencies are handled for |
| 4286 | independent pipelines""" |
| 4287 | # It's a hack for fake gerrit, |
| 4288 | # as it implies repo creation upon the creation of any change |
| 4289 | self.init_repo("org/unknown") |
| 4290 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4291 | |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4292 | def test_crd_check_ignore_dependencies(self): |
| 4293 | "Test cross-repo dependencies can be ignored" |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4294 | self.updateConfigLayout('layout-ignore-dependencies') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4295 | self.sched.reconfigure(self.config) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4296 | |
| 4297 | self.gearman_server.hold_jobs_in_queue = True |
| 4298 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4299 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4300 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4301 | |
| 4302 | # A Depends-On: B |
| 4303 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4304 | A.subject, B.data['id']) |
| 4305 | # C git-depends on B |
| 4306 | C.setDependsOn(B, 1) |
| 4307 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4308 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4309 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4310 | self.waitUntilSettled() |
| 4311 | |
| 4312 | # Make sure none of the items share a change queue, and all |
| 4313 | # are live. |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4314 | tenant = self.sched.abide.tenants.get('openstack') |
| 4315 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4316 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4317 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4318 | for item in check_pipeline.getAllItems(): |
| 4319 | self.assertTrue(item.live) |
| 4320 | |
| 4321 | self.gearman_server.hold_jobs_in_queue = False |
| 4322 | self.gearman_server.release() |
| 4323 | self.waitUntilSettled() |
| 4324 | |
| 4325 | self.assertEqual(A.data['status'], 'NEW') |
| 4326 | self.assertEqual(B.data['status'], 'NEW') |
| 4327 | self.assertEqual(C.data['status'], 'NEW') |
| 4328 | self.assertEqual(A.reported, 1) |
| 4329 | self.assertEqual(B.reported, 1) |
| 4330 | self.assertEqual(C.reported, 1) |
| 4331 | |
| 4332 | # Each job should have tested exactly one change |
| 4333 | for job in self.history: |
| 4334 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4335 | |
| 4336 | def test_crd_check_transitive(self): |
| 4337 | "Test transitive cross-repo dependencies" |
| 4338 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4339 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4340 | # and C,2 (not C,1 which would indicate stale data in the |
| 4341 | # cache for B). |
| 4342 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4343 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4344 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4345 | |
| 4346 | # A Depends-On: B |
| 4347 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4348 | A.subject, B.data['id']) |
| 4349 | |
| 4350 | # B Depends-On: C |
| 4351 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4352 | B.subject, C.data['id']) |
| 4353 | |
| 4354 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4355 | self.waitUntilSettled() |
| 4356 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4357 | |
| 4358 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4359 | self.waitUntilSettled() |
| 4360 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4361 | |
| 4362 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4363 | self.waitUntilSettled() |
| 4364 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4365 | |
| 4366 | C.addPatchset() |
| 4367 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4368 | self.waitUntilSettled() |
| 4369 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4370 | |
| 4371 | A.addPatchset() |
| 4372 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4373 | self.waitUntilSettled() |
| 4374 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4375 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4376 | def test_crd_check_unknown(self): |
| 4377 | "Test unknown projects in independent pipeline" |
| 4378 | self.init_repo("org/unknown") |
| 4379 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4380 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4381 | # A Depends-On: B |
| 4382 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4383 | A.subject, B.data['id']) |
| 4384 | |
| 4385 | # Make sure zuul has seen an event on B. |
| 4386 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4387 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4388 | self.waitUntilSettled() |
| 4389 | |
| 4390 | self.assertEqual(A.data['status'], 'NEW') |
| 4391 | self.assertEqual(A.reported, 1) |
| 4392 | self.assertEqual(B.data['status'], 'NEW') |
| 4393 | self.assertEqual(B.reported, 0) |
| 4394 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4395 | def test_crd_cycle_join(self): |
| 4396 | "Test an updated change creates a cycle" |
| 4397 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4398 | |
| 4399 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4400 | self.waitUntilSettled() |
| 4401 | |
| 4402 | # Create B->A |
| 4403 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4404 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4405 | B.subject, A.data['id']) |
| 4406 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4407 | self.waitUntilSettled() |
| 4408 | |
| 4409 | # Update A to add A->B (a cycle). |
| 4410 | A.addPatchset() |
| 4411 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4412 | A.subject, B.data['id']) |
| 4413 | # Normally we would submit the patchset-created event for |
| 4414 | # processing here, however, we have no way of noting whether |
| 4415 | # the dependency cycle detection correctly raised an |
| 4416 | # exception, so instead, we reach into the source driver and |
| 4417 | # call the method that would ultimately be called by the event |
| 4418 | # processing. |
| 4419 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4420 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4421 | source = tenant.layout.pipelines['gate'].source |
| 4422 | |
| 4423 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4424 | # it easier for users to create events for testing. |
| 4425 | event = zuul.model.TriggerEvent() |
| 4426 | event.trigger_name = 'gerrit' |
| 4427 | event.change_number = '1' |
| 4428 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4429 | with testtools.ExpectedException( |
| 4430 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4431 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4432 | self.log.debug("Got expected dependency cycle exception") |
| 4433 | |
| 4434 | # Now if we update B to remove the depends-on, everything |
| 4435 | # should be okay. B; A->B |
| 4436 | |
| 4437 | B.addPatchset() |
| 4438 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4439 | |
| 4440 | source.getChange(event, True) |
| 4441 | event.change_number = '2' |
| 4442 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4443 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4444 | def test_disable_at(self): |
| 4445 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4446 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4447 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4448 | self.sched.reconfigure(self.config) |
| 4449 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4450 | tenant = self.sched.abide.tenants.get('openstack') |
| 4451 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4452 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4453 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4454 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4455 | |
| 4456 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4457 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4458 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4459 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4460 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4461 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4462 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4463 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4464 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4465 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4466 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4467 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4468 | self.executor_server.failJob('project-test1', A) |
| 4469 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4470 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4471 | self.executor_server.failJob('project-test1', D) |
| 4472 | self.executor_server.failJob('project-test1', E) |
| 4473 | self.executor_server.failJob('project-test1', F) |
| 4474 | self.executor_server.failJob('project-test1', G) |
| 4475 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4476 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4477 | self.executor_server.failJob('project-test1', J) |
| 4478 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4479 | |
| 4480 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4481 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4482 | self.waitUntilSettled() |
| 4483 | |
| 4484 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4485 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4486 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4487 | |
| 4488 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4489 | self.waitUntilSettled() |
| 4490 | |
| 4491 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4492 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4493 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4494 | |
| 4495 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4496 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4497 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4498 | self.waitUntilSettled() |
| 4499 | |
| 4500 | # We should be disabled now |
| 4501 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4502 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4503 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4504 | |
| 4505 | # We need to wait between each of these patches to make sure the |
| 4506 | # smtp messages come back in an expected order |
| 4507 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4508 | self.waitUntilSettled() |
| 4509 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4510 | self.waitUntilSettled() |
| 4511 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4512 | self.waitUntilSettled() |
| 4513 | |
| 4514 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4515 | # leaving a message on each change |
| 4516 | self.assertEqual(1, len(A.messages)) |
| 4517 | self.assertIn('Build failed.', A.messages[0]) |
| 4518 | self.assertEqual(1, len(B.messages)) |
| 4519 | self.assertIn('Build failed.', B.messages[0]) |
| 4520 | self.assertEqual(1, len(C.messages)) |
| 4521 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4522 | self.assertEqual(1, len(D.messages)) |
| 4523 | self.assertIn('Build failed.', D.messages[0]) |
| 4524 | self.assertEqual(1, len(E.messages)) |
| 4525 | self.assertIn('Build failed.', E.messages[0]) |
| 4526 | self.assertEqual(1, len(F.messages)) |
| 4527 | self.assertIn('Build failed.', F.messages[0]) |
| 4528 | |
| 4529 | # The last 3 (GHI) would have only reported via smtp. |
| 4530 | self.assertEqual(3, len(self.smtp_messages)) |
| 4531 | self.assertEqual(0, len(G.messages)) |
| 4532 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4533 | self.assertIn( |
| 4534 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4535 | self.assertEqual(0, len(H.messages)) |
| 4536 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4537 | self.assertIn( |
| 4538 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4539 | self.assertEqual(0, len(I.messages)) |
| 4540 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4541 | self.assertIn( |
| 4542 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4543 | |
| 4544 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4545 | # comes out of disabled |
| 4546 | self.sched.reconfigure(self.config) |
| 4547 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4548 | tenant = self.sched.abide.tenants.get('openstack') |
| 4549 | |
| 4550 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4551 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4552 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4553 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4554 | |
| 4555 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4556 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4557 | self.waitUntilSettled() |
| 4558 | |
| 4559 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4560 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4561 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4562 | |
| 4563 | # J and K went back to gerrit |
| 4564 | self.assertEqual(1, len(J.messages)) |
| 4565 | self.assertIn('Build failed.', J.messages[0]) |
| 4566 | self.assertEqual(1, len(K.messages)) |
| 4567 | self.assertIn('Build failed.', K.messages[0]) |
| 4568 | # No more messages reported via smtp |
| 4569 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4570 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4571 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4572 | "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] | 4573 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4574 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4575 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4576 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4577 | self.waitUntilSettled() |
| 4578 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4579 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4580 | self.waitUntilSettled() |
| 4581 | |
| 4582 | self.assertEqual(len(self.builds), 2) |
| 4583 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4584 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4585 | self.waitUntilSettled() |
| 4586 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4587 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4588 | self.assertEqual(len(self.builds), 1, |
| 4589 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4590 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4591 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4592 | self.waitUntilSettled() |
| 4593 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4594 | self.executor_server.hold_jobs_in_build = False |
| 4595 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4596 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4597 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4598 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4599 | self.assertEqual(A.reported, 1) |
| 4600 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4601 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4602 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4603 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4604 | |
| 4605 | self.fake_nodepool.paused = True |
| 4606 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4607 | A.addApproval('code-review', 2) |
| 4608 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4609 | self.waitUntilSettled() |
| 4610 | |
| 4611 | self.zk.client.stop() |
| 4612 | self.zk.client.start() |
| 4613 | self.fake_nodepool.paused = False |
| 4614 | self.waitUntilSettled() |
| 4615 | |
| 4616 | self.assertEqual(A.data['status'], 'MERGED') |
| 4617 | self.assertEqual(A.reported, 2) |
| 4618 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4619 | def test_nodepool_failure(self): |
| 4620 | "Test that jobs are reported after a nodepool failure" |
| 4621 | |
| 4622 | self.fake_nodepool.paused = True |
| 4623 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4624 | A.addApproval('code-review', 2) |
| 4625 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4626 | self.waitUntilSettled() |
| 4627 | |
| 4628 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4629 | self.fake_nodepool.addFailRequest(req) |
| 4630 | |
| 4631 | self.fake_nodepool.paused = False |
| 4632 | self.waitUntilSettled() |
| 4633 | |
| 4634 | self.assertEqual(A.data['status'], 'NEW') |
| 4635 | self.assertEqual(A.reported, 2) |
| 4636 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4637 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4638 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4639 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4640 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4641 | class TestDependencyGraph(ZuulTestCase): |
| 4642 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4643 | |
| 4644 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4645 | "Test a job in a dependency graph is queued only once" |
| 4646 | # Job dependencies, starting with A |
| 4647 | # A |
| 4648 | # / \ |
| 4649 | # B C |
| 4650 | # / \ / \ |
| 4651 | # D F E |
| 4652 | # | |
| 4653 | # G |
| 4654 | |
| 4655 | self.executor_server.hold_jobs_in_build = True |
| 4656 | change = self.fake_gerrit.addFakeChange( |
| 4657 | 'org/project', 'master', 'change') |
| 4658 | change.addApproval('code-review', 2) |
| 4659 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4660 | |
| 4661 | self.waitUntilSettled() |
| 4662 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4663 | |
| 4664 | self.executor_server.release('A') |
| 4665 | self.waitUntilSettled() |
| 4666 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4667 | |
| 4668 | self.executor_server.release('B') |
| 4669 | self.waitUntilSettled() |
| 4670 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4671 | |
| 4672 | self.executor_server.release('D') |
| 4673 | self.waitUntilSettled() |
| 4674 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4675 | |
| 4676 | self.executor_server.release('C') |
| 4677 | self.waitUntilSettled() |
| 4678 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4679 | |
| 4680 | self.executor_server.release('F') |
| 4681 | self.waitUntilSettled() |
| 4682 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4683 | |
| 4684 | self.executor_server.release('G') |
| 4685 | self.waitUntilSettled() |
| 4686 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4687 | |
| 4688 | self.executor_server.release('E') |
| 4689 | self.waitUntilSettled() |
| 4690 | self.assertEqual(len(self.builds), 0) |
| 4691 | |
| 4692 | self.executor_server.hold_jobs_in_build = False |
| 4693 | self.executor_server.release() |
| 4694 | self.waitUntilSettled() |
| 4695 | |
| 4696 | self.assertEqual(len(self.builds), 0) |
| 4697 | self.assertEqual(len(self.history), 7) |
| 4698 | |
| 4699 | self.assertEqual(change.data['status'], 'MERGED') |
| 4700 | self.assertEqual(change.reported, 2) |
| 4701 | |
| 4702 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4703 | "Test that a job waits till all dependencies are successful" |
| 4704 | # Job dependencies, starting with A |
| 4705 | # A |
| 4706 | # / \ |
| 4707 | # B C* |
| 4708 | # / \ / \ |
| 4709 | # D F E |
| 4710 | # | |
| 4711 | # G |
| 4712 | |
| 4713 | self.executor_server.hold_jobs_in_build = True |
| 4714 | change = self.fake_gerrit.addFakeChange( |
| 4715 | 'org/project', 'master', 'change') |
| 4716 | change.addApproval('code-review', 2) |
| 4717 | |
| 4718 | self.executor_server.failJob('C', change) |
| 4719 | |
| 4720 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4721 | |
| 4722 | self.waitUntilSettled() |
| 4723 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4724 | |
| 4725 | self.executor_server.release('A') |
| 4726 | self.waitUntilSettled() |
| 4727 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4728 | |
| 4729 | self.executor_server.release('B') |
| 4730 | self.waitUntilSettled() |
| 4731 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4732 | |
| 4733 | self.executor_server.release('D') |
| 4734 | self.waitUntilSettled() |
| 4735 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4736 | |
| 4737 | self.executor_server.release('C') |
| 4738 | self.waitUntilSettled() |
| 4739 | self.assertEqual(len(self.builds), 0) |
| 4740 | |
| 4741 | self.executor_server.hold_jobs_in_build = False |
| 4742 | self.executor_server.release() |
| 4743 | self.waitUntilSettled() |
| 4744 | |
| 4745 | self.assertEqual(len(self.builds), 0) |
| 4746 | self.assertEqual(len(self.history), 4) |
| 4747 | |
| 4748 | self.assertEqual(change.data['status'], 'NEW') |
| 4749 | self.assertEqual(change.reported, 2) |
| 4750 | |
| 4751 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4752 | class TestDuplicatePipeline(ZuulTestCase): |
| 4753 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4754 | |
| 4755 | def test_duplicate_pipelines(self): |
| 4756 | "Test that a change matching multiple pipelines works" |
| 4757 | |
| 4758 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4759 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4760 | self.waitUntilSettled() |
| 4761 | |
| 4762 | self.assertHistory([ |
| 4763 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4764 | pipeline='dup1'), |
| 4765 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4766 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4767 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4768 | |
| 4769 | self.assertEqual(len(A.messages), 2) |
| 4770 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4771 | if 'dup1' in A.messages[0]: |
| 4772 | self.assertIn('dup1', A.messages[0]) |
| 4773 | self.assertNotIn('dup2', A.messages[0]) |
| 4774 | self.assertIn('project-test1', A.messages[0]) |
| 4775 | self.assertIn('dup2', A.messages[1]) |
| 4776 | self.assertNotIn('dup1', A.messages[1]) |
| 4777 | self.assertIn('project-test1', A.messages[1]) |
| 4778 | else: |
| 4779 | self.assertIn('dup1', A.messages[1]) |
| 4780 | self.assertNotIn('dup2', A.messages[1]) |
| 4781 | self.assertIn('project-test1', A.messages[1]) |
| 4782 | self.assertIn('dup2', A.messages[0]) |
| 4783 | self.assertNotIn('dup1', A.messages[0]) |
| 4784 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4785 | |
| 4786 | |
| 4787 | class TestSchedulerOneJobProject(ZuulTestCase): |
| 4788 | tenant_config_file = 'config/one-job-project/main.yaml' |
| 4789 | |
| 4790 | def test_one_job_project(self): |
| 4791 | "Test that queueing works with one job" |
| 4792 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4793 | 'master', 'A') |
| 4794 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4795 | 'master', 'B') |
| 4796 | A.addApproval('code-review', 2) |
| 4797 | B.addApproval('code-review', 2) |
| 4798 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4799 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4800 | self.waitUntilSettled() |
| 4801 | |
| 4802 | self.assertEqual(A.data['status'], 'MERGED') |
| 4803 | self.assertEqual(A.reported, 2) |
| 4804 | self.assertEqual(B.data['status'], 'MERGED') |
| 4805 | self.assertEqual(B.reported, 2) |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4806 | |
| 4807 | |
| 4808 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4809 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4810 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4811 | def test_job_from_templates_executed(self): |
| 4812 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4813 | |
| 4814 | A = self.fake_gerrit.addFakeChange( |
| 4815 | 'org/templated-project', 'master', 'A') |
| 4816 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4817 | self.waitUntilSettled() |
| 4818 | |
| 4819 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4820 | 'SUCCESS') |
| 4821 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4822 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4823 | |
| 4824 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4825 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4826 | |
| 4827 | A = self.fake_gerrit.addFakeChange( |
| 4828 | 'org/layered-project', 'master', 'A') |
| 4829 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4830 | self.waitUntilSettled() |
| 4831 | |
| 4832 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4833 | 'SUCCESS') |
| 4834 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4835 | 'SUCCESS') |
| 4836 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4837 | ).result, 'SUCCESS') |
| 4838 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4839 | ).result, 'SUCCESS') |
| 4840 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4841 | ).result, 'SUCCESS') |
| 4842 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4843 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4844 | |
| 4845 | |
| 4846 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4847 | tenant_config_file = 'config/success-url/main.yaml' |
| 4848 | |
| 4849 | def test_success_url(self): |
| 4850 | "Ensure bad build params are ignored" |
| 4851 | self.sched.reconfigure(self.config) |
| 4852 | self.init_repo('org/docs') |
| 4853 | |
| 4854 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4855 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4856 | self.waitUntilSettled() |
| 4857 | |
| 4858 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4859 | self.assertEqual(len(self.history), 2) |
| 4860 | |
| 4861 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4862 | for build in self.history: |
| 4863 | if build.name == 'docs-draft-test': |
| 4864 | uuid = build.uuid[:7] |
| 4865 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4866 | |
| 4867 | # Two msgs: 'Starting...' + results |
| 4868 | self.assertEqual(len(self.smtp_messages), 2) |
| 4869 | body = self.smtp_messages[1]['body'].splitlines() |
| 4870 | self.assertEqual('Build succeeded.', body[0]) |
| 4871 | |
| 4872 | self.assertIn( |
| 4873 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4874 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4875 | body[2]) |
| 4876 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4877 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4878 | self.assertIn( |
| 4879 | '- docs-draft-test2 https://server/job', |
| 4880 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4881 | |
| 4882 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4883 | class TestSchedulerMerges(ZuulTestCase): |
| 4884 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4885 | |
| 4886 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4887 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4888 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4889 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4890 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4891 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4892 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4893 | A.addApproval('code-review', 2) |
| 4894 | B.addApproval('code-review', 2) |
| 4895 | C.addApproval('code-review', 2) |
| 4896 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4897 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4898 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4899 | self.waitUntilSettled() |
| 4900 | |
| 4901 | build = self.builds[-1] |
| 4902 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4903 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4904 | path = os.path.join(build.jobdir.src_root, project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4905 | repo = git.Repo(path) |
| 4906 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4907 | repo_messages.reverse() |
| 4908 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4909 | self.executor_server.hold_jobs_in_build = False |
| 4910 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4911 | self.waitUntilSettled() |
| 4912 | |
| 4913 | return repo_messages |
| 4914 | |
| 4915 | def _test_merge(self, mode): |
| 4916 | us_path = os.path.join( |
| 4917 | self.upstream_root, 'org/project-%s' % mode) |
| 4918 | expected_messages = [ |
| 4919 | 'initial commit', |
| 4920 | 'add content from fixture', |
| 4921 | # the intermediate commits order is nondeterministic |
| 4922 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4923 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4924 | ] |
| 4925 | result = self._test_project_merge_mode(mode) |
| 4926 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4927 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4928 | |
| 4929 | def test_project_merge_mode_merge(self): |
| 4930 | self._test_merge('merge') |
| 4931 | |
| 4932 | def test_project_merge_mode_merge_resolve(self): |
| 4933 | self._test_merge('merge-resolve') |
| 4934 | |
| 4935 | def test_project_merge_mode_cherrypick(self): |
| 4936 | expected_messages = [ |
| 4937 | 'initial commit', |
| 4938 | 'add content from fixture', |
| 4939 | 'A-1', |
| 4940 | 'B-1', |
| 4941 | 'C-1'] |
| 4942 | result = self._test_project_merge_mode('cherry-pick') |
| 4943 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4944 | |
| 4945 | def test_merge_branch(self): |
| 4946 | "Test that the right commits are on alternate branches" |
| 4947 | self.create_branch('org/project-merge-branches', 'mp') |
| 4948 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4949 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4950 | A = self.fake_gerrit.addFakeChange( |
| 4951 | 'org/project-merge-branches', 'mp', 'A') |
| 4952 | B = self.fake_gerrit.addFakeChange( |
| 4953 | 'org/project-merge-branches', 'mp', 'B') |
| 4954 | C = self.fake_gerrit.addFakeChange( |
| 4955 | 'org/project-merge-branches', 'mp', 'C') |
| 4956 | A.addApproval('code-review', 2) |
| 4957 | B.addApproval('code-review', 2) |
| 4958 | C.addApproval('code-review', 2) |
| 4959 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4960 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4961 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4962 | self.waitUntilSettled() |
| 4963 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4964 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4965 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4966 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4967 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4968 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4969 | self.waitUntilSettled() |
| 4970 | |
| 4971 | build = self.builds[-1] |
| 4972 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 4973 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4974 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4975 | build.jobdir.src_root, 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4976 | repo = git.Repo(path) |
| 4977 | |
| 4978 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4979 | repo_messages.reverse() |
| 4980 | correct_messages = [ |
| 4981 | 'initial commit', |
| 4982 | 'add content from fixture', |
| 4983 | 'mp commit', |
| 4984 | 'A-1', 'B-1', 'C-1'] |
| 4985 | self.assertEqual(repo_messages, correct_messages) |
| 4986 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4987 | self.executor_server.hold_jobs_in_build = False |
| 4988 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4989 | self.waitUntilSettled() |
| 4990 | |
| 4991 | def test_merge_multi_branch(self): |
| 4992 | "Test that dependent changes on multiple branches are merged" |
| 4993 | self.create_branch('org/project-merge-branches', 'mp') |
| 4994 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4995 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4996 | A = self.fake_gerrit.addFakeChange( |
| 4997 | 'org/project-merge-branches', 'master', 'A') |
| 4998 | B = self.fake_gerrit.addFakeChange( |
| 4999 | 'org/project-merge-branches', 'mp', 'B') |
| 5000 | C = self.fake_gerrit.addFakeChange( |
| 5001 | 'org/project-merge-branches', 'master', 'C') |
| 5002 | A.addApproval('code-review', 2) |
| 5003 | B.addApproval('code-review', 2) |
| 5004 | C.addApproval('code-review', 2) |
| 5005 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5006 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5007 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5008 | self.waitUntilSettled() |
| 5009 | |
| 5010 | job_A = None |
| 5011 | for job in self.builds: |
| 5012 | if 'project-merge' in job.name: |
| 5013 | job_A = job |
| 5014 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 5015 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 5016 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 5017 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 5018 | |
| 5019 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5020 | job_A.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5021 | repo = git.Repo(path) |
| 5022 | repo_messages = [c.message.strip() |
| 5023 | for c in repo.iter_commits(ref_A)] |
| 5024 | repo_messages.reverse() |
| 5025 | correct_messages = [ |
| 5026 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5027 | self.assertEqual(repo_messages, correct_messages) |
| 5028 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5029 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5030 | self.waitUntilSettled() |
| 5031 | |
| 5032 | job_B = None |
| 5033 | for job in self.builds: |
| 5034 | if 'project-merge' in job.name: |
| 5035 | job_B = job |
| 5036 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 5037 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 5038 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 5039 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 5040 | |
| 5041 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5042 | job_B.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5043 | repo = git.Repo(path) |
| 5044 | repo_messages = [c.message.strip() |
| 5045 | for c in repo.iter_commits(ref_B)] |
| 5046 | repo_messages.reverse() |
| 5047 | correct_messages = [ |
| 5048 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5049 | self.assertEqual(repo_messages, correct_messages) |
| 5050 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5051 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5052 | self.waitUntilSettled() |
| 5053 | |
| 5054 | job_C = None |
| 5055 | for job in self.builds: |
| 5056 | if 'project-merge' in job.name: |
| 5057 | job_C = job |
| 5058 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 5059 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 5060 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 5061 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
| 5062 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5063 | job_C.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5064 | repo = git.Repo(path) |
| 5065 | repo_messages = [c.message.strip() |
| 5066 | for c in repo.iter_commits(ref_C)] |
| 5067 | |
| 5068 | repo_messages.reverse() |
| 5069 | correct_messages = [ |
| 5070 | 'initial commit', 'add content from fixture', |
| 5071 | 'A-1', 'C-1'] |
| 5072 | # Ensure the right commits are in the history for this ref |
| 5073 | self.assertEqual(repo_messages, correct_messages) |
| 5074 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5075 | self.executor_server.hold_jobs_in_build = False |
| 5076 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5077 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5078 | |
| 5079 | |
| 5080 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5081 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5082 | |
| 5083 | def test_semaphore_tenant_isolation(self): |
| 5084 | "Test semaphores in multiple tenants" |
| 5085 | |
| 5086 | self.waitUntilSettled() |
| 5087 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5088 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5089 | |
| 5090 | self.executor_server.hold_jobs_in_build = True |
| 5091 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5092 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5093 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5094 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5095 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5096 | self.assertFalse('test-semaphore' in |
| 5097 | tenant_one.semaphore_handler.semaphores) |
| 5098 | self.assertFalse('test-semaphore' in |
| 5099 | tenant_two.semaphore_handler.semaphores) |
| 5100 | |
| 5101 | # add patches to project1 of tenant-one |
| 5102 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5103 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5104 | self.waitUntilSettled() |
| 5105 | |
| 5106 | # one build of project1-test1 must run |
| 5107 | # semaphore of tenant-one must be acquired once |
| 5108 | # semaphore of tenant-two must not be acquired |
| 5109 | self.assertEqual(len(self.builds), 1) |
| 5110 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5111 | self.assertTrue('test-semaphore' in |
| 5112 | tenant_one.semaphore_handler.semaphores) |
| 5113 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5114 | 'test-semaphore', [])), 1) |
| 5115 | self.assertFalse('test-semaphore' in |
| 5116 | tenant_two.semaphore_handler.semaphores) |
| 5117 | |
| 5118 | # add patches to project2 of tenant-two |
| 5119 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5120 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5121 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5122 | self.waitUntilSettled() |
| 5123 | |
| 5124 | # one build of project1-test1 must run |
| 5125 | # two builds of project2-test1 must run |
| 5126 | # semaphore of tenant-one must be acquired once |
| 5127 | # semaphore of tenant-two must be acquired twice |
| 5128 | self.assertEqual(len(self.builds), 3) |
| 5129 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5130 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5131 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5132 | self.assertTrue('test-semaphore' in |
| 5133 | tenant_one.semaphore_handler.semaphores) |
| 5134 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5135 | 'test-semaphore', [])), 1) |
| 5136 | self.assertTrue('test-semaphore' in |
| 5137 | tenant_two.semaphore_handler.semaphores) |
| 5138 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5139 | 'test-semaphore', [])), 2) |
| 5140 | |
| 5141 | self.executor_server.release('project1-test1') |
| 5142 | self.waitUntilSettled() |
| 5143 | |
| 5144 | # one build of project1-test1 must run |
| 5145 | # two builds of project2-test1 must run |
| 5146 | # semaphore of tenant-one must be acquired once |
| 5147 | # semaphore of tenant-two must be acquired twice |
| 5148 | self.assertEqual(len(self.builds), 3) |
| 5149 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5150 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5151 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5152 | self.assertTrue('test-semaphore' in |
| 5153 | tenant_one.semaphore_handler.semaphores) |
| 5154 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5155 | 'test-semaphore', [])), 1) |
| 5156 | self.assertTrue('test-semaphore' in |
| 5157 | tenant_two.semaphore_handler.semaphores) |
| 5158 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5159 | 'test-semaphore', [])), 2) |
| 5160 | |
| 5161 | self.executor_server.release('project2-test1') |
| 5162 | self.waitUntilSettled() |
| 5163 | |
| 5164 | # one build of project1-test1 must run |
| 5165 | # one build of project2-test1 must run |
| 5166 | # semaphore of tenant-one must be acquired once |
| 5167 | # semaphore of tenant-two must be acquired once |
| 5168 | self.assertEqual(len(self.builds), 2) |
| 5169 | self.assertTrue('test-semaphore' in |
| 5170 | tenant_one.semaphore_handler.semaphores) |
| 5171 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5172 | 'test-semaphore', [])), 1) |
| 5173 | self.assertTrue('test-semaphore' in |
| 5174 | tenant_two.semaphore_handler.semaphores) |
| 5175 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5176 | 'test-semaphore', [])), 1) |
| 5177 | |
| 5178 | self.executor_server.hold_jobs_in_build = False |
| 5179 | self.executor_server.release() |
| 5180 | |
| 5181 | self.waitUntilSettled() |
| 5182 | |
| 5183 | # no build must run |
| 5184 | # semaphore of tenant-one must not be acquired |
| 5185 | # semaphore of tenant-two must not be acquired |
| 5186 | self.assertEqual(len(self.builds), 0) |
| 5187 | self.assertFalse('test-semaphore' in |
| 5188 | tenant_one.semaphore_handler.semaphores) |
| 5189 | self.assertFalse('test-semaphore' in |
| 5190 | tenant_two.semaphore_handler.semaphores) |
| 5191 | |
| 5192 | self.assertEqual(A.reported, 1) |
| 5193 | self.assertEqual(B.reported, 1) |
| 5194 | |
| 5195 | |
| 5196 | class TestSemaphoreInRepo(ZuulTestCase): |
| 5197 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5198 | |
| 5199 | def test_semaphore_in_repo(self): |
| 5200 | "Test semaphores in repo config" |
| 5201 | |
| 5202 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5203 | # max value should not be evaluated dynamically but must be updated |
| 5204 | # after the change lands. |
| 5205 | |
| 5206 | self.waitUntilSettled() |
| 5207 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5208 | |
| 5209 | in_repo_conf = textwrap.dedent( |
| 5210 | """ |
| 5211 | - job: |
| 5212 | name: project-test2 |
| 5213 | semaphore: test-semaphore |
| 5214 | |
| 5215 | - project: |
| 5216 | name: org/project |
| 5217 | tenant-one-gate: |
| 5218 | jobs: |
| 5219 | - project-test2 |
| 5220 | |
| 5221 | # the max value in dynamic layout must be ignored |
| 5222 | - semaphore: |
| 5223 | name: test-semaphore |
| 5224 | max: 2 |
| 5225 | """) |
| 5226 | |
| 5227 | in_repo_playbook = textwrap.dedent( |
| 5228 | """ |
| 5229 | - hosts: all |
| 5230 | tasks: [] |
| 5231 | """) |
| 5232 | |
| 5233 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5234 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5235 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5236 | files=file_dict) |
| 5237 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5238 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5239 | B.setDependsOn(A, 1) |
| 5240 | C.setDependsOn(A, 1) |
| 5241 | |
| 5242 | self.executor_server.hold_jobs_in_build = True |
| 5243 | |
| 5244 | A.addApproval('code-review', 2) |
| 5245 | B.addApproval('code-review', 2) |
| 5246 | C.addApproval('code-review', 2) |
| 5247 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5248 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5249 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5250 | self.waitUntilSettled() |
| 5251 | |
| 5252 | # check that the layout in a queue item still has max value of 1 |
| 5253 | # for test-semaphore |
| 5254 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5255 | queue = None |
| 5256 | for queue_candidate in pipeline.queues: |
| 5257 | if queue_candidate.name == 'org/project': |
| 5258 | queue = queue_candidate |
| 5259 | break |
| 5260 | queue_item = queue.queue[0] |
| 5261 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5262 | dynamic_test_semaphore = \ |
| 5263 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5264 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5265 | |
| 5266 | # one build must be in queue, one semaphores acquired |
| 5267 | self.assertEqual(len(self.builds), 1) |
| 5268 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5269 | self.assertTrue('test-semaphore' in |
| 5270 | tenant.semaphore_handler.semaphores) |
| 5271 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5272 | 'test-semaphore', [])), 1) |
| 5273 | |
| 5274 | self.executor_server.release('project-test2') |
| 5275 | self.waitUntilSettled() |
| 5276 | |
| 5277 | # change A must be merged |
| 5278 | self.assertEqual(A.data['status'], 'MERGED') |
| 5279 | self.assertEqual(A.reported, 2) |
| 5280 | |
| 5281 | # send change-merged event as the gerrit mock doesn't send it |
| 5282 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5283 | self.waitUntilSettled() |
| 5284 | |
| 5285 | # now that change A was merged, the new semaphore max must be effective |
| 5286 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5287 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5288 | |
| 5289 | # two builds must be in queue, two semaphores acquired |
| 5290 | self.assertEqual(len(self.builds), 2) |
| 5291 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5292 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5293 | self.assertTrue('test-semaphore' in |
| 5294 | tenant.semaphore_handler.semaphores) |
| 5295 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5296 | 'test-semaphore', [])), 2) |
| 5297 | |
| 5298 | self.executor_server.release('project-test2') |
| 5299 | self.waitUntilSettled() |
| 5300 | |
| 5301 | self.assertEqual(len(self.builds), 0) |
| 5302 | self.assertFalse('test-semaphore' in |
| 5303 | tenant.semaphore_handler.semaphores) |
| 5304 | |
| 5305 | self.executor_server.hold_jobs_in_build = False |
| 5306 | self.executor_server.release() |
| 5307 | |
| 5308 | self.waitUntilSettled() |
| 5309 | self.assertEqual(len(self.builds), 0) |
| 5310 | |
| 5311 | self.assertEqual(A.reported, 2) |
| 5312 | self.assertEqual(B.reported, 2) |
| 5313 | self.assertEqual(C.reported, 2) |