James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 17 | import gc |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 18 | import json |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 19 | import textwrap |
| 20 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 21 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 22 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 23 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | import time |
Clint Byrum | 03454a5 | 2017-05-26 17:14:02 -0700 | [diff] [blame] | 25 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 27 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 28 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 29 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 31 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 32 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 33 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 34 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 35 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 36 | from tests.base import ( |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | ZuulTestCase, |
| 38 | repack_repo, |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 39 | simple_layout, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 40 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 41 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 42 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 43 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 44 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 45 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 46 | def test_jobs_executed(self): |
| 47 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 48 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 49 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 50 | A.addApproval('code-review', 2) |
| 51 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 52 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 53 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 54 | 'SUCCESS') |
| 55 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 56 | 'SUCCESS') |
| 57 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 58 | 'SUCCESS') |
| 59 | self.assertEqual(A.data['status'], 'MERGED') |
| 60 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 61 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 62 | 'image1') |
Adam Gandelman | eace469 | 2017-02-07 15:18:36 -0800 | [diff] [blame] | 63 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 64 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 65 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 66 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 67 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 68 | value='1|g') |
| 69 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 70 | kind='ms') |
| 71 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 72 | value='1|c') |
| 73 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 74 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 75 | value='1|c') |
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.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 78 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 79 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 80 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 81 | for build in self.builds: |
| 82 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 83 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 84 | def test_initial_pipeline_gauges(self): |
| 85 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 86 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 87 | value='0|g') |
| 88 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 89 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 90 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 91 | def test_job_branch(self): |
| 92 | "Test the correct variant of a job runs on a branch" |
| 93 | self.create_branch('org/project', 'stable') |
| 94 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 95 | A.addApproval('code-review', 2) |
| 96 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 97 | self.waitUntilSettled() |
| 98 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 99 | 'SUCCESS') |
| 100 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 101 | 'SUCCESS') |
| 102 | self.assertEqual(A.data['status'], 'MERGED') |
| 103 | self.assertEqual(A.reported, 2, |
| 104 | "A should report start and success") |
| 105 | self.assertIn('gate', A.messages[1], |
| 106 | "A should transit gate") |
| 107 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 108 | 'image2') |
| 109 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 110 | def test_parallel_changes(self): |
| 111 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 112 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 113 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 114 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 115 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 116 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 117 | A.addApproval('code-review', 2) |
| 118 | B.addApproval('code-review', 2) |
| 119 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 120 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 121 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 122 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 123 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 124 | |
| 125 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 126 | self.assertEqual(len(self.builds), 1) |
| 127 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 128 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 129 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 130 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 131 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 132 | self.assertEqual(len(self.builds), 3) |
| 133 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 134 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 135 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 136 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 137 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 138 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 139 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 140 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 141 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 142 | self.assertEqual(len(self.builds), 5) |
| 143 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 144 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 145 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 146 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 147 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 148 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 149 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 150 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 151 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 152 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 153 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 154 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 155 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 156 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 157 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 158 | self.assertEqual(len(self.builds), 6) |
| 159 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 160 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 161 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 162 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 163 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 164 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 165 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 167 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 168 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 169 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 170 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 171 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 172 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 173 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 174 | self.executor_server.hold_jobs_in_build = False |
| 175 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 176 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 177 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 178 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 179 | self.assertEqual(len(self.history), 9) |
| 180 | self.assertEqual(A.data['status'], 'MERGED') |
| 181 | self.assertEqual(B.data['status'], 'MERGED') |
| 182 | self.assertEqual(C.data['status'], 'MERGED') |
| 183 | self.assertEqual(A.reported, 2) |
| 184 | self.assertEqual(B.reported, 2) |
| 185 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 186 | |
| 187 | def test_failed_changes(self): |
| 188 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 189 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 190 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 191 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 192 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 193 | A.addApproval('code-review', 2) |
| 194 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 195 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 196 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 197 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 198 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 199 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 200 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 201 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 202 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 203 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 204 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 205 | # A/project-merge is complete |
| 206 | self.assertBuilds([ |
| 207 | dict(name='project-test1', changes='1,1'), |
| 208 | dict(name='project-test2', changes='1,1'), |
| 209 | dict(name='project-merge', changes='1,1 2,1'), |
| 210 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 211 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 212 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 213 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 214 | # A/project-merge is complete |
| 215 | # B/project-merge is complete |
| 216 | self.assertBuilds([ |
| 217 | dict(name='project-test1', changes='1,1'), |
| 218 | dict(name='project-test2', changes='1,1'), |
| 219 | dict(name='project-test1', changes='1,1 2,1'), |
| 220 | dict(name='project-test2', changes='1,1 2,1'), |
| 221 | ]) |
| 222 | |
| 223 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 224 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 225 | self.builds[0].release() |
| 226 | self.waitUntilSettled() |
| 227 | |
| 228 | self.orderedRelease() |
| 229 | self.assertHistory([ |
| 230 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 231 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 232 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 233 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 234 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 235 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 236 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 237 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 238 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 239 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 240 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 241 | self.assertEqual(A.data['status'], 'NEW') |
| 242 | self.assertEqual(B.data['status'], 'MERGED') |
| 243 | self.assertEqual(A.reported, 2) |
| 244 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 245 | |
| 246 | def test_independent_queues(self): |
| 247 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 248 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 249 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 250 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 251 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 252 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 253 | A.addApproval('code-review', 2) |
| 254 | B.addApproval('code-review', 2) |
| 255 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 256 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 257 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 258 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 259 | |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 260 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 261 | self.waitUntilSettled() |
| 262 | |
| 263 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 264 | self.waitUntilSettled() |
| 265 | |
| 266 | # 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] | 267 | self.assertBuilds([ |
| 268 | dict(name='project-merge', changes='1,1'), |
| 269 | dict(name='project-merge', changes='2,1'), |
| 270 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 271 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 272 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 273 | self.builds[0].release() |
| 274 | self.waitUntilSettled() |
| 275 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 276 | self.waitUntilSettled() |
| 277 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 278 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 279 | self.waitUntilSettled() |
| 280 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 281 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 282 | self.assertBuilds([ |
| 283 | dict(name='project-test1', changes='1,1'), |
| 284 | dict(name='project-test2', changes='1,1'), |
| 285 | dict(name='project-test1', changes='2,1'), |
| 286 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 287 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 288 | dict(name='project-test1', changes='2,1 3,1'), |
| 289 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 290 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 291 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 292 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 293 | self.orderedRelease() |
| 294 | self.assertHistory([ |
| 295 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 296 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 297 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 298 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 299 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 300 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 301 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 302 | dict( |
| 303 | name='project1-project2-integration', |
| 304 | result='SUCCESS', |
| 305 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 306 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 307 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 308 | dict(name='project1-project2-integration', |
| 309 | result='SUCCESS', |
| 310 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 311 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 312 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 313 | self.assertEqual(A.data['status'], 'MERGED') |
| 314 | self.assertEqual(B.data['status'], 'MERGED') |
| 315 | self.assertEqual(C.data['status'], 'MERGED') |
| 316 | self.assertEqual(A.reported, 2) |
| 317 | self.assertEqual(B.reported, 2) |
| 318 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 319 | |
| 320 | def test_failed_change_at_head(self): |
| 321 | "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] | 322 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 323 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 324 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 325 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 326 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 327 | A.addApproval('code-review', 2) |
| 328 | B.addApproval('code-review', 2) |
| 329 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 330 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 331 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 332 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 333 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 334 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 335 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 336 | |
| 337 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 338 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 339 | self.assertBuilds([ |
| 340 | dict(name='project-merge', changes='1,1'), |
| 341 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 342 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 347 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 348 | self.waitUntilSettled() |
| 349 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 350 | self.assertBuilds([ |
| 351 | dict(name='project-test1', changes='1,1'), |
| 352 | dict(name='project-test2', changes='1,1'), |
| 353 | dict(name='project-test1', changes='1,1 2,1'), |
| 354 | dict(name='project-test2', changes='1,1 2,1'), |
| 355 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 356 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 357 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 358 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 359 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 360 | self.waitUntilSettled() |
| 361 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 362 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 363 | self.assertBuilds([ |
| 364 | dict(name='project-test2', changes='1,1'), |
| 365 | dict(name='project-merge', changes='2,1'), |
| 366 | ]) |
| 367 | # Unordered history comparison because the aborts can finish |
| 368 | # in any order. |
| 369 | self.assertHistory([ |
| 370 | dict(name='project-merge', result='SUCCESS', |
| 371 | changes='1,1'), |
| 372 | dict(name='project-merge', result='SUCCESS', |
| 373 | changes='1,1 2,1'), |
| 374 | dict(name='project-merge', result='SUCCESS', |
| 375 | changes='1,1 2,1 3,1'), |
| 376 | dict(name='project-test1', result='FAILURE', |
| 377 | changes='1,1'), |
| 378 | dict(name='project-test1', result='ABORTED', |
| 379 | changes='1,1 2,1'), |
| 380 | dict(name='project-test2', result='ABORTED', |
| 381 | changes='1,1 2,1'), |
| 382 | dict(name='project-test1', result='ABORTED', |
| 383 | changes='1,1 2,1 3,1'), |
| 384 | dict(name='project-test2', result='ABORTED', |
| 385 | changes='1,1 2,1 3,1'), |
| 386 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 387 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 388 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 389 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 390 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 391 | self.waitUntilSettled() |
| 392 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 393 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 394 | self.assertBuilds([]) |
| 395 | self.assertHistory([ |
| 396 | dict(name='project-merge', result='SUCCESS', |
| 397 | changes='1,1'), |
| 398 | dict(name='project-merge', result='SUCCESS', |
| 399 | changes='1,1 2,1'), |
| 400 | dict(name='project-merge', result='SUCCESS', |
| 401 | changes='1,1 2,1 3,1'), |
| 402 | dict(name='project-test1', result='FAILURE', |
| 403 | changes='1,1'), |
| 404 | dict(name='project-test1', result='ABORTED', |
| 405 | changes='1,1 2,1'), |
| 406 | dict(name='project-test2', result='ABORTED', |
| 407 | changes='1,1 2,1'), |
| 408 | dict(name='project-test1', result='ABORTED', |
| 409 | changes='1,1 2,1 3,1'), |
| 410 | dict(name='project-test2', result='ABORTED', |
| 411 | changes='1,1 2,1 3,1'), |
| 412 | dict(name='project-merge', result='SUCCESS', |
| 413 | changes='2,1'), |
| 414 | dict(name='project-merge', result='SUCCESS', |
| 415 | changes='2,1 3,1'), |
| 416 | dict(name='project-test2', result='SUCCESS', |
| 417 | changes='1,1'), |
| 418 | dict(name='project-test1', result='SUCCESS', |
| 419 | changes='2,1'), |
| 420 | dict(name='project-test2', result='SUCCESS', |
| 421 | changes='2,1'), |
| 422 | dict(name='project-test1', result='SUCCESS', |
| 423 | changes='2,1 3,1'), |
| 424 | dict(name='project-test2', result='SUCCESS', |
| 425 | changes='2,1 3,1'), |
| 426 | ], ordered=False) |
| 427 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 428 | self.assertEqual(A.data['status'], 'NEW') |
| 429 | self.assertEqual(B.data['status'], 'MERGED') |
| 430 | self.assertEqual(C.data['status'], 'MERGED') |
| 431 | self.assertEqual(A.reported, 2) |
| 432 | self.assertEqual(B.reported, 2) |
| 433 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 434 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 435 | def test_failed_change_in_middle(self): |
| 436 | "Test a failed change in the middle of the queue" |
| 437 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 438 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 439 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 440 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 441 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 442 | A.addApproval('code-review', 2) |
| 443 | B.addApproval('code-review', 2) |
| 444 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 445 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 446 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 447 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 448 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 449 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 450 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 451 | |
| 452 | self.waitUntilSettled() |
| 453 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 458 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 459 | self.waitUntilSettled() |
| 460 | |
| 461 | self.assertEqual(len(self.builds), 6) |
| 462 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 463 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 464 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 465 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 466 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 467 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 468 | |
| 469 | self.release(self.builds[2]) |
| 470 | self.waitUntilSettled() |
| 471 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 472 | # project-test1 and project-test2 for A |
| 473 | # project-test2 for B |
| 474 | # project-merge for C (without B) |
| 475 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 476 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 477 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 478 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 479 | self.waitUntilSettled() |
| 480 | |
| 481 | # project-test1 and project-test2 for A |
| 482 | # project-test2 for B |
| 483 | # project-test1 and project-test2 for C |
| 484 | self.assertEqual(len(self.builds), 5) |
| 485 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 486 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 487 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 488 | builds = items[0].current_build_set.getBuilds() |
| 489 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 490 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 491 | builds = items[1].current_build_set.getBuilds() |
| 492 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 493 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 494 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 495 | builds = items[2].current_build_set.getBuilds() |
| 496 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 497 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 498 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 499 | self.executor_server.hold_jobs_in_build = False |
| 500 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 501 | self.waitUntilSettled() |
| 502 | |
| 503 | self.assertEqual(len(self.builds), 0) |
| 504 | self.assertEqual(len(self.history), 12) |
| 505 | self.assertEqual(A.data['status'], 'MERGED') |
| 506 | self.assertEqual(B.data['status'], 'NEW') |
| 507 | self.assertEqual(C.data['status'], 'MERGED') |
| 508 | self.assertEqual(A.reported, 2) |
| 509 | self.assertEqual(B.reported, 2) |
| 510 | self.assertEqual(C.reported, 2) |
| 511 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 512 | def test_failed_change_at_head_with_queue(self): |
| 513 | "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] | 514 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 515 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 516 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 517 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 518 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 519 | A.addApproval('code-review', 2) |
| 520 | B.addApproval('code-review', 2) |
| 521 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 522 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 523 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 524 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 525 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 526 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 527 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 528 | |
| 529 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 530 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 531 | self.assertEqual(len(self.builds), 0) |
| 532 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 533 | self.assertEqual(queue[0].name, b'executor:execute') |
| 534 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 535 | self.assertEqual(job_args['job'], 'project-merge') |
| 536 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 537 | |
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 | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 542 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 543 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 544 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 545 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 546 | self.assertEqual(len(self.builds), 0) |
| 547 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 548 | |
| 549 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 550 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 551 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 552 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 553 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 554 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 555 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 556 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 557 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 558 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 559 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 560 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 561 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 562 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 563 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 564 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 565 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 566 | 'project-test2') |
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.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 569 | self.waitUntilSettled() |
| 570 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 571 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 572 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 573 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 574 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 575 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 576 | self.gearman_server.hold_jobs_in_queue = False |
| 577 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 578 | self.waitUntilSettled() |
| 579 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 580 | self.assertEqual(len(self.builds), 0) |
| 581 | self.assertEqual(len(self.history), 11) |
| 582 | self.assertEqual(A.data['status'], 'NEW') |
| 583 | self.assertEqual(B.data['status'], 'MERGED') |
| 584 | self.assertEqual(C.data['status'], 'MERGED') |
| 585 | self.assertEqual(A.reported, 2) |
| 586 | self.assertEqual(B.reported, 2) |
| 587 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 588 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 589 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 590 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 591 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 592 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 593 | A.addApproval('code-review', 2) |
| 594 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 595 | self.waitUntilSettled() |
| 596 | time.sleep(2) |
| 597 | |
| 598 | data = json.loads(self.sched.formatStatusJSON()) |
| 599 | found_job = None |
| 600 | for pipeline in data['pipelines']: |
| 601 | if pipeline['name'] != 'gate': |
| 602 | continue |
| 603 | for queue in pipeline['change_queues']: |
| 604 | for head in queue['heads']: |
| 605 | for item in head: |
| 606 | for job in item['jobs']: |
| 607 | if job['name'] == 'project-merge': |
| 608 | found_job = job |
| 609 | break |
| 610 | |
| 611 | self.assertIsNotNone(found_job) |
| 612 | if iteration == 1: |
| 613 | self.assertIsNotNone(found_job['estimated_time']) |
| 614 | self.assertIsNone(found_job['remaining_time']) |
| 615 | else: |
| 616 | self.assertIsNotNone(found_job['estimated_time']) |
| 617 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 618 | self.assertIsNotNone(found_job['remaining_time']) |
| 619 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 620 | self.executor_server.hold_jobs_in_build = False |
| 621 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 622 | self.waitUntilSettled() |
| 623 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 624 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 625 | def test_time_database(self): |
| 626 | "Test the time database" |
| 627 | |
| 628 | self._test_time_database(1) |
| 629 | self._test_time_database(2) |
| 630 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 631 | def test_two_failed_changes_at_head(self): |
| 632 | "Test that changes are reparented correctly if 2 fail at head" |
| 633 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 634 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 635 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 636 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 637 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 638 | A.addApproval('code-review', 2) |
| 639 | B.addApproval('code-review', 2) |
| 640 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 641 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 642 | self.executor_server.failJob('project-test1', A) |
| 643 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 644 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 645 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 646 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 647 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 648 | self.waitUntilSettled() |
| 649 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 650 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 651 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 652 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 653 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 654 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 655 | self.waitUntilSettled() |
| 656 | |
| 657 | self.assertEqual(len(self.builds), 6) |
| 658 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 659 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 660 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 661 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 662 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 663 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 664 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 665 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 666 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 667 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 668 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 669 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 670 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 671 | |
| 672 | # Fail change B first |
| 673 | self.release(self.builds[2]) |
| 674 | self.waitUntilSettled() |
| 675 | |
| 676 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 677 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 678 | self.waitUntilSettled() |
| 679 | |
| 680 | self.assertEqual(len(self.builds), 5) |
| 681 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 682 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 683 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 684 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 685 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 686 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 687 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 688 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 689 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 690 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 691 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 692 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 693 | |
| 694 | # Finish running all passing jobs for change A |
| 695 | self.release(self.builds[1]) |
| 696 | self.waitUntilSettled() |
| 697 | # Fail and report change A |
| 698 | self.release(self.builds[0]) |
| 699 | self.waitUntilSettled() |
| 700 | |
| 701 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 702 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 703 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 704 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 705 | self.waitUntilSettled() |
| 706 | |
| 707 | self.assertEqual(len(self.builds), 4) |
| 708 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 709 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 710 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 711 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 712 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 713 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 714 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 715 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 716 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 717 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 718 | # After A failed and B and C restarted, B should be back in |
| 719 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 720 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 721 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 722 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 723 | self.executor_server.hold_jobs_in_build = False |
| 724 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 725 | self.waitUntilSettled() |
| 726 | |
| 727 | self.assertEqual(len(self.builds), 0) |
| 728 | self.assertEqual(len(self.history), 21) |
| 729 | self.assertEqual(A.data['status'], 'NEW') |
| 730 | self.assertEqual(B.data['status'], 'NEW') |
| 731 | self.assertEqual(C.data['status'], 'MERGED') |
| 732 | self.assertEqual(A.reported, 2) |
| 733 | self.assertEqual(B.reported, 2) |
| 734 | self.assertEqual(C.reported, 2) |
| 735 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 736 | def test_patch_order(self): |
| 737 | "Test that dependent patches are tested in the right order" |
| 738 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 739 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 740 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 741 | A.addApproval('code-review', 2) |
| 742 | B.addApproval('code-review', 2) |
| 743 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 744 | |
| 745 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 746 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 747 | M2.setMerged() |
| 748 | M1.setMerged() |
| 749 | |
| 750 | # C -> B -> A -> M1 -> M2 |
| 751 | # M2 is here to make sure it is never queried. If it is, it |
| 752 | # means zuul is walking down the entire history of merged |
| 753 | # changes. |
| 754 | |
| 755 | C.setDependsOn(B, 1) |
| 756 | B.setDependsOn(A, 1) |
| 757 | A.setDependsOn(M1, 1) |
| 758 | M1.setDependsOn(M2, 1) |
| 759 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 760 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 761 | |
| 762 | self.waitUntilSettled() |
| 763 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 764 | self.assertEqual(A.data['status'], 'NEW') |
| 765 | self.assertEqual(B.data['status'], 'NEW') |
| 766 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 767 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 768 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 769 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 770 | |
| 771 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 772 | self.assertEqual(M2.queried, 0) |
| 773 | self.assertEqual(A.data['status'], 'MERGED') |
| 774 | self.assertEqual(B.data['status'], 'MERGED') |
| 775 | self.assertEqual(C.data['status'], 'MERGED') |
| 776 | self.assertEqual(A.reported, 2) |
| 777 | self.assertEqual(B.reported, 2) |
| 778 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 779 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 780 | def test_needed_changes_enqueue(self): |
| 781 | "Test that a needed change is enqueued ahead" |
| 782 | # A Given a git tree like this, if we enqueue |
| 783 | # / \ change C, we should walk up and down the tree |
| 784 | # B G and enqueue changes in the order ABCDEFG. |
| 785 | # /|\ This is also the order that you would get if |
| 786 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 787 | # / the ordering is stable across re-enqueue events. |
| 788 | # D |
| 789 | |
| 790 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 791 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 792 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 793 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 794 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 795 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 796 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 797 | B.setDependsOn(A, 1) |
| 798 | C.setDependsOn(B, 1) |
| 799 | D.setDependsOn(C, 1) |
| 800 | E.setDependsOn(B, 1) |
| 801 | F.setDependsOn(B, 1) |
| 802 | G.setDependsOn(A, 1) |
| 803 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 804 | A.addApproval('code-review', 2) |
| 805 | B.addApproval('code-review', 2) |
| 806 | C.addApproval('code-review', 2) |
| 807 | D.addApproval('code-review', 2) |
| 808 | E.addApproval('code-review', 2) |
| 809 | F.addApproval('code-review', 2) |
| 810 | G.addApproval('code-review', 2) |
| 811 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 812 | |
| 813 | self.waitUntilSettled() |
| 814 | |
| 815 | self.assertEqual(A.data['status'], 'NEW') |
| 816 | self.assertEqual(B.data['status'], 'NEW') |
| 817 | self.assertEqual(C.data['status'], 'NEW') |
| 818 | self.assertEqual(D.data['status'], 'NEW') |
| 819 | self.assertEqual(E.data['status'], 'NEW') |
| 820 | self.assertEqual(F.data['status'], 'NEW') |
| 821 | self.assertEqual(G.data['status'], 'NEW') |
| 822 | |
| 823 | # We're about to add approvals to changes without adding the |
| 824 | # triggering events to Zuul, so that we can be sure that it is |
| 825 | # enqueing the changes based on dependencies, not because of |
| 826 | # triggering events. Since it will have the changes cached |
| 827 | # already (without approvals), we need to clear the cache |
| 828 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 829 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 830 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 831 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 832 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 833 | A.addApproval('approved', 1) |
| 834 | B.addApproval('approved', 1) |
| 835 | D.addApproval('approved', 1) |
| 836 | E.addApproval('approved', 1) |
| 837 | F.addApproval('approved', 1) |
| 838 | G.addApproval('approved', 1) |
| 839 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 840 | |
| 841 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 842 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 843 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 844 | self.executor_server.hold_jobs_in_build = False |
| 845 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 846 | self.waitUntilSettled() |
| 847 | |
| 848 | self.assertEqual(A.data['status'], 'MERGED') |
| 849 | self.assertEqual(B.data['status'], 'MERGED') |
| 850 | self.assertEqual(C.data['status'], 'MERGED') |
| 851 | self.assertEqual(D.data['status'], 'MERGED') |
| 852 | self.assertEqual(E.data['status'], 'MERGED') |
| 853 | self.assertEqual(F.data['status'], 'MERGED') |
| 854 | self.assertEqual(G.data['status'], 'MERGED') |
| 855 | self.assertEqual(A.reported, 2) |
| 856 | self.assertEqual(B.reported, 2) |
| 857 | self.assertEqual(C.reported, 2) |
| 858 | self.assertEqual(D.reported, 2) |
| 859 | self.assertEqual(E.reported, 2) |
| 860 | self.assertEqual(F.reported, 2) |
| 861 | self.assertEqual(G.reported, 2) |
| 862 | self.assertEqual(self.history[6].changes, |
| 863 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 864 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 865 | def test_source_cache(self): |
| 866 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 867 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 868 | |
| 869 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 870 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 871 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 872 | A.addApproval('code-review', 2) |
| 873 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 874 | |
| 875 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 876 | M1.setMerged() |
| 877 | |
| 878 | B.setDependsOn(A, 1) |
| 879 | A.setDependsOn(M1, 1) |
| 880 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 881 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 882 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 883 | |
| 884 | self.waitUntilSettled() |
| 885 | |
| 886 | for build in self.builds: |
| 887 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 888 | build.release() |
| 889 | self.waitUntilSettled() |
| 890 | for build in self.builds: |
| 891 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 892 | build.release() |
| 893 | self.waitUntilSettled() |
| 894 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 895 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 896 | self.waitUntilSettled() |
| 897 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 898 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 899 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 900 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 901 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 902 | self.executor_server.hold_jobs_in_build = False |
| 903 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 904 | self.waitUntilSettled() |
| 905 | |
| 906 | self.assertEqual(A.data['status'], 'MERGED') |
| 907 | self.assertEqual(B.data['status'], 'MERGED') |
| 908 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 909 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 910 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 911 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 912 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 913 | # TODO: move to test_gerrit (this is a unit test!) |
| 914 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 915 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 916 | (trusted, project) = tenant.getProject('org/project') |
| 917 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 918 | |
| 919 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 920 | # it easier for users to create events for testing. |
| 921 | event = zuul.model.TriggerEvent() |
| 922 | event.trigger_name = 'gerrit' |
| 923 | event.change_number = '1' |
| 924 | event.patch_number = '2' |
| 925 | |
| 926 | a = source.getChange(event) |
| 927 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 928 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 929 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 930 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 931 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 932 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 933 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 934 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 935 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 936 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 937 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 938 | def test_project_merge_conflict(self): |
| 939 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 940 | |
| 941 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 942 | A = self.fake_gerrit.addFakeChange('org/project', |
| 943 | 'master', 'A', |
| 944 | files={'conflict': 'foo'}) |
| 945 | B = self.fake_gerrit.addFakeChange('org/project', |
| 946 | 'master', 'B', |
| 947 | files={'conflict': 'bar'}) |
| 948 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 949 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 950 | A.addApproval('code-review', 2) |
| 951 | B.addApproval('code-review', 2) |
| 952 | C.addApproval('code-review', 2) |
| 953 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 954 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 955 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 956 | self.waitUntilSettled() |
| 957 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 958 | self.assertEqual(A.reported, 1) |
| 959 | self.assertEqual(B.reported, 1) |
| 960 | self.assertEqual(C.reported, 1) |
| 961 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 962 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 963 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 964 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 965 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 966 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 967 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 968 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 969 | self.gearman_server.hold_jobs_in_queue = False |
| 970 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 971 | self.waitUntilSettled() |
| 972 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 973 | self.assertEqual(A.data['status'], 'MERGED') |
| 974 | self.assertEqual(B.data['status'], 'NEW') |
| 975 | self.assertEqual(C.data['status'], 'MERGED') |
| 976 | self.assertEqual(A.reported, 2) |
| 977 | self.assertEqual(B.reported, 2) |
| 978 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 979 | |
| 980 | self.assertHistory([ |
| 981 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 982 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 983 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 984 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 985 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 986 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 987 | ], ordered=False) |
| 988 | |
| 989 | def test_delayed_merge_conflict(self): |
| 990 | "Test that delayed check merge conflicts are handled properly" |
| 991 | |
| 992 | # Hold jobs in the gearman queue so that we can test whether |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 993 | # the executor sucesfully merges a change based on an old |
| 994 | # repo state (frozen by the scheduler) which would otherwise |
| 995 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 996 | self.gearman_server.hold_jobs_in_queue = True |
| 997 | A = self.fake_gerrit.addFakeChange('org/project', |
| 998 | 'master', 'A', |
| 999 | files={'conflict': 'foo'}) |
| 1000 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1001 | 'master', 'B', |
| 1002 | files={'conflict': 'bar'}) |
| 1003 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1004 | 'master', 'C') |
| 1005 | C.setDependsOn(B, 1) |
| 1006 | |
| 1007 | # A enters the gate queue; B and C enter the check queue |
| 1008 | A.addApproval('code-review', 2) |
| 1009 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1010 | self.waitUntilSettled() |
| 1011 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1012 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1013 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1014 | self.waitUntilSettled() |
| 1015 | |
| 1016 | self.assertEqual(A.reported, 1) |
| 1017 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1018 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1019 | |
| 1020 | # A merges while B and C are queued in check |
| 1021 | # Release A project-merge |
| 1022 | queue = self.gearman_server.getQueue() |
| 1023 | self.release(queue[0]) |
| 1024 | self.waitUntilSettled() |
| 1025 | |
| 1026 | # Release A project-test* |
| 1027 | # gate has higher precedence, so A's test jobs are added in |
| 1028 | # front of the merge jobs for B and C |
| 1029 | queue = self.gearman_server.getQueue() |
| 1030 | self.release(queue[0]) |
| 1031 | self.release(queue[1]) |
| 1032 | self.waitUntilSettled() |
| 1033 | |
| 1034 | self.assertEqual(A.data['status'], 'MERGED') |
| 1035 | self.assertEqual(B.data['status'], 'NEW') |
| 1036 | self.assertEqual(C.data['status'], 'NEW') |
| 1037 | self.assertEqual(A.reported, 2) |
| 1038 | self.assertEqual(B.reported, 0) |
| 1039 | self.assertEqual(C.reported, 0) |
| 1040 | self.assertHistory([ |
| 1041 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1042 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1043 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1044 | ], ordered=False) |
| 1045 | |
| 1046 | # B and C report merge conflicts |
| 1047 | # Release B project-merge |
| 1048 | queue = self.gearman_server.getQueue() |
| 1049 | self.release(queue[0]) |
| 1050 | self.waitUntilSettled() |
| 1051 | |
| 1052 | # Release C |
| 1053 | self.gearman_server.hold_jobs_in_queue = False |
| 1054 | self.gearman_server.release() |
| 1055 | self.waitUntilSettled() |
| 1056 | |
| 1057 | self.assertEqual(A.data['status'], 'MERGED') |
| 1058 | self.assertEqual(B.data['status'], 'NEW') |
| 1059 | self.assertEqual(C.data['status'], 'NEW') |
| 1060 | self.assertEqual(A.reported, 2) |
| 1061 | self.assertEqual(B.reported, 1) |
| 1062 | self.assertEqual(C.reported, 1) |
| 1063 | |
| 1064 | self.assertHistory([ |
| 1065 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1066 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1067 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1068 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1069 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1070 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1071 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1072 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1073 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1074 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1075 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1076 | def test_post(self): |
| 1077 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1078 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1079 | e = { |
| 1080 | "type": "ref-updated", |
| 1081 | "submitter": { |
| 1082 | "name": "User Name", |
| 1083 | }, |
| 1084 | "refUpdate": { |
| 1085 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1086 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1087 | "refName": "master", |
| 1088 | "project": "org/project", |
| 1089 | } |
| 1090 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1091 | self.fake_gerrit.addEvent(e) |
| 1092 | self.waitUntilSettled() |
| 1093 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1094 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1095 | self.assertEqual(len(self.history), 1) |
| 1096 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1097 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1098 | def test_post_ignore_deletes(self): |
| 1099 | "Test that deleting refs does not trigger post jobs" |
| 1100 | |
| 1101 | e = { |
| 1102 | "type": "ref-updated", |
| 1103 | "submitter": { |
| 1104 | "name": "User Name", |
| 1105 | }, |
| 1106 | "refUpdate": { |
| 1107 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1108 | "newRev": "0000000000000000000000000000000000000000", |
| 1109 | "refName": "master", |
| 1110 | "project": "org/project", |
| 1111 | } |
| 1112 | } |
| 1113 | self.fake_gerrit.addEvent(e) |
| 1114 | self.waitUntilSettled() |
| 1115 | |
| 1116 | job_names = [x.name for x in self.history] |
| 1117 | self.assertEqual(len(self.history), 0) |
| 1118 | self.assertNotIn('project-post', job_names) |
| 1119 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1120 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1121 | def test_post_ignore_deletes_negative(self): |
| 1122 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1123 | e = { |
| 1124 | "type": "ref-updated", |
| 1125 | "submitter": { |
| 1126 | "name": "User Name", |
| 1127 | }, |
| 1128 | "refUpdate": { |
| 1129 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1130 | "newRev": "0000000000000000000000000000000000000000", |
| 1131 | "refName": "master", |
| 1132 | "project": "org/project", |
| 1133 | } |
| 1134 | } |
| 1135 | self.fake_gerrit.addEvent(e) |
| 1136 | self.waitUntilSettled() |
| 1137 | |
| 1138 | job_names = [x.name for x in self.history] |
| 1139 | self.assertEqual(len(self.history), 1) |
| 1140 | self.assertIn('project-post', job_names) |
| 1141 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1142 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1143 | def test_build_configuration_branch_interaction(self): |
| 1144 | "Test that switching between branches works" |
| 1145 | self.test_build_configuration() |
| 1146 | self.test_build_configuration_branch() |
| 1147 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1148 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1149 | repo = git.Repo(path) |
| 1150 | repo.heads.master.commit = repo.commit('init') |
| 1151 | self.test_build_configuration() |
| 1152 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1153 | def test_dependent_changes_dequeue(self): |
| 1154 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1155 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1156 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1157 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1158 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1159 | A.addApproval('code-review', 2) |
| 1160 | B.addApproval('code-review', 2) |
| 1161 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1162 | |
| 1163 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1164 | M1.setMerged() |
| 1165 | |
| 1166 | # C -> B -> A -> M1 |
| 1167 | |
| 1168 | C.setDependsOn(B, 1) |
| 1169 | B.setDependsOn(A, 1) |
| 1170 | A.setDependsOn(M1, 1) |
| 1171 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1172 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1173 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1174 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1175 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1176 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1177 | |
| 1178 | self.waitUntilSettled() |
| 1179 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1180 | self.assertEqual(A.data['status'], 'NEW') |
| 1181 | self.assertEqual(A.reported, 2) |
| 1182 | self.assertEqual(B.data['status'], 'NEW') |
| 1183 | self.assertEqual(B.reported, 2) |
| 1184 | self.assertEqual(C.data['status'], 'NEW') |
| 1185 | self.assertEqual(C.reported, 2) |
| 1186 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1187 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1188 | def test_failing_dependent_changes(self): |
| 1189 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1190 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1191 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1192 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1193 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1194 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1195 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1196 | A.addApproval('code-review', 2) |
| 1197 | B.addApproval('code-review', 2) |
| 1198 | C.addApproval('code-review', 2) |
| 1199 | D.addApproval('code-review', 2) |
| 1200 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1201 | |
| 1202 | # E, D -> C -> B, A |
| 1203 | |
| 1204 | D.setDependsOn(C, 1) |
| 1205 | C.setDependsOn(B, 1) |
| 1206 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1207 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1208 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1209 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1210 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1211 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1212 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1213 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1214 | |
| 1215 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1216 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1217 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1218 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1219 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1220 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1221 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1222 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1223 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1224 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1225 | self.waitUntilSettled() |
| 1226 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1227 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1228 | for build in self.builds: |
| 1229 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1230 | build.release() |
| 1231 | self.waitUntilSettled() |
| 1232 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1233 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1234 | self.waitUntilSettled() |
| 1235 | |
| 1236 | self.assertEqual(A.data['status'], 'MERGED') |
| 1237 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1238 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1239 | self.assertEqual(B.data['status'], 'NEW') |
| 1240 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1241 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1242 | self.assertEqual(C.data['status'], 'NEW') |
| 1243 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1244 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1245 | self.assertEqual(D.data['status'], 'NEW') |
| 1246 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1247 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1248 | self.assertEqual(E.data['status'], 'MERGED') |
| 1249 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1250 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1251 | self.assertEqual(len(self.history), 18) |
| 1252 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1253 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1254 | "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] | 1255 | # If it's dequeued more than once, we should see extra |
| 1256 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1257 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1258 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1259 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1260 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1261 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1262 | A.addApproval('code-review', 2) |
| 1263 | B.addApproval('code-review', 2) |
| 1264 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1265 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1266 | self.executor_server.failJob('project-test1', A) |
| 1267 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1268 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1269 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1270 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1271 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1272 | |
| 1273 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1274 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1275 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1276 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1277 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1278 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1279 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1280 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1281 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1282 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1283 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1284 | self.waitUntilSettled() |
| 1285 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1286 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1287 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1288 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1289 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1290 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1291 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1292 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1293 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1294 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1295 | self.waitUntilSettled() |
| 1296 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1297 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1298 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1299 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1300 | self.executor_server.hold_jobs_in_build = False |
| 1301 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1302 | self.waitUntilSettled() |
| 1303 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1304 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1305 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1306 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1307 | self.assertEqual(A.data['status'], 'NEW') |
| 1308 | self.assertEqual(B.data['status'], 'MERGED') |
| 1309 | self.assertEqual(C.data['status'], 'MERGED') |
| 1310 | self.assertEqual(A.reported, 2) |
| 1311 | self.assertEqual(B.reported, 2) |
| 1312 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1313 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1314 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1315 | def test_nonvoting_job(self): |
| 1316 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1317 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1318 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1319 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1320 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1321 | self.executor_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1322 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1323 | |
| 1324 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1325 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1326 | self.assertEqual(A.data['status'], 'MERGED') |
| 1327 | self.assertEqual(A.reported, 2) |
| 1328 | self.assertEqual( |
| 1329 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1330 | 'SUCCESS') |
| 1331 | self.assertEqual( |
| 1332 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1333 | 'SUCCESS') |
| 1334 | self.assertEqual( |
| 1335 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1336 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1337 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1338 | for build in self.builds: |
| 1339 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1340 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1341 | def test_check_queue_success(self): |
| 1342 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1343 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1344 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1345 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1346 | |
| 1347 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1348 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1349 | self.assertEqual(A.data['status'], 'NEW') |
| 1350 | self.assertEqual(A.reported, 1) |
| 1351 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1352 | 'SUCCESS') |
| 1353 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1354 | 'SUCCESS') |
| 1355 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1356 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1357 | |
| 1358 | def test_check_queue_failure(self): |
| 1359 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1360 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1361 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1362 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1363 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1364 | |
| 1365 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1366 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1367 | self.assertEqual(A.data['status'], 'NEW') |
| 1368 | self.assertEqual(A.reported, 1) |
| 1369 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1370 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1371 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1372 | 'SUCCESS') |
| 1373 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1374 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1375 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1376 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1377 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1378 | # This particular test does a large amount of merges and needs a little |
| 1379 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1380 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1381 | "test that dependent changes behind dequeued changes work" |
| 1382 | # This complicated test is a reproduction of a real life bug |
| 1383 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1384 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1385 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1386 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1387 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1388 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1389 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1390 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1391 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1392 | D.setDependsOn(C, 1) |
| 1393 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1394 | A.addApproval('code-review', 2) |
| 1395 | B.addApproval('code-review', 2) |
| 1396 | C.addApproval('code-review', 2) |
| 1397 | D.addApproval('code-review', 2) |
| 1398 | E.addApproval('code-review', 2) |
| 1399 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1400 | |
| 1401 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1402 | |
| 1403 | # Change object re-use in the gerrit trigger is hidden if |
| 1404 | # changes are added in quick succession; waiting makes it more |
| 1405 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1406 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1407 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1408 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1409 | self.waitUntilSettled() |
| 1410 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1411 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1412 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1413 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1414 | self.waitUntilSettled() |
| 1415 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1416 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1417 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1418 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1419 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1420 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1421 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1422 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1423 | self.waitUntilSettled() |
| 1424 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1425 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1426 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1427 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1428 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1429 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1430 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1431 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1432 | self.waitUntilSettled() |
| 1433 | |
| 1434 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1435 | |
| 1436 | # Grab pointers to the jobs we want to release before |
| 1437 | # releasing any, because list indexes may change as |
| 1438 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1439 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1440 | a.release() |
| 1441 | b.release() |
| 1442 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1443 | self.waitUntilSettled() |
| 1444 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1445 | self.executor_server.hold_jobs_in_build = False |
| 1446 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1447 | self.waitUntilSettled() |
| 1448 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1449 | self.assertEqual(A.data['status'], 'NEW') |
| 1450 | self.assertEqual(B.data['status'], 'MERGED') |
| 1451 | self.assertEqual(C.data['status'], 'MERGED') |
| 1452 | self.assertEqual(D.data['status'], 'MERGED') |
| 1453 | self.assertEqual(E.data['status'], 'MERGED') |
| 1454 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1455 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1456 | self.assertEqual(A.reported, 2) |
| 1457 | self.assertEqual(B.reported, 2) |
| 1458 | self.assertEqual(C.reported, 2) |
| 1459 | self.assertEqual(D.reported, 2) |
| 1460 | self.assertEqual(E.reported, 2) |
| 1461 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1462 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1463 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1464 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1465 | |
| 1466 | def test_merger_repack(self): |
| 1467 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1468 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1469 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1470 | A.addApproval('code-review', 2) |
| 1471 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1472 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1473 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1474 | 'SUCCESS') |
| 1475 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1476 | 'SUCCESS') |
| 1477 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1478 | 'SUCCESS') |
| 1479 | self.assertEqual(A.data['status'], 'MERGED') |
| 1480 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1481 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1482 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1483 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1484 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1485 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1486 | if os.path.exists(path): |
| 1487 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1488 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1489 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1490 | if os.path.exists(path): |
| 1491 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1492 | |
| 1493 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1494 | A.addApproval('code-review', 2) |
| 1495 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1496 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1497 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1498 | 'SUCCESS') |
| 1499 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1500 | 'SUCCESS') |
| 1501 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1502 | 'SUCCESS') |
| 1503 | self.assertEqual(A.data['status'], 'MERGED') |
| 1504 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1505 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1506 | def test_merger_repack_large_change(self): |
| 1507 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1508 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1509 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1510 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1511 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1512 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1513 | self.executor_server.merger._addProject('review.example.com', |
| 1514 | 'org/project', url) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1515 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1516 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1517 | # TODOv3(jeblair): add hostname to upstream root |
| 1518 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1519 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1520 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1521 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1522 | if os.path.exists(path): |
| 1523 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1524 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1525 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1526 | if os.path.exists(path): |
| 1527 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1528 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1529 | A.addApproval('code-review', 2) |
| 1530 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1531 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1532 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1533 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1534 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1535 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1536 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1537 | 'SUCCESS') |
| 1538 | self.assertEqual(A.data['status'], 'MERGED') |
| 1539 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1540 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1541 | def test_new_patchset_dequeues_old(self): |
| 1542 | "Test that a new patchset causes the old to be dequeued" |
| 1543 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1544 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1545 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1546 | M.setMerged() |
| 1547 | |
| 1548 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1549 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1550 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1551 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1552 | A.addApproval('code-review', 2) |
| 1553 | B.addApproval('code-review', 2) |
| 1554 | C.addApproval('code-review', 2) |
| 1555 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1556 | |
| 1557 | C.setDependsOn(B, 1) |
| 1558 | B.setDependsOn(A, 1) |
| 1559 | A.setDependsOn(M, 1) |
| 1560 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1561 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1562 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1563 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1564 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1565 | self.waitUntilSettled() |
| 1566 | |
| 1567 | B.addPatchset() |
| 1568 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1569 | self.waitUntilSettled() |
| 1570 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1571 | self.executor_server.hold_jobs_in_build = False |
| 1572 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1573 | self.waitUntilSettled() |
| 1574 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1575 | self.assertEqual(A.data['status'], 'MERGED') |
| 1576 | self.assertEqual(A.reported, 2) |
| 1577 | self.assertEqual(B.data['status'], 'NEW') |
| 1578 | self.assertEqual(B.reported, 2) |
| 1579 | self.assertEqual(C.data['status'], 'NEW') |
| 1580 | self.assertEqual(C.reported, 2) |
| 1581 | self.assertEqual(D.data['status'], 'MERGED') |
| 1582 | self.assertEqual(D.reported, 2) |
| 1583 | 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] | 1584 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1585 | def test_new_patchset_check(self): |
| 1586 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1587 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1588 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1589 | |
| 1590 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1591 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1592 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1593 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1594 | |
| 1595 | # Add two git-dependent changes |
| 1596 | B.setDependsOn(A, 1) |
| 1597 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1598 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1599 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1600 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1601 | |
| 1602 | # A live item, and a non-live/live pair |
| 1603 | items = check_pipeline.getAllItems() |
| 1604 | self.assertEqual(len(items), 3) |
| 1605 | |
| 1606 | self.assertEqual(items[0].change.number, '1') |
| 1607 | self.assertEqual(items[0].change.patchset, '1') |
| 1608 | self.assertFalse(items[0].live) |
| 1609 | |
| 1610 | self.assertEqual(items[1].change.number, '2') |
| 1611 | self.assertEqual(items[1].change.patchset, '1') |
| 1612 | self.assertTrue(items[1].live) |
| 1613 | |
| 1614 | self.assertEqual(items[2].change.number, '1') |
| 1615 | self.assertEqual(items[2].change.patchset, '1') |
| 1616 | self.assertTrue(items[2].live) |
| 1617 | |
| 1618 | # Add a new patchset to A |
| 1619 | A.addPatchset() |
| 1620 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1621 | self.waitUntilSettled() |
| 1622 | |
| 1623 | # The live copy of A,1 should be gone, but the non-live and B |
| 1624 | # should continue, and we should have a new A,2 |
| 1625 | items = check_pipeline.getAllItems() |
| 1626 | self.assertEqual(len(items), 3) |
| 1627 | |
| 1628 | self.assertEqual(items[0].change.number, '1') |
| 1629 | self.assertEqual(items[0].change.patchset, '1') |
| 1630 | self.assertFalse(items[0].live) |
| 1631 | |
| 1632 | self.assertEqual(items[1].change.number, '2') |
| 1633 | self.assertEqual(items[1].change.patchset, '1') |
| 1634 | self.assertTrue(items[1].live) |
| 1635 | |
| 1636 | self.assertEqual(items[2].change.number, '1') |
| 1637 | self.assertEqual(items[2].change.patchset, '2') |
| 1638 | self.assertTrue(items[2].live) |
| 1639 | |
| 1640 | # Add a new patchset to B |
| 1641 | B.addPatchset() |
| 1642 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1643 | self.waitUntilSettled() |
| 1644 | |
| 1645 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1646 | # but we should have a new B,2 (still based on A,1) |
| 1647 | items = check_pipeline.getAllItems() |
| 1648 | self.assertEqual(len(items), 3) |
| 1649 | |
| 1650 | self.assertEqual(items[0].change.number, '1') |
| 1651 | self.assertEqual(items[0].change.patchset, '2') |
| 1652 | self.assertTrue(items[0].live) |
| 1653 | |
| 1654 | self.assertEqual(items[1].change.number, '1') |
| 1655 | self.assertEqual(items[1].change.patchset, '1') |
| 1656 | self.assertFalse(items[1].live) |
| 1657 | |
| 1658 | self.assertEqual(items[2].change.number, '2') |
| 1659 | self.assertEqual(items[2].change.patchset, '2') |
| 1660 | self.assertTrue(items[2].live) |
| 1661 | |
| 1662 | self.builds[0].release() |
| 1663 | self.waitUntilSettled() |
| 1664 | self.builds[0].release() |
| 1665 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1666 | self.executor_server.hold_jobs_in_build = False |
| 1667 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1668 | self.waitUntilSettled() |
| 1669 | |
| 1670 | self.assertEqual(A.reported, 1) |
| 1671 | self.assertEqual(B.reported, 1) |
| 1672 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1673 | self.assertEqual(self.history[0].changes, '1,1') |
| 1674 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1675 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1676 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1677 | self.assertEqual(self.history[2].changes, '1,2') |
| 1678 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1679 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1680 | |
| 1681 | def test_abandoned_gate(self): |
| 1682 | "Test that an abandoned change is dequeued from gate" |
| 1683 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1684 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1685 | |
| 1686 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1687 | A.addApproval('code-review', 2) |
| 1688 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1689 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1690 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1691 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1692 | |
| 1693 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1694 | self.waitUntilSettled() |
| 1695 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1696 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1697 | self.waitUntilSettled() |
| 1698 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1699 | self.assertBuilds([]) |
| 1700 | self.assertHistory([ |
| 1701 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1702 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1703 | self.assertEqual(A.reported, 1, |
| 1704 | "Abandoned gate change should report only start") |
| 1705 | |
| 1706 | def test_abandoned_check(self): |
| 1707 | "Test that an abandoned change is dequeued from check" |
| 1708 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1709 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1710 | |
| 1711 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1712 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1713 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1714 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1715 | |
| 1716 | # Add two git-dependent changes |
| 1717 | B.setDependsOn(A, 1) |
| 1718 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1719 | self.waitUntilSettled() |
| 1720 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1721 | self.waitUntilSettled() |
| 1722 | # A live item, and a non-live/live pair |
| 1723 | items = check_pipeline.getAllItems() |
| 1724 | self.assertEqual(len(items), 3) |
| 1725 | |
| 1726 | self.assertEqual(items[0].change.number, '1') |
| 1727 | self.assertFalse(items[0].live) |
| 1728 | |
| 1729 | self.assertEqual(items[1].change.number, '2') |
| 1730 | self.assertTrue(items[1].live) |
| 1731 | |
| 1732 | self.assertEqual(items[2].change.number, '1') |
| 1733 | self.assertTrue(items[2].live) |
| 1734 | |
| 1735 | # Abandon A |
| 1736 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1737 | self.waitUntilSettled() |
| 1738 | |
| 1739 | # The live copy of A should be gone, but the non-live and B |
| 1740 | # should continue |
| 1741 | items = check_pipeline.getAllItems() |
| 1742 | self.assertEqual(len(items), 2) |
| 1743 | |
| 1744 | self.assertEqual(items[0].change.number, '1') |
| 1745 | self.assertFalse(items[0].live) |
| 1746 | |
| 1747 | self.assertEqual(items[1].change.number, '2') |
| 1748 | self.assertTrue(items[1].live) |
| 1749 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1750 | self.executor_server.hold_jobs_in_build = False |
| 1751 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1752 | self.waitUntilSettled() |
| 1753 | |
| 1754 | self.assertEqual(len(self.history), 4) |
| 1755 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1756 | 'Build should have been aborted') |
| 1757 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1758 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1759 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1760 | def test_abandoned_not_timer(self): |
| 1761 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1762 | # This test can not use simple_layout because it must start |
| 1763 | # with a configuration which does not include a |
| 1764 | # timer-triggered job so that we have an opportunity to set |
| 1765 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1766 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1767 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1768 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1769 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1770 | # The pipeline triggers every second, so we should have seen |
| 1771 | # several by now. |
| 1772 | time.sleep(5) |
| 1773 | self.waitUntilSettled() |
| 1774 | # Stop queuing timer triggered jobs so that the assertions |
| 1775 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1776 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1777 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1778 | self.sched.reconfigure(self.config) |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1779 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1780 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1781 | |
| 1782 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1783 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1784 | self.waitUntilSettled() |
| 1785 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1786 | |
| 1787 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1788 | self.waitUntilSettled() |
| 1789 | |
| 1790 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1791 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1792 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1793 | self.waitUntilSettled() |
| 1794 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1795 | def test_zuul_url_return(self): |
| 1796 | "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] | 1797 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1798 | self.executor_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1799 | |
| 1800 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1801 | A.addApproval('code-review', 2) |
| 1802 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1803 | self.waitUntilSettled() |
| 1804 | |
| 1805 | self.assertEqual(len(self.builds), 1) |
| 1806 | for build in self.builds: |
| 1807 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1808 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1809 | self.executor_server.hold_jobs_in_build = False |
| 1810 | self.executor_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1811 | self.waitUntilSettled() |
| 1812 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1813 | def test_new_patchset_dequeues_old_on_head(self): |
| 1814 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1815 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1816 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1817 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1818 | M.setMerged() |
| 1819 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1820 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1821 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1822 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1823 | A.addApproval('code-review', 2) |
| 1824 | B.addApproval('code-review', 2) |
| 1825 | C.addApproval('code-review', 2) |
| 1826 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1827 | |
| 1828 | C.setDependsOn(B, 1) |
| 1829 | B.setDependsOn(A, 1) |
| 1830 | A.setDependsOn(M, 1) |
| 1831 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1832 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1833 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1834 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1835 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1836 | self.waitUntilSettled() |
| 1837 | |
| 1838 | A.addPatchset() |
| 1839 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1840 | self.waitUntilSettled() |
| 1841 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1842 | self.executor_server.hold_jobs_in_build = False |
| 1843 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1844 | self.waitUntilSettled() |
| 1845 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1846 | self.assertEqual(A.data['status'], 'NEW') |
| 1847 | self.assertEqual(A.reported, 2) |
| 1848 | self.assertEqual(B.data['status'], 'NEW') |
| 1849 | self.assertEqual(B.reported, 2) |
| 1850 | self.assertEqual(C.data['status'], 'NEW') |
| 1851 | self.assertEqual(C.reported, 2) |
| 1852 | self.assertEqual(D.data['status'], 'MERGED') |
| 1853 | self.assertEqual(D.reported, 2) |
| 1854 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1855 | |
| 1856 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1857 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1858 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1859 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1860 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1861 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1862 | A.addApproval('code-review', 2) |
| 1863 | B.addApproval('code-review', 2) |
| 1864 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1865 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1866 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1867 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1868 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1869 | self.waitUntilSettled() |
| 1870 | |
| 1871 | B.addPatchset() |
| 1872 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1873 | self.waitUntilSettled() |
| 1874 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1875 | self.executor_server.hold_jobs_in_build = False |
| 1876 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1877 | self.waitUntilSettled() |
| 1878 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1879 | self.assertEqual(A.data['status'], 'MERGED') |
| 1880 | self.assertEqual(A.reported, 2) |
| 1881 | self.assertEqual(B.data['status'], 'NEW') |
| 1882 | self.assertEqual(B.reported, 2) |
| 1883 | self.assertEqual(C.data['status'], 'MERGED') |
| 1884 | self.assertEqual(C.reported, 2) |
| 1885 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1886 | |
| 1887 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1888 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1889 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1890 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1891 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1892 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1893 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1894 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1895 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1896 | self.waitUntilSettled() |
| 1897 | |
| 1898 | B.addPatchset() |
| 1899 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1900 | self.waitUntilSettled() |
| 1901 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1902 | self.executor_server.hold_jobs_in_build = False |
| 1903 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1904 | self.waitUntilSettled() |
| 1905 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1906 | self.assertEqual(A.data['status'], 'NEW') |
| 1907 | self.assertEqual(A.reported, 1) |
| 1908 | self.assertEqual(B.data['status'], 'NEW') |
| 1909 | self.assertEqual(B.reported, 1) |
| 1910 | self.assertEqual(C.data['status'], 'NEW') |
| 1911 | self.assertEqual(C.reported, 1) |
| 1912 | self.assertEqual(len(self.history), 10) |
| 1913 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1914 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1915 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1916 | def test_noop_job(self): |
| 1917 | "Test that the internal noop job works" |
| 1918 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1919 | A.addApproval('code-review', 2) |
| 1920 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1921 | self.waitUntilSettled() |
| 1922 | |
| 1923 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1924 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1925 | self.assertEqual(len(self.history), 0) |
| 1926 | self.assertEqual(A.data['status'], 'MERGED') |
| 1927 | self.assertEqual(A.reported, 2) |
| 1928 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 1929 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1930 | def test_no_job_project(self): |
| 1931 | "Test that reports with no jobs don't get sent" |
| 1932 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1933 | 'master', 'A') |
| 1934 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1935 | self.waitUntilSettled() |
| 1936 | |
| 1937 | # Change wasn't reported to |
| 1938 | self.assertEqual(A.reported, False) |
| 1939 | |
| 1940 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1941 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1942 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1943 | items = check_pipeline.getAllItems() |
| 1944 | self.assertEqual(len(items), 0) |
| 1945 | |
| 1946 | self.assertEqual(len(self.history), 0) |
| 1947 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1948 | def test_zuul_refs(self): |
| 1949 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1950 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1951 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1952 | M1.setMerged() |
| 1953 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1954 | M2.setMerged() |
| 1955 | |
| 1956 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1957 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1958 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1959 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1960 | A.addApproval('code-review', 2) |
| 1961 | B.addApproval('code-review', 2) |
| 1962 | C.addApproval('code-review', 2) |
| 1963 | D.addApproval('code-review', 2) |
| 1964 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1965 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1966 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1967 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1968 | |
| 1969 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1970 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1971 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1972 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1973 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1974 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1975 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1976 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1977 | self.waitUntilSettled() |
| 1978 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1979 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1980 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1981 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1982 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1983 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1984 | a_build = x |
| 1985 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1986 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1987 | b_build = x |
| 1988 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1989 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1990 | c_build = x |
| 1991 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1992 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1993 | d_build = x |
| 1994 | if a_build and b_build and c_build and d_build: |
| 1995 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1996 | |
| 1997 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1998 | self.assertIsNotNone(a_zref) |
| 1999 | self.assertIsNotNone(b_zref) |
| 2000 | self.assertIsNotNone(c_zref) |
| 2001 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2002 | |
| 2003 | # And they should all be different |
| 2004 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2005 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2006 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2007 | # should have a, not b, and should not be in project2 |
| 2008 | self.assertTrue(a_build.hasChanges(A)) |
| 2009 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2010 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2011 | # should have a and b, and should not be in project2 |
| 2012 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2013 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2014 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2015 | # should have a and b in 1, c in 2 |
| 2016 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2017 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2018 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2019 | # should have a and b in 1, c and d in 2 |
| 2020 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2021 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2022 | self.executor_server.hold_jobs_in_build = False |
| 2023 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2024 | self.waitUntilSettled() |
| 2025 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2026 | self.assertEqual(A.data['status'], 'MERGED') |
| 2027 | self.assertEqual(A.reported, 2) |
| 2028 | self.assertEqual(B.data['status'], 'MERGED') |
| 2029 | self.assertEqual(B.reported, 2) |
| 2030 | self.assertEqual(C.data['status'], 'MERGED') |
| 2031 | self.assertEqual(C.reported, 2) |
| 2032 | self.assertEqual(D.data['status'], 'MERGED') |
| 2033 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2034 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2035 | def test_rerun_on_error(self): |
| 2036 | "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] | 2037 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2038 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2039 | A.addApproval('code-review', 2) |
| 2040 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2041 | self.waitUntilSettled() |
| 2042 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2043 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2044 | self.executor_server.hold_jobs_in_build = False |
| 2045 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2046 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2047 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2048 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2049 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2050 | def test_statsd(self): |
| 2051 | "Test each of the statsd methods used in the scheduler" |
| 2052 | import extras |
| 2053 | statsd = extras.try_import('statsd.statsd') |
| 2054 | statsd.incr('test-incr') |
| 2055 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2056 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2057 | self.assertReportedStat('test-incr', '1|c') |
| 2058 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2059 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2060 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2061 | def test_stuck_job_cleanup(self): |
| 2062 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2063 | |
| 2064 | # 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] | 2065 | self.gearman_server.hold_jobs_in_queue = True |
| 2066 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2067 | A.addApproval('code-review', 2) |
| 2068 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2069 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2070 | # 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] | 2071 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2072 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2073 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2074 | self.sched.reconfigure(self.config) |
| 2075 | self.waitUntilSettled() |
| 2076 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2077 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2078 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2079 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2080 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2081 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2082 | |
| 2083 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2084 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2085 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2086 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2087 | def test_file_head(self): |
| 2088 | # This is a regression test for an observed bug. A change |
| 2089 | # with a file named "HEAD" in the root directory of the repo |
| 2090 | # was processed by a merger. It then was unable to reset the |
| 2091 | # repo because of: |
| 2092 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2093 | # with exit code 128 |
| 2094 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2095 | # and filename |
| 2096 | # Use '--' to separate filenames from revisions' |
| 2097 | |
| 2098 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2099 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2100 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2101 | |
| 2102 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2103 | self.waitUntilSettled() |
| 2104 | |
| 2105 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2106 | self.waitUntilSettled() |
| 2107 | |
| 2108 | self.assertIn('Build succeeded', A.messages[0]) |
| 2109 | self.assertIn('Build succeeded', B.messages[0]) |
| 2110 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2111 | def test_file_jobs(self): |
| 2112 | "Test that file jobs run only when appropriate" |
| 2113 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2114 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2115 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2116 | A.addApproval('code-review', 2) |
| 2117 | B.addApproval('code-review', 2) |
| 2118 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2119 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2120 | self.waitUntilSettled() |
| 2121 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2122 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2123 | if x.name == 'project-testfile'] |
| 2124 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2125 | self.assertEqual(len(testfile_jobs), 1) |
| 2126 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2127 | self.assertEqual(A.data['status'], 'MERGED') |
| 2128 | self.assertEqual(A.reported, 2) |
| 2129 | self.assertEqual(B.data['status'], 'MERGED') |
| 2130 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2131 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2132 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2133 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2134 | if should_skip: |
| 2135 | files = {'ignoreme': 'ignored\n'} |
| 2136 | else: |
| 2137 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2138 | |
| 2139 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2140 | 'master', |
| 2141 | 'test irrelevant-files', |
| 2142 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2143 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2144 | self.waitUntilSettled() |
| 2145 | |
| 2146 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2147 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2148 | |
| 2149 | if should_skip: |
| 2150 | self.assertEqual([], tested_change_ids) |
| 2151 | else: |
| 2152 | self.assertIn(change.data['number'], tested_change_ids) |
| 2153 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2154 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2155 | def test_irrelevant_files_match_skips_job(self): |
| 2156 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2157 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2158 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2159 | def test_irrelevant_files_no_match_runs_job(self): |
| 2160 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2161 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2162 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2163 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2164 | files = {'ignoreme': 'ignored\n'} |
| 2165 | |
| 2166 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2167 | 'master', |
| 2168 | 'test irrelevant-files', |
| 2169 | files=files) |
| 2170 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2171 | self.waitUntilSettled() |
| 2172 | |
| 2173 | run_jobs = set([build.name for build in self.history]) |
| 2174 | |
| 2175 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2176 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2177 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2178 | def test_queue_names(self): |
| 2179 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2180 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2181 | (trusted, project1) = tenant.getProject('org/project1') |
| 2182 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2183 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2184 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2185 | self.assertEqual(q1.name, 'integrated') |
| 2186 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2187 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2188 | def test_queue_precedence(self): |
| 2189 | "Test that queue precedence works" |
| 2190 | |
| 2191 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2192 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2193 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2194 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2195 | A.addApproval('code-review', 2) |
| 2196 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2197 | |
| 2198 | self.waitUntilSettled() |
| 2199 | self.gearman_server.hold_jobs_in_queue = False |
| 2200 | self.gearman_server.release() |
| 2201 | self.waitUntilSettled() |
| 2202 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2203 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2204 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2205 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2206 | self.waitUntilSettled() |
| 2207 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2208 | self.log.debug(self.history) |
| 2209 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2210 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2211 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2212 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2213 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2214 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2215 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2216 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2217 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2218 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2219 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2220 | A.addApproval('code-review', 2) |
| 2221 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2222 | self.waitUntilSettled() |
| 2223 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2224 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2225 | self.waitUntilSettled() |
| 2226 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2227 | port = self.webapp.server.socket.getsockname()[1] |
| 2228 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2229 | req = urllib.request.Request( |
| 2230 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2231 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2232 | headers = f.info() |
| 2233 | self.assertIn('Content-Length', headers) |
| 2234 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2235 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2236 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2237 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2238 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2239 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2240 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2241 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2242 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2243 | self.executor_server.hold_jobs_in_build = False |
| 2244 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2245 | self.waitUntilSettled() |
| 2246 | |
| 2247 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2248 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2249 | for p in data['pipelines']: |
| 2250 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2251 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2252 | self.assertEqual(q['window'], 20) |
| 2253 | else: |
| 2254 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2255 | for head in q['heads']: |
| 2256 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2257 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2258 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2259 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2260 | status_jobs.append(job) |
| 2261 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2262 | self.assertEqual('https://server/job/project-merge/0/', |
| 2263 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2264 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2265 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2266 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2267 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2268 | status_jobs[1]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2269 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2270 | status_jobs[1]['report_url']) |
| 2271 | |
| 2272 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2273 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2274 | status_jobs[2]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2275 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2276 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2277 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2278 | def test_live_reconfiguration(self): |
| 2279 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2280 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2281 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2282 | A.addApproval('code-review', 2) |
| 2283 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2284 | self.waitUntilSettled() |
| 2285 | |
| 2286 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2287 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2288 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2289 | self.executor_server.hold_jobs_in_build = False |
| 2290 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2291 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2292 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2293 | 'SUCCESS') |
| 2294 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2295 | 'SUCCESS') |
| 2296 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2297 | 'SUCCESS') |
| 2298 | self.assertEqual(A.data['status'], 'MERGED') |
| 2299 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2300 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2301 | def test_live_reconfiguration_merge_conflict(self): |
| 2302 | # A real-world bug: a change in a gate queue has a merge |
| 2303 | # conflict and a job is added to its project while it's |
| 2304 | # sitting in the queue. The job gets added to the change and |
| 2305 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2306 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2307 | |
| 2308 | # This change is fine. It's here to stop the queue long |
| 2309 | # enough for the next change to be subject to the |
| 2310 | # reconfiguration, as well as to provide a conflict for the |
| 2311 | # next change. This change will succeed and merge. |
| 2312 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2313 | A.addPatchset({'conflict': 'A'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2314 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2315 | |
| 2316 | # This change will be in merge conflict. During the |
| 2317 | # reconfiguration, we will add a job. We want to make sure |
| 2318 | # that doesn't cause it to get stuck. |
| 2319 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2320 | B.addPatchset({'conflict': 'B'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2321 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2322 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2323 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2324 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2325 | |
| 2326 | self.waitUntilSettled() |
| 2327 | |
| 2328 | # No jobs have run yet |
| 2329 | self.assertEqual(A.data['status'], 'NEW') |
| 2330 | self.assertEqual(A.reported, 1) |
| 2331 | self.assertEqual(B.data['status'], 'NEW') |
| 2332 | self.assertEqual(B.reported, 1) |
| 2333 | self.assertEqual(len(self.history), 0) |
| 2334 | |
| 2335 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2336 | self.commitConfigUpdate('common-config', |
| 2337 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2338 | self.sched.reconfigure(self.config) |
| 2339 | self.waitUntilSettled() |
| 2340 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2341 | self.executor_server.hold_jobs_in_build = False |
| 2342 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2343 | self.waitUntilSettled() |
| 2344 | |
| 2345 | self.assertEqual(A.data['status'], 'MERGED') |
| 2346 | self.assertEqual(A.reported, 2) |
| 2347 | self.assertEqual(B.data['status'], 'NEW') |
| 2348 | self.assertEqual(B.reported, 2) |
| 2349 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2350 | 'SUCCESS') |
| 2351 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2352 | 'SUCCESS') |
| 2353 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2354 | 'SUCCESS') |
| 2355 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2356 | 'SUCCESS') |
| 2357 | self.assertEqual(len(self.history), 4) |
| 2358 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2359 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2360 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2361 | # that tests a job added to a job tree with a failed root does |
| 2362 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2363 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2364 | |
| 2365 | # This change is fine. It's here to stop the queue long |
| 2366 | # enough for the next change to be subject to the |
| 2367 | # reconfiguration. This change will succeed and merge. |
| 2368 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2369 | A.addPatchset({'conflict': 'A'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2370 | A.addApproval('code-review', 2) |
| 2371 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2372 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2373 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2374 | self.waitUntilSettled() |
| 2375 | |
| 2376 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2377 | self.executor_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2378 | B.addApproval('code-review', 2) |
| 2379 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2380 | self.waitUntilSettled() |
| 2381 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2382 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2383 | self.waitUntilSettled() |
| 2384 | |
| 2385 | # Both -merge jobs have run, but no others. |
| 2386 | self.assertEqual(A.data['status'], 'NEW') |
| 2387 | self.assertEqual(A.reported, 1) |
| 2388 | self.assertEqual(B.data['status'], 'NEW') |
| 2389 | self.assertEqual(B.reported, 1) |
| 2390 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2391 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2392 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2393 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2394 | self.assertEqual(len(self.history), 2) |
| 2395 | |
| 2396 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2397 | self.commitConfigUpdate('common-config', |
| 2398 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2399 | self.sched.reconfigure(self.config) |
| 2400 | self.waitUntilSettled() |
| 2401 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2402 | self.executor_server.hold_jobs_in_build = False |
| 2403 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2404 | self.waitUntilSettled() |
| 2405 | |
| 2406 | self.assertEqual(A.data['status'], 'MERGED') |
| 2407 | self.assertEqual(A.reported, 2) |
| 2408 | self.assertEqual(B.data['status'], 'NEW') |
| 2409 | self.assertEqual(B.reported, 2) |
| 2410 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2411 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2412 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2413 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2414 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2415 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2416 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2417 | self.assertEqual(len(self.history), 5) |
| 2418 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2419 | def test_live_reconfiguration_failed_job(self): |
| 2420 | # Test that a change with a removed failing job does not |
| 2421 | # disrupt reconfiguration. If a change has a failed job and |
| 2422 | # that job is removed during a reconfiguration, we observed a |
| 2423 | # bug where the code to re-set build statuses would run on |
| 2424 | # that build and raise an exception because the job no longer |
| 2425 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2426 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2427 | |
| 2428 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2429 | |
| 2430 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2431 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2432 | |
| 2433 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2434 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2435 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2436 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2437 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2438 | self.waitUntilSettled() |
| 2439 | |
| 2440 | self.assertEqual(A.data['status'], 'NEW') |
| 2441 | self.assertEqual(A.reported, 0) |
| 2442 | |
| 2443 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2444 | 'SUCCESS') |
| 2445 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2446 | 'FAILURE') |
| 2447 | self.assertEqual(len(self.history), 2) |
| 2448 | |
| 2449 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2450 | self.commitConfigUpdate('common-config', |
| 2451 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2452 | self.sched.reconfigure(self.config) |
| 2453 | self.waitUntilSettled() |
| 2454 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2455 | self.executor_server.hold_jobs_in_build = False |
| 2456 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2457 | self.waitUntilSettled() |
| 2458 | |
| 2459 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2460 | 'SUCCESS') |
| 2461 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2462 | 'SUCCESS') |
| 2463 | self.assertEqual(len(self.history), 4) |
| 2464 | |
| 2465 | self.assertEqual(A.data['status'], 'NEW') |
| 2466 | self.assertEqual(A.reported, 1) |
| 2467 | self.assertIn('Build succeeded', A.messages[0]) |
| 2468 | # Ensure the removed job was not included in the report. |
| 2469 | self.assertNotIn('project-test1', A.messages[0]) |
| 2470 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2471 | def test_live_reconfiguration_shared_queue(self): |
| 2472 | # Test that a change with a failing job which was removed from |
| 2473 | # this project but otherwise still exists in the system does |
| 2474 | # not disrupt reconfiguration. |
| 2475 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2476 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2477 | |
| 2478 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2479 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2480 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2481 | |
| 2482 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2483 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2484 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2485 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2486 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2487 | self.waitUntilSettled() |
| 2488 | |
| 2489 | self.assertEqual(A.data['status'], 'NEW') |
| 2490 | self.assertEqual(A.reported, 0) |
| 2491 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2492 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2493 | 'SUCCESS') |
| 2494 | self.assertEqual(self.getJobFromHistory( |
| 2495 | 'project1-project2-integration').result, 'FAILURE') |
| 2496 | self.assertEqual(len(self.history), 2) |
| 2497 | |
| 2498 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2499 | self.commitConfigUpdate( |
| 2500 | 'common-config', |
| 2501 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2502 | self.sched.reconfigure(self.config) |
| 2503 | self.waitUntilSettled() |
| 2504 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2505 | self.executor_server.hold_jobs_in_build = False |
| 2506 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2507 | self.waitUntilSettled() |
| 2508 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2509 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2510 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2511 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2512 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2513 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2514 | 'SUCCESS') |
| 2515 | self.assertEqual(self.getJobFromHistory( |
| 2516 | 'project1-project2-integration').result, 'FAILURE') |
| 2517 | self.assertEqual(len(self.history), 4) |
| 2518 | |
| 2519 | self.assertEqual(A.data['status'], 'NEW') |
| 2520 | self.assertEqual(A.reported, 1) |
| 2521 | self.assertIn('Build succeeded', A.messages[0]) |
| 2522 | # Ensure the removed job was not included in the report. |
| 2523 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2524 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2525 | def test_double_live_reconfiguration_shared_queue(self): |
| 2526 | # This was a real-world regression. A change is added to |
| 2527 | # gate; a reconfigure happens, a second change which depends |
| 2528 | # on the first is added, and a second reconfiguration happens. |
| 2529 | # Ensure that both changes merge. |
| 2530 | |
| 2531 | # A failure may indicate incorrect caching or cleaning up of |
| 2532 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2533 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2534 | |
| 2535 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2536 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2537 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2538 | A.addApproval('code-review', 2) |
| 2539 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2540 | |
| 2541 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2542 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2543 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2544 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2545 | self.waitUntilSettled() |
| 2546 | |
| 2547 | # Reconfigure (with only one change in the pipeline). |
| 2548 | self.sched.reconfigure(self.config) |
| 2549 | self.waitUntilSettled() |
| 2550 | |
| 2551 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2552 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2553 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2554 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2555 | self.waitUntilSettled() |
| 2556 | |
| 2557 | # Reconfigure (with both in the pipeline). |
| 2558 | self.sched.reconfigure(self.config) |
| 2559 | self.waitUntilSettled() |
| 2560 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2561 | self.executor_server.hold_jobs_in_build = False |
| 2562 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2563 | self.waitUntilSettled() |
| 2564 | |
| 2565 | self.assertEqual(len(self.history), 8) |
| 2566 | |
| 2567 | self.assertEqual(A.data['status'], 'MERGED') |
| 2568 | self.assertEqual(A.reported, 2) |
| 2569 | self.assertEqual(B.data['status'], 'MERGED') |
| 2570 | self.assertEqual(B.reported, 2) |
| 2571 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2572 | def test_live_reconfiguration_del_project(self): |
| 2573 | # Test project deletion from layout |
| 2574 | # while changes are enqueued |
| 2575 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2576 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2577 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2578 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2579 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2580 | |
| 2581 | # A Depends-On: B |
| 2582 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2583 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2584 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2585 | |
| 2586 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2587 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2588 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2589 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2590 | self.waitUntilSettled() |
| 2591 | self.assertEqual(len(self.builds), 5) |
| 2592 | |
| 2593 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2594 | self.commitConfigUpdate( |
| 2595 | 'common-config', |
| 2596 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2597 | self.sched.reconfigure(self.config) |
| 2598 | self.waitUntilSettled() |
| 2599 | |
| 2600 | # Builds for C aborted, builds for A succeed, |
| 2601 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2602 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2603 | self.assertEqual(job_c.changes, '3,1') |
| 2604 | self.assertEqual(job_c.result, 'ABORTED') |
| 2605 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2606 | self.executor_server.hold_jobs_in_build = False |
| 2607 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2608 | self.waitUntilSettled() |
| 2609 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2610 | self.assertEqual( |
| 2611 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2612 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2613 | |
| 2614 | self.assertEqual(A.data['status'], 'NEW') |
| 2615 | self.assertEqual(B.data['status'], 'NEW') |
| 2616 | self.assertEqual(C.data['status'], 'NEW') |
| 2617 | self.assertEqual(A.reported, 1) |
| 2618 | self.assertEqual(B.reported, 0) |
| 2619 | self.assertEqual(C.reported, 0) |
| 2620 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2621 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2622 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2623 | self.assertIn('Build succeeded', A.messages[0]) |
| 2624 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2625 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2626 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2627 | self.updateConfigLayout( |
| 2628 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2629 | self.sched.reconfigure(self.config) |
| 2630 | |
| 2631 | self.init_repo("org/new-project") |
| 2632 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2633 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2634 | A.addApproval('code-review', 2) |
| 2635 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2636 | self.waitUntilSettled() |
| 2637 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2638 | 'SUCCESS') |
| 2639 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2640 | 'SUCCESS') |
| 2641 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2642 | 'SUCCESS') |
| 2643 | self.assertEqual(A.data['status'], 'MERGED') |
| 2644 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2645 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2646 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2647 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2648 | self.init_repo("org/delete-project") |
| 2649 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2650 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2651 | A.addApproval('code-review', 2) |
| 2652 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2653 | self.waitUntilSettled() |
| 2654 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2655 | 'SUCCESS') |
| 2656 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2657 | 'SUCCESS') |
| 2658 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2659 | 'SUCCESS') |
| 2660 | self.assertEqual(A.data['status'], 'MERGED') |
| 2661 | self.assertEqual(A.reported, 2) |
| 2662 | |
| 2663 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2664 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2665 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2666 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2667 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2668 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2669 | |
| 2670 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2671 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2672 | B.addApproval('code-review', 2) |
| 2673 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2674 | self.waitUntilSettled() |
| 2675 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2676 | 'SUCCESS') |
| 2677 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2678 | 'SUCCESS') |
| 2679 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2680 | 'SUCCESS') |
| 2681 | self.assertEqual(B.data['status'], 'MERGED') |
| 2682 | self.assertEqual(B.reported, 2) |
| 2683 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2684 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2685 | def test_tags(self): |
| 2686 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2687 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2688 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2689 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2690 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2691 | self.waitUntilSettled() |
| 2692 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2693 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2694 | |
| 2695 | results = {self.getJobFromHistory('merge', |
| 2696 | project='org/project1').uuid: 'extratag merge', |
| 2697 | self.getJobFromHistory('merge', |
| 2698 | project='org/project2').uuid: 'merge'} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2699 | |
| 2700 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2701 | self.assertEqual(results.get(build.uuid, ''), |
| 2702 | build.parameters['vars']['zuul'].get('tags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2703 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2704 | def test_timer(self): |
| 2705 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2706 | # This test can not use simple_layout because it must start |
| 2707 | # with a configuration which does not include a |
| 2708 | # timer-triggered job so that we have an opportunity to set |
| 2709 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2710 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2711 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2712 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2713 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2714 | # The pipeline triggers every second, so we should have seen |
| 2715 | # several by now. |
| 2716 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2717 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2718 | |
| 2719 | self.assertEqual(len(self.builds), 2) |
| 2720 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2721 | port = self.webapp.server.socket.getsockname()[1] |
| 2722 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2723 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2724 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2725 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2726 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2727 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2728 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2729 | # Stop queuing timer triggered jobs so that the assertions |
| 2730 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2731 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2732 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2733 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2734 | self.waitUntilSettled() |
| 2735 | |
| 2736 | self.assertEqual(self.getJobFromHistory( |
| 2737 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2738 | self.assertEqual(self.getJobFromHistory( |
| 2739 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2740 | |
| 2741 | data = json.loads(data) |
| 2742 | status_jobs = set() |
| 2743 | for p in data['pipelines']: |
| 2744 | for q in p['change_queues']: |
| 2745 | for head in q['heads']: |
| 2746 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2747 | for job in change['jobs']: |
| 2748 | status_jobs.add(job['name']) |
| 2749 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2750 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2751 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2752 | def test_idle(self): |
| 2753 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2754 | # This test can not use simple_layout because it must start |
| 2755 | # with a configuration which does not include a |
| 2756 | # timer-triggered job so that we have an opportunity to set |
| 2757 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2758 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2759 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2760 | for x in range(1, 3): |
| 2761 | # Test that timer triggers periodic jobs even across |
| 2762 | # layout config reloads. |
| 2763 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2764 | self.commitConfigUpdate('common-config', |
| 2765 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2766 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2767 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2768 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2769 | # The pipeline triggers every second, so we should have seen |
| 2770 | # several by now. |
| 2771 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2772 | |
| 2773 | # Stop queuing timer triggered jobs so that the assertions |
| 2774 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2775 | self.commitConfigUpdate('common-config', |
| 2776 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2777 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2778 | self.waitUntilSettled() |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2779 | self.assertEqual(len(self.builds), 2, |
| 2780 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2781 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2782 | self.waitUntilSettled() |
| 2783 | self.assertEqual(len(self.builds), 0) |
| 2784 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2785 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2786 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2787 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2788 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2789 | self.waitUntilSettled() |
| 2790 | |
| 2791 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2792 | self.waitUntilSettled() |
| 2793 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2794 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2795 | |
| 2796 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2797 | # work on the knowledge of what the first message should be as |
| 2798 | # it is only configured to go to SMTP. |
| 2799 | |
| 2800 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2801 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2802 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2803 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2804 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2805 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2806 | |
| 2807 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2808 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2809 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2810 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2811 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2812 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2813 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2814 | def test_timer_smtp(self): |
| 2815 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2816 | # This test can not use simple_layout because it must start |
| 2817 | # with a configuration which does not include a |
| 2818 | # timer-triggered job so that we have an opportunity to set |
| 2819 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2820 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2821 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2822 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2823 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2824 | # The pipeline triggers every second, so we should have seen |
| 2825 | # several by now. |
| 2826 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2827 | self.waitUntilSettled() |
| 2828 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2829 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2830 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2831 | self.waitUntilSettled() |
| 2832 | self.assertEqual(len(self.history), 2) |
| 2833 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2834 | self.assertEqual(self.getJobFromHistory( |
| 2835 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2836 | self.assertEqual(self.getJobFromHistory( |
| 2837 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2838 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2839 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2840 | |
| 2841 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2842 | # work on the knowledge of what the first message should be as |
| 2843 | # it is only configured to go to SMTP. |
| 2844 | |
| 2845 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2846 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2847 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2848 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2849 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2850 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2851 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2852 | # Stop queuing timer triggered jobs and let any that may have |
| 2853 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2854 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2855 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 2856 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2857 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2858 | self.waitUntilSettled() |
| 2859 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 2860 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 2861 | def test_timer_sshkey(self): |
| 2862 | "Test that a periodic job can setup SSH key authentication" |
| 2863 | self.worker.hold_jobs_in_build = True |
| 2864 | self.config.set('zuul', 'layout_config', |
| 2865 | 'tests/fixtures/layout-timer.yaml') |
| 2866 | self.sched.reconfigure(self.config) |
| 2867 | self.registerJobs() |
| 2868 | |
| 2869 | # The pipeline triggers every second, so we should have seen |
| 2870 | # several by now. |
| 2871 | time.sleep(5) |
| 2872 | self.waitUntilSettled() |
| 2873 | |
| 2874 | self.assertEqual(len(self.builds), 2) |
| 2875 | |
| 2876 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 2877 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 2878 | with open(ssh_wrapper) as f: |
| 2879 | ssh_wrapper_content = f.read() |
| 2880 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 2881 | # In the unit tests Merger runs in the same process, |
| 2882 | # so we see its' environment variables |
| 2883 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 2884 | |
| 2885 | self.worker.release('.*') |
| 2886 | self.waitUntilSettled() |
| 2887 | self.assertEqual(len(self.history), 2) |
| 2888 | |
| 2889 | self.assertEqual(self.getJobFromHistory( |
| 2890 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2891 | self.assertEqual(self.getJobFromHistory( |
| 2892 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2893 | |
| 2894 | # Stop queuing timer triggered jobs and let any that may have |
| 2895 | # queued through so that end of test assertions pass. |
| 2896 | self.config.set('zuul', 'layout_config', |
| 2897 | 'tests/fixtures/layout-no-timer.yaml') |
| 2898 | self.sched.reconfigure(self.config) |
| 2899 | self.registerJobs() |
| 2900 | self.waitUntilSettled() |
| 2901 | self.worker.release('.*') |
| 2902 | self.waitUntilSettled() |
| 2903 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2904 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2905 | "Test that the RPC client can enqueue a change" |
| 2906 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2907 | A.addApproval('code-review', 2) |
| 2908 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2909 | |
| 2910 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2911 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 2912 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2913 | r = client.enqueue(tenant='tenant-one', |
| 2914 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2915 | project='org/project', |
| 2916 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2917 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2918 | self.waitUntilSettled() |
| 2919 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2920 | 'SUCCESS') |
| 2921 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2922 | 'SUCCESS') |
| 2923 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2924 | 'SUCCESS') |
| 2925 | self.assertEqual(A.data['status'], 'MERGED') |
| 2926 | self.assertEqual(A.reported, 2) |
| 2927 | self.assertEqual(r, True) |
| 2928 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2929 | def test_client_enqueue_ref(self): |
| 2930 | "Test that the RPC client can enqueue a ref" |
| 2931 | |
| 2932 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2933 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 2934 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2935 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2936 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2937 | pipeline='post', |
| 2938 | project='org/project', |
| 2939 | trigger='gerrit', |
| 2940 | ref='master', |
| 2941 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 2942 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 2943 | self.waitUntilSettled() |
| 2944 | job_names = [x.name for x in self.history] |
| 2945 | self.assertEqual(len(self.history), 1) |
| 2946 | self.assertIn('project-post', job_names) |
| 2947 | self.assertEqual(r, True) |
| 2948 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2949 | def test_client_enqueue_negative(self): |
| 2950 | "Test that the RPC client returns errors" |
| 2951 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2952 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 2953 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2954 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2955 | "Invalid tenant"): |
| 2956 | r = client.enqueue(tenant='tenant-foo', |
| 2957 | pipeline='gate', |
| 2958 | project='org/project', |
| 2959 | trigger='gerrit', |
| 2960 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2961 | self.assertEqual(r, False) |
| 2962 | |
| 2963 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2964 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2965 | r = client.enqueue(tenant='tenant-one', |
| 2966 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2967 | project='project-does-not-exist', |
| 2968 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2969 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2970 | self.assertEqual(r, False) |
| 2971 | |
| 2972 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2973 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2974 | r = client.enqueue(tenant='tenant-one', |
| 2975 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2976 | project='org/project', |
| 2977 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2978 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2979 | self.assertEqual(r, False) |
| 2980 | |
| 2981 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2982 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2983 | r = client.enqueue(tenant='tenant-one', |
| 2984 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2985 | project='org/project', |
| 2986 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2987 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2988 | self.assertEqual(r, False) |
| 2989 | |
| 2990 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2991 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2992 | r = client.enqueue(tenant='tenant-one', |
| 2993 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2994 | project='org/project', |
| 2995 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2996 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2997 | self.assertEqual(r, False) |
| 2998 | |
| 2999 | self.waitUntilSettled() |
| 3000 | self.assertEqual(len(self.history), 0) |
| 3001 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3002 | |
| 3003 | def test_client_promote(self): |
| 3004 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3005 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3006 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3007 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3008 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3009 | A.addApproval('code-review', 2) |
| 3010 | B.addApproval('code-review', 2) |
| 3011 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3012 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3013 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3014 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3015 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3016 | |
| 3017 | self.waitUntilSettled() |
| 3018 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3019 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3020 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3021 | enqueue_times = {} |
| 3022 | for item in items: |
| 3023 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3024 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3025 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3026 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3027 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3028 | r = client.promote(tenant='tenant-one', |
| 3029 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3030 | change_ids=['2,1', '3,1']) |
| 3031 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3032 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3033 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3034 | for item in items: |
| 3035 | self.assertEqual( |
| 3036 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3037 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3038 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3039 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3040 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3041 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3042 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3043 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3044 | self.waitUntilSettled() |
| 3045 | |
| 3046 | self.assertEqual(len(self.builds), 6) |
| 3047 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3048 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3049 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3050 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3051 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3052 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3053 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3054 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3055 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3056 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3057 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3058 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3059 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3060 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3061 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3062 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3063 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3064 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3065 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3066 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3067 | self.waitUntilSettled() |
| 3068 | |
| 3069 | self.assertEqual(A.data['status'], 'MERGED') |
| 3070 | self.assertEqual(A.reported, 2) |
| 3071 | self.assertEqual(B.data['status'], 'MERGED') |
| 3072 | self.assertEqual(B.reported, 2) |
| 3073 | self.assertEqual(C.data['status'], 'MERGED') |
| 3074 | self.assertEqual(C.reported, 2) |
| 3075 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3076 | self.assertEqual(r, True) |
| 3077 | |
| 3078 | def test_client_promote_dependent(self): |
| 3079 | "Test that the RPC client can promote a dependent change" |
| 3080 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3081 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3082 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3083 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3084 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3085 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3086 | |
| 3087 | C.setDependsOn(B, 1) |
| 3088 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3089 | A.addApproval('code-review', 2) |
| 3090 | B.addApproval('code-review', 2) |
| 3091 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3092 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3093 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3094 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3095 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3096 | |
| 3097 | self.waitUntilSettled() |
| 3098 | |
| 3099 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3100 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3101 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3102 | r = client.promote(tenant='tenant-one', |
| 3103 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3104 | change_ids=['3,1']) |
| 3105 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3106 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3107 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3108 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3109 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3110 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3111 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3112 | self.waitUntilSettled() |
| 3113 | |
| 3114 | self.assertEqual(len(self.builds), 6) |
| 3115 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3116 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3117 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3118 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3119 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3120 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3121 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3122 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3123 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3124 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3125 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3126 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3127 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3128 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3129 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3130 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3131 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3132 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3133 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3134 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3135 | self.waitUntilSettled() |
| 3136 | |
| 3137 | self.assertEqual(A.data['status'], 'MERGED') |
| 3138 | self.assertEqual(A.reported, 2) |
| 3139 | self.assertEqual(B.data['status'], 'MERGED') |
| 3140 | self.assertEqual(B.reported, 2) |
| 3141 | self.assertEqual(C.data['status'], 'MERGED') |
| 3142 | self.assertEqual(C.reported, 2) |
| 3143 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3144 | self.assertEqual(r, True) |
| 3145 | |
| 3146 | def test_client_promote_negative(self): |
| 3147 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3148 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3149 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3150 | A.addApproval('code-review', 2) |
| 3151 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3152 | self.waitUntilSettled() |
| 3153 | |
| 3154 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3155 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3156 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3157 | |
| 3158 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3159 | r = client.promote(tenant='tenant-one', |
| 3160 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3161 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3162 | self.assertEqual(r, False) |
| 3163 | |
| 3164 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3165 | r = client.promote(tenant='tenant-one', |
| 3166 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3167 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3168 | self.assertEqual(r, False) |
| 3169 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3170 | self.executor_server.hold_jobs_in_build = False |
| 3171 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3172 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3173 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3174 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3175 | def test_queue_rate_limiting(self): |
| 3176 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3177 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3178 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3179 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3180 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3181 | |
| 3182 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3183 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3184 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3185 | A.addApproval('code-review', 2) |
| 3186 | B.addApproval('code-review', 2) |
| 3187 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3188 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3189 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3190 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3191 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3192 | self.waitUntilSettled() |
| 3193 | |
| 3194 | # Only A and B will have their merge jobs queued because |
| 3195 | # window is 2. |
| 3196 | self.assertEqual(len(self.builds), 2) |
| 3197 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3198 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3199 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3200 | # Release the merge jobs one at a time. |
| 3201 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3202 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3203 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3204 | self.waitUntilSettled() |
| 3205 | |
| 3206 | # Only A and B will have their test jobs queued because |
| 3207 | # window is 2. |
| 3208 | self.assertEqual(len(self.builds), 4) |
| 3209 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3210 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3211 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3212 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3213 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3214 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3215 | self.waitUntilSettled() |
| 3216 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3217 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3218 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3219 | # A failed so window is reduced by 1 to 1. |
| 3220 | self.assertEqual(queue.window, 1) |
| 3221 | self.assertEqual(queue.window_floor, 1) |
| 3222 | self.assertEqual(A.data['status'], 'NEW') |
| 3223 | |
| 3224 | # Gate is reset and only B's merge job is queued because |
| 3225 | # window shrunk to 1. |
| 3226 | self.assertEqual(len(self.builds), 1) |
| 3227 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3228 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3229 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3230 | self.waitUntilSettled() |
| 3231 | |
| 3232 | # Only B's test jobs are queued because window is still 1. |
| 3233 | self.assertEqual(len(self.builds), 2) |
| 3234 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3235 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3236 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3237 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3238 | self.waitUntilSettled() |
| 3239 | |
| 3240 | # B was successfully merged so window is increased to 2. |
| 3241 | self.assertEqual(queue.window, 2) |
| 3242 | self.assertEqual(queue.window_floor, 1) |
| 3243 | self.assertEqual(B.data['status'], 'MERGED') |
| 3244 | |
| 3245 | # Only C is left and its merge job is queued. |
| 3246 | self.assertEqual(len(self.builds), 1) |
| 3247 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3248 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3249 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3250 | self.waitUntilSettled() |
| 3251 | |
| 3252 | # After successful merge job the test jobs for C are queued. |
| 3253 | self.assertEqual(len(self.builds), 2) |
| 3254 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3255 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3256 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3257 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3258 | self.waitUntilSettled() |
| 3259 | |
| 3260 | # C successfully merged so window is bumped to 3. |
| 3261 | self.assertEqual(queue.window, 3) |
| 3262 | self.assertEqual(queue.window_floor, 1) |
| 3263 | self.assertEqual(C.data['status'], 'MERGED') |
| 3264 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3265 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3266 | def test_queue_rate_limiting_dependent(self): |
| 3267 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3268 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3269 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3270 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3271 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3272 | |
| 3273 | B.setDependsOn(A, 1) |
| 3274 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3275 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3276 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3277 | A.addApproval('code-review', 2) |
| 3278 | B.addApproval('code-review', 2) |
| 3279 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3280 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3281 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3282 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3283 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3284 | self.waitUntilSettled() |
| 3285 | |
| 3286 | # Only A and B will have their merge jobs queued because |
| 3287 | # window is 2. |
| 3288 | self.assertEqual(len(self.builds), 2) |
| 3289 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3290 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3291 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3292 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3293 | |
| 3294 | # Only A and B will have their test jobs queued because |
| 3295 | # window is 2. |
| 3296 | self.assertEqual(len(self.builds), 4) |
| 3297 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3298 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3299 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3300 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3301 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3302 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3303 | self.waitUntilSettled() |
| 3304 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3305 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3306 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3307 | # A failed so window is reduced by 1 to 1. |
| 3308 | self.assertEqual(queue.window, 1) |
| 3309 | self.assertEqual(queue.window_floor, 1) |
| 3310 | self.assertEqual(A.data['status'], 'NEW') |
| 3311 | self.assertEqual(B.data['status'], 'NEW') |
| 3312 | |
| 3313 | # Gate is reset and only C's merge job is queued because |
| 3314 | # window shrunk to 1 and A and B were dequeued. |
| 3315 | self.assertEqual(len(self.builds), 1) |
| 3316 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3317 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3318 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3319 | |
| 3320 | # Only C's test jobs are queued because window is still 1. |
| 3321 | self.assertEqual(len(self.builds), 2) |
| 3322 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3323 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3324 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3325 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3326 | self.waitUntilSettled() |
| 3327 | |
| 3328 | # C was successfully merged so window is increased to 2. |
| 3329 | self.assertEqual(queue.window, 2) |
| 3330 | self.assertEqual(queue.window_floor, 1) |
| 3331 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3332 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3333 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3334 | def test_worker_update_metadata(self): |
| 3335 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3336 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3337 | |
| 3338 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3339 | A.addApproval('code-review', 2) |
| 3340 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3341 | self.waitUntilSettled() |
| 3342 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3343 | self.assertEqual(len(self.executor.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3344 | |
| 3345 | self.log.debug('Current builds:') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3346 | self.log.debug(self.executor.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3347 | |
| 3348 | start = time.time() |
| 3349 | while True: |
| 3350 | if time.time() - start > 10: |
| 3351 | raise Exception("Timeout waiting for gearman server to report " |
| 3352 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3353 | build = list(self.executor.builds.values())[0] |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3354 | if build.worker.name == "My Worker": |
| 3355 | break |
| 3356 | else: |
| 3357 | time.sleep(0) |
| 3358 | |
| 3359 | self.log.debug(build) |
| 3360 | self.assertEqual("My Worker", build.worker.name) |
| 3361 | self.assertEqual("localhost", build.worker.hostname) |
| 3362 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3363 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3364 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3365 | self.assertEqual("v1.1", build.worker.version) |
| 3366 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3367 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3368 | self.executor_server.hold_jobs_in_build = False |
| 3369 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3370 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3371 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3372 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3373 | def test_footer_message(self): |
| 3374 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3375 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3376 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3377 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3378 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3379 | self.waitUntilSettled() |
| 3380 | |
| 3381 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3382 | B.addApproval('code-review', 2) |
| 3383 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3384 | self.waitUntilSettled() |
| 3385 | |
| 3386 | self.assertEqual(2, len(self.smtp_messages)) |
| 3387 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3388 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3389 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3390 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3391 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3392 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3393 | For CI problems and help debugging, contact ci@example.org""" |
| 3394 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3395 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3396 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3397 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3398 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3399 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3400 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3401 | def test_merge_failure_reporters(self): |
| 3402 | """Check that the config is set up correctly""" |
| 3403 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3404 | self.updateConfigLayout( |
| 3405 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3406 | self.sched.reconfigure(self.config) |
| 3407 | self.registerJobs() |
| 3408 | |
| 3409 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3410 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3411 | "dependencies was unable to be automatically merged with the " |
| 3412 | "current state of its repository. Please rebase the change and " |
| 3413 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3414 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3415 | self.assertEqual( |
| 3416 | "The merge failed! For more information...", |
| 3417 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3418 | |
| 3419 | self.assertEqual( |
| 3420 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3421 | self.assertEqual( |
| 3422 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3423 | |
| 3424 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3425 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3426 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3427 | |
| 3428 | self.assertTrue( |
| 3429 | ( |
| 3430 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3431 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3432 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3433 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3434 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3435 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3436 | ) or ( |
| 3437 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3438 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3439 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3440 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3441 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3442 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3443 | ) |
| 3444 | ) |
| 3445 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3446 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3447 | def test_merge_failure_reports(self): |
| 3448 | """Check that when a change fails to merge the correct message is sent |
| 3449 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3450 | self.updateConfigLayout( |
| 3451 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3452 | self.sched.reconfigure(self.config) |
| 3453 | self.registerJobs() |
| 3454 | |
| 3455 | # Check a test failure isn't reported to SMTP |
| 3456 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3457 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3458 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3459 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3460 | self.waitUntilSettled() |
| 3461 | |
| 3462 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3463 | self.assertEqual(0, len(self.smtp_messages)) |
| 3464 | |
| 3465 | # Check a merge failure is reported to SMTP |
| 3466 | # B should be merged, but C will conflict with B |
| 3467 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3468 | B.addPatchset(['conflict']) |
| 3469 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3470 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3471 | B.addApproval('code-review', 2) |
| 3472 | C.addApproval('code-review', 2) |
| 3473 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3474 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3475 | self.waitUntilSettled() |
| 3476 | |
| 3477 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3478 | self.assertEqual(1, len(self.smtp_messages)) |
| 3479 | self.assertEqual('The merge failed! For more information...', |
| 3480 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3481 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3482 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3483 | def test_default_merge_failure_reports(self): |
| 3484 | """Check that the default merge failure reports are correct.""" |
| 3485 | |
| 3486 | # A should report success, B should report merge failure. |
| 3487 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3488 | A.addPatchset(['conflict']) |
| 3489 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3490 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3491 | A.addApproval('code-review', 2) |
| 3492 | B.addApproval('code-review', 2) |
| 3493 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3494 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3495 | self.waitUntilSettled() |
| 3496 | |
| 3497 | self.assertEqual(3, len(self.history)) # A jobs |
| 3498 | self.assertEqual(A.reported, 2) |
| 3499 | self.assertEqual(B.reported, 2) |
| 3500 | self.assertEqual(A.data['status'], 'MERGED') |
| 3501 | self.assertEqual(B.data['status'], 'NEW') |
| 3502 | self.assertIn('Build succeeded', A.messages[1]) |
| 3503 | self.assertIn('Merge Failed', B.messages[1]) |
| 3504 | self.assertIn('automatically merged', B.messages[1]) |
| 3505 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3506 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3507 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3508 | def test_client_get_running_jobs(self): |
| 3509 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3510 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3511 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3512 | A.addApproval('code-review', 2) |
| 3513 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3514 | self.waitUntilSettled() |
| 3515 | |
| 3516 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3517 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3518 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3519 | |
| 3520 | # Wait for gearman server to send the initial workData back to zuul |
| 3521 | start = time.time() |
| 3522 | while True: |
| 3523 | if time.time() - start > 10: |
| 3524 | raise Exception("Timeout waiting for gearman server to report " |
| 3525 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3526 | build = list(self.executor_client.builds.values())[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3527 | if build.worker.name == "My Worker": |
| 3528 | break |
| 3529 | else: |
| 3530 | time.sleep(0) |
| 3531 | |
| 3532 | running_items = client.get_running_jobs() |
| 3533 | |
| 3534 | self.assertEqual(1, len(running_items)) |
| 3535 | running_item = running_items[0] |
| 3536 | self.assertEqual([], running_item['failing_reasons']) |
| 3537 | self.assertEqual([], running_item['items_behind']) |
| 3538 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3539 | self.assertEqual(None, running_item['item_ahead']) |
| 3540 | self.assertEqual('org/project', running_item['project']) |
| 3541 | self.assertEqual(None, running_item['remaining_time']) |
| 3542 | self.assertEqual(True, running_item['active']) |
| 3543 | self.assertEqual('1,1', running_item['id']) |
| 3544 | |
| 3545 | self.assertEqual(3, len(running_item['jobs'])) |
| 3546 | for job in running_item['jobs']: |
| 3547 | if job['name'] == 'project-merge': |
| 3548 | self.assertEqual('project-merge', job['name']) |
| 3549 | self.assertEqual('gate', job['pipeline']) |
| 3550 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3551 | self.assertEqual('https://server/job/project-merge/0/', |
| 3552 | job['url']) |
| 3553 | self.assertEqual(7, len(job['worker'])) |
| 3554 | self.assertEqual(False, job['canceled']) |
| 3555 | self.assertEqual(True, job['voting']) |
| 3556 | self.assertEqual(None, job['result']) |
| 3557 | self.assertEqual('gate', job['pipeline']) |
| 3558 | break |
| 3559 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3560 | self.executor_server.hold_jobs_in_build = False |
| 3561 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3562 | self.waitUntilSettled() |
| 3563 | |
| 3564 | running_items = client.get_running_jobs() |
| 3565 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3566 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3567 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3568 | def test_nonvoting_pipeline(self): |
| 3569 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3570 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3571 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3572 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3573 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3574 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3575 | |
| 3576 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3577 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3578 | self.assertEqual( |
| 3579 | self.getJobFromHistory('experimental-project-test').result, |
| 3580 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3581 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3582 | |
| 3583 | def test_crd_gate(self): |
| 3584 | "Test cross-repo dependencies" |
| 3585 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3586 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3587 | A.addApproval('code-review', 2) |
| 3588 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3589 | |
| 3590 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3591 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3592 | AM2.setMerged() |
| 3593 | AM1.setMerged() |
| 3594 | |
| 3595 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3596 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3597 | BM2.setMerged() |
| 3598 | BM1.setMerged() |
| 3599 | |
| 3600 | # A -> AM1 -> AM2 |
| 3601 | # B -> BM1 -> BM2 |
| 3602 | # A Depends-On: B |
| 3603 | # M2 is here to make sure it is never queried. If it is, it |
| 3604 | # means zuul is walking down the entire history of merged |
| 3605 | # changes. |
| 3606 | |
| 3607 | B.setDependsOn(BM1, 1) |
| 3608 | BM1.setDependsOn(BM2, 1) |
| 3609 | |
| 3610 | A.setDependsOn(AM1, 1) |
| 3611 | AM1.setDependsOn(AM2, 1) |
| 3612 | |
| 3613 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3614 | A.subject, B.data['id']) |
| 3615 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3616 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3617 | self.waitUntilSettled() |
| 3618 | |
| 3619 | self.assertEqual(A.data['status'], 'NEW') |
| 3620 | self.assertEqual(B.data['status'], 'NEW') |
| 3621 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3622 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3623 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3624 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3625 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3626 | B.addApproval('approved', 1) |
| 3627 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3628 | self.waitUntilSettled() |
| 3629 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3630 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3631 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3632 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3633 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3634 | self.executor_server.hold_jobs_in_build = False |
| 3635 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3636 | self.waitUntilSettled() |
| 3637 | |
| 3638 | self.assertEqual(AM2.queried, 0) |
| 3639 | self.assertEqual(BM2.queried, 0) |
| 3640 | self.assertEqual(A.data['status'], 'MERGED') |
| 3641 | self.assertEqual(B.data['status'], 'MERGED') |
| 3642 | self.assertEqual(A.reported, 2) |
| 3643 | self.assertEqual(B.reported, 2) |
| 3644 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3645 | changes = self.getJobFromHistory( |
| 3646 | 'project-merge', 'org/project1').changes |
| 3647 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3648 | |
| 3649 | def test_crd_branch(self): |
| 3650 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3651 | |
| 3652 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3653 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3654 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3655 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3656 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3657 | A.addApproval('code-review', 2) |
| 3658 | B.addApproval('code-review', 2) |
| 3659 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3660 | |
| 3661 | # A Depends-On: B+C |
| 3662 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3663 | A.subject, B.data['id']) |
| 3664 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3665 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3666 | B.addApproval('approved', 1) |
| 3667 | C.addApproval('approved', 1) |
| 3668 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3669 | self.waitUntilSettled() |
| 3670 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3671 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3672 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3673 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3674 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3675 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3676 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3677 | self.executor_server.hold_jobs_in_build = False |
| 3678 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3679 | self.waitUntilSettled() |
| 3680 | |
| 3681 | self.assertEqual(A.data['status'], 'MERGED') |
| 3682 | self.assertEqual(B.data['status'], 'MERGED') |
| 3683 | self.assertEqual(C.data['status'], 'MERGED') |
| 3684 | self.assertEqual(A.reported, 2) |
| 3685 | self.assertEqual(B.reported, 2) |
| 3686 | self.assertEqual(C.reported, 2) |
| 3687 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3688 | changes = self.getJobFromHistory( |
| 3689 | 'project-merge', 'org/project1').changes |
| 3690 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3691 | |
| 3692 | def test_crd_multiline(self): |
| 3693 | "Test multiple depends-on lines in commit" |
| 3694 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3695 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3696 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3697 | A.addApproval('code-review', 2) |
| 3698 | B.addApproval('code-review', 2) |
| 3699 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3700 | |
| 3701 | # A Depends-On: B+C |
| 3702 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3703 | A.subject, B.data['id'], C.data['id']) |
| 3704 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3705 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3706 | B.addApproval('approved', 1) |
| 3707 | C.addApproval('approved', 1) |
| 3708 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3709 | self.waitUntilSettled() |
| 3710 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3711 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3712 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3713 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3714 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3715 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3716 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3717 | self.executor_server.hold_jobs_in_build = False |
| 3718 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3719 | self.waitUntilSettled() |
| 3720 | |
| 3721 | self.assertEqual(A.data['status'], 'MERGED') |
| 3722 | self.assertEqual(B.data['status'], 'MERGED') |
| 3723 | self.assertEqual(C.data['status'], 'MERGED') |
| 3724 | self.assertEqual(A.reported, 2) |
| 3725 | self.assertEqual(B.reported, 2) |
| 3726 | self.assertEqual(C.reported, 2) |
| 3727 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3728 | changes = self.getJobFromHistory( |
| 3729 | 'project-merge', 'org/project1').changes |
| 3730 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3731 | |
| 3732 | def test_crd_unshared_gate(self): |
| 3733 | "Test cross-repo dependencies in unshared gate queues" |
| 3734 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3735 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3736 | A.addApproval('code-review', 2) |
| 3737 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3738 | |
| 3739 | # A Depends-On: B |
| 3740 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3741 | A.subject, B.data['id']) |
| 3742 | |
| 3743 | # A and B do not share a queue, make sure that A is unable to |
| 3744 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3745 | B.addApproval('approved', 1) |
| 3746 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3747 | self.waitUntilSettled() |
| 3748 | |
| 3749 | self.assertEqual(A.data['status'], 'NEW') |
| 3750 | self.assertEqual(B.data['status'], 'NEW') |
| 3751 | self.assertEqual(A.reported, 0) |
| 3752 | self.assertEqual(B.reported, 0) |
| 3753 | self.assertEqual(len(self.history), 0) |
| 3754 | |
| 3755 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3756 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3757 | self.waitUntilSettled() |
| 3758 | |
| 3759 | self.assertEqual(B.data['status'], 'MERGED') |
| 3760 | self.assertEqual(B.reported, 2) |
| 3761 | |
| 3762 | # Now that B is merged, A should be able to be enqueued and |
| 3763 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3764 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3765 | self.waitUntilSettled() |
| 3766 | |
| 3767 | self.assertEqual(A.data['status'], 'MERGED') |
| 3768 | self.assertEqual(A.reported, 2) |
| 3769 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3770 | def test_crd_gate_reverse(self): |
| 3771 | "Test reverse cross-repo dependencies" |
| 3772 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3773 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3774 | A.addApproval('code-review', 2) |
| 3775 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3776 | |
| 3777 | # A Depends-On: B |
| 3778 | |
| 3779 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3780 | A.subject, B.data['id']) |
| 3781 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3782 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3783 | self.waitUntilSettled() |
| 3784 | |
| 3785 | self.assertEqual(A.data['status'], 'NEW') |
| 3786 | self.assertEqual(B.data['status'], 'NEW') |
| 3787 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3788 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3789 | A.addApproval('approved', 1) |
| 3790 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3791 | self.waitUntilSettled() |
| 3792 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3793 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3794 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3795 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3796 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3797 | self.executor_server.hold_jobs_in_build = False |
| 3798 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3799 | self.waitUntilSettled() |
| 3800 | |
| 3801 | self.assertEqual(A.data['status'], 'MERGED') |
| 3802 | self.assertEqual(B.data['status'], 'MERGED') |
| 3803 | self.assertEqual(A.reported, 2) |
| 3804 | self.assertEqual(B.reported, 2) |
| 3805 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3806 | changes = self.getJobFromHistory( |
| 3807 | 'project-merge', 'org/project1').changes |
| 3808 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3809 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3810 | def test_crd_cycle(self): |
| 3811 | "Test cross-repo dependency cycles" |
| 3812 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3813 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3814 | A.addApproval('code-review', 2) |
| 3815 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3816 | |
| 3817 | # A -> B -> A (via commit-depends) |
| 3818 | |
| 3819 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3820 | A.subject, B.data['id']) |
| 3821 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3822 | B.subject, A.data['id']) |
| 3823 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3824 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3825 | self.waitUntilSettled() |
| 3826 | |
| 3827 | self.assertEqual(A.reported, 0) |
| 3828 | self.assertEqual(B.reported, 0) |
| 3829 | self.assertEqual(A.data['status'], 'NEW') |
| 3830 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3831 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3832 | def test_crd_gate_unknown(self): |
| 3833 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 3834 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3835 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3836 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3837 | A.addApproval('code-review', 2) |
| 3838 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3839 | |
| 3840 | # A Depends-On: B |
| 3841 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3842 | A.subject, B.data['id']) |
| 3843 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3844 | B.addApproval('approved', 1) |
| 3845 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3846 | self.waitUntilSettled() |
| 3847 | |
| 3848 | # Unknown projects cannot share a queue with any other |
| 3849 | # since they don't have common jobs with any other (they have no jobs). |
| 3850 | # Changes which depend on unknown project changes |
| 3851 | # should not be processed in dependent pipeline |
| 3852 | self.assertEqual(A.data['status'], 'NEW') |
| 3853 | self.assertEqual(B.data['status'], 'NEW') |
| 3854 | self.assertEqual(A.reported, 0) |
| 3855 | self.assertEqual(B.reported, 0) |
| 3856 | self.assertEqual(len(self.history), 0) |
| 3857 | |
| 3858 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3859 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3860 | B.setMerged() |
| 3861 | self.waitUntilSettled() |
| 3862 | self.assertEqual(len(self.history), 0) |
| 3863 | |
| 3864 | # Now that B is merged, A should be able to be enqueued and |
| 3865 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3866 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3867 | self.waitUntilSettled() |
| 3868 | |
| 3869 | self.assertEqual(A.data['status'], 'MERGED') |
| 3870 | self.assertEqual(A.reported, 2) |
| 3871 | self.assertEqual(B.data['status'], 'MERGED') |
| 3872 | self.assertEqual(B.reported, 0) |
| 3873 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3874 | def test_crd_check(self): |
| 3875 | "Test cross-repo dependencies in independent pipelines" |
| 3876 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3877 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3878 | self.gearman_server.hold_jobs_in_queue = True |
| 3879 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3880 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3881 | |
| 3882 | # A Depends-On: B |
| 3883 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3884 | A.subject, B.data['id']) |
| 3885 | |
| 3886 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3887 | self.waitUntilSettled() |
| 3888 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3889 | self.gearman_server.hold_jobs_in_queue = False |
| 3890 | self.gearman_server.release() |
| 3891 | self.waitUntilSettled() |
| 3892 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3893 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3894 | self.waitUntilSettled() |
| 3895 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 3896 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3897 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3898 | self.executor_server.hold_jobs_in_build = False |
| 3899 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3900 | self.waitUntilSettled() |
| 3901 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3902 | self.assertEqual(A.data['status'], 'NEW') |
| 3903 | self.assertEqual(B.data['status'], 'NEW') |
| 3904 | self.assertEqual(A.reported, 1) |
| 3905 | self.assertEqual(B.reported, 0) |
| 3906 | |
| 3907 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3908 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3909 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3910 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3911 | def test_crd_check_git_depends(self): |
| 3912 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 3913 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3914 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3915 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3916 | |
| 3917 | # Add two git-dependent changes and make sure they both report |
| 3918 | # success. |
| 3919 | B.setDependsOn(A, 1) |
| 3920 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3921 | self.waitUntilSettled() |
| 3922 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3923 | self.waitUntilSettled() |
| 3924 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 3925 | self.orderedRelease() |
| 3926 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3927 | self.waitUntilSettled() |
| 3928 | |
| 3929 | self.assertEqual(A.data['status'], 'NEW') |
| 3930 | self.assertEqual(B.data['status'], 'NEW') |
| 3931 | self.assertEqual(A.reported, 1) |
| 3932 | self.assertEqual(B.reported, 1) |
| 3933 | |
| 3934 | self.assertEqual(self.history[0].changes, '1,1') |
| 3935 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3936 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3937 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3938 | |
| 3939 | self.assertIn('Build succeeded', A.messages[0]) |
| 3940 | self.assertIn('Build succeeded', B.messages[0]) |
| 3941 | |
| 3942 | def test_crd_check_duplicate(self): |
| 3943 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3944 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3945 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3946 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3947 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3948 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3949 | |
| 3950 | # Add two git-dependent changes... |
| 3951 | B.setDependsOn(A, 1) |
| 3952 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3953 | self.waitUntilSettled() |
| 3954 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 3955 | |
| 3956 | # ...make sure the live one is not duplicated... |
| 3957 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3958 | self.waitUntilSettled() |
| 3959 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 3960 | |
| 3961 | # ...but the non-live one is able to be. |
| 3962 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3963 | self.waitUntilSettled() |
| 3964 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 3965 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 3966 | # Release jobs in order to avoid races with change A jobs |
| 3967 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 3968 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3969 | self.executor_server.hold_jobs_in_build = False |
| 3970 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3971 | self.waitUntilSettled() |
| 3972 | |
| 3973 | self.assertEqual(A.data['status'], 'NEW') |
| 3974 | self.assertEqual(B.data['status'], 'NEW') |
| 3975 | self.assertEqual(A.reported, 1) |
| 3976 | self.assertEqual(B.reported, 1) |
| 3977 | |
| 3978 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 3979 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3980 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3981 | |
| 3982 | self.assertIn('Build succeeded', A.messages[0]) |
| 3983 | self.assertIn('Build succeeded', B.messages[0]) |
| 3984 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3985 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3986 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 3987 | |
| 3988 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3989 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 3990 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3991 | |
| 3992 | # A Depends-On: B |
| 3993 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3994 | A.subject, B.data['id']) |
| 3995 | |
| 3996 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3997 | self.waitUntilSettled() |
| 3998 | |
| 3999 | self.sched.reconfigure(self.config) |
| 4000 | |
| 4001 | # Make sure the items still share a change queue, and the |
| 4002 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4003 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4004 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4005 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4006 | first_item = queue.queue[0] |
| 4007 | for item in queue.queue: |
| 4008 | self.assertEqual(item.queue, first_item.queue) |
| 4009 | self.assertFalse(first_item.live) |
| 4010 | self.assertTrue(queue.queue[1].live) |
| 4011 | |
| 4012 | self.gearman_server.hold_jobs_in_queue = False |
| 4013 | self.gearman_server.release() |
| 4014 | self.waitUntilSettled() |
| 4015 | |
| 4016 | self.assertEqual(A.data['status'], 'NEW') |
| 4017 | self.assertEqual(B.data['status'], 'NEW') |
| 4018 | self.assertEqual(A.reported, 1) |
| 4019 | self.assertEqual(B.reported, 0) |
| 4020 | |
| 4021 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4022 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4023 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4024 | def test_crd_check_reconfiguration(self): |
| 4025 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4026 | |
| 4027 | def test_crd_undefined_project(self): |
| 4028 | """Test that undefined projects in dependencies are handled for |
| 4029 | independent pipelines""" |
| 4030 | # It's a hack for fake gerrit, |
| 4031 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4032 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4033 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4034 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4035 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4036 | def test_crd_check_ignore_dependencies(self): |
| 4037 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4038 | |
| 4039 | self.gearman_server.hold_jobs_in_queue = True |
| 4040 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4041 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4042 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4043 | |
| 4044 | # A Depends-On: B |
| 4045 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4046 | A.subject, B.data['id']) |
| 4047 | # C git-depends on B |
| 4048 | C.setDependsOn(B, 1) |
| 4049 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4050 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4051 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4052 | self.waitUntilSettled() |
| 4053 | |
| 4054 | # Make sure none of the items share a change queue, and all |
| 4055 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4056 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4057 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4058 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4059 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4060 | for item in check_pipeline.getAllItems(): |
| 4061 | self.assertTrue(item.live) |
| 4062 | |
| 4063 | self.gearman_server.hold_jobs_in_queue = False |
| 4064 | self.gearman_server.release() |
| 4065 | self.waitUntilSettled() |
| 4066 | |
| 4067 | self.assertEqual(A.data['status'], 'NEW') |
| 4068 | self.assertEqual(B.data['status'], 'NEW') |
| 4069 | self.assertEqual(C.data['status'], 'NEW') |
| 4070 | self.assertEqual(A.reported, 1) |
| 4071 | self.assertEqual(B.reported, 1) |
| 4072 | self.assertEqual(C.reported, 1) |
| 4073 | |
| 4074 | # Each job should have tested exactly one change |
| 4075 | for job in self.history: |
| 4076 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4077 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4078 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4079 | def test_crd_check_transitive(self): |
| 4080 | "Test transitive cross-repo dependencies" |
| 4081 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4082 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4083 | # and C,2 (not C,1 which would indicate stale data in the |
| 4084 | # cache for B). |
| 4085 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4086 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4087 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4088 | |
| 4089 | # A Depends-On: B |
| 4090 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4091 | A.subject, B.data['id']) |
| 4092 | |
| 4093 | # B Depends-On: C |
| 4094 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4095 | B.subject, C.data['id']) |
| 4096 | |
| 4097 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4098 | self.waitUntilSettled() |
| 4099 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4100 | |
| 4101 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4102 | self.waitUntilSettled() |
| 4103 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4104 | |
| 4105 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4106 | self.waitUntilSettled() |
| 4107 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4108 | |
| 4109 | C.addPatchset() |
| 4110 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4111 | self.waitUntilSettled() |
| 4112 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4113 | |
| 4114 | A.addPatchset() |
| 4115 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4116 | self.waitUntilSettled() |
| 4117 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4118 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4119 | def test_crd_check_unknown(self): |
| 4120 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4121 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4122 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4123 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4124 | # A Depends-On: B |
| 4125 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4126 | A.subject, B.data['id']) |
| 4127 | |
| 4128 | # Make sure zuul has seen an event on B. |
| 4129 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4130 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4131 | self.waitUntilSettled() |
| 4132 | |
| 4133 | self.assertEqual(A.data['status'], 'NEW') |
| 4134 | self.assertEqual(A.reported, 1) |
| 4135 | self.assertEqual(B.data['status'], 'NEW') |
| 4136 | self.assertEqual(B.reported, 0) |
| 4137 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4138 | def test_crd_cycle_join(self): |
| 4139 | "Test an updated change creates a cycle" |
| 4140 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4141 | |
| 4142 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4143 | self.waitUntilSettled() |
| 4144 | |
| 4145 | # Create B->A |
| 4146 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4147 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4148 | B.subject, A.data['id']) |
| 4149 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4150 | self.waitUntilSettled() |
| 4151 | |
| 4152 | # Update A to add A->B (a cycle). |
| 4153 | A.addPatchset() |
| 4154 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4155 | A.subject, B.data['id']) |
| 4156 | # Normally we would submit the patchset-created event for |
| 4157 | # processing here, however, we have no way of noting whether |
| 4158 | # the dependency cycle detection correctly raised an |
| 4159 | # exception, so instead, we reach into the source driver and |
| 4160 | # call the method that would ultimately be called by the event |
| 4161 | # processing. |
| 4162 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4163 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 4164 | (trusted, project) = tenant.getProject('org/project') |
| 4165 | source = project.source |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4166 | |
| 4167 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4168 | # it easier for users to create events for testing. |
| 4169 | event = zuul.model.TriggerEvent() |
| 4170 | event.trigger_name = 'gerrit' |
| 4171 | event.change_number = '1' |
| 4172 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4173 | with testtools.ExpectedException( |
| 4174 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4175 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4176 | self.log.debug("Got expected dependency cycle exception") |
| 4177 | |
| 4178 | # Now if we update B to remove the depends-on, everything |
| 4179 | # should be okay. B; A->B |
| 4180 | |
| 4181 | B.addPatchset() |
| 4182 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4183 | |
| 4184 | source.getChange(event, True) |
| 4185 | event.change_number = '2' |
| 4186 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4187 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4188 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4189 | def test_disable_at(self): |
| 4190 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4191 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4192 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4193 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4194 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4195 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4196 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4197 | |
| 4198 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4199 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4200 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4201 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4202 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4203 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4204 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4205 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4206 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4207 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4208 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4209 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4210 | self.executor_server.failJob('project-test1', A) |
| 4211 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4212 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4213 | self.executor_server.failJob('project-test1', D) |
| 4214 | self.executor_server.failJob('project-test1', E) |
| 4215 | self.executor_server.failJob('project-test1', F) |
| 4216 | self.executor_server.failJob('project-test1', G) |
| 4217 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4218 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4219 | self.executor_server.failJob('project-test1', J) |
| 4220 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4221 | |
| 4222 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4223 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4224 | self.waitUntilSettled() |
| 4225 | |
| 4226 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4227 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4228 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4229 | |
| 4230 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4231 | self.waitUntilSettled() |
| 4232 | |
| 4233 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4234 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4235 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4236 | |
| 4237 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4238 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4239 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4240 | self.waitUntilSettled() |
| 4241 | |
| 4242 | # We should be disabled now |
| 4243 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4244 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4245 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4246 | |
| 4247 | # We need to wait between each of these patches to make sure the |
| 4248 | # smtp messages come back in an expected order |
| 4249 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4250 | self.waitUntilSettled() |
| 4251 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4252 | self.waitUntilSettled() |
| 4253 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4254 | self.waitUntilSettled() |
| 4255 | |
| 4256 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4257 | # leaving a message on each change |
| 4258 | self.assertEqual(1, len(A.messages)) |
| 4259 | self.assertIn('Build failed.', A.messages[0]) |
| 4260 | self.assertEqual(1, len(B.messages)) |
| 4261 | self.assertIn('Build failed.', B.messages[0]) |
| 4262 | self.assertEqual(1, len(C.messages)) |
| 4263 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4264 | self.assertEqual(1, len(D.messages)) |
| 4265 | self.assertIn('Build failed.', D.messages[0]) |
| 4266 | self.assertEqual(1, len(E.messages)) |
| 4267 | self.assertIn('Build failed.', E.messages[0]) |
| 4268 | self.assertEqual(1, len(F.messages)) |
| 4269 | self.assertIn('Build failed.', F.messages[0]) |
| 4270 | |
| 4271 | # The last 3 (GHI) would have only reported via smtp. |
| 4272 | self.assertEqual(3, len(self.smtp_messages)) |
| 4273 | self.assertEqual(0, len(G.messages)) |
| 4274 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4275 | self.assertIn( |
| 4276 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4277 | self.assertEqual(0, len(H.messages)) |
| 4278 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4279 | self.assertIn( |
| 4280 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4281 | self.assertEqual(0, len(I.messages)) |
| 4282 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4283 | self.assertIn( |
| 4284 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4285 | |
| 4286 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4287 | # comes out of disabled |
| 4288 | self.sched.reconfigure(self.config) |
| 4289 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4290 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4291 | |
| 4292 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4293 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4294 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4295 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4296 | |
| 4297 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4298 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4299 | self.waitUntilSettled() |
| 4300 | |
| 4301 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4302 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4303 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4304 | |
| 4305 | # J and K went back to gerrit |
| 4306 | self.assertEqual(1, len(J.messages)) |
| 4307 | self.assertIn('Build failed.', J.messages[0]) |
| 4308 | self.assertEqual(1, len(K.messages)) |
| 4309 | self.assertIn('Build failed.', K.messages[0]) |
| 4310 | # No more messages reported via smtp |
| 4311 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4312 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4313 | @simple_layout('layouts/one-job-project.yaml') |
| 4314 | def test_one_job_project(self): |
| 4315 | "Test that queueing works with one job" |
| 4316 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4317 | 'master', 'A') |
| 4318 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4319 | 'master', 'B') |
| 4320 | A.addApproval('code-review', 2) |
| 4321 | B.addApproval('code-review', 2) |
| 4322 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4323 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4324 | self.waitUntilSettled() |
| 4325 | |
| 4326 | self.assertEqual(A.data['status'], 'MERGED') |
| 4327 | self.assertEqual(A.reported, 2) |
| 4328 | self.assertEqual(B.data['status'], 'MERGED') |
| 4329 | self.assertEqual(B.reported, 2) |
| 4330 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4331 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4332 | "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] | 4333 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4334 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4335 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4336 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4337 | self.waitUntilSettled() |
| 4338 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4339 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4340 | self.waitUntilSettled() |
| 4341 | |
| 4342 | self.assertEqual(len(self.builds), 2) |
| 4343 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4344 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4345 | self.waitUntilSettled() |
| 4346 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4347 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4348 | self.assertEqual(len(self.builds), 1, |
| 4349 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4350 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4351 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4352 | self.waitUntilSettled() |
| 4353 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4354 | self.executor_server.hold_jobs_in_build = False |
| 4355 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4356 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4357 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4358 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4359 | self.assertEqual(A.reported, 1) |
| 4360 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4361 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4362 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4363 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4364 | |
| 4365 | self.fake_nodepool.paused = True |
| 4366 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4367 | A.addApproval('code-review', 2) |
| 4368 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4369 | self.waitUntilSettled() |
| 4370 | |
| 4371 | self.zk.client.stop() |
| 4372 | self.zk.client.start() |
| 4373 | self.fake_nodepool.paused = False |
| 4374 | self.waitUntilSettled() |
| 4375 | |
| 4376 | self.assertEqual(A.data['status'], 'MERGED') |
| 4377 | self.assertEqual(A.reported, 2) |
| 4378 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4379 | def test_nodepool_failure(self): |
| 4380 | "Test that jobs are reported after a nodepool failure" |
| 4381 | |
| 4382 | self.fake_nodepool.paused = True |
| 4383 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4384 | A.addApproval('code-review', 2) |
| 4385 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4386 | self.waitUntilSettled() |
| 4387 | |
| 4388 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4389 | self.fake_nodepool.addFailRequest(req) |
| 4390 | |
| 4391 | self.fake_nodepool.paused = False |
| 4392 | self.waitUntilSettled() |
| 4393 | |
| 4394 | self.assertEqual(A.data['status'], 'NEW') |
| 4395 | self.assertEqual(A.reported, 2) |
| 4396 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4397 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4398 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4399 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4400 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4401 | class TestExecutor(ZuulTestCase): |
| 4402 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4403 | |
| 4404 | def assertFinalState(self): |
| 4405 | # In this test, we expect to shut down in a non-final state, |
| 4406 | # so skip these checks. |
| 4407 | pass |
| 4408 | |
| 4409 | def assertCleanShutdown(self): |
| 4410 | self.log.debug("Assert clean shutdown") |
| 4411 | |
| 4412 | # After shutdown, make sure no jobs are running |
| 4413 | self.assertEqual({}, self.executor_server.job_workers) |
| 4414 | |
| 4415 | # Make sure that git.Repo objects have been garbage collected. |
| 4416 | repos = [] |
| 4417 | gc.collect() |
| 4418 | for obj in gc.get_objects(): |
| 4419 | if isinstance(obj, git.Repo): |
| 4420 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4421 | repos.append(obj) |
| 4422 | self.assertEqual(len(repos), 0) |
| 4423 | |
| 4424 | def test_executor_shutdown(self): |
| 4425 | "Test that the executor can shut down with jobs running" |
| 4426 | |
| 4427 | self.executor_server.hold_jobs_in_build = True |
| 4428 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4429 | A.addApproval('code-review', 2) |
| 4430 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4431 | self.waitUntilSettled() |
| 4432 | |
| 4433 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4434 | class TestDependencyGraph(ZuulTestCase): |
| 4435 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4436 | |
| 4437 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4438 | "Test a job in a dependency graph is queued only once" |
| 4439 | # Job dependencies, starting with A |
| 4440 | # A |
| 4441 | # / \ |
| 4442 | # B C |
| 4443 | # / \ / \ |
| 4444 | # D F E |
| 4445 | # | |
| 4446 | # G |
| 4447 | |
| 4448 | self.executor_server.hold_jobs_in_build = True |
| 4449 | change = self.fake_gerrit.addFakeChange( |
| 4450 | 'org/project', 'master', 'change') |
| 4451 | change.addApproval('code-review', 2) |
| 4452 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4453 | |
| 4454 | self.waitUntilSettled() |
| 4455 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4456 | |
| 4457 | self.executor_server.release('A') |
| 4458 | self.waitUntilSettled() |
| 4459 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4460 | |
| 4461 | self.executor_server.release('B') |
| 4462 | self.waitUntilSettled() |
| 4463 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4464 | |
| 4465 | self.executor_server.release('D') |
| 4466 | self.waitUntilSettled() |
| 4467 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4468 | |
| 4469 | self.executor_server.release('C') |
| 4470 | self.waitUntilSettled() |
| 4471 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4472 | |
| 4473 | self.executor_server.release('F') |
| 4474 | self.waitUntilSettled() |
| 4475 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4476 | |
| 4477 | self.executor_server.release('G') |
| 4478 | self.waitUntilSettled() |
| 4479 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4480 | |
| 4481 | self.executor_server.release('E') |
| 4482 | self.waitUntilSettled() |
| 4483 | self.assertEqual(len(self.builds), 0) |
| 4484 | |
| 4485 | self.executor_server.hold_jobs_in_build = False |
| 4486 | self.executor_server.release() |
| 4487 | self.waitUntilSettled() |
| 4488 | |
| 4489 | self.assertEqual(len(self.builds), 0) |
| 4490 | self.assertEqual(len(self.history), 7) |
| 4491 | |
| 4492 | self.assertEqual(change.data['status'], 'MERGED') |
| 4493 | self.assertEqual(change.reported, 2) |
| 4494 | |
| 4495 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4496 | "Test that a job waits till all dependencies are successful" |
| 4497 | # Job dependencies, starting with A |
| 4498 | # A |
| 4499 | # / \ |
| 4500 | # B C* |
| 4501 | # / \ / \ |
| 4502 | # D F E |
| 4503 | # | |
| 4504 | # G |
| 4505 | |
| 4506 | self.executor_server.hold_jobs_in_build = True |
| 4507 | change = self.fake_gerrit.addFakeChange( |
| 4508 | 'org/project', 'master', 'change') |
| 4509 | change.addApproval('code-review', 2) |
| 4510 | |
| 4511 | self.executor_server.failJob('C', change) |
| 4512 | |
| 4513 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4514 | |
| 4515 | self.waitUntilSettled() |
| 4516 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4517 | |
| 4518 | self.executor_server.release('A') |
| 4519 | self.waitUntilSettled() |
| 4520 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4521 | |
| 4522 | self.executor_server.release('B') |
| 4523 | self.waitUntilSettled() |
| 4524 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4525 | |
| 4526 | self.executor_server.release('D') |
| 4527 | self.waitUntilSettled() |
| 4528 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4529 | |
| 4530 | self.executor_server.release('C') |
| 4531 | self.waitUntilSettled() |
| 4532 | self.assertEqual(len(self.builds), 0) |
| 4533 | |
| 4534 | self.executor_server.hold_jobs_in_build = False |
| 4535 | self.executor_server.release() |
| 4536 | self.waitUntilSettled() |
| 4537 | |
| 4538 | self.assertEqual(len(self.builds), 0) |
| 4539 | self.assertEqual(len(self.history), 4) |
| 4540 | |
| 4541 | self.assertEqual(change.data['status'], 'NEW') |
| 4542 | self.assertEqual(change.reported, 2) |
| 4543 | |
| 4544 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4545 | class TestDuplicatePipeline(ZuulTestCase): |
| 4546 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4547 | |
| 4548 | def test_duplicate_pipelines(self): |
| 4549 | "Test that a change matching multiple pipelines works" |
| 4550 | |
| 4551 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4552 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4553 | self.waitUntilSettled() |
| 4554 | |
| 4555 | self.assertHistory([ |
| 4556 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4557 | pipeline='dup1'), |
| 4558 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4559 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4560 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4561 | |
| 4562 | self.assertEqual(len(A.messages), 2) |
| 4563 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4564 | if 'dup1' in A.messages[0]: |
| 4565 | self.assertIn('dup1', A.messages[0]) |
| 4566 | self.assertNotIn('dup2', A.messages[0]) |
| 4567 | self.assertIn('project-test1', A.messages[0]) |
| 4568 | self.assertIn('dup2', A.messages[1]) |
| 4569 | self.assertNotIn('dup1', A.messages[1]) |
| 4570 | self.assertIn('project-test1', A.messages[1]) |
| 4571 | else: |
| 4572 | self.assertIn('dup1', A.messages[1]) |
| 4573 | self.assertNotIn('dup2', A.messages[1]) |
| 4574 | self.assertIn('project-test1', A.messages[1]) |
| 4575 | self.assertIn('dup2', A.messages[0]) |
| 4576 | self.assertNotIn('dup1', A.messages[0]) |
| 4577 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4578 | |
| 4579 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4580 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4581 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4582 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4583 | def test_job_from_templates_executed(self): |
| 4584 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4585 | |
| 4586 | A = self.fake_gerrit.addFakeChange( |
| 4587 | 'org/templated-project', 'master', 'A') |
| 4588 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4589 | self.waitUntilSettled() |
| 4590 | |
| 4591 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4592 | 'SUCCESS') |
| 4593 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4594 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4595 | |
| 4596 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4597 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4598 | |
| 4599 | A = self.fake_gerrit.addFakeChange( |
| 4600 | 'org/layered-project', 'master', 'A') |
| 4601 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4602 | self.waitUntilSettled() |
| 4603 | |
| 4604 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4605 | 'SUCCESS') |
| 4606 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4607 | 'SUCCESS') |
| 4608 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4609 | ).result, 'SUCCESS') |
| 4610 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4611 | ).result, 'SUCCESS') |
| 4612 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4613 | ).result, 'SUCCESS') |
| 4614 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4615 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4616 | |
| 4617 | |
| 4618 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4619 | tenant_config_file = 'config/success-url/main.yaml' |
| 4620 | |
| 4621 | def test_success_url(self): |
| 4622 | "Ensure bad build params are ignored" |
| 4623 | self.sched.reconfigure(self.config) |
| 4624 | self.init_repo('org/docs') |
| 4625 | |
| 4626 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4627 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4628 | self.waitUntilSettled() |
| 4629 | |
| 4630 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4631 | self.assertEqual(len(self.history), 2) |
| 4632 | |
| 4633 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4634 | for build in self.history: |
| 4635 | if build.name == 'docs-draft-test': |
| 4636 | uuid = build.uuid[:7] |
| 4637 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4638 | |
| 4639 | # Two msgs: 'Starting...' + results |
| 4640 | self.assertEqual(len(self.smtp_messages), 2) |
| 4641 | body = self.smtp_messages[1]['body'].splitlines() |
| 4642 | self.assertEqual('Build succeeded.', body[0]) |
| 4643 | |
| 4644 | self.assertIn( |
| 4645 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4646 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4647 | body[2]) |
| 4648 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4649 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4650 | self.assertIn( |
| 4651 | '- docs-draft-test2 https://server/job', |
| 4652 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4653 | |
| 4654 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4655 | class TestSchedulerMerges(ZuulTestCase): |
| 4656 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4657 | |
| 4658 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4659 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4660 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4661 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4662 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4663 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4664 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4665 | A.addApproval('code-review', 2) |
| 4666 | B.addApproval('code-review', 2) |
| 4667 | C.addApproval('code-review', 2) |
| 4668 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4669 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4670 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4671 | self.waitUntilSettled() |
| 4672 | |
| 4673 | build = self.builds[-1] |
| 4674 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4675 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4676 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4677 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4678 | repo = git.Repo(path) |
| 4679 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4680 | repo_messages.reverse() |
| 4681 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4682 | self.executor_server.hold_jobs_in_build = False |
| 4683 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4684 | self.waitUntilSettled() |
| 4685 | |
| 4686 | return repo_messages |
| 4687 | |
| 4688 | def _test_merge(self, mode): |
| 4689 | us_path = os.path.join( |
| 4690 | self.upstream_root, 'org/project-%s' % mode) |
| 4691 | expected_messages = [ |
| 4692 | 'initial commit', |
| 4693 | 'add content from fixture', |
| 4694 | # the intermediate commits order is nondeterministic |
| 4695 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4696 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4697 | ] |
| 4698 | result = self._test_project_merge_mode(mode) |
| 4699 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4700 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4701 | |
| 4702 | def test_project_merge_mode_merge(self): |
| 4703 | self._test_merge('merge') |
| 4704 | |
| 4705 | def test_project_merge_mode_merge_resolve(self): |
| 4706 | self._test_merge('merge-resolve') |
| 4707 | |
| 4708 | def test_project_merge_mode_cherrypick(self): |
| 4709 | expected_messages = [ |
| 4710 | 'initial commit', |
| 4711 | 'add content from fixture', |
| 4712 | 'A-1', |
| 4713 | 'B-1', |
| 4714 | 'C-1'] |
| 4715 | result = self._test_project_merge_mode('cherry-pick') |
| 4716 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4717 | |
| 4718 | def test_merge_branch(self): |
| 4719 | "Test that the right commits are on alternate branches" |
| 4720 | self.create_branch('org/project-merge-branches', 'mp') |
| 4721 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4722 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4723 | A = self.fake_gerrit.addFakeChange( |
| 4724 | 'org/project-merge-branches', 'mp', 'A') |
| 4725 | B = self.fake_gerrit.addFakeChange( |
| 4726 | 'org/project-merge-branches', 'mp', 'B') |
| 4727 | C = self.fake_gerrit.addFakeChange( |
| 4728 | 'org/project-merge-branches', 'mp', 'C') |
| 4729 | A.addApproval('code-review', 2) |
| 4730 | B.addApproval('code-review', 2) |
| 4731 | C.addApproval('code-review', 2) |
| 4732 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4733 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4734 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4735 | self.waitUntilSettled() |
| 4736 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4737 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4738 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4739 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4740 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4741 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4742 | self.waitUntilSettled() |
| 4743 | |
| 4744 | build = self.builds[-1] |
| 4745 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 4746 | ref = self.getParameter(build, 'ZUUL_REF') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4747 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4748 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4749 | repo = git.Repo(path) |
| 4750 | |
| 4751 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4752 | repo_messages.reverse() |
| 4753 | correct_messages = [ |
| 4754 | 'initial commit', |
| 4755 | 'add content from fixture', |
| 4756 | 'mp commit', |
| 4757 | 'A-1', 'B-1', 'C-1'] |
| 4758 | self.assertEqual(repo_messages, correct_messages) |
| 4759 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4760 | self.executor_server.hold_jobs_in_build = False |
| 4761 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4762 | self.waitUntilSettled() |
| 4763 | |
| 4764 | def test_merge_multi_branch(self): |
| 4765 | "Test that dependent changes on multiple branches are merged" |
| 4766 | self.create_branch('org/project-merge-branches', 'mp') |
| 4767 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4768 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4769 | A = self.fake_gerrit.addFakeChange( |
| 4770 | 'org/project-merge-branches', 'master', 'A') |
| 4771 | B = self.fake_gerrit.addFakeChange( |
| 4772 | 'org/project-merge-branches', 'mp', 'B') |
| 4773 | C = self.fake_gerrit.addFakeChange( |
| 4774 | 'org/project-merge-branches', 'master', 'C') |
| 4775 | A.addApproval('code-review', 2) |
| 4776 | B.addApproval('code-review', 2) |
| 4777 | C.addApproval('code-review', 2) |
| 4778 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4779 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4780 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4781 | self.waitUntilSettled() |
| 4782 | |
| 4783 | job_A = None |
| 4784 | for job in self.builds: |
| 4785 | if 'project-merge' in job.name: |
| 4786 | job_A = job |
| 4787 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 4788 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 4789 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 4790 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 4791 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4792 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 4793 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4794 | repo = git.Repo(path) |
| 4795 | repo_messages = [c.message.strip() |
| 4796 | for c in repo.iter_commits(ref_A)] |
| 4797 | repo_messages.reverse() |
| 4798 | correct_messages = [ |
| 4799 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4800 | self.assertEqual(repo_messages, correct_messages) |
| 4801 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4802 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4803 | self.waitUntilSettled() |
| 4804 | |
| 4805 | job_B = None |
| 4806 | for job in self.builds: |
| 4807 | if 'project-merge' in job.name: |
| 4808 | job_B = job |
| 4809 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 4810 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 4811 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 4812 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 4813 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4814 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 4815 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4816 | repo = git.Repo(path) |
| 4817 | repo_messages = [c.message.strip() |
| 4818 | for c in repo.iter_commits(ref_B)] |
| 4819 | repo_messages.reverse() |
| 4820 | correct_messages = [ |
| 4821 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4822 | self.assertEqual(repo_messages, correct_messages) |
| 4823 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4824 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4825 | self.waitUntilSettled() |
| 4826 | |
| 4827 | job_C = None |
| 4828 | for job in self.builds: |
| 4829 | if 'project-merge' in job.name: |
| 4830 | job_C = job |
| 4831 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 4832 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 4833 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 4834 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4835 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 4836 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4837 | repo = git.Repo(path) |
| 4838 | repo_messages = [c.message.strip() |
| 4839 | for c in repo.iter_commits(ref_C)] |
| 4840 | |
| 4841 | repo_messages.reverse() |
| 4842 | correct_messages = [ |
| 4843 | 'initial commit', 'add content from fixture', |
| 4844 | 'A-1', 'C-1'] |
| 4845 | # Ensure the right commits are in the history for this ref |
| 4846 | self.assertEqual(repo_messages, correct_messages) |
| 4847 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4848 | self.executor_server.hold_jobs_in_build = False |
| 4849 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4850 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 4851 | |
| 4852 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 4853 | class TestSemaphore(ZuulTestCase): |
| 4854 | tenant_config_file = 'config/semaphore/main.yaml' |
| 4855 | |
| 4856 | def test_semaphore_one(self): |
| 4857 | "Test semaphores with max=1 (mutex)" |
| 4858 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4859 | |
| 4860 | self.executor_server.hold_jobs_in_build = True |
| 4861 | |
| 4862 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4863 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4864 | self.assertFalse('test-semaphore' in |
| 4865 | tenant.semaphore_handler.semaphores) |
| 4866 | |
| 4867 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4868 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4869 | self.waitUntilSettled() |
| 4870 | |
| 4871 | self.assertEqual(len(self.builds), 3) |
| 4872 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4873 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 4874 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 4875 | |
| 4876 | self.executor_server.release('semaphore-one-test1') |
| 4877 | self.waitUntilSettled() |
| 4878 | |
| 4879 | self.assertEqual(len(self.builds), 3) |
| 4880 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4881 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4882 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 4883 | self.assertTrue('test-semaphore' in |
| 4884 | tenant.semaphore_handler.semaphores) |
| 4885 | |
| 4886 | self.executor_server.release('semaphore-one-test2') |
| 4887 | self.waitUntilSettled() |
| 4888 | |
| 4889 | self.assertEqual(len(self.builds), 3) |
| 4890 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4891 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4892 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 4893 | self.assertTrue('test-semaphore' in |
| 4894 | tenant.semaphore_handler.semaphores) |
| 4895 | |
| 4896 | self.executor_server.release('semaphore-one-test1') |
| 4897 | self.waitUntilSettled() |
| 4898 | |
| 4899 | self.assertEqual(len(self.builds), 3) |
| 4900 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4901 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4902 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 4903 | self.assertTrue('test-semaphore' in |
| 4904 | tenant.semaphore_handler.semaphores) |
| 4905 | |
| 4906 | self.executor_server.release('semaphore-one-test2') |
| 4907 | self.waitUntilSettled() |
| 4908 | |
| 4909 | self.assertEqual(len(self.builds), 2) |
| 4910 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4911 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4912 | self.assertFalse('test-semaphore' in |
| 4913 | tenant.semaphore_handler.semaphores) |
| 4914 | |
| 4915 | self.executor_server.hold_jobs_in_build = False |
| 4916 | self.executor_server.release() |
| 4917 | |
| 4918 | self.waitUntilSettled() |
| 4919 | self.assertEqual(len(self.builds), 0) |
| 4920 | |
| 4921 | self.assertEqual(A.reported, 1) |
| 4922 | self.assertEqual(B.reported, 1) |
| 4923 | self.assertFalse('test-semaphore' in |
| 4924 | tenant.semaphore_handler.semaphores) |
| 4925 | |
| 4926 | def test_semaphore_two(self): |
| 4927 | "Test semaphores with max>1" |
| 4928 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4929 | |
| 4930 | self.executor_server.hold_jobs_in_build = True |
| 4931 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4932 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4933 | self.assertFalse('test-semaphore-two' in |
| 4934 | tenant.semaphore_handler.semaphores) |
| 4935 | |
| 4936 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4937 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4938 | self.waitUntilSettled() |
| 4939 | |
| 4940 | self.assertEqual(len(self.builds), 4) |
| 4941 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4942 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 4943 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 4944 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 4945 | self.assertTrue('test-semaphore-two' in |
| 4946 | tenant.semaphore_handler.semaphores) |
| 4947 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4948 | 'test-semaphore-two', [])), 2) |
| 4949 | |
| 4950 | self.executor_server.release('semaphore-two-test1') |
| 4951 | self.waitUntilSettled() |
| 4952 | |
| 4953 | self.assertEqual(len(self.builds), 4) |
| 4954 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4955 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 4956 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 4957 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 4958 | self.assertTrue('test-semaphore-two' in |
| 4959 | tenant.semaphore_handler.semaphores) |
| 4960 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4961 | 'test-semaphore-two', [])), 2) |
| 4962 | |
| 4963 | self.executor_server.release('semaphore-two-test2') |
| 4964 | self.waitUntilSettled() |
| 4965 | |
| 4966 | self.assertEqual(len(self.builds), 4) |
| 4967 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4968 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4969 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 4970 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 4971 | self.assertTrue('test-semaphore-two' in |
| 4972 | tenant.semaphore_handler.semaphores) |
| 4973 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4974 | 'test-semaphore-two', [])), 2) |
| 4975 | |
| 4976 | self.executor_server.release('semaphore-two-test1') |
| 4977 | self.waitUntilSettled() |
| 4978 | |
| 4979 | self.assertEqual(len(self.builds), 3) |
| 4980 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4981 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4982 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 4983 | self.assertTrue('test-semaphore-two' in |
| 4984 | tenant.semaphore_handler.semaphores) |
| 4985 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4986 | 'test-semaphore-two', [])), 1) |
| 4987 | |
| 4988 | self.executor_server.release('semaphore-two-test2') |
| 4989 | self.waitUntilSettled() |
| 4990 | |
| 4991 | self.assertEqual(len(self.builds), 2) |
| 4992 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4993 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4994 | self.assertFalse('test-semaphore-two' in |
| 4995 | tenant.semaphore_handler.semaphores) |
| 4996 | |
| 4997 | self.executor_server.hold_jobs_in_build = False |
| 4998 | self.executor_server.release() |
| 4999 | |
| 5000 | self.waitUntilSettled() |
| 5001 | self.assertEqual(len(self.builds), 0) |
| 5002 | |
| 5003 | self.assertEqual(A.reported, 1) |
| 5004 | self.assertEqual(B.reported, 1) |
| 5005 | |
| 5006 | def test_semaphore_abandon(self): |
| 5007 | "Test abandon with job semaphores" |
| 5008 | self.executor_server.hold_jobs_in_build = True |
| 5009 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5010 | check_pipeline = tenant.layout.pipelines['check'] |
| 5011 | |
| 5012 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5013 | self.assertFalse('test-semaphore' in |
| 5014 | tenant.semaphore_handler.semaphores) |
| 5015 | |
| 5016 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5017 | self.waitUntilSettled() |
| 5018 | |
| 5019 | self.assertTrue('test-semaphore' in |
| 5020 | tenant.semaphore_handler.semaphores) |
| 5021 | |
| 5022 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5023 | self.waitUntilSettled() |
| 5024 | |
| 5025 | # The check pipeline should be empty |
| 5026 | items = check_pipeline.getAllItems() |
| 5027 | self.assertEqual(len(items), 0) |
| 5028 | |
| 5029 | # The semaphore should be released |
| 5030 | self.assertFalse('test-semaphore' in |
| 5031 | tenant.semaphore_handler.semaphores) |
| 5032 | |
| 5033 | self.executor_server.hold_jobs_in_build = False |
| 5034 | self.executor_server.release() |
| 5035 | self.waitUntilSettled() |
| 5036 | |
| 5037 | def test_semaphore_reconfigure(self): |
| 5038 | "Test reconfigure with job semaphores" |
| 5039 | self.executor_server.hold_jobs_in_build = True |
| 5040 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5041 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5042 | self.assertFalse('test-semaphore' in |
| 5043 | tenant.semaphore_handler.semaphores) |
| 5044 | |
| 5045 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5046 | self.waitUntilSettled() |
| 5047 | |
| 5048 | self.assertTrue('test-semaphore' in |
| 5049 | tenant.semaphore_handler.semaphores) |
| 5050 | |
| 5051 | # reconfigure without layout change |
| 5052 | self.sched.reconfigure(self.config) |
| 5053 | self.waitUntilSettled() |
| 5054 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5055 | |
| 5056 | # semaphore still must be held |
| 5057 | self.assertTrue('test-semaphore' in |
| 5058 | tenant.semaphore_handler.semaphores) |
| 5059 | |
| 5060 | self.commitConfigUpdate( |
| 5061 | 'common-config', |
| 5062 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5063 | self.sched.reconfigure(self.config) |
| 5064 | self.waitUntilSettled() |
| 5065 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5066 | |
| 5067 | self.executor_server.release('project-test1') |
| 5068 | self.waitUntilSettled() |
| 5069 | |
| 5070 | # There should be no builds anymore |
| 5071 | self.assertEqual(len(self.builds), 0) |
| 5072 | |
| 5073 | # The semaphore should be released |
| 5074 | self.assertFalse('test-semaphore' in |
| 5075 | tenant.semaphore_handler.semaphores) |
| 5076 | |
| 5077 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5078 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5079 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5080 | |
| 5081 | def test_semaphore_tenant_isolation(self): |
| 5082 | "Test semaphores in multiple tenants" |
| 5083 | |
| 5084 | self.waitUntilSettled() |
| 5085 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5086 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5087 | |
| 5088 | self.executor_server.hold_jobs_in_build = True |
| 5089 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5090 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5091 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5092 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5093 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5094 | self.assertFalse('test-semaphore' in |
| 5095 | tenant_one.semaphore_handler.semaphores) |
| 5096 | self.assertFalse('test-semaphore' in |
| 5097 | tenant_two.semaphore_handler.semaphores) |
| 5098 | |
| 5099 | # add patches to project1 of tenant-one |
| 5100 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5101 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5102 | self.waitUntilSettled() |
| 5103 | |
| 5104 | # one build of project1-test1 must run |
| 5105 | # semaphore of tenant-one must be acquired once |
| 5106 | # semaphore of tenant-two must not be acquired |
| 5107 | self.assertEqual(len(self.builds), 1) |
| 5108 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5109 | self.assertTrue('test-semaphore' in |
| 5110 | tenant_one.semaphore_handler.semaphores) |
| 5111 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5112 | 'test-semaphore', [])), 1) |
| 5113 | self.assertFalse('test-semaphore' in |
| 5114 | tenant_two.semaphore_handler.semaphores) |
| 5115 | |
| 5116 | # add patches to project2 of tenant-two |
| 5117 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5118 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5119 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5120 | self.waitUntilSettled() |
| 5121 | |
| 5122 | # one build of project1-test1 must run |
| 5123 | # two builds of project2-test1 must run |
| 5124 | # semaphore of tenant-one must be acquired once |
| 5125 | # semaphore of tenant-two must be acquired twice |
| 5126 | self.assertEqual(len(self.builds), 3) |
| 5127 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5128 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5129 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5130 | self.assertTrue('test-semaphore' in |
| 5131 | tenant_one.semaphore_handler.semaphores) |
| 5132 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5133 | 'test-semaphore', [])), 1) |
| 5134 | self.assertTrue('test-semaphore' in |
| 5135 | tenant_two.semaphore_handler.semaphores) |
| 5136 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5137 | 'test-semaphore', [])), 2) |
| 5138 | |
| 5139 | self.executor_server.release('project1-test1') |
| 5140 | self.waitUntilSettled() |
| 5141 | |
| 5142 | # one build of project1-test1 must run |
| 5143 | # two builds of project2-test1 must run |
| 5144 | # semaphore of tenant-one must be acquired once |
| 5145 | # semaphore of tenant-two must be acquired twice |
| 5146 | self.assertEqual(len(self.builds), 3) |
| 5147 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5148 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5149 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5150 | self.assertTrue('test-semaphore' in |
| 5151 | tenant_one.semaphore_handler.semaphores) |
| 5152 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5153 | 'test-semaphore', [])), 1) |
| 5154 | self.assertTrue('test-semaphore' in |
| 5155 | tenant_two.semaphore_handler.semaphores) |
| 5156 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5157 | 'test-semaphore', [])), 2) |
| 5158 | |
| 5159 | self.executor_server.release('project2-test1') |
| 5160 | self.waitUntilSettled() |
| 5161 | |
| 5162 | # one build of project1-test1 must run |
| 5163 | # one build of project2-test1 must run |
| 5164 | # semaphore of tenant-one must be acquired once |
| 5165 | # semaphore of tenant-two must be acquired once |
| 5166 | self.assertEqual(len(self.builds), 2) |
| 5167 | self.assertTrue('test-semaphore' in |
| 5168 | tenant_one.semaphore_handler.semaphores) |
| 5169 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5170 | 'test-semaphore', [])), 1) |
| 5171 | self.assertTrue('test-semaphore' in |
| 5172 | tenant_two.semaphore_handler.semaphores) |
| 5173 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5174 | 'test-semaphore', [])), 1) |
| 5175 | |
| 5176 | self.executor_server.hold_jobs_in_build = False |
| 5177 | self.executor_server.release() |
| 5178 | |
| 5179 | self.waitUntilSettled() |
| 5180 | |
| 5181 | # no build must run |
| 5182 | # semaphore of tenant-one must not be acquired |
| 5183 | # semaphore of tenant-two must not be acquired |
| 5184 | self.assertEqual(len(self.builds), 0) |
| 5185 | self.assertFalse('test-semaphore' in |
| 5186 | tenant_one.semaphore_handler.semaphores) |
| 5187 | self.assertFalse('test-semaphore' in |
| 5188 | tenant_two.semaphore_handler.semaphores) |
| 5189 | |
| 5190 | self.assertEqual(A.reported, 1) |
| 5191 | self.assertEqual(B.reported, 1) |
| 5192 | |
| 5193 | |
| 5194 | class TestSemaphoreInRepo(ZuulTestCase): |
| 5195 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5196 | |
| 5197 | def test_semaphore_in_repo(self): |
| 5198 | "Test semaphores in repo config" |
| 5199 | |
| 5200 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5201 | # max value should not be evaluated dynamically but must be updated |
| 5202 | # after the change lands. |
| 5203 | |
| 5204 | self.waitUntilSettled() |
| 5205 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5206 | |
| 5207 | in_repo_conf = textwrap.dedent( |
| 5208 | """ |
| 5209 | - job: |
| 5210 | name: project-test2 |
| 5211 | semaphore: test-semaphore |
| 5212 | |
| 5213 | - project: |
| 5214 | name: org/project |
| 5215 | tenant-one-gate: |
| 5216 | jobs: |
| 5217 | - project-test2 |
| 5218 | |
| 5219 | # the max value in dynamic layout must be ignored |
| 5220 | - semaphore: |
| 5221 | name: test-semaphore |
| 5222 | max: 2 |
| 5223 | """) |
| 5224 | |
| 5225 | in_repo_playbook = textwrap.dedent( |
| 5226 | """ |
| 5227 | - hosts: all |
| 5228 | tasks: [] |
| 5229 | """) |
| 5230 | |
| 5231 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5232 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5233 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5234 | files=file_dict) |
| 5235 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5236 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5237 | B.setDependsOn(A, 1) |
| 5238 | C.setDependsOn(A, 1) |
| 5239 | |
| 5240 | self.executor_server.hold_jobs_in_build = True |
| 5241 | |
| 5242 | A.addApproval('code-review', 2) |
| 5243 | B.addApproval('code-review', 2) |
| 5244 | C.addApproval('code-review', 2) |
| 5245 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5246 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5247 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5248 | self.waitUntilSettled() |
| 5249 | |
| 5250 | # check that the layout in a queue item still has max value of 1 |
| 5251 | # for test-semaphore |
| 5252 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5253 | queue = None |
| 5254 | for queue_candidate in pipeline.queues: |
| 5255 | if queue_candidate.name == 'org/project': |
| 5256 | queue = queue_candidate |
| 5257 | break |
| 5258 | queue_item = queue.queue[0] |
| 5259 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5260 | dynamic_test_semaphore = \ |
| 5261 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5262 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5263 | |
| 5264 | # one build must be in queue, one semaphores acquired |
| 5265 | self.assertEqual(len(self.builds), 1) |
| 5266 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5267 | self.assertTrue('test-semaphore' in |
| 5268 | tenant.semaphore_handler.semaphores) |
| 5269 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5270 | 'test-semaphore', [])), 1) |
| 5271 | |
| 5272 | self.executor_server.release('project-test2') |
| 5273 | self.waitUntilSettled() |
| 5274 | |
| 5275 | # change A must be merged |
| 5276 | self.assertEqual(A.data['status'], 'MERGED') |
| 5277 | self.assertEqual(A.reported, 2) |
| 5278 | |
| 5279 | # send change-merged event as the gerrit mock doesn't send it |
| 5280 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5281 | self.waitUntilSettled() |
| 5282 | |
| 5283 | # now that change A was merged, the new semaphore max must be effective |
| 5284 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5285 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5286 | |
| 5287 | # two builds must be in queue, two semaphores acquired |
| 5288 | self.assertEqual(len(self.builds), 2) |
| 5289 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5290 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5291 | self.assertTrue('test-semaphore' in |
| 5292 | tenant.semaphore_handler.semaphores) |
| 5293 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5294 | 'test-semaphore', [])), 2) |
| 5295 | |
| 5296 | self.executor_server.release('project-test2') |
| 5297 | self.waitUntilSettled() |
| 5298 | |
| 5299 | self.assertEqual(len(self.builds), 0) |
| 5300 | self.assertFalse('test-semaphore' in |
| 5301 | tenant.semaphore_handler.semaphores) |
| 5302 | |
| 5303 | self.executor_server.hold_jobs_in_build = False |
| 5304 | self.executor_server.release() |
| 5305 | |
| 5306 | self.waitUntilSettled() |
| 5307 | self.assertEqual(len(self.builds), 0) |
| 5308 | |
| 5309 | self.assertEqual(A.reported, 2) |
| 5310 | self.assertEqual(B.reported, 2) |
| 5311 | self.assertEqual(C.reported, 2) |