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 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 929 | @skip("Disabled for early v3 development") |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 930 | def test_build_configuration_conflict(self): |
| 931 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 932 | |
| 933 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 934 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 935 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 936 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 937 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 938 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 939 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 940 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 941 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 942 | A.addApproval('code-review', 2) |
| 943 | B.addApproval('code-review', 2) |
| 944 | C.addApproval('code-review', 2) |
| 945 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 946 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 947 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 948 | self.waitUntilSettled() |
| 949 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 950 | self.assertEqual(A.reported, 1) |
| 951 | self.assertEqual(B.reported, 1) |
| 952 | self.assertEqual(C.reported, 1) |
| 953 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 954 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 955 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 956 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 957 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 958 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 959 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 960 | |
| 961 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 962 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 963 | self.gearman_server.hold_jobs_in_queue = False |
| 964 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 965 | self.waitUntilSettled() |
| 966 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 967 | self.assertEqual(A.data['status'], 'MERGED') |
| 968 | self.assertEqual(B.data['status'], 'NEW') |
| 969 | self.assertEqual(C.data['status'], 'MERGED') |
| 970 | self.assertEqual(A.reported, 2) |
| 971 | self.assertEqual(B.reported, 2) |
| 972 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 973 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 974 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 975 | def test_post(self): |
| 976 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 977 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 978 | e = { |
| 979 | "type": "ref-updated", |
| 980 | "submitter": { |
| 981 | "name": "User Name", |
| 982 | }, |
| 983 | "refUpdate": { |
| 984 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 985 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 986 | "refName": "master", |
| 987 | "project": "org/project", |
| 988 | } |
| 989 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 990 | self.fake_gerrit.addEvent(e) |
| 991 | self.waitUntilSettled() |
| 992 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 993 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 994 | self.assertEqual(len(self.history), 1) |
| 995 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 996 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 997 | def test_post_ignore_deletes(self): |
| 998 | "Test that deleting refs does not trigger post jobs" |
| 999 | |
| 1000 | e = { |
| 1001 | "type": "ref-updated", |
| 1002 | "submitter": { |
| 1003 | "name": "User Name", |
| 1004 | }, |
| 1005 | "refUpdate": { |
| 1006 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1007 | "newRev": "0000000000000000000000000000000000000000", |
| 1008 | "refName": "master", |
| 1009 | "project": "org/project", |
| 1010 | } |
| 1011 | } |
| 1012 | self.fake_gerrit.addEvent(e) |
| 1013 | self.waitUntilSettled() |
| 1014 | |
| 1015 | job_names = [x.name for x in self.history] |
| 1016 | self.assertEqual(len(self.history), 0) |
| 1017 | self.assertNotIn('project-post', job_names) |
| 1018 | |
| 1019 | def test_post_ignore_deletes_negative(self): |
| 1020 | "Test that deleting refs does trigger post jobs" |
| 1021 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1022 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1023 | self.sched.reconfigure(self.config) |
| 1024 | |
| 1025 | e = { |
| 1026 | "type": "ref-updated", |
| 1027 | "submitter": { |
| 1028 | "name": "User Name", |
| 1029 | }, |
| 1030 | "refUpdate": { |
| 1031 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1032 | "newRev": "0000000000000000000000000000000000000000", |
| 1033 | "refName": "master", |
| 1034 | "project": "org/project", |
| 1035 | } |
| 1036 | } |
| 1037 | self.fake_gerrit.addEvent(e) |
| 1038 | self.waitUntilSettled() |
| 1039 | |
| 1040 | job_names = [x.name for x in self.history] |
| 1041 | self.assertEqual(len(self.history), 1) |
| 1042 | self.assertIn('project-post', job_names) |
| 1043 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1044 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1045 | def test_build_configuration_branch_interaction(self): |
| 1046 | "Test that switching between branches works" |
| 1047 | self.test_build_configuration() |
| 1048 | self.test_build_configuration_branch() |
| 1049 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1050 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1051 | repo = git.Repo(path) |
| 1052 | repo.heads.master.commit = repo.commit('init') |
| 1053 | self.test_build_configuration() |
| 1054 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1055 | def test_dependent_changes_dequeue(self): |
| 1056 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1057 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1058 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1059 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1060 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1061 | A.addApproval('code-review', 2) |
| 1062 | B.addApproval('code-review', 2) |
| 1063 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1064 | |
| 1065 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1066 | M1.setMerged() |
| 1067 | |
| 1068 | # C -> B -> A -> M1 |
| 1069 | |
| 1070 | C.setDependsOn(B, 1) |
| 1071 | B.setDependsOn(A, 1) |
| 1072 | A.setDependsOn(M1, 1) |
| 1073 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1074 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1075 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1076 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1077 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1078 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1079 | |
| 1080 | self.waitUntilSettled() |
| 1081 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1082 | self.assertEqual(A.data['status'], 'NEW') |
| 1083 | self.assertEqual(A.reported, 2) |
| 1084 | self.assertEqual(B.data['status'], 'NEW') |
| 1085 | self.assertEqual(B.reported, 2) |
| 1086 | self.assertEqual(C.data['status'], 'NEW') |
| 1087 | self.assertEqual(C.reported, 2) |
| 1088 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1089 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1090 | def test_failing_dependent_changes(self): |
| 1091 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1092 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1093 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1094 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1095 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1096 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1097 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1098 | A.addApproval('code-review', 2) |
| 1099 | B.addApproval('code-review', 2) |
| 1100 | C.addApproval('code-review', 2) |
| 1101 | D.addApproval('code-review', 2) |
| 1102 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1103 | |
| 1104 | # E, D -> C -> B, A |
| 1105 | |
| 1106 | D.setDependsOn(C, 1) |
| 1107 | C.setDependsOn(B, 1) |
| 1108 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1109 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1110 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1111 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1112 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1113 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1114 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1115 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1116 | |
| 1117 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1118 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1119 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1120 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1121 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1122 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1123 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1124 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1125 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1126 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1127 | self.waitUntilSettled() |
| 1128 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1129 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1130 | for build in self.builds: |
| 1131 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1132 | build.release() |
| 1133 | self.waitUntilSettled() |
| 1134 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1135 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1136 | self.waitUntilSettled() |
| 1137 | |
| 1138 | self.assertEqual(A.data['status'], 'MERGED') |
| 1139 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1140 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1141 | self.assertEqual(B.data['status'], 'NEW') |
| 1142 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1143 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1144 | self.assertEqual(C.data['status'], 'NEW') |
| 1145 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1146 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1147 | self.assertEqual(D.data['status'], 'NEW') |
| 1148 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1149 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1150 | self.assertEqual(E.data['status'], 'MERGED') |
| 1151 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1152 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1153 | self.assertEqual(len(self.history), 18) |
| 1154 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1155 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1156 | "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] | 1157 | # If it's dequeued more than once, we should see extra |
| 1158 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1159 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1160 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1161 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1162 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1163 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1164 | A.addApproval('code-review', 2) |
| 1165 | B.addApproval('code-review', 2) |
| 1166 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1167 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1168 | self.executor_server.failJob('project-test1', A) |
| 1169 | self.executor_server.failJob('project-test2', A) |
| 1170 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1171 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1172 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1173 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1174 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1175 | |
| 1176 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1177 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1178 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1179 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1180 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1181 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1182 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1183 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1184 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1185 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1186 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1187 | self.waitUntilSettled() |
| 1188 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1189 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1190 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1191 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1192 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1193 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1194 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1195 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1196 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1197 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1198 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1199 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1200 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1201 | self.waitUntilSettled() |
| 1202 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1203 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1204 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1205 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1206 | self.executor_server.hold_jobs_in_build = False |
| 1207 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1208 | self.waitUntilSettled() |
| 1209 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1210 | self.assertEqual(len(self.builds), 0) |
| 1211 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1212 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1213 | self.assertEqual(A.data['status'], 'NEW') |
| 1214 | self.assertEqual(B.data['status'], 'MERGED') |
| 1215 | self.assertEqual(C.data['status'], 'MERGED') |
| 1216 | self.assertEqual(A.reported, 2) |
| 1217 | self.assertEqual(B.reported, 2) |
| 1218 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1219 | |
| 1220 | def test_nonvoting_job(self): |
| 1221 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1222 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1223 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1224 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1225 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1226 | self.executor_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1227 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1228 | |
| 1229 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1230 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1231 | self.assertEqual(A.data['status'], 'MERGED') |
| 1232 | self.assertEqual(A.reported, 2) |
| 1233 | self.assertEqual( |
| 1234 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1235 | 'SUCCESS') |
| 1236 | self.assertEqual( |
| 1237 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1238 | 'SUCCESS') |
| 1239 | self.assertEqual( |
| 1240 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1241 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1242 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1243 | for build in self.builds: |
| 1244 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1245 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1246 | def test_check_queue_success(self): |
| 1247 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1248 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1249 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1250 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1251 | |
| 1252 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1253 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1254 | self.assertEqual(A.data['status'], 'NEW') |
| 1255 | self.assertEqual(A.reported, 1) |
| 1256 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1257 | 'SUCCESS') |
| 1258 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1259 | 'SUCCESS') |
| 1260 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1261 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1262 | |
| 1263 | def test_check_queue_failure(self): |
| 1264 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1265 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1266 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1267 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1268 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1269 | |
| 1270 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1271 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1272 | self.assertEqual(A.data['status'], 'NEW') |
| 1273 | self.assertEqual(A.reported, 1) |
| 1274 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1275 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1276 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1277 | 'SUCCESS') |
| 1278 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1279 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1280 | |
| 1281 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1282 | # This particular test does a large amount of merges and needs a little |
| 1283 | # more time to complete |
| 1284 | self.wait_timeout = 90 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1285 | "test that dependent changes behind dequeued changes work" |
| 1286 | # This complicated test is a reproduction of a real life bug |
| 1287 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1288 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1289 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1290 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1291 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1292 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1293 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1294 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1295 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1296 | D.setDependsOn(C, 1) |
| 1297 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1298 | A.addApproval('code-review', 2) |
| 1299 | B.addApproval('code-review', 2) |
| 1300 | C.addApproval('code-review', 2) |
| 1301 | D.addApproval('code-review', 2) |
| 1302 | E.addApproval('code-review', 2) |
| 1303 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1304 | |
| 1305 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1306 | |
| 1307 | # Change object re-use in the gerrit trigger is hidden if |
| 1308 | # changes are added in quick succession; waiting makes it more |
| 1309 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1310 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1311 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1312 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1313 | self.waitUntilSettled() |
| 1314 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1315 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1316 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1317 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1318 | self.waitUntilSettled() |
| 1319 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1320 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1321 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1322 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1323 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1324 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1325 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1326 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1327 | self.waitUntilSettled() |
| 1328 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1329 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1330 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1331 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1332 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1333 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1334 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1335 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1336 | self.waitUntilSettled() |
| 1337 | |
| 1338 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1339 | |
| 1340 | # Grab pointers to the jobs we want to release before |
| 1341 | # releasing any, because list indexes may change as |
| 1342 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1343 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1344 | a.release() |
| 1345 | b.release() |
| 1346 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1347 | self.waitUntilSettled() |
| 1348 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1349 | self.executor_server.hold_jobs_in_build = False |
| 1350 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1351 | self.waitUntilSettled() |
| 1352 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1353 | self.assertEqual(A.data['status'], 'NEW') |
| 1354 | self.assertEqual(B.data['status'], 'MERGED') |
| 1355 | self.assertEqual(C.data['status'], 'MERGED') |
| 1356 | self.assertEqual(D.data['status'], 'MERGED') |
| 1357 | self.assertEqual(E.data['status'], 'MERGED') |
| 1358 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1359 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1360 | self.assertEqual(A.reported, 2) |
| 1361 | self.assertEqual(B.reported, 2) |
| 1362 | self.assertEqual(C.reported, 2) |
| 1363 | self.assertEqual(D.reported, 2) |
| 1364 | self.assertEqual(E.reported, 2) |
| 1365 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1366 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1367 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1368 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1369 | |
| 1370 | def test_merger_repack(self): |
| 1371 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1372 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1373 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1374 | A.addApproval('code-review', 2) |
| 1375 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1376 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1377 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1378 | 'SUCCESS') |
| 1379 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1380 | 'SUCCESS') |
| 1381 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1382 | 'SUCCESS') |
| 1383 | self.assertEqual(A.data['status'], 'MERGED') |
| 1384 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1385 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1386 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1387 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1388 | path = os.path.join(self.merger_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1389 | if os.path.exists(path): |
| 1390 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1391 | path = os.path.join(self.executor_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1392 | if os.path.exists(path): |
| 1393 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1394 | |
| 1395 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1396 | A.addApproval('code-review', 2) |
| 1397 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1398 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1399 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1400 | 'SUCCESS') |
| 1401 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1402 | 'SUCCESS') |
| 1403 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1404 | 'SUCCESS') |
| 1405 | self.assertEqual(A.data['status'], 'MERGED') |
| 1406 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1407 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1408 | def test_merger_repack_large_change(self): |
| 1409 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1410 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1411 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1412 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1413 | url = self.fake_gerrit.getGitUrl( |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1414 | tenant.layout.project_configs.get('org/project1')) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1415 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1416 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1417 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1418 | path = os.path.join(self.upstream_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1419 | repack_repo(path) |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1420 | path = os.path.join(self.merger_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1421 | if os.path.exists(path): |
| 1422 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1423 | path = os.path.join(self.executor_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1424 | if os.path.exists(path): |
| 1425 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1426 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1427 | A.addApproval('code-review', 2) |
| 1428 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1429 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1430 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1431 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1432 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1433 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1434 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1435 | 'SUCCESS') |
| 1436 | self.assertEqual(A.data['status'], 'MERGED') |
| 1437 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1438 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1439 | def test_new_patchset_dequeues_old(self): |
| 1440 | "Test that a new patchset causes the old to be dequeued" |
| 1441 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1442 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1443 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1444 | M.setMerged() |
| 1445 | |
| 1446 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1447 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1448 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1449 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1450 | A.addApproval('code-review', 2) |
| 1451 | B.addApproval('code-review', 2) |
| 1452 | C.addApproval('code-review', 2) |
| 1453 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1454 | |
| 1455 | C.setDependsOn(B, 1) |
| 1456 | B.setDependsOn(A, 1) |
| 1457 | A.setDependsOn(M, 1) |
| 1458 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1459 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1460 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1461 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1462 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1463 | self.waitUntilSettled() |
| 1464 | |
| 1465 | B.addPatchset() |
| 1466 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1467 | self.waitUntilSettled() |
| 1468 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1469 | self.executor_server.hold_jobs_in_build = False |
| 1470 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1471 | self.waitUntilSettled() |
| 1472 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1473 | self.assertEqual(A.data['status'], 'MERGED') |
| 1474 | self.assertEqual(A.reported, 2) |
| 1475 | self.assertEqual(B.data['status'], 'NEW') |
| 1476 | self.assertEqual(B.reported, 2) |
| 1477 | self.assertEqual(C.data['status'], 'NEW') |
| 1478 | self.assertEqual(C.reported, 2) |
| 1479 | self.assertEqual(D.data['status'], 'MERGED') |
| 1480 | self.assertEqual(D.reported, 2) |
| 1481 | 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] | 1482 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1483 | def test_new_patchset_check(self): |
| 1484 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1485 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1486 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1487 | |
| 1488 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1489 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1490 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1491 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1492 | |
| 1493 | # Add two git-dependent changes |
| 1494 | B.setDependsOn(A, 1) |
| 1495 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1496 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1497 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1498 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1499 | |
| 1500 | # A live item, and a non-live/live pair |
| 1501 | items = check_pipeline.getAllItems() |
| 1502 | self.assertEqual(len(items), 3) |
| 1503 | |
| 1504 | self.assertEqual(items[0].change.number, '1') |
| 1505 | self.assertEqual(items[0].change.patchset, '1') |
| 1506 | self.assertFalse(items[0].live) |
| 1507 | |
| 1508 | self.assertEqual(items[1].change.number, '2') |
| 1509 | self.assertEqual(items[1].change.patchset, '1') |
| 1510 | self.assertTrue(items[1].live) |
| 1511 | |
| 1512 | self.assertEqual(items[2].change.number, '1') |
| 1513 | self.assertEqual(items[2].change.patchset, '1') |
| 1514 | self.assertTrue(items[2].live) |
| 1515 | |
| 1516 | # Add a new patchset to A |
| 1517 | A.addPatchset() |
| 1518 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1519 | self.waitUntilSettled() |
| 1520 | |
| 1521 | # The live copy of A,1 should be gone, but the non-live and B |
| 1522 | # should continue, and we should have a new A,2 |
| 1523 | items = check_pipeline.getAllItems() |
| 1524 | self.assertEqual(len(items), 3) |
| 1525 | |
| 1526 | self.assertEqual(items[0].change.number, '1') |
| 1527 | self.assertEqual(items[0].change.patchset, '1') |
| 1528 | self.assertFalse(items[0].live) |
| 1529 | |
| 1530 | self.assertEqual(items[1].change.number, '2') |
| 1531 | self.assertEqual(items[1].change.patchset, '1') |
| 1532 | self.assertTrue(items[1].live) |
| 1533 | |
| 1534 | self.assertEqual(items[2].change.number, '1') |
| 1535 | self.assertEqual(items[2].change.patchset, '2') |
| 1536 | self.assertTrue(items[2].live) |
| 1537 | |
| 1538 | # Add a new patchset to B |
| 1539 | B.addPatchset() |
| 1540 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1541 | self.waitUntilSettled() |
| 1542 | |
| 1543 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1544 | # but we should have a new B,2 (still based on A,1) |
| 1545 | items = check_pipeline.getAllItems() |
| 1546 | self.assertEqual(len(items), 3) |
| 1547 | |
| 1548 | self.assertEqual(items[0].change.number, '1') |
| 1549 | self.assertEqual(items[0].change.patchset, '2') |
| 1550 | self.assertTrue(items[0].live) |
| 1551 | |
| 1552 | self.assertEqual(items[1].change.number, '1') |
| 1553 | self.assertEqual(items[1].change.patchset, '1') |
| 1554 | self.assertFalse(items[1].live) |
| 1555 | |
| 1556 | self.assertEqual(items[2].change.number, '2') |
| 1557 | self.assertEqual(items[2].change.patchset, '2') |
| 1558 | self.assertTrue(items[2].live) |
| 1559 | |
| 1560 | self.builds[0].release() |
| 1561 | self.waitUntilSettled() |
| 1562 | self.builds[0].release() |
| 1563 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1564 | self.executor_server.hold_jobs_in_build = False |
| 1565 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1566 | self.waitUntilSettled() |
| 1567 | |
| 1568 | self.assertEqual(A.reported, 1) |
| 1569 | self.assertEqual(B.reported, 1) |
| 1570 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1571 | self.assertEqual(self.history[0].changes, '1,1') |
| 1572 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1573 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1574 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1575 | self.assertEqual(self.history[2].changes, '1,2') |
| 1576 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1577 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1578 | |
| 1579 | def test_abandoned_gate(self): |
| 1580 | "Test that an abandoned change is dequeued from gate" |
| 1581 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1582 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1583 | |
| 1584 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1585 | A.addApproval('code-review', 2) |
| 1586 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1587 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1588 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1589 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1590 | |
| 1591 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1592 | self.waitUntilSettled() |
| 1593 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1594 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1595 | self.waitUntilSettled() |
| 1596 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1597 | self.assertBuilds([]) |
| 1598 | self.assertHistory([ |
| 1599 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1600 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1601 | self.assertEqual(A.reported, 1, |
| 1602 | "Abandoned gate change should report only start") |
| 1603 | |
| 1604 | def test_abandoned_check(self): |
| 1605 | "Test that an abandoned change is dequeued from check" |
| 1606 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1607 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1608 | |
| 1609 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1610 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1611 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1612 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1613 | |
| 1614 | # Add two git-dependent changes |
| 1615 | B.setDependsOn(A, 1) |
| 1616 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1617 | self.waitUntilSettled() |
| 1618 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1619 | self.waitUntilSettled() |
| 1620 | # A live item, and a non-live/live pair |
| 1621 | items = check_pipeline.getAllItems() |
| 1622 | self.assertEqual(len(items), 3) |
| 1623 | |
| 1624 | self.assertEqual(items[0].change.number, '1') |
| 1625 | self.assertFalse(items[0].live) |
| 1626 | |
| 1627 | self.assertEqual(items[1].change.number, '2') |
| 1628 | self.assertTrue(items[1].live) |
| 1629 | |
| 1630 | self.assertEqual(items[2].change.number, '1') |
| 1631 | self.assertTrue(items[2].live) |
| 1632 | |
| 1633 | # Abandon A |
| 1634 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1635 | self.waitUntilSettled() |
| 1636 | |
| 1637 | # The live copy of A should be gone, but the non-live and B |
| 1638 | # should continue |
| 1639 | items = check_pipeline.getAllItems() |
| 1640 | self.assertEqual(len(items), 2) |
| 1641 | |
| 1642 | self.assertEqual(items[0].change.number, '1') |
| 1643 | self.assertFalse(items[0].live) |
| 1644 | |
| 1645 | self.assertEqual(items[1].change.number, '2') |
| 1646 | self.assertTrue(items[1].live) |
| 1647 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1648 | self.executor_server.hold_jobs_in_build = False |
| 1649 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1650 | self.waitUntilSettled() |
| 1651 | |
| 1652 | self.assertEqual(len(self.history), 4) |
| 1653 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1654 | 'Build should have been aborted') |
| 1655 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1656 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1657 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1658 | def test_abandoned_not_timer(self): |
| 1659 | "Test that an abandoned change does not cancel timer jobs" |
| 1660 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1661 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1662 | |
| 1663 | # Start timer trigger - also org/project |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1664 | self.updateConfigLayout('layout-idle') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1665 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1666 | # The pipeline triggers every second, so we should have seen |
| 1667 | # several by now. |
| 1668 | time.sleep(5) |
| 1669 | self.waitUntilSettled() |
| 1670 | # Stop queuing timer triggered jobs so that the assertions |
| 1671 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1672 | # Must be in same repo, so overwrite config with another one |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 1673 | self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1674 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1675 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1676 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1677 | |
| 1678 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1679 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1680 | self.waitUntilSettled() |
| 1681 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1682 | |
| 1683 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1684 | self.waitUntilSettled() |
| 1685 | |
| 1686 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1687 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1688 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1689 | self.waitUntilSettled() |
| 1690 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1691 | def test_zuul_url_return(self): |
| 1692 | "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] | 1693 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1694 | self.executor_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1695 | |
| 1696 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1697 | A.addApproval('code-review', 2) |
| 1698 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1699 | self.waitUntilSettled() |
| 1700 | |
| 1701 | self.assertEqual(len(self.builds), 1) |
| 1702 | for build in self.builds: |
| 1703 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1704 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1705 | self.executor_server.hold_jobs_in_build = False |
| 1706 | self.executor_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1707 | self.waitUntilSettled() |
| 1708 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1709 | def test_new_patchset_dequeues_old_on_head(self): |
| 1710 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1711 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1712 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1713 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1714 | M.setMerged() |
| 1715 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1716 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1717 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1718 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1719 | A.addApproval('code-review', 2) |
| 1720 | B.addApproval('code-review', 2) |
| 1721 | C.addApproval('code-review', 2) |
| 1722 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1723 | |
| 1724 | C.setDependsOn(B, 1) |
| 1725 | B.setDependsOn(A, 1) |
| 1726 | A.setDependsOn(M, 1) |
| 1727 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1728 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1729 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1730 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1731 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1732 | self.waitUntilSettled() |
| 1733 | |
| 1734 | A.addPatchset() |
| 1735 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1736 | self.waitUntilSettled() |
| 1737 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1738 | self.executor_server.hold_jobs_in_build = False |
| 1739 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1740 | self.waitUntilSettled() |
| 1741 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1742 | self.assertEqual(A.data['status'], 'NEW') |
| 1743 | self.assertEqual(A.reported, 2) |
| 1744 | self.assertEqual(B.data['status'], 'NEW') |
| 1745 | self.assertEqual(B.reported, 2) |
| 1746 | self.assertEqual(C.data['status'], 'NEW') |
| 1747 | self.assertEqual(C.reported, 2) |
| 1748 | self.assertEqual(D.data['status'], 'MERGED') |
| 1749 | self.assertEqual(D.reported, 2) |
| 1750 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1751 | |
| 1752 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1753 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1754 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1755 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1756 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1757 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1758 | A.addApproval('code-review', 2) |
| 1759 | B.addApproval('code-review', 2) |
| 1760 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1761 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1762 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1763 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1764 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1765 | self.waitUntilSettled() |
| 1766 | |
| 1767 | B.addPatchset() |
| 1768 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1769 | self.waitUntilSettled() |
| 1770 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1771 | self.executor_server.hold_jobs_in_build = False |
| 1772 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1773 | self.waitUntilSettled() |
| 1774 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1775 | self.assertEqual(A.data['status'], 'MERGED') |
| 1776 | self.assertEqual(A.reported, 2) |
| 1777 | self.assertEqual(B.data['status'], 'NEW') |
| 1778 | self.assertEqual(B.reported, 2) |
| 1779 | self.assertEqual(C.data['status'], 'MERGED') |
| 1780 | self.assertEqual(C.reported, 2) |
| 1781 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1782 | |
| 1783 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1784 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1785 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1786 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1787 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1788 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1789 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1790 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1791 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1792 | self.waitUntilSettled() |
| 1793 | |
| 1794 | B.addPatchset() |
| 1795 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1796 | self.waitUntilSettled() |
| 1797 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1798 | self.executor_server.hold_jobs_in_build = False |
| 1799 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1800 | self.waitUntilSettled() |
| 1801 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1802 | self.assertEqual(A.data['status'], 'NEW') |
| 1803 | self.assertEqual(A.reported, 1) |
| 1804 | self.assertEqual(B.data['status'], 'NEW') |
| 1805 | self.assertEqual(B.reported, 1) |
| 1806 | self.assertEqual(C.data['status'], 'NEW') |
| 1807 | self.assertEqual(C.reported, 1) |
| 1808 | self.assertEqual(len(self.history), 10) |
| 1809 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1810 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1811 | def test_noop_job(self): |
| 1812 | "Test that the internal noop job works" |
| 1813 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1814 | A.addApproval('code-review', 2) |
| 1815 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1816 | self.waitUntilSettled() |
| 1817 | |
| 1818 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1819 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1820 | self.assertEqual(len(self.history), 0) |
| 1821 | self.assertEqual(A.data['status'], 'MERGED') |
| 1822 | self.assertEqual(A.reported, 2) |
| 1823 | |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1824 | def test_no_job_project(self): |
| 1825 | "Test that reports with no jobs don't get sent" |
| 1826 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1827 | 'master', 'A') |
| 1828 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1829 | self.waitUntilSettled() |
| 1830 | |
| 1831 | # Change wasn't reported to |
| 1832 | self.assertEqual(A.reported, False) |
| 1833 | |
| 1834 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1835 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1836 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1837 | items = check_pipeline.getAllItems() |
| 1838 | self.assertEqual(len(items), 0) |
| 1839 | |
| 1840 | self.assertEqual(len(self.history), 0) |
| 1841 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1842 | def test_zuul_refs(self): |
| 1843 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1844 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1845 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1846 | M1.setMerged() |
| 1847 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1848 | M2.setMerged() |
| 1849 | |
| 1850 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1851 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1852 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1853 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1854 | A.addApproval('code-review', 2) |
| 1855 | B.addApproval('code-review', 2) |
| 1856 | C.addApproval('code-review', 2) |
| 1857 | D.addApproval('code-review', 2) |
| 1858 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1859 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1860 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1861 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1862 | |
| 1863 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1864 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1865 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1866 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1867 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1868 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1869 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1870 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1871 | self.waitUntilSettled() |
| 1872 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1873 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1874 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1875 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1876 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1877 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1878 | a_build = x |
| 1879 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1880 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1881 | b_build = x |
| 1882 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1883 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1884 | c_build = x |
| 1885 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1886 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1887 | d_build = x |
| 1888 | if a_build and b_build and c_build and d_build: |
| 1889 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1890 | |
| 1891 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1892 | self.assertIsNotNone(a_zref) |
| 1893 | self.assertIsNotNone(b_zref) |
| 1894 | self.assertIsNotNone(c_zref) |
| 1895 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1896 | |
| 1897 | # And they should all be different |
| 1898 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1899 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1900 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1901 | # should have a, not b, and should not be in project2 |
| 1902 | self.assertTrue(a_build.hasChanges(A)) |
| 1903 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1904 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1905 | # should have a and b, and should not be in project2 |
| 1906 | self.assertTrue(b_build.hasChanges(A, B)) |
| 1907 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1908 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1909 | # should have a and b in 1, c in 2 |
| 1910 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 1911 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1912 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1913 | # should have a and b in 1, c and d in 2 |
| 1914 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1915 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1916 | self.executor_server.hold_jobs_in_build = False |
| 1917 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1918 | self.waitUntilSettled() |
| 1919 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1920 | self.assertEqual(A.data['status'], 'MERGED') |
| 1921 | self.assertEqual(A.reported, 2) |
| 1922 | self.assertEqual(B.data['status'], 'MERGED') |
| 1923 | self.assertEqual(B.reported, 2) |
| 1924 | self.assertEqual(C.data['status'], 'MERGED') |
| 1925 | self.assertEqual(C.reported, 2) |
| 1926 | self.assertEqual(D.data['status'], 'MERGED') |
| 1927 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1928 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1929 | def test_rerun_on_error(self): |
| 1930 | "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] | 1931 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1932 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1933 | A.addApproval('code-review', 2) |
| 1934 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1935 | self.waitUntilSettled() |
| 1936 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 1937 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1938 | self.executor_server.hold_jobs_in_build = False |
| 1939 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1940 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 1941 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1942 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 1943 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1944 | def test_statsd(self): |
| 1945 | "Test each of the statsd methods used in the scheduler" |
| 1946 | import extras |
| 1947 | statsd = extras.try_import('statsd.statsd') |
| 1948 | statsd.incr('test-incr') |
| 1949 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1950 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1951 | self.assertReportedStat('test-incr', '1|c') |
| 1952 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1953 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1954 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1955 | def test_stuck_job_cleanup(self): |
| 1956 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 1957 | |
| 1958 | # 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] | 1959 | self.gearman_server.hold_jobs_in_queue = True |
| 1960 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1961 | A.addApproval('code-review', 2) |
| 1962 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1963 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 1964 | # 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] | 1965 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 1966 | |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 1967 | self.commitLayoutUpdate('common-config', 'layout-no-jobs') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1968 | self.sched.reconfigure(self.config) |
| 1969 | self.waitUntilSettled() |
| 1970 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1971 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1972 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 1973 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1974 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1975 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1976 | |
| 1977 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1978 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1979 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 1980 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 1981 | def test_file_head(self): |
| 1982 | # This is a regression test for an observed bug. A change |
| 1983 | # with a file named "HEAD" in the root directory of the repo |
| 1984 | # was processed by a merger. It then was unable to reset the |
| 1985 | # repo because of: |
| 1986 | # GitCommandError: 'git reset --hard HEAD' returned |
| 1987 | # with exit code 128 |
| 1988 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 1989 | # and filename |
| 1990 | # Use '--' to separate filenames from revisions' |
| 1991 | |
| 1992 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 1993 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 1994 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1995 | |
| 1996 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1997 | self.waitUntilSettled() |
| 1998 | |
| 1999 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2000 | self.waitUntilSettled() |
| 2001 | |
| 2002 | self.assertIn('Build succeeded', A.messages[0]) |
| 2003 | self.assertIn('Build succeeded', B.messages[0]) |
| 2004 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2005 | def test_file_jobs(self): |
| 2006 | "Test that file jobs run only when appropriate" |
| 2007 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2008 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2009 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2010 | A.addApproval('code-review', 2) |
| 2011 | B.addApproval('code-review', 2) |
| 2012 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2013 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2014 | self.waitUntilSettled() |
| 2015 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2016 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2017 | if x.name == 'project-testfile'] |
| 2018 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2019 | self.assertEqual(len(testfile_jobs), 1) |
| 2020 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2021 | self.assertEqual(A.data['status'], 'MERGED') |
| 2022 | self.assertEqual(A.reported, 2) |
| 2023 | self.assertEqual(B.data['status'], 'MERGED') |
| 2024 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2025 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2026 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2027 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2028 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2029 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2030 | |
| 2031 | if should_skip: |
| 2032 | files = {'ignoreme': 'ignored\n'} |
| 2033 | else: |
| 2034 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2035 | |
| 2036 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2037 | 'master', |
| 2038 | 'test irrelevant-files', |
| 2039 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2040 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2041 | self.waitUntilSettled() |
| 2042 | |
| 2043 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2044 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2045 | |
| 2046 | if should_skip: |
| 2047 | self.assertEqual([], tested_change_ids) |
| 2048 | else: |
| 2049 | self.assertIn(change.data['number'], tested_change_ids) |
| 2050 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2051 | def test_irrelevant_files_match_skips_job(self): |
| 2052 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2053 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2054 | def test_irrelevant_files_no_match_runs_job(self): |
| 2055 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2056 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2057 | def test_inherited_jobs_keep_matchers(self): |
| 2058 | self.updateConfigLayout('layout-inheritance') |
| 2059 | self.sched.reconfigure(self.config) |
| 2060 | |
| 2061 | files = {'ignoreme': 'ignored\n'} |
| 2062 | |
| 2063 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2064 | 'master', |
| 2065 | 'test irrelevant-files', |
| 2066 | files=files) |
| 2067 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2068 | self.waitUntilSettled() |
| 2069 | |
| 2070 | run_jobs = set([build.name for build in self.history]) |
| 2071 | |
| 2072 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2073 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2074 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2075 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2076 | def test_test_config(self): |
| 2077 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2078 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2079 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2080 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2081 | def test_queue_names(self): |
| 2082 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2083 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2084 | source = tenant.layout.pipelines['gate'].source |
| 2085 | project1 = source.getProject('org/project1') |
| 2086 | project2 = source.getProject('org/project2') |
| 2087 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2088 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2089 | self.assertEqual(q1.name, 'integrated') |
| 2090 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2091 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2092 | def test_queue_precedence(self): |
| 2093 | "Test that queue precedence works" |
| 2094 | |
| 2095 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2096 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2097 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2098 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2099 | A.addApproval('code-review', 2) |
| 2100 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2101 | |
| 2102 | self.waitUntilSettled() |
| 2103 | self.gearman_server.hold_jobs_in_queue = False |
| 2104 | self.gearman_server.release() |
| 2105 | self.waitUntilSettled() |
| 2106 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2107 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2108 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2109 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2110 | self.waitUntilSettled() |
| 2111 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2112 | self.log.debug(self.history) |
| 2113 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2114 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2115 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2116 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2117 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2118 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2119 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2120 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2121 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2122 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2123 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2124 | A.addApproval('code-review', 2) |
| 2125 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2126 | self.waitUntilSettled() |
| 2127 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2128 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2129 | self.waitUntilSettled() |
| 2130 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2131 | port = self.webapp.server.socket.getsockname()[1] |
| 2132 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2133 | req = urllib.request.Request( |
| 2134 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2135 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2136 | headers = f.info() |
| 2137 | self.assertIn('Content-Length', headers) |
| 2138 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2139 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2140 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2141 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2142 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2143 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2144 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2145 | data = f.read() |
| 2146 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2147 | self.executor_server.hold_jobs_in_build = False |
| 2148 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2149 | self.waitUntilSettled() |
| 2150 | |
| 2151 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2152 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2153 | for p in data['pipelines']: |
| 2154 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2155 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2156 | self.assertEqual(q['window'], 20) |
| 2157 | else: |
| 2158 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2159 | for head in q['heads']: |
| 2160 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2161 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2162 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2163 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2164 | status_jobs.append(job) |
| 2165 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2166 | self.assertEqual('https://server/job/project-merge/0/', |
| 2167 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2168 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2169 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2170 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2171 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2172 | status_jobs[1]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2173 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2174 | status_jobs[1]['report_url']) |
| 2175 | |
| 2176 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2177 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2178 | status_jobs[2]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2179 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2180 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2181 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2182 | def test_semaphore_one(self): |
| 2183 | "Test semaphores with max=1 (mutex)" |
| 2184 | self.updateConfigLayout('layout-semaphore') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2185 | self.sched.reconfigure(self.config) |
| 2186 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2187 | self.waitUntilSettled() |
| 2188 | tenant = self.sched.abide.tenants.get('openstack') |
| 2189 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2190 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2191 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2192 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2193 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2194 | self.assertFalse('test-semaphore' in |
| 2195 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2196 | |
| 2197 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2198 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2199 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2200 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2201 | self.assertEqual(len(self.builds), 3) |
| 2202 | self.assertEqual(self.builds[0].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2203 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2204 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2205 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2206 | self.executor_server.release('semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2207 | self.waitUntilSettled() |
| 2208 | |
| 2209 | self.assertEqual(len(self.builds), 3) |
| 2210 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2211 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2212 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 2213 | self.assertTrue('test-semaphore' in |
| 2214 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2215 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2216 | self.executor_server.release('semaphore-one-test2') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2217 | self.waitUntilSettled() |
| 2218 | |
| 2219 | self.assertEqual(len(self.builds), 3) |
| 2220 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2221 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2222 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 2223 | self.assertTrue('test-semaphore' in |
| 2224 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2225 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2226 | self.executor_server.release('semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2227 | self.waitUntilSettled() |
| 2228 | |
| 2229 | self.assertEqual(len(self.builds), 3) |
| 2230 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2231 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2232 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 2233 | self.assertTrue('test-semaphore' in |
| 2234 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2235 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2236 | self.executor_server.release('semaphore-one-test2') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2237 | self.waitUntilSettled() |
| 2238 | |
| 2239 | self.assertEqual(len(self.builds), 2) |
| 2240 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2241 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2242 | self.assertFalse('test-semaphore' in |
| 2243 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2244 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2245 | self.executor_server.hold_jobs_in_build = False |
| 2246 | self.executor_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2247 | |
| 2248 | self.waitUntilSettled() |
| 2249 | self.assertEqual(len(self.builds), 0) |
| 2250 | |
| 2251 | self.assertEqual(A.reported, 1) |
| 2252 | self.assertEqual(B.reported, 1) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2253 | self.assertFalse('test-semaphore' in |
| 2254 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2255 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2256 | def test_semaphore_two(self): |
| 2257 | "Test semaphores with max>1" |
| 2258 | self.updateConfigLayout('layout-semaphore') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2259 | self.sched.reconfigure(self.config) |
| 2260 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2261 | self.waitUntilSettled() |
| 2262 | tenant = self.sched.abide.tenants.get('openstack') |
| 2263 | |
| 2264 | self.executor_server.hold_jobs_in_build = True |
| 2265 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2266 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2267 | self.assertFalse('test-semaphore-two' in |
| 2268 | tenant.semaphore_handler.semaphores) |
| 2269 | |
| 2270 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2271 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2272 | self.waitUntilSettled() |
| 2273 | |
| 2274 | self.assertEqual(len(self.builds), 4) |
| 2275 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2276 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 2277 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 2278 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 2279 | self.assertTrue('test-semaphore-two' in |
| 2280 | tenant.semaphore_handler.semaphores) |
| 2281 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2282 | 'test-semaphore-two', [])), 2) |
| 2283 | |
| 2284 | self.executor_server.release('semaphore-two-test1') |
| 2285 | self.waitUntilSettled() |
| 2286 | |
| 2287 | self.assertEqual(len(self.builds), 4) |
| 2288 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2289 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 2290 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2291 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 2292 | self.assertTrue('test-semaphore-two' in |
| 2293 | tenant.semaphore_handler.semaphores) |
| 2294 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2295 | 'test-semaphore-two', [])), 2) |
| 2296 | |
| 2297 | self.executor_server.release('semaphore-two-test2') |
| 2298 | self.waitUntilSettled() |
| 2299 | |
| 2300 | self.assertEqual(len(self.builds), 4) |
| 2301 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2302 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2303 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 2304 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 2305 | self.assertTrue('test-semaphore-two' in |
| 2306 | tenant.semaphore_handler.semaphores) |
| 2307 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2308 | 'test-semaphore-two', [])), 2) |
| 2309 | |
| 2310 | self.executor_server.release('semaphore-two-test1') |
| 2311 | self.waitUntilSettled() |
| 2312 | |
| 2313 | self.assertEqual(len(self.builds), 3) |
| 2314 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2315 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2316 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 2317 | self.assertTrue('test-semaphore-two' in |
| 2318 | tenant.semaphore_handler.semaphores) |
| 2319 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2320 | 'test-semaphore-two', [])), 1) |
| 2321 | |
| 2322 | self.executor_server.release('semaphore-two-test2') |
| 2323 | self.waitUntilSettled() |
| 2324 | |
| 2325 | self.assertEqual(len(self.builds), 2) |
| 2326 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2327 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2328 | self.assertFalse('test-semaphore-two' in |
| 2329 | tenant.semaphore_handler.semaphores) |
| 2330 | |
| 2331 | self.executor_server.hold_jobs_in_build = False |
| 2332 | self.executor_server.release() |
| 2333 | |
| 2334 | self.waitUntilSettled() |
| 2335 | self.assertEqual(len(self.builds), 0) |
| 2336 | |
| 2337 | self.assertEqual(A.reported, 1) |
| 2338 | self.assertEqual(B.reported, 1) |
| 2339 | |
| 2340 | def test_semaphore_abandon(self): |
| 2341 | "Test abandon with job semaphores" |
| 2342 | self.updateConfigLayout('layout-semaphore') |
| 2343 | self.sched.reconfigure(self.config) |
| 2344 | |
| 2345 | self.waitUntilSettled() |
| 2346 | tenant = self.sched.abide.tenants.get('openstack') |
| 2347 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2348 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2349 | |
| 2350 | tenant = self.sched.abide.tenants.get('openstack') |
| 2351 | check_pipeline = tenant.layout.pipelines['check'] |
| 2352 | |
| 2353 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2354 | self.assertFalse('test-semaphore' in |
| 2355 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2356 | |
| 2357 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2358 | self.waitUntilSettled() |
| 2359 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2360 | self.assertTrue('test-semaphore' in |
| 2361 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2362 | |
| 2363 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2364 | self.waitUntilSettled() |
| 2365 | |
| 2366 | # The check pipeline should be empty |
| 2367 | items = check_pipeline.getAllItems() |
| 2368 | self.assertEqual(len(items), 0) |
| 2369 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2370 | # The semaphore should be released |
| 2371 | self.assertFalse('test-semaphore' in |
| 2372 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2373 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2374 | self.executor_server.hold_jobs_in_build = False |
| 2375 | self.executor_server.release() |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2376 | self.waitUntilSettled() |
| 2377 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2378 | def test_semaphore_reconfigure(self): |
| 2379 | "Test reconfigure with job semaphores" |
| 2380 | self.updateConfigLayout('layout-semaphore') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2381 | self.sched.reconfigure(self.config) |
| 2382 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2383 | self.waitUntilSettled() |
| 2384 | tenant = self.sched.abide.tenants.get('openstack') |
| 2385 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2386 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2387 | |
| 2388 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2389 | self.assertFalse('test-semaphore' in |
| 2390 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2391 | |
| 2392 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2393 | self.waitUntilSettled() |
| 2394 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2395 | self.assertTrue('test-semaphore' in |
| 2396 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2397 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2398 | # reconfigure without layout change |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2399 | self.sched.reconfigure(self.config) |
| 2400 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2401 | tenant = self.sched.abide.tenants.get('openstack') |
| 2402 | |
| 2403 | # semaphore still must be held |
| 2404 | self.assertTrue('test-semaphore' in |
| 2405 | tenant.semaphore_handler.semaphores) |
| 2406 | |
| 2407 | self.updateConfigLayout('layout-semaphore-reconfiguration') |
| 2408 | self.sched.reconfigure(self.config) |
| 2409 | self.waitUntilSettled() |
| 2410 | tenant = self.sched.abide.tenants.get('openstack') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2411 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2412 | self.executor_server.release('project-test1') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2413 | self.waitUntilSettled() |
| 2414 | |
| 2415 | # There should be no builds anymore |
| 2416 | self.assertEqual(len(self.builds), 0) |
| 2417 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2418 | # The semaphore should be released |
| 2419 | self.assertFalse('test-semaphore' in |
| 2420 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2421 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2422 | def test_live_reconfiguration(self): |
| 2423 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2424 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2425 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2426 | A.addApproval('code-review', 2) |
| 2427 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2428 | self.waitUntilSettled() |
| 2429 | |
| 2430 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2431 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2432 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2433 | self.executor_server.hold_jobs_in_build = False |
| 2434 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2435 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2436 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2437 | 'SUCCESS') |
| 2438 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2439 | 'SUCCESS') |
| 2440 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2441 | 'SUCCESS') |
| 2442 | self.assertEqual(A.data['status'], 'MERGED') |
| 2443 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2444 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2445 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2446 | def test_live_reconfiguration_merge_conflict(self): |
| 2447 | # A real-world bug: a change in a gate queue has a merge |
| 2448 | # conflict and a job is added to its project while it's |
| 2449 | # sitting in the queue. The job gets added to the change and |
| 2450 | # enqueued and the change gets stuck. |
| 2451 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2452 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2453 | |
| 2454 | # This change is fine. It's here to stop the queue long |
| 2455 | # enough for the next change to be subject to the |
| 2456 | # reconfiguration, as well as to provide a conflict for the |
| 2457 | # next change. This change will succeed and merge. |
| 2458 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2459 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2460 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2461 | |
| 2462 | # This change will be in merge conflict. During the |
| 2463 | # reconfiguration, we will add a job. We want to make sure |
| 2464 | # that doesn't cause it to get stuck. |
| 2465 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2466 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2467 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2468 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2469 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2470 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2471 | |
| 2472 | self.waitUntilSettled() |
| 2473 | |
| 2474 | # No jobs have run yet |
| 2475 | self.assertEqual(A.data['status'], 'NEW') |
| 2476 | self.assertEqual(A.reported, 1) |
| 2477 | self.assertEqual(B.data['status'], 'NEW') |
| 2478 | self.assertEqual(B.reported, 1) |
| 2479 | self.assertEqual(len(self.history), 0) |
| 2480 | |
| 2481 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2482 | self.updateConfigLayout( |
| 2483 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2484 | self.sched.reconfigure(self.config) |
| 2485 | self.waitUntilSettled() |
| 2486 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2487 | self.executor_server.hold_jobs_in_build = False |
| 2488 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2489 | self.waitUntilSettled() |
| 2490 | |
| 2491 | self.assertEqual(A.data['status'], 'MERGED') |
| 2492 | self.assertEqual(A.reported, 2) |
| 2493 | self.assertEqual(B.data['status'], 'NEW') |
| 2494 | self.assertEqual(B.reported, 2) |
| 2495 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2496 | 'SUCCESS') |
| 2497 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2498 | 'SUCCESS') |
| 2499 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2500 | 'SUCCESS') |
| 2501 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2502 | 'SUCCESS') |
| 2503 | self.assertEqual(len(self.history), 4) |
| 2504 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2505 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2506 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2507 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2508 | # that tests a job added to a job tree with a failed root does |
| 2509 | # not run. |
| 2510 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2511 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2512 | |
| 2513 | # This change is fine. It's here to stop the queue long |
| 2514 | # enough for the next change to be subject to the |
| 2515 | # reconfiguration. This change will succeed and merge. |
| 2516 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2517 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2518 | A.addApproval('code-review', 2) |
| 2519 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2520 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2521 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2522 | self.waitUntilSettled() |
| 2523 | |
| 2524 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2525 | self.executor_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2526 | B.addApproval('code-review', 2) |
| 2527 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2528 | self.waitUntilSettled() |
| 2529 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2530 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2531 | self.waitUntilSettled() |
| 2532 | |
| 2533 | # Both -merge jobs have run, but no others. |
| 2534 | self.assertEqual(A.data['status'], 'NEW') |
| 2535 | self.assertEqual(A.reported, 1) |
| 2536 | self.assertEqual(B.data['status'], 'NEW') |
| 2537 | self.assertEqual(B.reported, 1) |
| 2538 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2539 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2540 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2541 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2542 | self.assertEqual(len(self.history), 2) |
| 2543 | |
| 2544 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2545 | self.updateConfigLayout( |
| 2546 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2547 | self.sched.reconfigure(self.config) |
| 2548 | self.waitUntilSettled() |
| 2549 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2550 | self.executor_server.hold_jobs_in_build = False |
| 2551 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2552 | self.waitUntilSettled() |
| 2553 | |
| 2554 | self.assertEqual(A.data['status'], 'MERGED') |
| 2555 | self.assertEqual(A.reported, 2) |
| 2556 | self.assertEqual(B.data['status'], 'NEW') |
| 2557 | self.assertEqual(B.reported, 2) |
| 2558 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2559 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2560 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2561 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2562 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2563 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2564 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2565 | self.assertEqual(len(self.history), 5) |
| 2566 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2567 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2568 | def test_live_reconfiguration_failed_job(self): |
| 2569 | # Test that a change with a removed failing job does not |
| 2570 | # disrupt reconfiguration. If a change has a failed job and |
| 2571 | # that job is removed during a reconfiguration, we observed a |
| 2572 | # bug where the code to re-set build statuses would run on |
| 2573 | # that build and raise an exception because the job no longer |
| 2574 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2575 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2576 | |
| 2577 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2578 | |
| 2579 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2580 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2581 | |
| 2582 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2583 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2584 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2585 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2586 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2587 | self.waitUntilSettled() |
| 2588 | |
| 2589 | self.assertEqual(A.data['status'], 'NEW') |
| 2590 | self.assertEqual(A.reported, 0) |
| 2591 | |
| 2592 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2593 | 'SUCCESS') |
| 2594 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2595 | 'FAILURE') |
| 2596 | self.assertEqual(len(self.history), 2) |
| 2597 | |
| 2598 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2599 | self.updateConfigLayout( |
| 2600 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2601 | self.sched.reconfigure(self.config) |
| 2602 | self.waitUntilSettled() |
| 2603 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2604 | self.executor_server.hold_jobs_in_build = False |
| 2605 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2606 | self.waitUntilSettled() |
| 2607 | |
| 2608 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2609 | 'SUCCESS') |
| 2610 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2611 | 'SUCCESS') |
| 2612 | self.assertEqual(len(self.history), 4) |
| 2613 | |
| 2614 | self.assertEqual(A.data['status'], 'NEW') |
| 2615 | self.assertEqual(A.reported, 1) |
| 2616 | self.assertIn('Build succeeded', A.messages[0]) |
| 2617 | # Ensure the removed job was not included in the report. |
| 2618 | self.assertNotIn('project-test1', A.messages[0]) |
| 2619 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2620 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2621 | def test_live_reconfiguration_shared_queue(self): |
| 2622 | # Test that a change with a failing job which was removed from |
| 2623 | # this project but otherwise still exists in the system does |
| 2624 | # not disrupt reconfiguration. |
| 2625 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2626 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2627 | |
| 2628 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2629 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2630 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2631 | |
| 2632 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2633 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2634 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2635 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2636 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2637 | self.waitUntilSettled() |
| 2638 | |
| 2639 | self.assertEqual(A.data['status'], 'NEW') |
| 2640 | self.assertEqual(A.reported, 0) |
| 2641 | |
| 2642 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2643 | 'SUCCESS') |
| 2644 | self.assertEqual(self.getJobFromHistory( |
| 2645 | 'project1-project2-integration').result, 'FAILURE') |
| 2646 | self.assertEqual(len(self.history), 2) |
| 2647 | |
| 2648 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2649 | self.updateConfigLayout( |
| 2650 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2651 | self.sched.reconfigure(self.config) |
| 2652 | self.waitUntilSettled() |
| 2653 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2654 | self.executor_server.hold_jobs_in_build = False |
| 2655 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2656 | self.waitUntilSettled() |
| 2657 | |
| 2658 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2659 | 'SUCCESS') |
| 2660 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2661 | 'SUCCESS') |
| 2662 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2663 | 'SUCCESS') |
| 2664 | self.assertEqual(self.getJobFromHistory( |
| 2665 | 'project1-project2-integration').result, 'FAILURE') |
| 2666 | self.assertEqual(len(self.history), 4) |
| 2667 | |
| 2668 | self.assertEqual(A.data['status'], 'NEW') |
| 2669 | self.assertEqual(A.reported, 1) |
| 2670 | self.assertIn('Build succeeded', A.messages[0]) |
| 2671 | # Ensure the removed job was not included in the report. |
| 2672 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2673 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2674 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2675 | def test_double_live_reconfiguration_shared_queue(self): |
| 2676 | # This was a real-world regression. A change is added to |
| 2677 | # gate; a reconfigure happens, a second change which depends |
| 2678 | # on the first is added, and a second reconfiguration happens. |
| 2679 | # Ensure that both changes merge. |
| 2680 | |
| 2681 | # A failure may indicate incorrect caching or cleaning up of |
| 2682 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2683 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2684 | |
| 2685 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2686 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2687 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2688 | A.addApproval('code-review', 2) |
| 2689 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2690 | |
| 2691 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2692 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2693 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2694 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2695 | self.waitUntilSettled() |
| 2696 | |
| 2697 | # Reconfigure (with only one change in the pipeline). |
| 2698 | self.sched.reconfigure(self.config) |
| 2699 | self.waitUntilSettled() |
| 2700 | |
| 2701 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2702 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2703 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2704 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2705 | self.waitUntilSettled() |
| 2706 | |
| 2707 | # Reconfigure (with both in the pipeline). |
| 2708 | self.sched.reconfigure(self.config) |
| 2709 | self.waitUntilSettled() |
| 2710 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2711 | self.executor_server.hold_jobs_in_build = False |
| 2712 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2713 | self.waitUntilSettled() |
| 2714 | |
| 2715 | self.assertEqual(len(self.history), 8) |
| 2716 | |
| 2717 | self.assertEqual(A.data['status'], 'MERGED') |
| 2718 | self.assertEqual(A.reported, 2) |
| 2719 | self.assertEqual(B.data['status'], 'MERGED') |
| 2720 | self.assertEqual(B.reported, 2) |
| 2721 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2722 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2723 | def test_live_reconfiguration_del_project(self): |
| 2724 | # Test project deletion from layout |
| 2725 | # while changes are enqueued |
| 2726 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2727 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2728 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2729 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2730 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2731 | |
| 2732 | # A Depends-On: B |
| 2733 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2734 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2735 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2736 | |
| 2737 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2738 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2739 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2740 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2741 | self.waitUntilSettled() |
| 2742 | self.assertEqual(len(self.builds), 5) |
| 2743 | |
| 2744 | # This layout defines only org/project, not org/project1 |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2745 | self.updateConfigLayout( |
| 2746 | 'tests/fixtures/layout-live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2747 | self.sched.reconfigure(self.config) |
| 2748 | self.waitUntilSettled() |
| 2749 | |
| 2750 | # Builds for C aborted, builds for A succeed, |
| 2751 | # and have change B applied ahead |
| 2752 | job_c = self.getJobFromHistory('project1-test1') |
| 2753 | self.assertEqual(job_c.changes, '3,1') |
| 2754 | self.assertEqual(job_c.result, 'ABORTED') |
| 2755 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2756 | self.executor_server.hold_jobs_in_build = False |
| 2757 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2758 | self.waitUntilSettled() |
| 2759 | |
| 2760 | self.assertEqual(self.getJobFromHistory('project-test1').changes, |
| 2761 | '2,1 1,1') |
| 2762 | |
| 2763 | self.assertEqual(A.data['status'], 'NEW') |
| 2764 | self.assertEqual(B.data['status'], 'NEW') |
| 2765 | self.assertEqual(C.data['status'], 'NEW') |
| 2766 | self.assertEqual(A.reported, 1) |
| 2767 | self.assertEqual(B.reported, 0) |
| 2768 | self.assertEqual(C.reported, 0) |
| 2769 | |
| 2770 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 2771 | self.assertIn('Build succeeded', A.messages[0]) |
| 2772 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2773 | @skip("Disabled for early v3 development") |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2774 | def test_live_reconfiguration_functions(self): |
| 2775 | "Test live reconfiguration with a custom function" |
| 2776 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2777 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2778 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2779 | A.addApproval('code-review', 2) |
| 2780 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2781 | self.waitUntilSettled() |
| 2782 | |
| 2783 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2784 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2785 | 'debian') |
| 2786 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2787 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2788 | self.updateConfigLayout( |
| 2789 | 'tests/fixtures/layout-live-reconfiguration-functions.yaml') |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2790 | self.sched.reconfigure(self.config) |
| 2791 | self.worker.build_history = [] |
| 2792 | |
| 2793 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2794 | B.addApproval('code-review', 2) |
| 2795 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2796 | self.waitUntilSettled() |
| 2797 | |
| 2798 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2799 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2800 | 'wheezy') |
| 2801 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2802 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2803 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2804 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2805 | self.updateConfigLayout( |
| 2806 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2807 | self.sched.reconfigure(self.config) |
| 2808 | |
| 2809 | self.init_repo("org/new-project") |
| 2810 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2811 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2812 | A.addApproval('code-review', 2) |
| 2813 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2814 | self.waitUntilSettled() |
| 2815 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2816 | 'SUCCESS') |
| 2817 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2818 | 'SUCCESS') |
| 2819 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2820 | 'SUCCESS') |
| 2821 | self.assertEqual(A.data['status'], 'MERGED') |
| 2822 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2823 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2824 | def test_repo_deleted(self): |
Paul Belanger | 66e9596 | 2016-11-11 12:11:06 -0500 | [diff] [blame] | 2825 | self.updateConfigLayout('layout-repo-deleted') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2826 | self.sched.reconfigure(self.config) |
| 2827 | |
| 2828 | self.init_repo("org/delete-project") |
| 2829 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2830 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2831 | A.addApproval('code-review', 2) |
| 2832 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2833 | self.waitUntilSettled() |
| 2834 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2835 | 'SUCCESS') |
| 2836 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2837 | 'SUCCESS') |
| 2838 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2839 | 'SUCCESS') |
| 2840 | self.assertEqual(A.data['status'], 'MERGED') |
| 2841 | self.assertEqual(A.reported, 2) |
| 2842 | |
| 2843 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2844 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2845 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2846 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2847 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2848 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2849 | |
| 2850 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2851 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2852 | B.addApproval('code-review', 2) |
| 2853 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2854 | self.waitUntilSettled() |
| 2855 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2856 | 'SUCCESS') |
| 2857 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2858 | 'SUCCESS') |
| 2859 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2860 | 'SUCCESS') |
| 2861 | self.assertEqual(B.data['status'], 'MERGED') |
| 2862 | self.assertEqual(B.reported, 2) |
| 2863 | |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2864 | def test_tags(self): |
| 2865 | "Test job tags" |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2866 | self.updateConfigLayout('layout-tags') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2867 | self.sched.reconfigure(self.config) |
| 2868 | |
| 2869 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2870 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2871 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2872 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2873 | self.waitUntilSettled() |
| 2874 | |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2875 | self.assertEqual(len(self.history), 8) |
| 2876 | |
| 2877 | results = {self.getJobFromHistory('merge', |
| 2878 | project='org/project1').uuid: 'extratag merge', |
| 2879 | self.getJobFromHistory('merge', |
| 2880 | project='org/project2').uuid: 'merge'} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2881 | |
| 2882 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2883 | self.assertEqual(results.get(build.uuid, ''), |
| 2884 | build.parameters['vars']['zuul'].get('tags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2885 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2886 | def test_timer(self): |
| 2887 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2888 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2889 | self.updateConfigLayout('layout-timer') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2890 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2891 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2892 | # The pipeline triggers every second, so we should have seen |
| 2893 | # several by now. |
| 2894 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2895 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2896 | |
| 2897 | self.assertEqual(len(self.builds), 2) |
| 2898 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2899 | port = self.webapp.server.socket.getsockname()[1] |
| 2900 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2901 | req = urllib.request.Request( |
| 2902 | "http://localhost:%s/openstack/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2903 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2904 | data = f.read() |
| 2905 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2906 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2907 | # Stop queuing timer triggered jobs so that the assertions |
| 2908 | # below don't race against more jobs being queued. |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2909 | self.commitLayoutUpdate('layout-timer', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2910 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2911 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2912 | self.waitUntilSettled() |
| 2913 | |
| 2914 | self.assertEqual(self.getJobFromHistory( |
| 2915 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2916 | self.assertEqual(self.getJobFromHistory( |
| 2917 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2918 | |
| 2919 | data = json.loads(data) |
| 2920 | status_jobs = set() |
| 2921 | for p in data['pipelines']: |
| 2922 | for q in p['change_queues']: |
| 2923 | for head in q['heads']: |
| 2924 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2925 | for job in change['jobs']: |
| 2926 | status_jobs.add(job['name']) |
| 2927 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2928 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2929 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2930 | def test_idle(self): |
| 2931 | "Test that frequent periodic jobs work" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2932 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2933 | self.updateConfigLayout('layout-idle') |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2934 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2935 | for x in range(1, 3): |
| 2936 | # Test that timer triggers periodic jobs even across |
| 2937 | # layout config reloads. |
| 2938 | # Start timer trigger |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2939 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2940 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2941 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2942 | # The pipeline triggers every second, so we should have seen |
| 2943 | # several by now. |
| 2944 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2945 | |
| 2946 | # Stop queuing timer triggered jobs so that the assertions |
| 2947 | # below don't race against more jobs being queued. |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2948 | before = self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2949 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2950 | self.waitUntilSettled() |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2951 | self.assertEqual(len(self.builds), 2, |
| 2952 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2953 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2954 | self.waitUntilSettled() |
| 2955 | self.assertEqual(len(self.builds), 0) |
| 2956 | self.assertEqual(len(self.history), x * 2) |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2957 | # Revert back to layout-idle |
| 2958 | repo = git.Repo(os.path.join(self.test_root, |
| 2959 | 'upstream', |
| 2960 | 'layout-idle')) |
| 2961 | repo.git.reset('--hard', before) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2962 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2963 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 2964 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2965 | self.sched.reconfigure(self.config) |
| 2966 | |
| 2967 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2968 | self.waitUntilSettled() |
| 2969 | |
| 2970 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2971 | self.waitUntilSettled() |
| 2972 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2973 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2974 | |
| 2975 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2976 | # work on the knowledge of what the first message should be as |
| 2977 | # it is only configured to go to SMTP. |
| 2978 | |
| 2979 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2980 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2981 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2982 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2983 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2984 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2985 | |
| 2986 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2987 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2988 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2989 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2990 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2991 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2992 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2993 | def test_timer_smtp(self): |
| 2994 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2995 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 2996 | self.updateConfigLayout('layout-timer-smtp') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2997 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2998 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2999 | # The pipeline triggers every second, so we should have seen |
| 3000 | # several by now. |
| 3001 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3002 | self.waitUntilSettled() |
| 3003 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3004 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3005 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3006 | self.waitUntilSettled() |
| 3007 | self.assertEqual(len(self.history), 2) |
| 3008 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3009 | self.assertEqual(self.getJobFromHistory( |
| 3010 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3011 | self.assertEqual(self.getJobFromHistory( |
| 3012 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3013 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3014 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3015 | |
| 3016 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3017 | # work on the knowledge of what the first message should be as |
| 3018 | # it is only configured to go to SMTP. |
| 3019 | |
| 3020 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3021 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3022 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3023 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3024 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3025 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3026 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3027 | # Stop queuing timer triggered jobs and let any that may have |
| 3028 | # queued through so that end of test assertions pass. |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 3029 | self.commitLayoutUpdate('layout-timer-smtp', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3030 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3031 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3032 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3033 | self.waitUntilSettled() |
| 3034 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3035 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3036 | def test_timer_sshkey(self): |
| 3037 | "Test that a periodic job can setup SSH key authentication" |
| 3038 | self.worker.hold_jobs_in_build = True |
| 3039 | self.config.set('zuul', 'layout_config', |
| 3040 | 'tests/fixtures/layout-timer.yaml') |
| 3041 | self.sched.reconfigure(self.config) |
| 3042 | self.registerJobs() |
| 3043 | |
| 3044 | # The pipeline triggers every second, so we should have seen |
| 3045 | # several by now. |
| 3046 | time.sleep(5) |
| 3047 | self.waitUntilSettled() |
| 3048 | |
| 3049 | self.assertEqual(len(self.builds), 2) |
| 3050 | |
| 3051 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3052 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3053 | with open(ssh_wrapper) as f: |
| 3054 | ssh_wrapper_content = f.read() |
| 3055 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3056 | # In the unit tests Merger runs in the same process, |
| 3057 | # so we see its' environment variables |
| 3058 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3059 | |
| 3060 | self.worker.release('.*') |
| 3061 | self.waitUntilSettled() |
| 3062 | self.assertEqual(len(self.history), 2) |
| 3063 | |
| 3064 | self.assertEqual(self.getJobFromHistory( |
| 3065 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3066 | self.assertEqual(self.getJobFromHistory( |
| 3067 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3068 | |
| 3069 | # Stop queuing timer triggered jobs and let any that may have |
| 3070 | # queued through so that end of test assertions pass. |
| 3071 | self.config.set('zuul', 'layout_config', |
| 3072 | 'tests/fixtures/layout-no-timer.yaml') |
| 3073 | self.sched.reconfigure(self.config) |
| 3074 | self.registerJobs() |
| 3075 | self.waitUntilSettled() |
| 3076 | self.worker.release('.*') |
| 3077 | self.waitUntilSettled() |
| 3078 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3079 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3080 | "Test that the RPC client can enqueue a change" |
| 3081 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3082 | A.addApproval('code-review', 2) |
| 3083 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3084 | |
| 3085 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3086 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3087 | r = client.enqueue(tenant='tenant-one', |
| 3088 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3089 | project='org/project', |
| 3090 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3091 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3092 | self.waitUntilSettled() |
| 3093 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3094 | 'SUCCESS') |
| 3095 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3096 | 'SUCCESS') |
| 3097 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3098 | 'SUCCESS') |
| 3099 | self.assertEqual(A.data['status'], 'MERGED') |
| 3100 | self.assertEqual(A.reported, 2) |
| 3101 | self.assertEqual(r, True) |
| 3102 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3103 | def test_client_enqueue_ref(self): |
| 3104 | "Test that the RPC client can enqueue a ref" |
| 3105 | |
| 3106 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3107 | self.gearman_server.port) |
| 3108 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3109 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3110 | pipeline='post', |
| 3111 | project='org/project', |
| 3112 | trigger='gerrit', |
| 3113 | ref='master', |
| 3114 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3115 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3116 | self.waitUntilSettled() |
| 3117 | job_names = [x.name for x in self.history] |
| 3118 | self.assertEqual(len(self.history), 1) |
| 3119 | self.assertIn('project-post', job_names) |
| 3120 | self.assertEqual(r, True) |
| 3121 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3122 | def test_client_enqueue_negative(self): |
| 3123 | "Test that the RPC client returns errors" |
| 3124 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3125 | self.gearman_server.port) |
| 3126 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3127 | "Invalid tenant"): |
| 3128 | r = client.enqueue(tenant='tenant-foo', |
| 3129 | pipeline='gate', |
| 3130 | project='org/project', |
| 3131 | trigger='gerrit', |
| 3132 | change='1,1') |
| 3133 | client.shutdown() |
| 3134 | self.assertEqual(r, False) |
| 3135 | |
| 3136 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3137 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3138 | r = client.enqueue(tenant='tenant-one', |
| 3139 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3140 | project='project-does-not-exist', |
| 3141 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3142 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3143 | client.shutdown() |
| 3144 | self.assertEqual(r, False) |
| 3145 | |
| 3146 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3147 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3148 | r = client.enqueue(tenant='tenant-one', |
| 3149 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3150 | project='org/project', |
| 3151 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3152 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3153 | client.shutdown() |
| 3154 | self.assertEqual(r, False) |
| 3155 | |
| 3156 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3157 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3158 | r = client.enqueue(tenant='tenant-one', |
| 3159 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3160 | project='org/project', |
| 3161 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3162 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3163 | client.shutdown() |
| 3164 | self.assertEqual(r, False) |
| 3165 | |
| 3166 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3167 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3168 | r = client.enqueue(tenant='tenant-one', |
| 3169 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3170 | project='org/project', |
| 3171 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3172 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3173 | client.shutdown() |
| 3174 | self.assertEqual(r, False) |
| 3175 | |
| 3176 | self.waitUntilSettled() |
| 3177 | self.assertEqual(len(self.history), 0) |
| 3178 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3179 | |
| 3180 | def test_client_promote(self): |
| 3181 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3182 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3183 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3184 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3185 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3186 | A.addApproval('code-review', 2) |
| 3187 | B.addApproval('code-review', 2) |
| 3188 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3189 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3190 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3191 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3192 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3193 | |
| 3194 | self.waitUntilSettled() |
| 3195 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3196 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3197 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3198 | enqueue_times = {} |
| 3199 | for item in items: |
| 3200 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3201 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3202 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3203 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3204 | r = client.promote(tenant='tenant-one', |
| 3205 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3206 | change_ids=['2,1', '3,1']) |
| 3207 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3208 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3209 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3210 | for item in items: |
| 3211 | self.assertEqual( |
| 3212 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3213 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3214 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3215 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3216 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3217 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3218 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3219 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3220 | self.waitUntilSettled() |
| 3221 | |
| 3222 | self.assertEqual(len(self.builds), 6) |
| 3223 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3224 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3225 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3226 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3227 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3228 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3229 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3230 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3231 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3232 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3233 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3234 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3235 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3236 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3237 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3238 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3239 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3240 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3241 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3242 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3243 | self.waitUntilSettled() |
| 3244 | |
| 3245 | self.assertEqual(A.data['status'], 'MERGED') |
| 3246 | self.assertEqual(A.reported, 2) |
| 3247 | self.assertEqual(B.data['status'], 'MERGED') |
| 3248 | self.assertEqual(B.reported, 2) |
| 3249 | self.assertEqual(C.data['status'], 'MERGED') |
| 3250 | self.assertEqual(C.reported, 2) |
| 3251 | |
| 3252 | client.shutdown() |
| 3253 | self.assertEqual(r, True) |
| 3254 | |
| 3255 | def test_client_promote_dependent(self): |
| 3256 | "Test that the RPC client can promote a dependent change" |
| 3257 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3258 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3259 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3260 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3261 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3262 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3263 | |
| 3264 | C.setDependsOn(B, 1) |
| 3265 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3266 | A.addApproval('code-review', 2) |
| 3267 | B.addApproval('code-review', 2) |
| 3268 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3269 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3270 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3271 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3272 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3273 | |
| 3274 | self.waitUntilSettled() |
| 3275 | |
| 3276 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3277 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3278 | r = client.promote(tenant='tenant-one', |
| 3279 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3280 | change_ids=['3,1']) |
| 3281 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3282 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3283 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3284 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3285 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3286 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3287 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3288 | self.waitUntilSettled() |
| 3289 | |
| 3290 | self.assertEqual(len(self.builds), 6) |
| 3291 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3292 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3293 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3294 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3295 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3296 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3297 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3298 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3299 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3300 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3301 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3302 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3303 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3304 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3305 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3306 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3307 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3308 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3309 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3310 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3311 | self.waitUntilSettled() |
| 3312 | |
| 3313 | self.assertEqual(A.data['status'], 'MERGED') |
| 3314 | self.assertEqual(A.reported, 2) |
| 3315 | self.assertEqual(B.data['status'], 'MERGED') |
| 3316 | self.assertEqual(B.reported, 2) |
| 3317 | self.assertEqual(C.data['status'], 'MERGED') |
| 3318 | self.assertEqual(C.reported, 2) |
| 3319 | |
| 3320 | client.shutdown() |
| 3321 | self.assertEqual(r, True) |
| 3322 | |
| 3323 | def test_client_promote_negative(self): |
| 3324 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3325 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3326 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3327 | A.addApproval('code-review', 2) |
| 3328 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3329 | self.waitUntilSettled() |
| 3330 | |
| 3331 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3332 | self.gearman_server.port) |
| 3333 | |
| 3334 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3335 | r = client.promote(tenant='tenant-one', |
| 3336 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3337 | change_ids=['2,1', '3,1']) |
| 3338 | client.shutdown() |
| 3339 | self.assertEqual(r, False) |
| 3340 | |
| 3341 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3342 | r = client.promote(tenant='tenant-one', |
| 3343 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3344 | change_ids=['4,1']) |
| 3345 | client.shutdown() |
| 3346 | self.assertEqual(r, False) |
| 3347 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3348 | self.executor_server.hold_jobs_in_build = False |
| 3349 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3350 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3351 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3352 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3353 | def test_queue_rate_limiting(self): |
| 3354 | "Test that DependentPipelines are rate limited with dep across window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3355 | self.updateConfigLayout( |
| 3356 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3357 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3358 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3359 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3360 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3361 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3362 | |
| 3363 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3364 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3365 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3366 | A.addApproval('code-review', 2) |
| 3367 | B.addApproval('code-review', 2) |
| 3368 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3369 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3370 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3371 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3372 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3373 | self.waitUntilSettled() |
| 3374 | |
| 3375 | # Only A and B will have their merge jobs queued because |
| 3376 | # window is 2. |
| 3377 | self.assertEqual(len(self.builds), 2) |
| 3378 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3379 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3380 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3381 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3382 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3383 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3384 | self.waitUntilSettled() |
| 3385 | |
| 3386 | # Only A and B will have their test jobs queued because |
| 3387 | # window is 2. |
| 3388 | self.assertEqual(len(self.builds), 4) |
| 3389 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3390 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3391 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3392 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3393 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3394 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3395 | self.waitUntilSettled() |
| 3396 | |
| 3397 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3398 | # A failed so window is reduced by 1 to 1. |
| 3399 | self.assertEqual(queue.window, 1) |
| 3400 | self.assertEqual(queue.window_floor, 1) |
| 3401 | self.assertEqual(A.data['status'], 'NEW') |
| 3402 | |
| 3403 | # Gate is reset and only B's merge job is queued because |
| 3404 | # window shrunk to 1. |
| 3405 | self.assertEqual(len(self.builds), 1) |
| 3406 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3407 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3408 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3409 | self.waitUntilSettled() |
| 3410 | |
| 3411 | # Only B's test jobs are queued because window is still 1. |
| 3412 | self.assertEqual(len(self.builds), 2) |
| 3413 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3414 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3415 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3416 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3417 | self.waitUntilSettled() |
| 3418 | |
| 3419 | # B was successfully merged so window is increased to 2. |
| 3420 | self.assertEqual(queue.window, 2) |
| 3421 | self.assertEqual(queue.window_floor, 1) |
| 3422 | self.assertEqual(B.data['status'], 'MERGED') |
| 3423 | |
| 3424 | # Only C is left and its merge job is queued. |
| 3425 | self.assertEqual(len(self.builds), 1) |
| 3426 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3427 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3428 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3429 | self.waitUntilSettled() |
| 3430 | |
| 3431 | # After successful merge job the test jobs for C are queued. |
| 3432 | self.assertEqual(len(self.builds), 2) |
| 3433 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3434 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3435 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3436 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3437 | self.waitUntilSettled() |
| 3438 | |
| 3439 | # C successfully merged so window is bumped to 3. |
| 3440 | self.assertEqual(queue.window, 3) |
| 3441 | self.assertEqual(queue.window_floor, 1) |
| 3442 | self.assertEqual(C.data['status'], 'MERGED') |
| 3443 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3444 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3445 | def test_queue_rate_limiting_dependent(self): |
| 3446 | "Test that DependentPipelines are rate limited with dep in window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3447 | self.updateConfigLayout( |
| 3448 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3449 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3450 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3451 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3452 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3453 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3454 | |
| 3455 | B.setDependsOn(A, 1) |
| 3456 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3457 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3458 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3459 | A.addApproval('code-review', 2) |
| 3460 | B.addApproval('code-review', 2) |
| 3461 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3462 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3463 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3464 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3465 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3466 | self.waitUntilSettled() |
| 3467 | |
| 3468 | # Only A and B will have their merge jobs queued because |
| 3469 | # window is 2. |
| 3470 | self.assertEqual(len(self.builds), 2) |
| 3471 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3472 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3473 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3474 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3475 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3476 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3477 | self.waitUntilSettled() |
| 3478 | |
| 3479 | # Only A and B will have their test jobs queued because |
| 3480 | # window is 2. |
| 3481 | self.assertEqual(len(self.builds), 4) |
| 3482 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3483 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3484 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3485 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3486 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3487 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3488 | self.waitUntilSettled() |
| 3489 | |
| 3490 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3491 | # A failed so window is reduced by 1 to 1. |
| 3492 | self.assertEqual(queue.window, 1) |
| 3493 | self.assertEqual(queue.window_floor, 1) |
| 3494 | self.assertEqual(A.data['status'], 'NEW') |
| 3495 | self.assertEqual(B.data['status'], 'NEW') |
| 3496 | |
| 3497 | # Gate is reset and only C's merge job is queued because |
| 3498 | # window shrunk to 1 and A and B were dequeued. |
| 3499 | self.assertEqual(len(self.builds), 1) |
| 3500 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3501 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3502 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3503 | self.waitUntilSettled() |
| 3504 | |
| 3505 | # Only C's test jobs are queued because window is still 1. |
| 3506 | self.assertEqual(len(self.builds), 2) |
| 3507 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3508 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3509 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3510 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3511 | self.waitUntilSettled() |
| 3512 | |
| 3513 | # C was successfully merged so window is increased to 2. |
| 3514 | self.assertEqual(queue.window, 2) |
| 3515 | self.assertEqual(queue.window_floor, 1) |
| 3516 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3517 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3518 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3519 | def test_worker_update_metadata(self): |
| 3520 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3521 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3522 | |
| 3523 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3524 | A.addApproval('code-review', 2) |
| 3525 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3526 | self.waitUntilSettled() |
| 3527 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3528 | self.assertEqual(len(self.executor.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3529 | |
| 3530 | self.log.debug('Current builds:') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3531 | self.log.debug(self.executor.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3532 | |
| 3533 | start = time.time() |
| 3534 | while True: |
| 3535 | if time.time() - start > 10: |
| 3536 | raise Exception("Timeout waiting for gearman server to report " |
| 3537 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3538 | build = self.executor.builds.values()[0] |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3539 | if build.worker.name == "My Worker": |
| 3540 | break |
| 3541 | else: |
| 3542 | time.sleep(0) |
| 3543 | |
| 3544 | self.log.debug(build) |
| 3545 | self.assertEqual("My Worker", build.worker.name) |
| 3546 | self.assertEqual("localhost", build.worker.hostname) |
| 3547 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3548 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3549 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3550 | self.assertEqual("v1.1", build.worker.version) |
| 3551 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3552 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3553 | self.executor_server.hold_jobs_in_build = False |
| 3554 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3555 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3556 | |
| 3557 | def test_footer_message(self): |
| 3558 | "Test a pipeline's footer message is correctly added to the report." |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3559 | self.updateConfigLayout('layout-footer-message') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3560 | self.sched.reconfigure(self.config) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3561 | |
| 3562 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3563 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3564 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3565 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3566 | self.waitUntilSettled() |
| 3567 | |
| 3568 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3569 | B.addApproval('code-review', 2) |
| 3570 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3571 | self.waitUntilSettled() |
| 3572 | |
| 3573 | self.assertEqual(2, len(self.smtp_messages)) |
| 3574 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3575 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3576 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3577 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3578 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3579 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3580 | For CI problems and help debugging, contact ci@example.org""" |
| 3581 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3582 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3583 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3584 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3585 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3586 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3587 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3588 | def test_merge_failure_reporters(self): |
| 3589 | """Check that the config is set up correctly""" |
| 3590 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3591 | self.updateConfigLayout( |
| 3592 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3593 | self.sched.reconfigure(self.config) |
| 3594 | self.registerJobs() |
| 3595 | |
| 3596 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3597 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3598 | "dependencies was unable to be automatically merged with the " |
| 3599 | "current state of its repository. Please rebase the change and " |
| 3600 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3601 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3602 | self.assertEqual( |
| 3603 | "The merge failed! For more information...", |
| 3604 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3605 | |
| 3606 | self.assertEqual( |
| 3607 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3608 | self.assertEqual( |
| 3609 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3610 | |
| 3611 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3612 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3613 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3614 | |
| 3615 | self.assertTrue( |
| 3616 | ( |
| 3617 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3618 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3619 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3620 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3621 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3622 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3623 | ) or ( |
| 3624 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3625 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3626 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3627 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3628 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3629 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3630 | ) |
| 3631 | ) |
| 3632 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3633 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3634 | def test_merge_failure_reports(self): |
| 3635 | """Check that when a change fails to merge the correct message is sent |
| 3636 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3637 | self.updateConfigLayout( |
| 3638 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3639 | self.sched.reconfigure(self.config) |
| 3640 | self.registerJobs() |
| 3641 | |
| 3642 | # Check a test failure isn't reported to SMTP |
| 3643 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3644 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3645 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3646 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3647 | self.waitUntilSettled() |
| 3648 | |
| 3649 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3650 | self.assertEqual(0, len(self.smtp_messages)) |
| 3651 | |
| 3652 | # Check a merge failure is reported to SMTP |
| 3653 | # B should be merged, but C will conflict with B |
| 3654 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3655 | B.addPatchset(['conflict']) |
| 3656 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3657 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3658 | B.addApproval('code-review', 2) |
| 3659 | C.addApproval('code-review', 2) |
| 3660 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3661 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3662 | self.waitUntilSettled() |
| 3663 | |
| 3664 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3665 | self.assertEqual(1, len(self.smtp_messages)) |
| 3666 | self.assertEqual('The merge failed! For more information...', |
| 3667 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3668 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3669 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3670 | def test_default_merge_failure_reports(self): |
| 3671 | """Check that the default merge failure reports are correct.""" |
| 3672 | |
| 3673 | # A should report success, B should report merge failure. |
| 3674 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3675 | A.addPatchset(['conflict']) |
| 3676 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3677 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3678 | A.addApproval('code-review', 2) |
| 3679 | B.addApproval('code-review', 2) |
| 3680 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3681 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3682 | self.waitUntilSettled() |
| 3683 | |
| 3684 | self.assertEqual(3, len(self.history)) # A jobs |
| 3685 | self.assertEqual(A.reported, 2) |
| 3686 | self.assertEqual(B.reported, 2) |
| 3687 | self.assertEqual(A.data['status'], 'MERGED') |
| 3688 | self.assertEqual(B.data['status'], 'NEW') |
| 3689 | self.assertIn('Build succeeded', A.messages[1]) |
| 3690 | self.assertIn('Merge Failed', B.messages[1]) |
| 3691 | self.assertIn('automatically merged', B.messages[1]) |
| 3692 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3693 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3694 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3695 | def test_client_get_running_jobs(self): |
| 3696 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3697 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3698 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3699 | A.addApproval('code-review', 2) |
| 3700 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3701 | self.waitUntilSettled() |
| 3702 | |
| 3703 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3704 | self.gearman_server.port) |
| 3705 | |
| 3706 | # Wait for gearman server to send the initial workData back to zuul |
| 3707 | start = time.time() |
| 3708 | while True: |
| 3709 | if time.time() - start > 10: |
| 3710 | raise Exception("Timeout waiting for gearman server to report " |
| 3711 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3712 | build = self.executor_client.builds.values()[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3713 | if build.worker.name == "My Worker": |
| 3714 | break |
| 3715 | else: |
| 3716 | time.sleep(0) |
| 3717 | |
| 3718 | running_items = client.get_running_jobs() |
| 3719 | |
| 3720 | self.assertEqual(1, len(running_items)) |
| 3721 | running_item = running_items[0] |
| 3722 | self.assertEqual([], running_item['failing_reasons']) |
| 3723 | self.assertEqual([], running_item['items_behind']) |
| 3724 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3725 | self.assertEqual(None, running_item['item_ahead']) |
| 3726 | self.assertEqual('org/project', running_item['project']) |
| 3727 | self.assertEqual(None, running_item['remaining_time']) |
| 3728 | self.assertEqual(True, running_item['active']) |
| 3729 | self.assertEqual('1,1', running_item['id']) |
| 3730 | |
| 3731 | self.assertEqual(3, len(running_item['jobs'])) |
| 3732 | for job in running_item['jobs']: |
| 3733 | if job['name'] == 'project-merge': |
| 3734 | self.assertEqual('project-merge', job['name']) |
| 3735 | self.assertEqual('gate', job['pipeline']) |
| 3736 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3737 | self.assertEqual('https://server/job/project-merge/0/', |
| 3738 | job['url']) |
| 3739 | self.assertEqual(7, len(job['worker'])) |
| 3740 | self.assertEqual(False, job['canceled']) |
| 3741 | self.assertEqual(True, job['voting']) |
| 3742 | self.assertEqual(None, job['result']) |
| 3743 | self.assertEqual('gate', job['pipeline']) |
| 3744 | break |
| 3745 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3746 | self.executor_server.hold_jobs_in_build = False |
| 3747 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3748 | self.waitUntilSettled() |
| 3749 | |
| 3750 | running_items = client.get_running_jobs() |
| 3751 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3752 | |
| 3753 | def test_nonvoting_pipeline(self): |
| 3754 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3755 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3756 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3757 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3758 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3759 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3760 | |
| 3761 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3762 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3763 | self.assertEqual( |
| 3764 | self.getJobFromHistory('experimental-project-test').result, |
| 3765 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3766 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3767 | |
| 3768 | def test_crd_gate(self): |
| 3769 | "Test cross-repo dependencies" |
| 3770 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3771 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3772 | A.addApproval('code-review', 2) |
| 3773 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3774 | |
| 3775 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3776 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3777 | AM2.setMerged() |
| 3778 | AM1.setMerged() |
| 3779 | |
| 3780 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3781 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3782 | BM2.setMerged() |
| 3783 | BM1.setMerged() |
| 3784 | |
| 3785 | # A -> AM1 -> AM2 |
| 3786 | # B -> BM1 -> BM2 |
| 3787 | # A Depends-On: B |
| 3788 | # M2 is here to make sure it is never queried. If it is, it |
| 3789 | # means zuul is walking down the entire history of merged |
| 3790 | # changes. |
| 3791 | |
| 3792 | B.setDependsOn(BM1, 1) |
| 3793 | BM1.setDependsOn(BM2, 1) |
| 3794 | |
| 3795 | A.setDependsOn(AM1, 1) |
| 3796 | AM1.setDependsOn(AM2, 1) |
| 3797 | |
| 3798 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3799 | A.subject, B.data['id']) |
| 3800 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3801 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3802 | self.waitUntilSettled() |
| 3803 | |
| 3804 | self.assertEqual(A.data['status'], 'NEW') |
| 3805 | self.assertEqual(B.data['status'], 'NEW') |
| 3806 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3807 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3808 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3809 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3810 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3811 | B.addApproval('approved', 1) |
| 3812 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3813 | self.waitUntilSettled() |
| 3814 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3815 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3816 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3817 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3818 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3819 | self.executor_server.hold_jobs_in_build = False |
| 3820 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3821 | self.waitUntilSettled() |
| 3822 | |
| 3823 | self.assertEqual(AM2.queried, 0) |
| 3824 | self.assertEqual(BM2.queried, 0) |
| 3825 | self.assertEqual(A.data['status'], 'MERGED') |
| 3826 | self.assertEqual(B.data['status'], 'MERGED') |
| 3827 | self.assertEqual(A.reported, 2) |
| 3828 | self.assertEqual(B.reported, 2) |
| 3829 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3830 | changes = self.getJobFromHistory( |
| 3831 | 'project-merge', 'org/project1').changes |
| 3832 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3833 | |
| 3834 | def test_crd_branch(self): |
| 3835 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3836 | |
| 3837 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3838 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3839 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3840 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3841 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3842 | A.addApproval('code-review', 2) |
| 3843 | B.addApproval('code-review', 2) |
| 3844 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3845 | |
| 3846 | # A Depends-On: B+C |
| 3847 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3848 | A.subject, B.data['id']) |
| 3849 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3850 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3851 | B.addApproval('approved', 1) |
| 3852 | C.addApproval('approved', 1) |
| 3853 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3854 | self.waitUntilSettled() |
| 3855 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3856 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3857 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3858 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3859 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3860 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3861 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3862 | self.executor_server.hold_jobs_in_build = False |
| 3863 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3864 | self.waitUntilSettled() |
| 3865 | |
| 3866 | self.assertEqual(A.data['status'], 'MERGED') |
| 3867 | self.assertEqual(B.data['status'], 'MERGED') |
| 3868 | self.assertEqual(C.data['status'], 'MERGED') |
| 3869 | self.assertEqual(A.reported, 2) |
| 3870 | self.assertEqual(B.reported, 2) |
| 3871 | self.assertEqual(C.reported, 2) |
| 3872 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3873 | changes = self.getJobFromHistory( |
| 3874 | 'project-merge', 'org/project1').changes |
| 3875 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3876 | |
| 3877 | def test_crd_multiline(self): |
| 3878 | "Test multiple depends-on lines in commit" |
| 3879 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3880 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3881 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3882 | A.addApproval('code-review', 2) |
| 3883 | B.addApproval('code-review', 2) |
| 3884 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3885 | |
| 3886 | # A Depends-On: B+C |
| 3887 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3888 | A.subject, B.data['id'], C.data['id']) |
| 3889 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3890 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3891 | B.addApproval('approved', 1) |
| 3892 | C.addApproval('approved', 1) |
| 3893 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3894 | self.waitUntilSettled() |
| 3895 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3896 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3897 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3898 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3899 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3900 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3901 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3902 | self.executor_server.hold_jobs_in_build = False |
| 3903 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3904 | self.waitUntilSettled() |
| 3905 | |
| 3906 | self.assertEqual(A.data['status'], 'MERGED') |
| 3907 | self.assertEqual(B.data['status'], 'MERGED') |
| 3908 | self.assertEqual(C.data['status'], 'MERGED') |
| 3909 | self.assertEqual(A.reported, 2) |
| 3910 | self.assertEqual(B.reported, 2) |
| 3911 | self.assertEqual(C.reported, 2) |
| 3912 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3913 | changes = self.getJobFromHistory( |
| 3914 | 'project-merge', 'org/project1').changes |
| 3915 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3916 | |
| 3917 | def test_crd_unshared_gate(self): |
| 3918 | "Test cross-repo dependencies in unshared gate queues" |
| 3919 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3920 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3921 | A.addApproval('code-review', 2) |
| 3922 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3923 | |
| 3924 | # A Depends-On: B |
| 3925 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3926 | A.subject, B.data['id']) |
| 3927 | |
| 3928 | # A and B do not share a queue, make sure that A is unable to |
| 3929 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3930 | B.addApproval('approved', 1) |
| 3931 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3932 | self.waitUntilSettled() |
| 3933 | |
| 3934 | self.assertEqual(A.data['status'], 'NEW') |
| 3935 | self.assertEqual(B.data['status'], 'NEW') |
| 3936 | self.assertEqual(A.reported, 0) |
| 3937 | self.assertEqual(B.reported, 0) |
| 3938 | self.assertEqual(len(self.history), 0) |
| 3939 | |
| 3940 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3941 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3942 | self.waitUntilSettled() |
| 3943 | |
| 3944 | self.assertEqual(B.data['status'], 'MERGED') |
| 3945 | self.assertEqual(B.reported, 2) |
| 3946 | |
| 3947 | # Now that B is merged, A should be able to be enqueued and |
| 3948 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3949 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3950 | self.waitUntilSettled() |
| 3951 | |
| 3952 | self.assertEqual(A.data['status'], 'MERGED') |
| 3953 | self.assertEqual(A.reported, 2) |
| 3954 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3955 | def test_crd_gate_reverse(self): |
| 3956 | "Test reverse cross-repo dependencies" |
| 3957 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3958 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3959 | A.addApproval('code-review', 2) |
| 3960 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3961 | |
| 3962 | # A Depends-On: B |
| 3963 | |
| 3964 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3965 | A.subject, B.data['id']) |
| 3966 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3967 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3968 | self.waitUntilSettled() |
| 3969 | |
| 3970 | self.assertEqual(A.data['status'], 'NEW') |
| 3971 | self.assertEqual(B.data['status'], 'NEW') |
| 3972 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3973 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3974 | A.addApproval('approved', 1) |
| 3975 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3976 | self.waitUntilSettled() |
| 3977 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3978 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3979 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3980 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3981 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3982 | self.executor_server.hold_jobs_in_build = False |
| 3983 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3984 | self.waitUntilSettled() |
| 3985 | |
| 3986 | self.assertEqual(A.data['status'], 'MERGED') |
| 3987 | self.assertEqual(B.data['status'], 'MERGED') |
| 3988 | self.assertEqual(A.reported, 2) |
| 3989 | self.assertEqual(B.reported, 2) |
| 3990 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3991 | changes = self.getJobFromHistory( |
| 3992 | 'project-merge', 'org/project1').changes |
| 3993 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3994 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3995 | def test_crd_cycle(self): |
| 3996 | "Test cross-repo dependency cycles" |
| 3997 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3998 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3999 | A.addApproval('code-review', 2) |
| 4000 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4001 | |
| 4002 | # A -> B -> A (via commit-depends) |
| 4003 | |
| 4004 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4005 | A.subject, B.data['id']) |
| 4006 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4007 | B.subject, A.data['id']) |
| 4008 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4009 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4010 | self.waitUntilSettled() |
| 4011 | |
| 4012 | self.assertEqual(A.reported, 0) |
| 4013 | self.assertEqual(B.reported, 0) |
| 4014 | self.assertEqual(A.data['status'], 'NEW') |
| 4015 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4016 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4017 | def test_crd_gate_unknown(self): |
| 4018 | "Test unknown projects in dependent pipeline" |
| 4019 | self.init_repo("org/unknown") |
| 4020 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4021 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4022 | A.addApproval('code-review', 2) |
| 4023 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4024 | |
| 4025 | # A Depends-On: B |
| 4026 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4027 | A.subject, B.data['id']) |
| 4028 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4029 | B.addApproval('approved', 1) |
| 4030 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4031 | self.waitUntilSettled() |
| 4032 | |
| 4033 | # Unknown projects cannot share a queue with any other |
| 4034 | # since they don't have common jobs with any other (they have no jobs). |
| 4035 | # Changes which depend on unknown project changes |
| 4036 | # should not be processed in dependent pipeline |
| 4037 | self.assertEqual(A.data['status'], 'NEW') |
| 4038 | self.assertEqual(B.data['status'], 'NEW') |
| 4039 | self.assertEqual(A.reported, 0) |
| 4040 | self.assertEqual(B.reported, 0) |
| 4041 | self.assertEqual(len(self.history), 0) |
| 4042 | |
| 4043 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4044 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4045 | B.setMerged() |
| 4046 | self.waitUntilSettled() |
| 4047 | self.assertEqual(len(self.history), 0) |
| 4048 | |
| 4049 | # Now that B is merged, A should be able to be enqueued and |
| 4050 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4051 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4052 | self.waitUntilSettled() |
| 4053 | |
| 4054 | self.assertEqual(A.data['status'], 'MERGED') |
| 4055 | self.assertEqual(A.reported, 2) |
| 4056 | self.assertEqual(B.data['status'], 'MERGED') |
| 4057 | self.assertEqual(B.reported, 0) |
| 4058 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4059 | def test_crd_check(self): |
| 4060 | "Test cross-repo dependencies in independent pipelines" |
| 4061 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4062 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4063 | self.gearman_server.hold_jobs_in_queue = True |
| 4064 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4065 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4066 | |
| 4067 | # A Depends-On: B |
| 4068 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4069 | A.subject, B.data['id']) |
| 4070 | |
| 4071 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4072 | self.waitUntilSettled() |
| 4073 | |
| 4074 | queue = self.gearman_server.getQueue() |
| 4075 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 4076 | self.gearman_server.hold_jobs_in_queue = False |
| 4077 | self.gearman_server.release() |
| 4078 | self.waitUntilSettled() |
| 4079 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4080 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4081 | self.waitUntilSettled() |
| 4082 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4083 | 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] | 4084 | repo = git.Repo(path) |
| 4085 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4086 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4087 | correct_messages = [ |
| 4088 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4089 | self.assertEqual(repo_messages, correct_messages) |
| 4090 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4091 | 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] | 4092 | repo = git.Repo(path) |
| 4093 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4094 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4095 | correct_messages = [ |
| 4096 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4097 | self.assertEqual(repo_messages, correct_messages) |
| 4098 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4099 | self.executor_server.hold_jobs_in_build = False |
| 4100 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4101 | self.waitUntilSettled() |
| 4102 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4103 | self.assertEqual(A.data['status'], 'NEW') |
| 4104 | self.assertEqual(B.data['status'], 'NEW') |
| 4105 | self.assertEqual(A.reported, 1) |
| 4106 | self.assertEqual(B.reported, 0) |
| 4107 | |
| 4108 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4109 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4110 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4111 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4112 | def test_crd_check_git_depends(self): |
| 4113 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4114 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4115 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4116 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4117 | |
| 4118 | # Add two git-dependent changes and make sure they both report |
| 4119 | # success. |
| 4120 | B.setDependsOn(A, 1) |
| 4121 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4122 | self.waitUntilSettled() |
| 4123 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4124 | self.waitUntilSettled() |
| 4125 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4126 | self.orderedRelease() |
| 4127 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4128 | self.waitUntilSettled() |
| 4129 | |
| 4130 | self.assertEqual(A.data['status'], 'NEW') |
| 4131 | self.assertEqual(B.data['status'], 'NEW') |
| 4132 | self.assertEqual(A.reported, 1) |
| 4133 | self.assertEqual(B.reported, 1) |
| 4134 | |
| 4135 | self.assertEqual(self.history[0].changes, '1,1') |
| 4136 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4137 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4138 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4139 | |
| 4140 | self.assertIn('Build succeeded', A.messages[0]) |
| 4141 | self.assertIn('Build succeeded', B.messages[0]) |
| 4142 | |
| 4143 | def test_crd_check_duplicate(self): |
| 4144 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4145 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4146 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4147 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4148 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4149 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4150 | |
| 4151 | # Add two git-dependent changes... |
| 4152 | B.setDependsOn(A, 1) |
| 4153 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4154 | self.waitUntilSettled() |
| 4155 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4156 | |
| 4157 | # ...make sure the live one is not duplicated... |
| 4158 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4159 | self.waitUntilSettled() |
| 4160 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4161 | |
| 4162 | # ...but the non-live one is able to be. |
| 4163 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4164 | self.waitUntilSettled() |
| 4165 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4166 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4167 | # Release jobs in order to avoid races with change A jobs |
| 4168 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4169 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4170 | self.executor_server.hold_jobs_in_build = False |
| 4171 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4172 | self.waitUntilSettled() |
| 4173 | |
| 4174 | self.assertEqual(A.data['status'], 'NEW') |
| 4175 | self.assertEqual(B.data['status'], 'NEW') |
| 4176 | self.assertEqual(A.reported, 1) |
| 4177 | self.assertEqual(B.reported, 1) |
| 4178 | |
| 4179 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4180 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4181 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4182 | |
| 4183 | self.assertIn('Build succeeded', A.messages[0]) |
| 4184 | self.assertIn('Build succeeded', B.messages[0]) |
| 4185 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4186 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4187 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4188 | |
| 4189 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4190 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4191 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4192 | |
| 4193 | # A Depends-On: B |
| 4194 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4195 | A.subject, B.data['id']) |
| 4196 | |
| 4197 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4198 | self.waitUntilSettled() |
| 4199 | |
| 4200 | self.sched.reconfigure(self.config) |
| 4201 | |
| 4202 | # Make sure the items still share a change queue, and the |
| 4203 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4204 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4205 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4206 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4207 | first_item = queue.queue[0] |
| 4208 | for item in queue.queue: |
| 4209 | self.assertEqual(item.queue, first_item.queue) |
| 4210 | self.assertFalse(first_item.live) |
| 4211 | self.assertTrue(queue.queue[1].live) |
| 4212 | |
| 4213 | self.gearman_server.hold_jobs_in_queue = False |
| 4214 | self.gearman_server.release() |
| 4215 | self.waitUntilSettled() |
| 4216 | |
| 4217 | self.assertEqual(A.data['status'], 'NEW') |
| 4218 | self.assertEqual(B.data['status'], 'NEW') |
| 4219 | self.assertEqual(A.reported, 1) |
| 4220 | self.assertEqual(B.reported, 0) |
| 4221 | |
| 4222 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4223 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4224 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4225 | def test_crd_check_reconfiguration(self): |
| 4226 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4227 | |
| 4228 | def test_crd_undefined_project(self): |
| 4229 | """Test that undefined projects in dependencies are handled for |
| 4230 | independent pipelines""" |
| 4231 | # It's a hack for fake gerrit, |
| 4232 | # as it implies repo creation upon the creation of any change |
| 4233 | self.init_repo("org/unknown") |
| 4234 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4235 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4236 | @skip("Disabled for early v3 development") |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4237 | def test_crd_check_ignore_dependencies(self): |
| 4238 | "Test cross-repo dependencies can be ignored" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4239 | self.updateConfigLayout( |
| 4240 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4241 | self.sched.reconfigure(self.config) |
| 4242 | self.registerJobs() |
| 4243 | |
| 4244 | self.gearman_server.hold_jobs_in_queue = True |
| 4245 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4246 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4247 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4248 | |
| 4249 | # A Depends-On: B |
| 4250 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4251 | A.subject, B.data['id']) |
| 4252 | # C git-depends on B |
| 4253 | C.setDependsOn(B, 1) |
| 4254 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4255 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4256 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4257 | self.waitUntilSettled() |
| 4258 | |
| 4259 | # Make sure none of the items share a change queue, and all |
| 4260 | # are live. |
| 4261 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4262 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4263 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4264 | for item in check_pipeline.getAllItems(): |
| 4265 | self.assertTrue(item.live) |
| 4266 | |
| 4267 | self.gearman_server.hold_jobs_in_queue = False |
| 4268 | self.gearman_server.release() |
| 4269 | self.waitUntilSettled() |
| 4270 | |
| 4271 | self.assertEqual(A.data['status'], 'NEW') |
| 4272 | self.assertEqual(B.data['status'], 'NEW') |
| 4273 | self.assertEqual(C.data['status'], 'NEW') |
| 4274 | self.assertEqual(A.reported, 1) |
| 4275 | self.assertEqual(B.reported, 1) |
| 4276 | self.assertEqual(C.reported, 1) |
| 4277 | |
| 4278 | # Each job should have tested exactly one change |
| 4279 | for job in self.history: |
| 4280 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4281 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4282 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4283 | def test_crd_check_transitive(self): |
| 4284 | "Test transitive cross-repo dependencies" |
| 4285 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4286 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4287 | # and C,2 (not C,1 which would indicate stale data in the |
| 4288 | # cache for B). |
| 4289 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4290 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4291 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4292 | |
| 4293 | # A Depends-On: B |
| 4294 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4295 | A.subject, B.data['id']) |
| 4296 | |
| 4297 | # B Depends-On: C |
| 4298 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4299 | B.subject, C.data['id']) |
| 4300 | |
| 4301 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4302 | self.waitUntilSettled() |
| 4303 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4304 | |
| 4305 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4306 | self.waitUntilSettled() |
| 4307 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4308 | |
| 4309 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4310 | self.waitUntilSettled() |
| 4311 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4312 | |
| 4313 | C.addPatchset() |
| 4314 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4315 | self.waitUntilSettled() |
| 4316 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4317 | |
| 4318 | A.addPatchset() |
| 4319 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4320 | self.waitUntilSettled() |
| 4321 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4322 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4323 | def test_crd_check_unknown(self): |
| 4324 | "Test unknown projects in independent pipeline" |
| 4325 | self.init_repo("org/unknown") |
| 4326 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4327 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4328 | # A Depends-On: B |
| 4329 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4330 | A.subject, B.data['id']) |
| 4331 | |
| 4332 | # Make sure zuul has seen an event on B. |
| 4333 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4334 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4335 | self.waitUntilSettled() |
| 4336 | |
| 4337 | self.assertEqual(A.data['status'], 'NEW') |
| 4338 | self.assertEqual(A.reported, 1) |
| 4339 | self.assertEqual(B.data['status'], 'NEW') |
| 4340 | self.assertEqual(B.reported, 0) |
| 4341 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4342 | def test_crd_cycle_join(self): |
| 4343 | "Test an updated change creates a cycle" |
| 4344 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4345 | |
| 4346 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4347 | self.waitUntilSettled() |
| 4348 | |
| 4349 | # Create B->A |
| 4350 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4351 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4352 | B.subject, A.data['id']) |
| 4353 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4354 | self.waitUntilSettled() |
| 4355 | |
| 4356 | # Update A to add A->B (a cycle). |
| 4357 | A.addPatchset() |
| 4358 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4359 | A.subject, B.data['id']) |
| 4360 | # Normally we would submit the patchset-created event for |
| 4361 | # processing here, however, we have no way of noting whether |
| 4362 | # the dependency cycle detection correctly raised an |
| 4363 | # exception, so instead, we reach into the source driver and |
| 4364 | # call the method that would ultimately be called by the event |
| 4365 | # processing. |
| 4366 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4367 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4368 | source = tenant.layout.pipelines['gate'].source |
| 4369 | |
| 4370 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4371 | # it easier for users to create events for testing. |
| 4372 | event = zuul.model.TriggerEvent() |
| 4373 | event.trigger_name = 'gerrit' |
| 4374 | event.change_number = '1' |
| 4375 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4376 | with testtools.ExpectedException( |
| 4377 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4378 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4379 | self.log.debug("Got expected dependency cycle exception") |
| 4380 | |
| 4381 | # Now if we update B to remove the depends-on, everything |
| 4382 | # should be okay. B; A->B |
| 4383 | |
| 4384 | B.addPatchset() |
| 4385 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4386 | |
| 4387 | source.getChange(event, True) |
| 4388 | event.change_number = '2' |
| 4389 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4390 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4391 | def test_disable_at(self): |
| 4392 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4393 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4394 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4395 | self.sched.reconfigure(self.config) |
| 4396 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4397 | tenant = self.sched.abide.tenants.get('openstack') |
| 4398 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4399 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4400 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4401 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4402 | |
| 4403 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4404 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4405 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4406 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4407 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4408 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4409 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4410 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4411 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4412 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4413 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4414 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4415 | self.executor_server.failJob('project-test1', A) |
| 4416 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4417 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4418 | self.executor_server.failJob('project-test1', D) |
| 4419 | self.executor_server.failJob('project-test1', E) |
| 4420 | self.executor_server.failJob('project-test1', F) |
| 4421 | self.executor_server.failJob('project-test1', G) |
| 4422 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4423 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4424 | self.executor_server.failJob('project-test1', J) |
| 4425 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4426 | |
| 4427 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4428 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4429 | self.waitUntilSettled() |
| 4430 | |
| 4431 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4432 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4433 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4434 | |
| 4435 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4436 | self.waitUntilSettled() |
| 4437 | |
| 4438 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4439 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4440 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4441 | |
| 4442 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4443 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4444 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4445 | self.waitUntilSettled() |
| 4446 | |
| 4447 | # We should be disabled now |
| 4448 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4449 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4450 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4451 | |
| 4452 | # We need to wait between each of these patches to make sure the |
| 4453 | # smtp messages come back in an expected order |
| 4454 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4455 | self.waitUntilSettled() |
| 4456 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4457 | self.waitUntilSettled() |
| 4458 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4459 | self.waitUntilSettled() |
| 4460 | |
| 4461 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4462 | # leaving a message on each change |
| 4463 | self.assertEqual(1, len(A.messages)) |
| 4464 | self.assertIn('Build failed.', A.messages[0]) |
| 4465 | self.assertEqual(1, len(B.messages)) |
| 4466 | self.assertIn('Build failed.', B.messages[0]) |
| 4467 | self.assertEqual(1, len(C.messages)) |
| 4468 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4469 | self.assertEqual(1, len(D.messages)) |
| 4470 | self.assertIn('Build failed.', D.messages[0]) |
| 4471 | self.assertEqual(1, len(E.messages)) |
| 4472 | self.assertIn('Build failed.', E.messages[0]) |
| 4473 | self.assertEqual(1, len(F.messages)) |
| 4474 | self.assertIn('Build failed.', F.messages[0]) |
| 4475 | |
| 4476 | # The last 3 (GHI) would have only reported via smtp. |
| 4477 | self.assertEqual(3, len(self.smtp_messages)) |
| 4478 | self.assertEqual(0, len(G.messages)) |
| 4479 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4480 | self.assertIn( |
| 4481 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4482 | self.assertEqual(0, len(H.messages)) |
| 4483 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4484 | self.assertIn( |
| 4485 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4486 | self.assertEqual(0, len(I.messages)) |
| 4487 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4488 | self.assertIn( |
| 4489 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4490 | |
| 4491 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4492 | # comes out of disabled |
| 4493 | self.sched.reconfigure(self.config) |
| 4494 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4495 | tenant = self.sched.abide.tenants.get('openstack') |
| 4496 | |
| 4497 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4498 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4499 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4500 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4501 | |
| 4502 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4503 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4504 | self.waitUntilSettled() |
| 4505 | |
| 4506 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4507 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4508 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4509 | |
| 4510 | # J and K went back to gerrit |
| 4511 | self.assertEqual(1, len(J.messages)) |
| 4512 | self.assertIn('Build failed.', J.messages[0]) |
| 4513 | self.assertEqual(1, len(K.messages)) |
| 4514 | self.assertIn('Build failed.', K.messages[0]) |
| 4515 | # No more messages reported via smtp |
| 4516 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4517 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4518 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4519 | "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] | 4520 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4521 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4522 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4523 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4524 | self.waitUntilSettled() |
| 4525 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4526 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4527 | self.waitUntilSettled() |
| 4528 | |
| 4529 | self.assertEqual(len(self.builds), 2) |
| 4530 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4531 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4532 | self.waitUntilSettled() |
| 4533 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4534 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4535 | self.assertEqual(len(self.builds), 1, |
| 4536 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4537 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4538 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4539 | self.waitUntilSettled() |
| 4540 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4541 | self.executor_server.hold_jobs_in_build = False |
| 4542 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4543 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4544 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4545 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4546 | self.assertEqual(A.reported, 1) |
| 4547 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4548 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4549 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4550 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4551 | |
| 4552 | self.fake_nodepool.paused = True |
| 4553 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4554 | A.addApproval('code-review', 2) |
| 4555 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4556 | self.waitUntilSettled() |
| 4557 | |
| 4558 | self.zk.client.stop() |
| 4559 | self.zk.client.start() |
| 4560 | self.fake_nodepool.paused = False |
| 4561 | self.waitUntilSettled() |
| 4562 | |
| 4563 | self.assertEqual(A.data['status'], 'MERGED') |
| 4564 | self.assertEqual(A.reported, 2) |
| 4565 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4566 | def test_nodepool_failure(self): |
| 4567 | "Test that jobs are reported after a nodepool failure" |
| 4568 | |
| 4569 | self.fake_nodepool.paused = True |
| 4570 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4571 | A.addApproval('code-review', 2) |
| 4572 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4573 | self.waitUntilSettled() |
| 4574 | |
| 4575 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4576 | self.fake_nodepool.addFailRequest(req) |
| 4577 | |
| 4578 | self.fake_nodepool.paused = False |
| 4579 | self.waitUntilSettled() |
| 4580 | |
| 4581 | self.assertEqual(A.data['status'], 'NEW') |
| 4582 | self.assertEqual(A.reported, 2) |
| 4583 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4584 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4585 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4586 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4587 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4588 | class TestDependencyGraph(ZuulTestCase): |
| 4589 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4590 | |
| 4591 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4592 | "Test a job in a dependency graph is queued only once" |
| 4593 | # Job dependencies, starting with A |
| 4594 | # A |
| 4595 | # / \ |
| 4596 | # B C |
| 4597 | # / \ / \ |
| 4598 | # D F E |
| 4599 | # | |
| 4600 | # G |
| 4601 | |
| 4602 | self.executor_server.hold_jobs_in_build = True |
| 4603 | change = self.fake_gerrit.addFakeChange( |
| 4604 | 'org/project', 'master', 'change') |
| 4605 | change.addApproval('code-review', 2) |
| 4606 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4607 | |
| 4608 | self.waitUntilSettled() |
| 4609 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4610 | |
| 4611 | self.executor_server.release('A') |
| 4612 | self.waitUntilSettled() |
| 4613 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4614 | |
| 4615 | self.executor_server.release('B') |
| 4616 | self.waitUntilSettled() |
| 4617 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4618 | |
| 4619 | self.executor_server.release('D') |
| 4620 | self.waitUntilSettled() |
| 4621 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4622 | |
| 4623 | self.executor_server.release('C') |
| 4624 | self.waitUntilSettled() |
| 4625 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4626 | |
| 4627 | self.executor_server.release('F') |
| 4628 | self.waitUntilSettled() |
| 4629 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4630 | |
| 4631 | self.executor_server.release('G') |
| 4632 | self.waitUntilSettled() |
| 4633 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4634 | |
| 4635 | self.executor_server.release('E') |
| 4636 | self.waitUntilSettled() |
| 4637 | self.assertEqual(len(self.builds), 0) |
| 4638 | |
| 4639 | self.executor_server.hold_jobs_in_build = False |
| 4640 | self.executor_server.release() |
| 4641 | self.waitUntilSettled() |
| 4642 | |
| 4643 | self.assertEqual(len(self.builds), 0) |
| 4644 | self.assertEqual(len(self.history), 7) |
| 4645 | |
| 4646 | self.assertEqual(change.data['status'], 'MERGED') |
| 4647 | self.assertEqual(change.reported, 2) |
| 4648 | |
| 4649 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4650 | "Test that a job waits till all dependencies are successful" |
| 4651 | # Job dependencies, starting with A |
| 4652 | # A |
| 4653 | # / \ |
| 4654 | # B C* |
| 4655 | # / \ / \ |
| 4656 | # D F E |
| 4657 | # | |
| 4658 | # G |
| 4659 | |
| 4660 | self.executor_server.hold_jobs_in_build = True |
| 4661 | change = self.fake_gerrit.addFakeChange( |
| 4662 | 'org/project', 'master', 'change') |
| 4663 | change.addApproval('code-review', 2) |
| 4664 | |
| 4665 | self.executor_server.failJob('C', change) |
| 4666 | |
| 4667 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4668 | |
| 4669 | self.waitUntilSettled() |
| 4670 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4671 | |
| 4672 | self.executor_server.release('A') |
| 4673 | self.waitUntilSettled() |
| 4674 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4675 | |
| 4676 | self.executor_server.release('B') |
| 4677 | self.waitUntilSettled() |
| 4678 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4679 | |
| 4680 | self.executor_server.release('D') |
| 4681 | self.waitUntilSettled() |
| 4682 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4683 | |
| 4684 | self.executor_server.release('C') |
| 4685 | self.waitUntilSettled() |
| 4686 | self.assertEqual(len(self.builds), 0) |
| 4687 | |
| 4688 | self.executor_server.hold_jobs_in_build = False |
| 4689 | self.executor_server.release() |
| 4690 | self.waitUntilSettled() |
| 4691 | |
| 4692 | self.assertEqual(len(self.builds), 0) |
| 4693 | self.assertEqual(len(self.history), 4) |
| 4694 | |
| 4695 | self.assertEqual(change.data['status'], 'NEW') |
| 4696 | self.assertEqual(change.reported, 2) |
| 4697 | |
| 4698 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4699 | class TestDuplicatePipeline(ZuulTestCase): |
| 4700 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4701 | |
| 4702 | def test_duplicate_pipelines(self): |
| 4703 | "Test that a change matching multiple pipelines works" |
| 4704 | |
| 4705 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4706 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4707 | self.waitUntilSettled() |
| 4708 | |
| 4709 | self.assertHistory([ |
| 4710 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4711 | pipeline='dup1'), |
| 4712 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4713 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4714 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4715 | |
| 4716 | self.assertEqual(len(A.messages), 2) |
| 4717 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4718 | if 'dup1' in A.messages[0]: |
| 4719 | self.assertIn('dup1', A.messages[0]) |
| 4720 | self.assertNotIn('dup2', A.messages[0]) |
| 4721 | self.assertIn('project-test1', A.messages[0]) |
| 4722 | self.assertIn('dup2', A.messages[1]) |
| 4723 | self.assertNotIn('dup1', A.messages[1]) |
| 4724 | self.assertIn('project-test1', A.messages[1]) |
| 4725 | else: |
| 4726 | self.assertIn('dup1', A.messages[1]) |
| 4727 | self.assertNotIn('dup2', A.messages[1]) |
| 4728 | self.assertIn('project-test1', A.messages[1]) |
| 4729 | self.assertIn('dup2', A.messages[0]) |
| 4730 | self.assertNotIn('dup1', A.messages[0]) |
| 4731 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4732 | |
| 4733 | |
| 4734 | class TestSchedulerOneJobProject(ZuulTestCase): |
| 4735 | tenant_config_file = 'config/one-job-project/main.yaml' |
| 4736 | |
| 4737 | def test_one_job_project(self): |
| 4738 | "Test that queueing works with one job" |
| 4739 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4740 | 'master', 'A') |
| 4741 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4742 | 'master', 'B') |
| 4743 | A.addApproval('code-review', 2) |
| 4744 | B.addApproval('code-review', 2) |
| 4745 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4746 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4747 | self.waitUntilSettled() |
| 4748 | |
| 4749 | self.assertEqual(A.data['status'], 'MERGED') |
| 4750 | self.assertEqual(A.reported, 2) |
| 4751 | self.assertEqual(B.data['status'], 'MERGED') |
| 4752 | self.assertEqual(B.reported, 2) |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4753 | |
| 4754 | |
| 4755 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4756 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4757 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4758 | def test_job_from_templates_executed(self): |
| 4759 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4760 | |
| 4761 | A = self.fake_gerrit.addFakeChange( |
| 4762 | 'org/templated-project', 'master', 'A') |
| 4763 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4764 | self.waitUntilSettled() |
| 4765 | |
| 4766 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4767 | 'SUCCESS') |
| 4768 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4769 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4770 | |
| 4771 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4772 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4773 | |
| 4774 | A = self.fake_gerrit.addFakeChange( |
| 4775 | 'org/layered-project', 'master', 'A') |
| 4776 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4777 | self.waitUntilSettled() |
| 4778 | |
| 4779 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4780 | 'SUCCESS') |
| 4781 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4782 | 'SUCCESS') |
| 4783 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4784 | ).result, 'SUCCESS') |
| 4785 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4786 | ).result, 'SUCCESS') |
| 4787 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4788 | ).result, 'SUCCESS') |
| 4789 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4790 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4791 | |
| 4792 | |
| 4793 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4794 | tenant_config_file = 'config/success-url/main.yaml' |
| 4795 | |
| 4796 | def test_success_url(self): |
| 4797 | "Ensure bad build params are ignored" |
| 4798 | self.sched.reconfigure(self.config) |
| 4799 | self.init_repo('org/docs') |
| 4800 | |
| 4801 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4802 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4803 | self.waitUntilSettled() |
| 4804 | |
| 4805 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4806 | self.assertEqual(len(self.history), 2) |
| 4807 | |
| 4808 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4809 | for build in self.history: |
| 4810 | if build.name == 'docs-draft-test': |
| 4811 | uuid = build.uuid[:7] |
| 4812 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4813 | |
| 4814 | # Two msgs: 'Starting...' + results |
| 4815 | self.assertEqual(len(self.smtp_messages), 2) |
| 4816 | body = self.smtp_messages[1]['body'].splitlines() |
| 4817 | self.assertEqual('Build succeeded.', body[0]) |
| 4818 | |
| 4819 | self.assertIn( |
| 4820 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4821 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4822 | body[2]) |
| 4823 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4824 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4825 | self.assertIn( |
| 4826 | '- docs-draft-test2 https://server/job', |
| 4827 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4828 | |
| 4829 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4830 | class TestSchedulerMerges(ZuulTestCase): |
| 4831 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4832 | |
| 4833 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4834 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4835 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4836 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4837 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4838 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4839 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4840 | A.addApproval('code-review', 2) |
| 4841 | B.addApproval('code-review', 2) |
| 4842 | C.addApproval('code-review', 2) |
| 4843 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4844 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4845 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4846 | self.waitUntilSettled() |
| 4847 | |
| 4848 | build = self.builds[-1] |
| 4849 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4850 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4851 | path = os.path.join(build.jobdir.src_root, project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4852 | repo = git.Repo(path) |
| 4853 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4854 | repo_messages.reverse() |
| 4855 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4856 | self.executor_server.hold_jobs_in_build = False |
| 4857 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4858 | self.waitUntilSettled() |
| 4859 | |
| 4860 | return repo_messages |
| 4861 | |
| 4862 | def _test_merge(self, mode): |
| 4863 | us_path = os.path.join( |
| 4864 | self.upstream_root, 'org/project-%s' % mode) |
| 4865 | expected_messages = [ |
| 4866 | 'initial commit', |
| 4867 | 'add content from fixture', |
| 4868 | # the intermediate commits order is nondeterministic |
| 4869 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4870 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4871 | ] |
| 4872 | result = self._test_project_merge_mode(mode) |
| 4873 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4874 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4875 | |
| 4876 | def test_project_merge_mode_merge(self): |
| 4877 | self._test_merge('merge') |
| 4878 | |
| 4879 | def test_project_merge_mode_merge_resolve(self): |
| 4880 | self._test_merge('merge-resolve') |
| 4881 | |
| 4882 | def test_project_merge_mode_cherrypick(self): |
| 4883 | expected_messages = [ |
| 4884 | 'initial commit', |
| 4885 | 'add content from fixture', |
| 4886 | 'A-1', |
| 4887 | 'B-1', |
| 4888 | 'C-1'] |
| 4889 | result = self._test_project_merge_mode('cherry-pick') |
| 4890 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4891 | |
| 4892 | def test_merge_branch(self): |
| 4893 | "Test that the right commits are on alternate branches" |
| 4894 | self.create_branch('org/project-merge-branches', 'mp') |
| 4895 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4896 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4897 | A = self.fake_gerrit.addFakeChange( |
| 4898 | 'org/project-merge-branches', 'mp', 'A') |
| 4899 | B = self.fake_gerrit.addFakeChange( |
| 4900 | 'org/project-merge-branches', 'mp', 'B') |
| 4901 | C = self.fake_gerrit.addFakeChange( |
| 4902 | 'org/project-merge-branches', 'mp', 'C') |
| 4903 | A.addApproval('code-review', 2) |
| 4904 | B.addApproval('code-review', 2) |
| 4905 | C.addApproval('code-review', 2) |
| 4906 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4907 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4908 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4909 | self.waitUntilSettled() |
| 4910 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4911 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4912 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4913 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4914 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4915 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4916 | self.waitUntilSettled() |
| 4917 | |
| 4918 | build = self.builds[-1] |
| 4919 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 4920 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4921 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4922 | build.jobdir.src_root, 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4923 | repo = git.Repo(path) |
| 4924 | |
| 4925 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4926 | repo_messages.reverse() |
| 4927 | correct_messages = [ |
| 4928 | 'initial commit', |
| 4929 | 'add content from fixture', |
| 4930 | 'mp commit', |
| 4931 | 'A-1', 'B-1', 'C-1'] |
| 4932 | self.assertEqual(repo_messages, correct_messages) |
| 4933 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4934 | self.executor_server.hold_jobs_in_build = False |
| 4935 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4936 | self.waitUntilSettled() |
| 4937 | |
| 4938 | def test_merge_multi_branch(self): |
| 4939 | "Test that dependent changes on multiple branches are merged" |
| 4940 | self.create_branch('org/project-merge-branches', 'mp') |
| 4941 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4942 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4943 | A = self.fake_gerrit.addFakeChange( |
| 4944 | 'org/project-merge-branches', 'master', 'A') |
| 4945 | B = self.fake_gerrit.addFakeChange( |
| 4946 | 'org/project-merge-branches', 'mp', 'B') |
| 4947 | C = self.fake_gerrit.addFakeChange( |
| 4948 | 'org/project-merge-branches', 'master', 'C') |
| 4949 | A.addApproval('code-review', 2) |
| 4950 | B.addApproval('code-review', 2) |
| 4951 | C.addApproval('code-review', 2) |
| 4952 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4953 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4954 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4955 | self.waitUntilSettled() |
| 4956 | |
| 4957 | job_A = None |
| 4958 | for job in self.builds: |
| 4959 | if 'project-merge' in job.name: |
| 4960 | job_A = job |
| 4961 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 4962 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 4963 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 4964 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 4965 | |
| 4966 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4967 | job_A.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4968 | repo = git.Repo(path) |
| 4969 | repo_messages = [c.message.strip() |
| 4970 | for c in repo.iter_commits(ref_A)] |
| 4971 | repo_messages.reverse() |
| 4972 | correct_messages = [ |
| 4973 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4974 | self.assertEqual(repo_messages, correct_messages) |
| 4975 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4976 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4977 | self.waitUntilSettled() |
| 4978 | |
| 4979 | job_B = None |
| 4980 | for job in self.builds: |
| 4981 | if 'project-merge' in job.name: |
| 4982 | job_B = job |
| 4983 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 4984 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 4985 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 4986 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 4987 | |
| 4988 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4989 | job_B.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4990 | repo = git.Repo(path) |
| 4991 | repo_messages = [c.message.strip() |
| 4992 | for c in repo.iter_commits(ref_B)] |
| 4993 | repo_messages.reverse() |
| 4994 | correct_messages = [ |
| 4995 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4996 | self.assertEqual(repo_messages, correct_messages) |
| 4997 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4998 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4999 | self.waitUntilSettled() |
| 5000 | |
| 5001 | job_C = None |
| 5002 | for job in self.builds: |
| 5003 | if 'project-merge' in job.name: |
| 5004 | job_C = job |
| 5005 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 5006 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 5007 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 5008 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
| 5009 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5010 | job_C.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5011 | repo = git.Repo(path) |
| 5012 | repo_messages = [c.message.strip() |
| 5013 | for c in repo.iter_commits(ref_C)] |
| 5014 | |
| 5015 | repo_messages.reverse() |
| 5016 | correct_messages = [ |
| 5017 | 'initial commit', 'add content from fixture', |
| 5018 | 'A-1', 'C-1'] |
| 5019 | # Ensure the right commits are in the history for this ref |
| 5020 | self.assertEqual(repo_messages, correct_messages) |
| 5021 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5022 | self.executor_server.hold_jobs_in_build = False |
| 5023 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5024 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5025 | |
| 5026 | |
| 5027 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5028 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5029 | |
| 5030 | def test_semaphore_tenant_isolation(self): |
| 5031 | "Test semaphores in multiple tenants" |
| 5032 | |
| 5033 | self.waitUntilSettled() |
| 5034 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5035 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5036 | |
| 5037 | self.executor_server.hold_jobs_in_build = True |
| 5038 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5039 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5040 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5041 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5042 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5043 | self.assertFalse('test-semaphore' in |
| 5044 | tenant_one.semaphore_handler.semaphores) |
| 5045 | self.assertFalse('test-semaphore' in |
| 5046 | tenant_two.semaphore_handler.semaphores) |
| 5047 | |
| 5048 | # add patches to project1 of tenant-one |
| 5049 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5050 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5051 | self.waitUntilSettled() |
| 5052 | |
| 5053 | # one build of project1-test1 must run |
| 5054 | # semaphore of tenant-one must be acquired once |
| 5055 | # semaphore of tenant-two must not be acquired |
| 5056 | self.assertEqual(len(self.builds), 1) |
| 5057 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5058 | self.assertTrue('test-semaphore' in |
| 5059 | tenant_one.semaphore_handler.semaphores) |
| 5060 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5061 | 'test-semaphore', [])), 1) |
| 5062 | self.assertFalse('test-semaphore' in |
| 5063 | tenant_two.semaphore_handler.semaphores) |
| 5064 | |
| 5065 | # add patches to project2 of tenant-two |
| 5066 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5067 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5068 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5069 | self.waitUntilSettled() |
| 5070 | |
| 5071 | # one build of project1-test1 must run |
| 5072 | # two builds of project2-test1 must run |
| 5073 | # semaphore of tenant-one must be acquired once |
| 5074 | # semaphore of tenant-two must be acquired twice |
| 5075 | self.assertEqual(len(self.builds), 3) |
| 5076 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5077 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5078 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5079 | self.assertTrue('test-semaphore' in |
| 5080 | tenant_one.semaphore_handler.semaphores) |
| 5081 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5082 | 'test-semaphore', [])), 1) |
| 5083 | self.assertTrue('test-semaphore' in |
| 5084 | tenant_two.semaphore_handler.semaphores) |
| 5085 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5086 | 'test-semaphore', [])), 2) |
| 5087 | |
| 5088 | self.executor_server.release('project1-test1') |
| 5089 | self.waitUntilSettled() |
| 5090 | |
| 5091 | # one build of project1-test1 must run |
| 5092 | # two builds of project2-test1 must run |
| 5093 | # semaphore of tenant-one must be acquired once |
| 5094 | # semaphore of tenant-two must be acquired twice |
| 5095 | self.assertEqual(len(self.builds), 3) |
| 5096 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5097 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5098 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5099 | self.assertTrue('test-semaphore' in |
| 5100 | tenant_one.semaphore_handler.semaphores) |
| 5101 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5102 | 'test-semaphore', [])), 1) |
| 5103 | self.assertTrue('test-semaphore' in |
| 5104 | tenant_two.semaphore_handler.semaphores) |
| 5105 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5106 | 'test-semaphore', [])), 2) |
| 5107 | |
| 5108 | self.executor_server.release('project2-test1') |
| 5109 | self.waitUntilSettled() |
| 5110 | |
| 5111 | # one build of project1-test1 must run |
| 5112 | # one build of project2-test1 must run |
| 5113 | # semaphore of tenant-one must be acquired once |
| 5114 | # semaphore of tenant-two must be acquired once |
| 5115 | self.assertEqual(len(self.builds), 2) |
| 5116 | self.assertTrue('test-semaphore' in |
| 5117 | tenant_one.semaphore_handler.semaphores) |
| 5118 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5119 | 'test-semaphore', [])), 1) |
| 5120 | self.assertTrue('test-semaphore' in |
| 5121 | tenant_two.semaphore_handler.semaphores) |
| 5122 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5123 | 'test-semaphore', [])), 1) |
| 5124 | |
| 5125 | self.executor_server.hold_jobs_in_build = False |
| 5126 | self.executor_server.release() |
| 5127 | |
| 5128 | self.waitUntilSettled() |
| 5129 | |
| 5130 | # no build must run |
| 5131 | # semaphore of tenant-one must not be acquired |
| 5132 | # semaphore of tenant-two must not be acquired |
| 5133 | self.assertEqual(len(self.builds), 0) |
| 5134 | self.assertFalse('test-semaphore' in |
| 5135 | tenant_one.semaphore_handler.semaphores) |
| 5136 | self.assertFalse('test-semaphore' in |
| 5137 | tenant_two.semaphore_handler.semaphores) |
| 5138 | |
| 5139 | self.assertEqual(A.reported, 1) |
| 5140 | self.assertEqual(B.reported, 1) |
| 5141 | |
| 5142 | |
| 5143 | class TestSemaphoreInRepo(ZuulTestCase): |
| 5144 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5145 | |
| 5146 | def test_semaphore_in_repo(self): |
| 5147 | "Test semaphores in repo config" |
| 5148 | |
| 5149 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5150 | # max value should not be evaluated dynamically but must be updated |
| 5151 | # after the change lands. |
| 5152 | |
| 5153 | self.waitUntilSettled() |
| 5154 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5155 | |
| 5156 | in_repo_conf = textwrap.dedent( |
| 5157 | """ |
| 5158 | - job: |
| 5159 | name: project-test2 |
| 5160 | semaphore: test-semaphore |
| 5161 | |
| 5162 | - project: |
| 5163 | name: org/project |
| 5164 | tenant-one-gate: |
| 5165 | jobs: |
| 5166 | - project-test2 |
| 5167 | |
| 5168 | # the max value in dynamic layout must be ignored |
| 5169 | - semaphore: |
| 5170 | name: test-semaphore |
| 5171 | max: 2 |
| 5172 | """) |
| 5173 | |
| 5174 | in_repo_playbook = textwrap.dedent( |
| 5175 | """ |
| 5176 | - hosts: all |
| 5177 | tasks: [] |
| 5178 | """) |
| 5179 | |
| 5180 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5181 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5182 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5183 | files=file_dict) |
| 5184 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5185 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5186 | B.setDependsOn(A, 1) |
| 5187 | C.setDependsOn(A, 1) |
| 5188 | |
| 5189 | self.executor_server.hold_jobs_in_build = True |
| 5190 | |
| 5191 | A.addApproval('code-review', 2) |
| 5192 | B.addApproval('code-review', 2) |
| 5193 | C.addApproval('code-review', 2) |
| 5194 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5195 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5196 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5197 | self.waitUntilSettled() |
| 5198 | |
| 5199 | # check that the layout in a queue item still has max value of 1 |
| 5200 | # for test-semaphore |
| 5201 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5202 | queue = None |
| 5203 | for queue_candidate in pipeline.queues: |
| 5204 | if queue_candidate.name == 'org/project': |
| 5205 | queue = queue_candidate |
| 5206 | break |
| 5207 | queue_item = queue.queue[0] |
| 5208 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5209 | dynamic_test_semaphore = \ |
| 5210 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5211 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5212 | |
| 5213 | # one build must be in queue, one semaphores acquired |
| 5214 | self.assertEqual(len(self.builds), 1) |
| 5215 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5216 | self.assertTrue('test-semaphore' in |
| 5217 | tenant.semaphore_handler.semaphores) |
| 5218 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5219 | 'test-semaphore', [])), 1) |
| 5220 | |
| 5221 | self.executor_server.release('project-test2') |
| 5222 | self.waitUntilSettled() |
| 5223 | |
| 5224 | # change A must be merged |
| 5225 | self.assertEqual(A.data['status'], 'MERGED') |
| 5226 | self.assertEqual(A.reported, 2) |
| 5227 | |
| 5228 | # send change-merged event as the gerrit mock doesn't send it |
| 5229 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5230 | self.waitUntilSettled() |
| 5231 | |
| 5232 | # now that change A was merged, the new semaphore max must be effective |
| 5233 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5234 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5235 | |
| 5236 | # two builds must be in queue, two semaphores acquired |
| 5237 | self.assertEqual(len(self.builds), 2) |
| 5238 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5239 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5240 | self.assertTrue('test-semaphore' in |
| 5241 | tenant.semaphore_handler.semaphores) |
| 5242 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5243 | 'test-semaphore', [])), 2) |
| 5244 | |
| 5245 | self.executor_server.release('project-test2') |
| 5246 | self.waitUntilSettled() |
| 5247 | |
| 5248 | self.assertEqual(len(self.builds), 0) |
| 5249 | self.assertFalse('test-semaphore' in |
| 5250 | tenant.semaphore_handler.semaphores) |
| 5251 | |
| 5252 | self.executor_server.hold_jobs_in_build = False |
| 5253 | self.executor_server.release() |
| 5254 | |
| 5255 | self.waitUntilSettled() |
| 5256 | self.assertEqual(len(self.builds), 0) |
| 5257 | |
| 5258 | self.assertEqual(A.reported, 2) |
| 5259 | self.assertEqual(B.reported, 2) |
| 5260 | self.assertEqual(C.reported, 2) |