James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 17 | import gc |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 18 | import json |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 19 | import textwrap |
| 20 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 21 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 22 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 23 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | import time |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 25 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 27 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 28 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 29 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 31 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 32 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 33 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 34 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 35 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 36 | from tests.base import ( |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | ZuulTestCase, |
| 38 | repack_repo, |
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) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 533 | self.assertEqual(queue[0].name, 'executor:execute') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 534 | job_args = json.loads(queue[0].arguments) |
| 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( |
| 550 | json.loads(queue[0].arguments)['job'], 'project-test1') |
| 551 | self.assertEqual( |
| 552 | json.loads(queue[1].arguments)['job'], 'project-test2') |
| 553 | self.assertEqual( |
| 554 | json.loads(queue[2].arguments)['job'], 'project-test1') |
| 555 | self.assertEqual( |
| 556 | json.loads(queue[3].arguments)['job'], 'project-test2') |
| 557 | self.assertEqual( |
| 558 | json.loads(queue[4].arguments)['job'], 'project-test1') |
| 559 | self.assertEqual( |
| 560 | json.loads(queue[5].arguments)['job'], 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 561 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 562 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 563 | self.waitUntilSettled() |
| 564 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 565 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 566 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 567 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 568 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 569 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 570 | self.gearman_server.hold_jobs_in_queue = False |
| 571 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 572 | self.waitUntilSettled() |
| 573 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 574 | self.assertEqual(len(self.builds), 0) |
| 575 | self.assertEqual(len(self.history), 11) |
| 576 | self.assertEqual(A.data['status'], 'NEW') |
| 577 | self.assertEqual(B.data['status'], 'MERGED') |
| 578 | self.assertEqual(C.data['status'], 'MERGED') |
| 579 | self.assertEqual(A.reported, 2) |
| 580 | self.assertEqual(B.reported, 2) |
| 581 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 582 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 583 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 584 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 585 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 586 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 587 | A.addApproval('code-review', 2) |
| 588 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 589 | self.waitUntilSettled() |
| 590 | time.sleep(2) |
| 591 | |
| 592 | data = json.loads(self.sched.formatStatusJSON()) |
| 593 | found_job = None |
| 594 | for pipeline in data['pipelines']: |
| 595 | if pipeline['name'] != 'gate': |
| 596 | continue |
| 597 | for queue in pipeline['change_queues']: |
| 598 | for head in queue['heads']: |
| 599 | for item in head: |
| 600 | for job in item['jobs']: |
| 601 | if job['name'] == 'project-merge': |
| 602 | found_job = job |
| 603 | break |
| 604 | |
| 605 | self.assertIsNotNone(found_job) |
| 606 | if iteration == 1: |
| 607 | self.assertIsNotNone(found_job['estimated_time']) |
| 608 | self.assertIsNone(found_job['remaining_time']) |
| 609 | else: |
| 610 | self.assertIsNotNone(found_job['estimated_time']) |
| 611 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 612 | self.assertIsNotNone(found_job['remaining_time']) |
| 613 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 614 | self.executor_server.hold_jobs_in_build = False |
| 615 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 616 | self.waitUntilSettled() |
| 617 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 618 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 619 | def test_time_database(self): |
| 620 | "Test the time database" |
| 621 | |
| 622 | self._test_time_database(1) |
| 623 | self._test_time_database(2) |
| 624 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 625 | def test_two_failed_changes_at_head(self): |
| 626 | "Test that changes are reparented correctly if 2 fail at head" |
| 627 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 628 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 629 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 630 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 631 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 632 | A.addApproval('code-review', 2) |
| 633 | B.addApproval('code-review', 2) |
| 634 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 635 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 636 | self.executor_server.failJob('project-test1', A) |
| 637 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 638 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 639 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 640 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 641 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 642 | self.waitUntilSettled() |
| 643 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 644 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 645 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 646 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 647 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 648 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 649 | self.waitUntilSettled() |
| 650 | |
| 651 | self.assertEqual(len(self.builds), 6) |
| 652 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 653 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 654 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 655 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 656 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 657 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 658 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 659 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 660 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 661 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 662 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 663 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 664 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 665 | |
| 666 | # Fail change B first |
| 667 | self.release(self.builds[2]) |
| 668 | self.waitUntilSettled() |
| 669 | |
| 670 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 671 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 672 | self.waitUntilSettled() |
| 673 | |
| 674 | self.assertEqual(len(self.builds), 5) |
| 675 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 676 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 677 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 678 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 679 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 680 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 681 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 682 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 683 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 684 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 685 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 686 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 687 | |
| 688 | # Finish running all passing jobs for change A |
| 689 | self.release(self.builds[1]) |
| 690 | self.waitUntilSettled() |
| 691 | # Fail and report change A |
| 692 | self.release(self.builds[0]) |
| 693 | self.waitUntilSettled() |
| 694 | |
| 695 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 696 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 697 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 698 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 699 | self.waitUntilSettled() |
| 700 | |
| 701 | self.assertEqual(len(self.builds), 4) |
| 702 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 703 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 704 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 705 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 706 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 707 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 708 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 709 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 710 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 711 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 712 | # After A failed and B and C restarted, B should be back in |
| 713 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 714 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 715 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 716 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 717 | self.executor_server.hold_jobs_in_build = False |
| 718 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 719 | self.waitUntilSettled() |
| 720 | |
| 721 | self.assertEqual(len(self.builds), 0) |
| 722 | self.assertEqual(len(self.history), 21) |
| 723 | self.assertEqual(A.data['status'], 'NEW') |
| 724 | self.assertEqual(B.data['status'], 'NEW') |
| 725 | self.assertEqual(C.data['status'], 'MERGED') |
| 726 | self.assertEqual(A.reported, 2) |
| 727 | self.assertEqual(B.reported, 2) |
| 728 | self.assertEqual(C.reported, 2) |
| 729 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 730 | def test_patch_order(self): |
| 731 | "Test that dependent patches are tested in the right order" |
| 732 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 733 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 734 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 735 | A.addApproval('code-review', 2) |
| 736 | B.addApproval('code-review', 2) |
| 737 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 738 | |
| 739 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 740 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 741 | M2.setMerged() |
| 742 | M1.setMerged() |
| 743 | |
| 744 | # C -> B -> A -> M1 -> M2 |
| 745 | # M2 is here to make sure it is never queried. If it is, it |
| 746 | # means zuul is walking down the entire history of merged |
| 747 | # changes. |
| 748 | |
| 749 | C.setDependsOn(B, 1) |
| 750 | B.setDependsOn(A, 1) |
| 751 | A.setDependsOn(M1, 1) |
| 752 | M1.setDependsOn(M2, 1) |
| 753 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 754 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 755 | |
| 756 | self.waitUntilSettled() |
| 757 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 758 | self.assertEqual(A.data['status'], 'NEW') |
| 759 | self.assertEqual(B.data['status'], 'NEW') |
| 760 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 761 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 762 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 763 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 764 | |
| 765 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 766 | self.assertEqual(M2.queried, 0) |
| 767 | self.assertEqual(A.data['status'], 'MERGED') |
| 768 | self.assertEqual(B.data['status'], 'MERGED') |
| 769 | self.assertEqual(C.data['status'], 'MERGED') |
| 770 | self.assertEqual(A.reported, 2) |
| 771 | self.assertEqual(B.reported, 2) |
| 772 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 773 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 774 | def test_needed_changes_enqueue(self): |
| 775 | "Test that a needed change is enqueued ahead" |
| 776 | # A Given a git tree like this, if we enqueue |
| 777 | # / \ change C, we should walk up and down the tree |
| 778 | # B G and enqueue changes in the order ABCDEFG. |
| 779 | # /|\ This is also the order that you would get if |
| 780 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 781 | # / the ordering is stable across re-enqueue events. |
| 782 | # D |
| 783 | |
| 784 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 785 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 786 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 787 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 788 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 789 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 790 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 791 | B.setDependsOn(A, 1) |
| 792 | C.setDependsOn(B, 1) |
| 793 | D.setDependsOn(C, 1) |
| 794 | E.setDependsOn(B, 1) |
| 795 | F.setDependsOn(B, 1) |
| 796 | G.setDependsOn(A, 1) |
| 797 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 798 | A.addApproval('code-review', 2) |
| 799 | B.addApproval('code-review', 2) |
| 800 | C.addApproval('code-review', 2) |
| 801 | D.addApproval('code-review', 2) |
| 802 | E.addApproval('code-review', 2) |
| 803 | F.addApproval('code-review', 2) |
| 804 | G.addApproval('code-review', 2) |
| 805 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 806 | |
| 807 | self.waitUntilSettled() |
| 808 | |
| 809 | self.assertEqual(A.data['status'], 'NEW') |
| 810 | self.assertEqual(B.data['status'], 'NEW') |
| 811 | self.assertEqual(C.data['status'], 'NEW') |
| 812 | self.assertEqual(D.data['status'], 'NEW') |
| 813 | self.assertEqual(E.data['status'], 'NEW') |
| 814 | self.assertEqual(F.data['status'], 'NEW') |
| 815 | self.assertEqual(G.data['status'], 'NEW') |
| 816 | |
| 817 | # We're about to add approvals to changes without adding the |
| 818 | # triggering events to Zuul, so that we can be sure that it is |
| 819 | # enqueing the changes based on dependencies, not because of |
| 820 | # triggering events. Since it will have the changes cached |
| 821 | # already (without approvals), we need to clear the cache |
| 822 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 823 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 824 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 825 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 826 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 827 | A.addApproval('approved', 1) |
| 828 | B.addApproval('approved', 1) |
| 829 | D.addApproval('approved', 1) |
| 830 | E.addApproval('approved', 1) |
| 831 | F.addApproval('approved', 1) |
| 832 | G.addApproval('approved', 1) |
| 833 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 834 | |
| 835 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 836 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 837 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 838 | self.executor_server.hold_jobs_in_build = False |
| 839 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 840 | self.waitUntilSettled() |
| 841 | |
| 842 | self.assertEqual(A.data['status'], 'MERGED') |
| 843 | self.assertEqual(B.data['status'], 'MERGED') |
| 844 | self.assertEqual(C.data['status'], 'MERGED') |
| 845 | self.assertEqual(D.data['status'], 'MERGED') |
| 846 | self.assertEqual(E.data['status'], 'MERGED') |
| 847 | self.assertEqual(F.data['status'], 'MERGED') |
| 848 | self.assertEqual(G.data['status'], 'MERGED') |
| 849 | self.assertEqual(A.reported, 2) |
| 850 | self.assertEqual(B.reported, 2) |
| 851 | self.assertEqual(C.reported, 2) |
| 852 | self.assertEqual(D.reported, 2) |
| 853 | self.assertEqual(E.reported, 2) |
| 854 | self.assertEqual(F.reported, 2) |
| 855 | self.assertEqual(G.reported, 2) |
| 856 | self.assertEqual(self.history[6].changes, |
| 857 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 858 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 859 | def test_source_cache(self): |
| 860 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 861 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 862 | |
| 863 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 864 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 865 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 866 | A.addApproval('code-review', 2) |
| 867 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 868 | |
| 869 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 870 | M1.setMerged() |
| 871 | |
| 872 | B.setDependsOn(A, 1) |
| 873 | A.setDependsOn(M1, 1) |
| 874 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 875 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 876 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 877 | |
| 878 | self.waitUntilSettled() |
| 879 | |
| 880 | for build in self.builds: |
| 881 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 882 | build.release() |
| 883 | self.waitUntilSettled() |
| 884 | for build in self.builds: |
| 885 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 886 | build.release() |
| 887 | self.waitUntilSettled() |
| 888 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 889 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 890 | self.waitUntilSettled() |
| 891 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 892 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 893 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 894 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 895 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 896 | self.executor_server.hold_jobs_in_build = False |
| 897 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 898 | self.waitUntilSettled() |
| 899 | |
| 900 | self.assertEqual(A.data['status'], 'MERGED') |
| 901 | self.assertEqual(B.data['status'], 'MERGED') |
| 902 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 903 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 904 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 905 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 906 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 907 | # TODO: move to test_gerrit (this is a unit test!) |
| 908 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 909 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 910 | (trusted, project) = tenant.getProject('org/project') |
| 911 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 912 | |
| 913 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 914 | # it easier for users to create events for testing. |
| 915 | event = zuul.model.TriggerEvent() |
| 916 | event.trigger_name = 'gerrit' |
| 917 | event.change_number = '1' |
| 918 | event.patch_number = '2' |
| 919 | |
| 920 | a = source.getChange(event) |
| 921 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 922 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 923 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 924 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 925 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 926 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 927 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 928 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 929 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 930 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 931 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 932 | def test_project_merge_conflict(self): |
| 933 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 934 | |
| 935 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 936 | A = self.fake_gerrit.addFakeChange('org/project', |
| 937 | 'master', 'A', |
| 938 | files={'conflict': 'foo'}) |
| 939 | B = self.fake_gerrit.addFakeChange('org/project', |
| 940 | 'master', 'B', |
| 941 | files={'conflict': 'bar'}) |
| 942 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 943 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 944 | A.addApproval('code-review', 2) |
| 945 | B.addApproval('code-review', 2) |
| 946 | C.addApproval('code-review', 2) |
| 947 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 948 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 949 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 950 | self.waitUntilSettled() |
| 951 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 952 | self.assertEqual(A.reported, 1) |
| 953 | self.assertEqual(B.reported, 1) |
| 954 | self.assertEqual(C.reported, 1) |
| 955 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 956 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 957 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 958 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 959 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 960 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 961 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 962 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 963 | self.gearman_server.hold_jobs_in_queue = False |
| 964 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 965 | self.waitUntilSettled() |
| 966 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 967 | self.assertEqual(A.data['status'], 'MERGED') |
| 968 | self.assertEqual(B.data['status'], 'NEW') |
| 969 | self.assertEqual(C.data['status'], 'MERGED') |
| 970 | self.assertEqual(A.reported, 2) |
| 971 | self.assertEqual(B.reported, 2) |
| 972 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 973 | |
| 974 | self.assertHistory([ |
| 975 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 976 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 977 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 978 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 979 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 980 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 981 | ], ordered=False) |
| 982 | |
| 983 | def test_delayed_merge_conflict(self): |
| 984 | "Test that delayed check merge conflicts are handled properly" |
| 985 | |
| 986 | # Hold jobs in the gearman queue so that we can test whether |
| 987 | # the executor returns a merge failure after the scheduler has |
| 988 | # successfully merged. |
| 989 | self.gearman_server.hold_jobs_in_queue = True |
| 990 | A = self.fake_gerrit.addFakeChange('org/project', |
| 991 | 'master', 'A', |
| 992 | files={'conflict': 'foo'}) |
| 993 | B = self.fake_gerrit.addFakeChange('org/project', |
| 994 | 'master', 'B', |
| 995 | files={'conflict': 'bar'}) |
| 996 | C = self.fake_gerrit.addFakeChange('org/project', |
| 997 | 'master', 'C') |
| 998 | C.setDependsOn(B, 1) |
| 999 | |
| 1000 | # A enters the gate queue; B and C enter the check queue |
| 1001 | A.addApproval('code-review', 2) |
| 1002 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1003 | self.waitUntilSettled() |
| 1004 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1005 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1006 | self.waitUntilSettled() |
| 1007 | |
| 1008 | self.assertEqual(A.reported, 1) |
| 1009 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1010 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1011 | |
| 1012 | # A merges while B and C are queued in check |
| 1013 | # Release A project-merge |
| 1014 | queue = self.gearman_server.getQueue() |
| 1015 | self.release(queue[0]) |
| 1016 | self.waitUntilSettled() |
| 1017 | |
| 1018 | # Release A project-test* |
| 1019 | # gate has higher precedence, so A's test jobs are added in |
| 1020 | # front of the merge jobs for B and C |
| 1021 | queue = self.gearman_server.getQueue() |
| 1022 | self.release(queue[0]) |
| 1023 | self.release(queue[1]) |
| 1024 | self.waitUntilSettled() |
| 1025 | |
| 1026 | self.assertEqual(A.data['status'], 'MERGED') |
| 1027 | self.assertEqual(B.data['status'], 'NEW') |
| 1028 | self.assertEqual(C.data['status'], 'NEW') |
| 1029 | self.assertEqual(A.reported, 2) |
| 1030 | self.assertEqual(B.reported, 0) |
| 1031 | self.assertEqual(C.reported, 0) |
| 1032 | self.assertHistory([ |
| 1033 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1034 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1035 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1036 | ], ordered=False) |
| 1037 | |
| 1038 | # B and C report merge conflicts |
| 1039 | # Release B project-merge |
| 1040 | queue = self.gearman_server.getQueue() |
| 1041 | self.release(queue[0]) |
| 1042 | self.waitUntilSettled() |
| 1043 | |
| 1044 | # Release C |
| 1045 | self.gearman_server.hold_jobs_in_queue = False |
| 1046 | self.gearman_server.release() |
| 1047 | self.waitUntilSettled() |
| 1048 | |
| 1049 | self.assertEqual(A.data['status'], 'MERGED') |
| 1050 | self.assertEqual(B.data['status'], 'NEW') |
| 1051 | self.assertEqual(C.data['status'], 'NEW') |
| 1052 | self.assertEqual(A.reported, 2) |
| 1053 | self.assertEqual(B.reported, 1) |
| 1054 | self.assertEqual(C.reported, 1) |
| 1055 | |
| 1056 | self.assertHistory([ |
| 1057 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1058 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1059 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1060 | dict(name='project-merge', result='MERGER_FAILURE', changes='2,1'), |
| 1061 | dict(name='project-merge', result='MERGER_FAILURE', |
| 1062 | changes='2,1 3,1'), |
| 1063 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1064 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1065 | def test_post(self): |
| 1066 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1067 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1068 | e = { |
| 1069 | "type": "ref-updated", |
| 1070 | "submitter": { |
| 1071 | "name": "User Name", |
| 1072 | }, |
| 1073 | "refUpdate": { |
| 1074 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1075 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1076 | "refName": "master", |
| 1077 | "project": "org/project", |
| 1078 | } |
| 1079 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1080 | self.fake_gerrit.addEvent(e) |
| 1081 | self.waitUntilSettled() |
| 1082 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1083 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1084 | self.assertEqual(len(self.history), 1) |
| 1085 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1086 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1087 | def test_post_ignore_deletes(self): |
| 1088 | "Test that deleting refs does not trigger post jobs" |
| 1089 | |
| 1090 | e = { |
| 1091 | "type": "ref-updated", |
| 1092 | "submitter": { |
| 1093 | "name": "User Name", |
| 1094 | }, |
| 1095 | "refUpdate": { |
| 1096 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1097 | "newRev": "0000000000000000000000000000000000000000", |
| 1098 | "refName": "master", |
| 1099 | "project": "org/project", |
| 1100 | } |
| 1101 | } |
| 1102 | self.fake_gerrit.addEvent(e) |
| 1103 | self.waitUntilSettled() |
| 1104 | |
| 1105 | job_names = [x.name for x in self.history] |
| 1106 | self.assertEqual(len(self.history), 0) |
| 1107 | self.assertNotIn('project-post', job_names) |
| 1108 | |
| 1109 | def test_post_ignore_deletes_negative(self): |
| 1110 | "Test that deleting refs does trigger post jobs" |
| 1111 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1112 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1113 | self.sched.reconfigure(self.config) |
| 1114 | |
| 1115 | e = { |
| 1116 | "type": "ref-updated", |
| 1117 | "submitter": { |
| 1118 | "name": "User Name", |
| 1119 | }, |
| 1120 | "refUpdate": { |
| 1121 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1122 | "newRev": "0000000000000000000000000000000000000000", |
| 1123 | "refName": "master", |
| 1124 | "project": "org/project", |
| 1125 | } |
| 1126 | } |
| 1127 | self.fake_gerrit.addEvent(e) |
| 1128 | self.waitUntilSettled() |
| 1129 | |
| 1130 | job_names = [x.name for x in self.history] |
| 1131 | self.assertEqual(len(self.history), 1) |
| 1132 | self.assertIn('project-post', job_names) |
| 1133 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1134 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1135 | def test_build_configuration_branch_interaction(self): |
| 1136 | "Test that switching between branches works" |
| 1137 | self.test_build_configuration() |
| 1138 | self.test_build_configuration_branch() |
| 1139 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1140 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1141 | repo = git.Repo(path) |
| 1142 | repo.heads.master.commit = repo.commit('init') |
| 1143 | self.test_build_configuration() |
| 1144 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1145 | def test_dependent_changes_dequeue(self): |
| 1146 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1147 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1148 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1149 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1150 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1151 | A.addApproval('code-review', 2) |
| 1152 | B.addApproval('code-review', 2) |
| 1153 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1154 | |
| 1155 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1156 | M1.setMerged() |
| 1157 | |
| 1158 | # C -> B -> A -> M1 |
| 1159 | |
| 1160 | C.setDependsOn(B, 1) |
| 1161 | B.setDependsOn(A, 1) |
| 1162 | A.setDependsOn(M1, 1) |
| 1163 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1164 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1165 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1166 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1167 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1168 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1169 | |
| 1170 | self.waitUntilSettled() |
| 1171 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1172 | self.assertEqual(A.data['status'], 'NEW') |
| 1173 | self.assertEqual(A.reported, 2) |
| 1174 | self.assertEqual(B.data['status'], 'NEW') |
| 1175 | self.assertEqual(B.reported, 2) |
| 1176 | self.assertEqual(C.data['status'], 'NEW') |
| 1177 | self.assertEqual(C.reported, 2) |
| 1178 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1179 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1180 | def test_failing_dependent_changes(self): |
| 1181 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1182 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1183 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1184 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1185 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1186 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1187 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1188 | A.addApproval('code-review', 2) |
| 1189 | B.addApproval('code-review', 2) |
| 1190 | C.addApproval('code-review', 2) |
| 1191 | D.addApproval('code-review', 2) |
| 1192 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1193 | |
| 1194 | # E, D -> C -> B, A |
| 1195 | |
| 1196 | D.setDependsOn(C, 1) |
| 1197 | C.setDependsOn(B, 1) |
| 1198 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1199 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1200 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1201 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1202 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1203 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1204 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1205 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1206 | |
| 1207 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1208 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1209 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1210 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1211 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1212 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1213 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1214 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1215 | self.waitUntilSettled() |
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() |
| 1218 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1219 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1220 | for build in self.builds: |
| 1221 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1222 | build.release() |
| 1223 | self.waitUntilSettled() |
| 1224 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1225 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1226 | self.waitUntilSettled() |
| 1227 | |
| 1228 | self.assertEqual(A.data['status'], 'MERGED') |
| 1229 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1230 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1231 | self.assertEqual(B.data['status'], 'NEW') |
| 1232 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1233 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1234 | self.assertEqual(C.data['status'], 'NEW') |
| 1235 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1236 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1237 | self.assertEqual(D.data['status'], 'NEW') |
| 1238 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1239 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1240 | self.assertEqual(E.data['status'], 'MERGED') |
| 1241 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1242 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1243 | self.assertEqual(len(self.history), 18) |
| 1244 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1245 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1246 | "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] | 1247 | # If it's dequeued more than once, we should see extra |
| 1248 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1249 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1250 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1251 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1252 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1253 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1254 | A.addApproval('code-review', 2) |
| 1255 | B.addApproval('code-review', 2) |
| 1256 | C.addApproval('code-review', 2) |
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.failJob('project-test1', A) |
| 1259 | self.executor_server.failJob('project-test2', A) |
| 1260 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1261 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1262 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1263 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1264 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1265 | |
| 1266 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1267 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1268 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1269 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1270 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1271 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1272 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1273 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1274 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1275 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1276 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1277 | self.waitUntilSettled() |
| 1278 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1279 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1280 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1281 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1282 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1283 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1284 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1285 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1286 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1287 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1288 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1289 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1290 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1291 | self.waitUntilSettled() |
| 1292 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1293 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1294 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1295 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1296 | self.executor_server.hold_jobs_in_build = False |
| 1297 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1298 | self.waitUntilSettled() |
| 1299 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1300 | self.assertEqual(len(self.builds), 0) |
| 1301 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1302 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1303 | self.assertEqual(A.data['status'], 'NEW') |
| 1304 | self.assertEqual(B.data['status'], 'MERGED') |
| 1305 | self.assertEqual(C.data['status'], 'MERGED') |
| 1306 | self.assertEqual(A.reported, 2) |
| 1307 | self.assertEqual(B.reported, 2) |
| 1308 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1309 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1310 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1311 | def test_nonvoting_job(self): |
| 1312 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1313 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1314 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1315 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1316 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1317 | self.executor_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1318 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1319 | |
| 1320 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1321 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1322 | self.assertEqual(A.data['status'], 'MERGED') |
| 1323 | self.assertEqual(A.reported, 2) |
| 1324 | self.assertEqual( |
| 1325 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1326 | 'SUCCESS') |
| 1327 | self.assertEqual( |
| 1328 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1329 | 'SUCCESS') |
| 1330 | self.assertEqual( |
| 1331 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1332 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1333 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1334 | for build in self.builds: |
| 1335 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1336 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1337 | def test_check_queue_success(self): |
| 1338 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1339 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1340 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1341 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1342 | |
| 1343 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1344 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1345 | self.assertEqual(A.data['status'], 'NEW') |
| 1346 | self.assertEqual(A.reported, 1) |
| 1347 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1348 | 'SUCCESS') |
| 1349 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1350 | 'SUCCESS') |
| 1351 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1352 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1353 | |
| 1354 | def test_check_queue_failure(self): |
| 1355 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1356 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1357 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1358 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1359 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1360 | |
| 1361 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1362 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1363 | self.assertEqual(A.data['status'], 'NEW') |
| 1364 | self.assertEqual(A.reported, 1) |
| 1365 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1366 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1367 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1368 | 'SUCCESS') |
| 1369 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1370 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1371 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame^] | 1372 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1373 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1374 | # This particular test does a large amount of merges and needs a little |
| 1375 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1376 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1377 | "test that dependent changes behind dequeued changes work" |
| 1378 | # This complicated test is a reproduction of a real life bug |
| 1379 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1380 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1381 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1382 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1383 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1384 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1385 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1386 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1387 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1388 | D.setDependsOn(C, 1) |
| 1389 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1390 | A.addApproval('code-review', 2) |
| 1391 | B.addApproval('code-review', 2) |
| 1392 | C.addApproval('code-review', 2) |
| 1393 | D.addApproval('code-review', 2) |
| 1394 | E.addApproval('code-review', 2) |
| 1395 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1396 | |
| 1397 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1398 | |
| 1399 | # Change object re-use in the gerrit trigger is hidden if |
| 1400 | # changes are added in quick succession; waiting makes it more |
| 1401 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1402 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1403 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1404 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1405 | self.waitUntilSettled() |
| 1406 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1407 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1408 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1409 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1410 | self.waitUntilSettled() |
| 1411 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1412 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1413 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1414 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1415 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1416 | self.fake_gerrit.addEvent(E.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(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1419 | self.waitUntilSettled() |
| 1420 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1421 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1422 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1423 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1424 | self.waitUntilSettled() |
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() |
| 1429 | |
| 1430 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1431 | |
| 1432 | # Grab pointers to the jobs we want to release before |
| 1433 | # releasing any, because list indexes may change as |
| 1434 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1435 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1436 | a.release() |
| 1437 | b.release() |
| 1438 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1439 | self.waitUntilSettled() |
| 1440 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1441 | self.executor_server.hold_jobs_in_build = False |
| 1442 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1443 | self.waitUntilSettled() |
| 1444 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1445 | self.assertEqual(A.data['status'], 'NEW') |
| 1446 | self.assertEqual(B.data['status'], 'MERGED') |
| 1447 | self.assertEqual(C.data['status'], 'MERGED') |
| 1448 | self.assertEqual(D.data['status'], 'MERGED') |
| 1449 | self.assertEqual(E.data['status'], 'MERGED') |
| 1450 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1451 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1452 | self.assertEqual(A.reported, 2) |
| 1453 | self.assertEqual(B.reported, 2) |
| 1454 | self.assertEqual(C.reported, 2) |
| 1455 | self.assertEqual(D.reported, 2) |
| 1456 | self.assertEqual(E.reported, 2) |
| 1457 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1458 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1459 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1460 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1461 | |
| 1462 | def test_merger_repack(self): |
| 1463 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1464 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1465 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1466 | A.addApproval('code-review', 2) |
| 1467 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1468 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1469 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1470 | 'SUCCESS') |
| 1471 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1472 | 'SUCCESS') |
| 1473 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1474 | 'SUCCESS') |
| 1475 | self.assertEqual(A.data['status'], 'MERGED') |
| 1476 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1477 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1478 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1479 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1480 | path = os.path.join(self.merger_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1481 | if os.path.exists(path): |
| 1482 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1483 | path = os.path.join(self.executor_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1484 | if os.path.exists(path): |
| 1485 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1486 | |
| 1487 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1488 | A.addApproval('code-review', 2) |
| 1489 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1490 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1491 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1492 | 'SUCCESS') |
| 1493 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1494 | 'SUCCESS') |
| 1495 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1496 | 'SUCCESS') |
| 1497 | self.assertEqual(A.data['status'], 'MERGED') |
| 1498 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1499 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1500 | def test_merger_repack_large_change(self): |
| 1501 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1502 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1503 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1504 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1505 | trusted, project = tenant.getProject('org/project1') |
| 1506 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1507 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1508 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1509 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1510 | path = os.path.join(self.upstream_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1511 | repack_repo(path) |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1512 | path = os.path.join(self.merger_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1513 | if os.path.exists(path): |
| 1514 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1515 | path = os.path.join(self.executor_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1516 | if os.path.exists(path): |
| 1517 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1518 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1519 | A.addApproval('code-review', 2) |
| 1520 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1521 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1522 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1523 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1524 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1525 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1526 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1527 | 'SUCCESS') |
| 1528 | self.assertEqual(A.data['status'], 'MERGED') |
| 1529 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1530 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1531 | def test_new_patchset_dequeues_old(self): |
| 1532 | "Test that a new patchset causes the old to be dequeued" |
| 1533 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1534 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1535 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1536 | M.setMerged() |
| 1537 | |
| 1538 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1539 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1540 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1541 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1542 | A.addApproval('code-review', 2) |
| 1543 | B.addApproval('code-review', 2) |
| 1544 | C.addApproval('code-review', 2) |
| 1545 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1546 | |
| 1547 | C.setDependsOn(B, 1) |
| 1548 | B.setDependsOn(A, 1) |
| 1549 | A.setDependsOn(M, 1) |
| 1550 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1551 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1552 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1553 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1554 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1555 | self.waitUntilSettled() |
| 1556 | |
| 1557 | B.addPatchset() |
| 1558 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1559 | self.waitUntilSettled() |
| 1560 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1561 | self.executor_server.hold_jobs_in_build = False |
| 1562 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1563 | self.waitUntilSettled() |
| 1564 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1565 | self.assertEqual(A.data['status'], 'MERGED') |
| 1566 | self.assertEqual(A.reported, 2) |
| 1567 | self.assertEqual(B.data['status'], 'NEW') |
| 1568 | self.assertEqual(B.reported, 2) |
| 1569 | self.assertEqual(C.data['status'], 'NEW') |
| 1570 | self.assertEqual(C.reported, 2) |
| 1571 | self.assertEqual(D.data['status'], 'MERGED') |
| 1572 | self.assertEqual(D.reported, 2) |
| 1573 | 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] | 1574 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1575 | def test_new_patchset_check(self): |
| 1576 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1577 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1578 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1579 | |
| 1580 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1581 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1582 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1583 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1584 | |
| 1585 | # Add two git-dependent changes |
| 1586 | B.setDependsOn(A, 1) |
| 1587 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1588 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1589 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1590 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1591 | |
| 1592 | # A live item, and a non-live/live pair |
| 1593 | items = check_pipeline.getAllItems() |
| 1594 | self.assertEqual(len(items), 3) |
| 1595 | |
| 1596 | self.assertEqual(items[0].change.number, '1') |
| 1597 | self.assertEqual(items[0].change.patchset, '1') |
| 1598 | self.assertFalse(items[0].live) |
| 1599 | |
| 1600 | self.assertEqual(items[1].change.number, '2') |
| 1601 | self.assertEqual(items[1].change.patchset, '1') |
| 1602 | self.assertTrue(items[1].live) |
| 1603 | |
| 1604 | self.assertEqual(items[2].change.number, '1') |
| 1605 | self.assertEqual(items[2].change.patchset, '1') |
| 1606 | self.assertTrue(items[2].live) |
| 1607 | |
| 1608 | # Add a new patchset to A |
| 1609 | A.addPatchset() |
| 1610 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1611 | self.waitUntilSettled() |
| 1612 | |
| 1613 | # The live copy of A,1 should be gone, but the non-live and B |
| 1614 | # should continue, and we should have a new A,2 |
| 1615 | items = check_pipeline.getAllItems() |
| 1616 | self.assertEqual(len(items), 3) |
| 1617 | |
| 1618 | self.assertEqual(items[0].change.number, '1') |
| 1619 | self.assertEqual(items[0].change.patchset, '1') |
| 1620 | self.assertFalse(items[0].live) |
| 1621 | |
| 1622 | self.assertEqual(items[1].change.number, '2') |
| 1623 | self.assertEqual(items[1].change.patchset, '1') |
| 1624 | self.assertTrue(items[1].live) |
| 1625 | |
| 1626 | self.assertEqual(items[2].change.number, '1') |
| 1627 | self.assertEqual(items[2].change.patchset, '2') |
| 1628 | self.assertTrue(items[2].live) |
| 1629 | |
| 1630 | # Add a new patchset to B |
| 1631 | B.addPatchset() |
| 1632 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1633 | self.waitUntilSettled() |
| 1634 | |
| 1635 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1636 | # but we should have a new B,2 (still based on A,1) |
| 1637 | items = check_pipeline.getAllItems() |
| 1638 | self.assertEqual(len(items), 3) |
| 1639 | |
| 1640 | self.assertEqual(items[0].change.number, '1') |
| 1641 | self.assertEqual(items[0].change.patchset, '2') |
| 1642 | self.assertTrue(items[0].live) |
| 1643 | |
| 1644 | self.assertEqual(items[1].change.number, '1') |
| 1645 | self.assertEqual(items[1].change.patchset, '1') |
| 1646 | self.assertFalse(items[1].live) |
| 1647 | |
| 1648 | self.assertEqual(items[2].change.number, '2') |
| 1649 | self.assertEqual(items[2].change.patchset, '2') |
| 1650 | self.assertTrue(items[2].live) |
| 1651 | |
| 1652 | self.builds[0].release() |
| 1653 | self.waitUntilSettled() |
| 1654 | self.builds[0].release() |
| 1655 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1656 | self.executor_server.hold_jobs_in_build = False |
| 1657 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1658 | self.waitUntilSettled() |
| 1659 | |
| 1660 | self.assertEqual(A.reported, 1) |
| 1661 | self.assertEqual(B.reported, 1) |
| 1662 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1663 | self.assertEqual(self.history[0].changes, '1,1') |
| 1664 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1665 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1666 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1667 | self.assertEqual(self.history[2].changes, '1,2') |
| 1668 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1669 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1670 | |
| 1671 | def test_abandoned_gate(self): |
| 1672 | "Test that an abandoned change is dequeued from gate" |
| 1673 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1674 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1675 | |
| 1676 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1677 | A.addApproval('code-review', 2) |
| 1678 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1679 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1680 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1681 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1682 | |
| 1683 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1684 | self.waitUntilSettled() |
| 1685 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1686 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1687 | self.waitUntilSettled() |
| 1688 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1689 | self.assertBuilds([]) |
| 1690 | self.assertHistory([ |
| 1691 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1692 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1693 | self.assertEqual(A.reported, 1, |
| 1694 | "Abandoned gate change should report only start") |
| 1695 | |
| 1696 | def test_abandoned_check(self): |
| 1697 | "Test that an abandoned change is dequeued from check" |
| 1698 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1699 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1700 | |
| 1701 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1702 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1703 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1704 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1705 | |
| 1706 | # Add two git-dependent changes |
| 1707 | B.setDependsOn(A, 1) |
| 1708 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1709 | self.waitUntilSettled() |
| 1710 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1711 | self.waitUntilSettled() |
| 1712 | # A live item, and a non-live/live pair |
| 1713 | items = check_pipeline.getAllItems() |
| 1714 | self.assertEqual(len(items), 3) |
| 1715 | |
| 1716 | self.assertEqual(items[0].change.number, '1') |
| 1717 | self.assertFalse(items[0].live) |
| 1718 | |
| 1719 | self.assertEqual(items[1].change.number, '2') |
| 1720 | self.assertTrue(items[1].live) |
| 1721 | |
| 1722 | self.assertEqual(items[2].change.number, '1') |
| 1723 | self.assertTrue(items[2].live) |
| 1724 | |
| 1725 | # Abandon A |
| 1726 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1727 | self.waitUntilSettled() |
| 1728 | |
| 1729 | # The live copy of A should be gone, but the non-live and B |
| 1730 | # should continue |
| 1731 | items = check_pipeline.getAllItems() |
| 1732 | self.assertEqual(len(items), 2) |
| 1733 | |
| 1734 | self.assertEqual(items[0].change.number, '1') |
| 1735 | self.assertFalse(items[0].live) |
| 1736 | |
| 1737 | self.assertEqual(items[1].change.number, '2') |
| 1738 | self.assertTrue(items[1].live) |
| 1739 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1740 | self.executor_server.hold_jobs_in_build = False |
| 1741 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1742 | self.waitUntilSettled() |
| 1743 | |
| 1744 | self.assertEqual(len(self.history), 4) |
| 1745 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1746 | 'Build should have been aborted') |
| 1747 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1748 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1749 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1750 | def test_abandoned_not_timer(self): |
| 1751 | "Test that an abandoned change does not cancel timer jobs" |
| 1752 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1753 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1754 | |
| 1755 | # Start timer trigger - also org/project |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1756 | self.updateConfigLayout('layout-idle') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1757 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1758 | # The pipeline triggers every second, so we should have seen |
| 1759 | # several by now. |
| 1760 | time.sleep(5) |
| 1761 | self.waitUntilSettled() |
| 1762 | # Stop queuing timer triggered jobs so that the assertions |
| 1763 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1764 | # Must be in same repo, so overwrite config with another one |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 1765 | self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1766 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1767 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1768 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1769 | |
| 1770 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1771 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1772 | self.waitUntilSettled() |
| 1773 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1774 | |
| 1775 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1776 | self.waitUntilSettled() |
| 1777 | |
| 1778 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1779 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1780 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1781 | self.waitUntilSettled() |
| 1782 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1783 | def test_zuul_url_return(self): |
| 1784 | "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] | 1785 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1786 | self.executor_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1787 | |
| 1788 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1789 | A.addApproval('code-review', 2) |
| 1790 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1791 | self.waitUntilSettled() |
| 1792 | |
| 1793 | self.assertEqual(len(self.builds), 1) |
| 1794 | for build in self.builds: |
| 1795 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1796 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1797 | self.executor_server.hold_jobs_in_build = False |
| 1798 | self.executor_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1799 | self.waitUntilSettled() |
| 1800 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1801 | def test_new_patchset_dequeues_old_on_head(self): |
| 1802 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1803 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1804 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1805 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1806 | M.setMerged() |
| 1807 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1808 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1809 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1810 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1811 | A.addApproval('code-review', 2) |
| 1812 | B.addApproval('code-review', 2) |
| 1813 | C.addApproval('code-review', 2) |
| 1814 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1815 | |
| 1816 | C.setDependsOn(B, 1) |
| 1817 | B.setDependsOn(A, 1) |
| 1818 | A.setDependsOn(M, 1) |
| 1819 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1820 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1821 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1822 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1823 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1824 | self.waitUntilSettled() |
| 1825 | |
| 1826 | A.addPatchset() |
| 1827 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1828 | self.waitUntilSettled() |
| 1829 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1830 | self.executor_server.hold_jobs_in_build = False |
| 1831 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1832 | self.waitUntilSettled() |
| 1833 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1834 | self.assertEqual(A.data['status'], 'NEW') |
| 1835 | self.assertEqual(A.reported, 2) |
| 1836 | self.assertEqual(B.data['status'], 'NEW') |
| 1837 | self.assertEqual(B.reported, 2) |
| 1838 | self.assertEqual(C.data['status'], 'NEW') |
| 1839 | self.assertEqual(C.reported, 2) |
| 1840 | self.assertEqual(D.data['status'], 'MERGED') |
| 1841 | self.assertEqual(D.reported, 2) |
| 1842 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1843 | |
| 1844 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1845 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1846 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1847 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1848 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1849 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1850 | A.addApproval('code-review', 2) |
| 1851 | B.addApproval('code-review', 2) |
| 1852 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1853 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1854 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1855 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1856 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1857 | self.waitUntilSettled() |
| 1858 | |
| 1859 | B.addPatchset() |
| 1860 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1861 | self.waitUntilSettled() |
| 1862 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1863 | self.executor_server.hold_jobs_in_build = False |
| 1864 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1865 | self.waitUntilSettled() |
| 1866 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1867 | self.assertEqual(A.data['status'], 'MERGED') |
| 1868 | self.assertEqual(A.reported, 2) |
| 1869 | self.assertEqual(B.data['status'], 'NEW') |
| 1870 | self.assertEqual(B.reported, 2) |
| 1871 | self.assertEqual(C.data['status'], 'MERGED') |
| 1872 | self.assertEqual(C.reported, 2) |
| 1873 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1874 | |
| 1875 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1876 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1877 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1878 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1879 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1880 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1881 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1882 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1883 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1884 | self.waitUntilSettled() |
| 1885 | |
| 1886 | B.addPatchset() |
| 1887 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1888 | self.waitUntilSettled() |
| 1889 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1890 | self.executor_server.hold_jobs_in_build = False |
| 1891 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1892 | self.waitUntilSettled() |
| 1893 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1894 | self.assertEqual(A.data['status'], 'NEW') |
| 1895 | self.assertEqual(A.reported, 1) |
| 1896 | self.assertEqual(B.data['status'], 'NEW') |
| 1897 | self.assertEqual(B.reported, 1) |
| 1898 | self.assertEqual(C.data['status'], 'NEW') |
| 1899 | self.assertEqual(C.reported, 1) |
| 1900 | self.assertEqual(len(self.history), 10) |
| 1901 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1902 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1903 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1904 | def test_noop_job(self): |
| 1905 | "Test that the internal noop job works" |
| 1906 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1907 | A.addApproval('code-review', 2) |
| 1908 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1909 | self.waitUntilSettled() |
| 1910 | |
| 1911 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1912 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1913 | self.assertEqual(len(self.history), 0) |
| 1914 | self.assertEqual(A.data['status'], 'MERGED') |
| 1915 | self.assertEqual(A.reported, 2) |
| 1916 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 1917 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1918 | def test_no_job_project(self): |
| 1919 | "Test that reports with no jobs don't get sent" |
| 1920 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1921 | 'master', 'A') |
| 1922 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1923 | self.waitUntilSettled() |
| 1924 | |
| 1925 | # Change wasn't reported to |
| 1926 | self.assertEqual(A.reported, False) |
| 1927 | |
| 1928 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1929 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1930 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1931 | items = check_pipeline.getAllItems() |
| 1932 | self.assertEqual(len(items), 0) |
| 1933 | |
| 1934 | self.assertEqual(len(self.history), 0) |
| 1935 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1936 | def test_zuul_refs(self): |
| 1937 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1938 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1939 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1940 | M1.setMerged() |
| 1941 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1942 | M2.setMerged() |
| 1943 | |
| 1944 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1945 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1946 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1947 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1948 | A.addApproval('code-review', 2) |
| 1949 | B.addApproval('code-review', 2) |
| 1950 | C.addApproval('code-review', 2) |
| 1951 | D.addApproval('code-review', 2) |
| 1952 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1953 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1954 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1955 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1956 | |
| 1957 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1958 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1959 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1960 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1961 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1962 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1963 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1964 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1965 | self.waitUntilSettled() |
| 1966 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1967 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1968 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1969 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1970 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1971 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1972 | a_build = x |
| 1973 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1974 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1975 | b_build = x |
| 1976 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1977 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1978 | c_build = x |
| 1979 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1980 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1981 | d_build = x |
| 1982 | if a_build and b_build and c_build and d_build: |
| 1983 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1984 | |
| 1985 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1986 | self.assertIsNotNone(a_zref) |
| 1987 | self.assertIsNotNone(b_zref) |
| 1988 | self.assertIsNotNone(c_zref) |
| 1989 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1990 | |
| 1991 | # And they should all be different |
| 1992 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1993 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1994 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1995 | # should have a, not b, and should not be in project2 |
| 1996 | self.assertTrue(a_build.hasChanges(A)) |
| 1997 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1998 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1999 | # should have a and b, and should not be in project2 |
| 2000 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2001 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2002 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2003 | # should have a and b in 1, c in 2 |
| 2004 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2005 | self.assertFalse(c_build.hasChanges(D)) |
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 and b in 1, c and d in 2 |
| 2008 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2009 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2010 | self.executor_server.hold_jobs_in_build = False |
| 2011 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2012 | self.waitUntilSettled() |
| 2013 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2014 | self.assertEqual(A.data['status'], 'MERGED') |
| 2015 | self.assertEqual(A.reported, 2) |
| 2016 | self.assertEqual(B.data['status'], 'MERGED') |
| 2017 | self.assertEqual(B.reported, 2) |
| 2018 | self.assertEqual(C.data['status'], 'MERGED') |
| 2019 | self.assertEqual(C.reported, 2) |
| 2020 | self.assertEqual(D.data['status'], 'MERGED') |
| 2021 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2022 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2023 | def test_rerun_on_error(self): |
| 2024 | "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] | 2025 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2026 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2027 | A.addApproval('code-review', 2) |
| 2028 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2029 | self.waitUntilSettled() |
| 2030 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2031 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2032 | self.executor_server.hold_jobs_in_build = False |
| 2033 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2034 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2035 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2036 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2037 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2038 | def test_statsd(self): |
| 2039 | "Test each of the statsd methods used in the scheduler" |
| 2040 | import extras |
| 2041 | statsd = extras.try_import('statsd.statsd') |
| 2042 | statsd.incr('test-incr') |
| 2043 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2044 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2045 | self.assertReportedStat('test-incr', '1|c') |
| 2046 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2047 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2048 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2049 | def test_stuck_job_cleanup(self): |
| 2050 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2051 | |
| 2052 | # 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] | 2053 | self.gearman_server.hold_jobs_in_queue = True |
| 2054 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2055 | A.addApproval('code-review', 2) |
| 2056 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2057 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2058 | # 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] | 2059 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2060 | |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2061 | self.commitLayoutUpdate('common-config', 'layout-no-jobs') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2062 | self.sched.reconfigure(self.config) |
| 2063 | self.waitUntilSettled() |
| 2064 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2065 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2066 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2067 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2068 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2069 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2070 | |
| 2071 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2072 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2073 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2074 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2075 | def test_file_head(self): |
| 2076 | # This is a regression test for an observed bug. A change |
| 2077 | # with a file named "HEAD" in the root directory of the repo |
| 2078 | # was processed by a merger. It then was unable to reset the |
| 2079 | # repo because of: |
| 2080 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2081 | # with exit code 128 |
| 2082 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2083 | # and filename |
| 2084 | # Use '--' to separate filenames from revisions' |
| 2085 | |
| 2086 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2087 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2088 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2089 | |
| 2090 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2091 | self.waitUntilSettled() |
| 2092 | |
| 2093 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2094 | self.waitUntilSettled() |
| 2095 | |
| 2096 | self.assertIn('Build succeeded', A.messages[0]) |
| 2097 | self.assertIn('Build succeeded', B.messages[0]) |
| 2098 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2099 | def test_file_jobs(self): |
| 2100 | "Test that file jobs run only when appropriate" |
| 2101 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2102 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2103 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2104 | A.addApproval('code-review', 2) |
| 2105 | B.addApproval('code-review', 2) |
| 2106 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2107 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2108 | self.waitUntilSettled() |
| 2109 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2110 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2111 | if x.name == 'project-testfile'] |
| 2112 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2113 | self.assertEqual(len(testfile_jobs), 1) |
| 2114 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2115 | self.assertEqual(A.data['status'], 'MERGED') |
| 2116 | self.assertEqual(A.reported, 2) |
| 2117 | self.assertEqual(B.data['status'], 'MERGED') |
| 2118 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2119 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2120 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2121 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2122 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2123 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2124 | |
| 2125 | if should_skip: |
| 2126 | files = {'ignoreme': 'ignored\n'} |
| 2127 | else: |
| 2128 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2129 | |
| 2130 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2131 | 'master', |
| 2132 | 'test irrelevant-files', |
| 2133 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2134 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2135 | self.waitUntilSettled() |
| 2136 | |
| 2137 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2138 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2139 | |
| 2140 | if should_skip: |
| 2141 | self.assertEqual([], tested_change_ids) |
| 2142 | else: |
| 2143 | self.assertIn(change.data['number'], tested_change_ids) |
| 2144 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2145 | def test_irrelevant_files_match_skips_job(self): |
| 2146 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2147 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2148 | def test_irrelevant_files_no_match_runs_job(self): |
| 2149 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2150 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2151 | def test_inherited_jobs_keep_matchers(self): |
| 2152 | self.updateConfigLayout('layout-inheritance') |
| 2153 | self.sched.reconfigure(self.config) |
| 2154 | |
| 2155 | files = {'ignoreme': 'ignored\n'} |
| 2156 | |
| 2157 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2158 | 'master', |
| 2159 | 'test irrelevant-files', |
| 2160 | files=files) |
| 2161 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2162 | self.waitUntilSettled() |
| 2163 | |
| 2164 | run_jobs = set([build.name for build in self.history]) |
| 2165 | |
| 2166 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2167 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2168 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2169 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2170 | def test_test_config(self): |
| 2171 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2172 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2173 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2174 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2175 | def test_queue_names(self): |
| 2176 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2177 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2178 | (trusted, project1) = tenant.getProject('org/project1') |
| 2179 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2180 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2181 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2182 | self.assertEqual(q1.name, 'integrated') |
| 2183 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2184 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2185 | def test_queue_precedence(self): |
| 2186 | "Test that queue precedence works" |
| 2187 | |
| 2188 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2189 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2190 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2191 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2192 | A.addApproval('code-review', 2) |
| 2193 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2194 | |
| 2195 | self.waitUntilSettled() |
| 2196 | self.gearman_server.hold_jobs_in_queue = False |
| 2197 | self.gearman_server.release() |
| 2198 | self.waitUntilSettled() |
| 2199 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2200 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2201 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2202 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2203 | self.waitUntilSettled() |
| 2204 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2205 | self.log.debug(self.history) |
| 2206 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2207 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2208 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2209 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2210 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2211 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2212 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2213 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2214 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2215 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2216 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2217 | A.addApproval('code-review', 2) |
| 2218 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2219 | self.waitUntilSettled() |
| 2220 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2221 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2222 | self.waitUntilSettled() |
| 2223 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2224 | port = self.webapp.server.socket.getsockname()[1] |
| 2225 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2226 | req = urllib.request.Request( |
| 2227 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2228 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2229 | headers = f.info() |
| 2230 | self.assertIn('Content-Length', headers) |
| 2231 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2232 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2233 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2234 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2235 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2236 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2237 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2238 | data = f.read() |
| 2239 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2240 | self.executor_server.hold_jobs_in_build = False |
| 2241 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2242 | self.waitUntilSettled() |
| 2243 | |
| 2244 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2245 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2246 | for p in data['pipelines']: |
| 2247 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2248 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2249 | self.assertEqual(q['window'], 20) |
| 2250 | else: |
| 2251 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2252 | for head in q['heads']: |
| 2253 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2254 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2255 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2256 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2257 | status_jobs.append(job) |
| 2258 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2259 | self.assertEqual('https://server/job/project-merge/0/', |
| 2260 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2261 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2262 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2263 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2264 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2265 | status_jobs[1]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2266 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2267 | status_jobs[1]['report_url']) |
| 2268 | |
| 2269 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2270 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2271 | status_jobs[2]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2272 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2273 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2274 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2275 | def test_semaphore_one(self): |
| 2276 | "Test semaphores with max=1 (mutex)" |
| 2277 | self.updateConfigLayout('layout-semaphore') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2278 | self.sched.reconfigure(self.config) |
| 2279 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2280 | self.waitUntilSettled() |
| 2281 | tenant = self.sched.abide.tenants.get('openstack') |
| 2282 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2283 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2284 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2285 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2286 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2287 | self.assertFalse('test-semaphore' in |
| 2288 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2289 | |
| 2290 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2291 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2292 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2293 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2294 | self.assertEqual(len(self.builds), 3) |
| 2295 | self.assertEqual(self.builds[0].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2296 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2297 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2298 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2299 | self.executor_server.release('semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2300 | self.waitUntilSettled() |
| 2301 | |
| 2302 | self.assertEqual(len(self.builds), 3) |
| 2303 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2304 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2305 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 2306 | self.assertTrue('test-semaphore' in |
| 2307 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2308 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2309 | self.executor_server.release('semaphore-one-test2') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2310 | self.waitUntilSettled() |
| 2311 | |
| 2312 | self.assertEqual(len(self.builds), 3) |
| 2313 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2314 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2315 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 2316 | self.assertTrue('test-semaphore' in |
| 2317 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2318 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2319 | self.executor_server.release('semaphore-one-test1') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2320 | self.waitUntilSettled() |
| 2321 | |
| 2322 | self.assertEqual(len(self.builds), 3) |
| 2323 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2324 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2325 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 2326 | self.assertTrue('test-semaphore' in |
| 2327 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2328 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2329 | self.executor_server.release('semaphore-one-test2') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2330 | self.waitUntilSettled() |
| 2331 | |
| 2332 | self.assertEqual(len(self.builds), 2) |
| 2333 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2334 | self.assertEqual(self.builds[1].name, 'project-test1') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2335 | self.assertFalse('test-semaphore' in |
| 2336 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2337 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2338 | self.executor_server.hold_jobs_in_build = False |
| 2339 | self.executor_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2340 | |
| 2341 | self.waitUntilSettled() |
| 2342 | self.assertEqual(len(self.builds), 0) |
| 2343 | |
| 2344 | self.assertEqual(A.reported, 1) |
| 2345 | self.assertEqual(B.reported, 1) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2346 | self.assertFalse('test-semaphore' in |
| 2347 | tenant.semaphore_handler.semaphores) |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2348 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2349 | def test_semaphore_two(self): |
| 2350 | "Test semaphores with max>1" |
| 2351 | self.updateConfigLayout('layout-semaphore') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2352 | self.sched.reconfigure(self.config) |
| 2353 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2354 | self.waitUntilSettled() |
| 2355 | tenant = self.sched.abide.tenants.get('openstack') |
| 2356 | |
| 2357 | self.executor_server.hold_jobs_in_build = True |
| 2358 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2359 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2360 | self.assertFalse('test-semaphore-two' in |
| 2361 | tenant.semaphore_handler.semaphores) |
| 2362 | |
| 2363 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2364 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2365 | self.waitUntilSettled() |
| 2366 | |
| 2367 | self.assertEqual(len(self.builds), 4) |
| 2368 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2369 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 2370 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 2371 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 2372 | self.assertTrue('test-semaphore-two' in |
| 2373 | tenant.semaphore_handler.semaphores) |
| 2374 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2375 | 'test-semaphore-two', [])), 2) |
| 2376 | |
| 2377 | self.executor_server.release('semaphore-two-test1') |
| 2378 | self.waitUntilSettled() |
| 2379 | |
| 2380 | self.assertEqual(len(self.builds), 4) |
| 2381 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2382 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 2383 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2384 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 2385 | self.assertTrue('test-semaphore-two' in |
| 2386 | tenant.semaphore_handler.semaphores) |
| 2387 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2388 | 'test-semaphore-two', [])), 2) |
| 2389 | |
| 2390 | self.executor_server.release('semaphore-two-test2') |
| 2391 | self.waitUntilSettled() |
| 2392 | |
| 2393 | self.assertEqual(len(self.builds), 4) |
| 2394 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2395 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2396 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 2397 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 2398 | self.assertTrue('test-semaphore-two' in |
| 2399 | tenant.semaphore_handler.semaphores) |
| 2400 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2401 | 'test-semaphore-two', [])), 2) |
| 2402 | |
| 2403 | self.executor_server.release('semaphore-two-test1') |
| 2404 | self.waitUntilSettled() |
| 2405 | |
| 2406 | self.assertEqual(len(self.builds), 3) |
| 2407 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2408 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2409 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 2410 | self.assertTrue('test-semaphore-two' in |
| 2411 | tenant.semaphore_handler.semaphores) |
| 2412 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 2413 | 'test-semaphore-two', [])), 1) |
| 2414 | |
| 2415 | self.executor_server.release('semaphore-two-test2') |
| 2416 | self.waitUntilSettled() |
| 2417 | |
| 2418 | self.assertEqual(len(self.builds), 2) |
| 2419 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2420 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2421 | self.assertFalse('test-semaphore-two' in |
| 2422 | tenant.semaphore_handler.semaphores) |
| 2423 | |
| 2424 | self.executor_server.hold_jobs_in_build = False |
| 2425 | self.executor_server.release() |
| 2426 | |
| 2427 | self.waitUntilSettled() |
| 2428 | self.assertEqual(len(self.builds), 0) |
| 2429 | |
| 2430 | self.assertEqual(A.reported, 1) |
| 2431 | self.assertEqual(B.reported, 1) |
| 2432 | |
| 2433 | def test_semaphore_abandon(self): |
| 2434 | "Test abandon with job semaphores" |
| 2435 | self.updateConfigLayout('layout-semaphore') |
| 2436 | self.sched.reconfigure(self.config) |
| 2437 | |
| 2438 | self.waitUntilSettled() |
| 2439 | tenant = self.sched.abide.tenants.get('openstack') |
| 2440 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2441 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2442 | |
| 2443 | tenant = self.sched.abide.tenants.get('openstack') |
| 2444 | check_pipeline = tenant.layout.pipelines['check'] |
| 2445 | |
| 2446 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2447 | self.assertFalse('test-semaphore' in |
| 2448 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2449 | |
| 2450 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2451 | self.waitUntilSettled() |
| 2452 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2453 | self.assertTrue('test-semaphore' in |
| 2454 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2455 | |
| 2456 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2457 | self.waitUntilSettled() |
| 2458 | |
| 2459 | # The check pipeline should be empty |
| 2460 | items = check_pipeline.getAllItems() |
| 2461 | self.assertEqual(len(items), 0) |
| 2462 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2463 | # The semaphore should be released |
| 2464 | self.assertFalse('test-semaphore' in |
| 2465 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2466 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2467 | self.executor_server.hold_jobs_in_build = False |
| 2468 | self.executor_server.release() |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2469 | self.waitUntilSettled() |
| 2470 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2471 | def test_semaphore_reconfigure(self): |
| 2472 | "Test reconfigure with job semaphores" |
| 2473 | self.updateConfigLayout('layout-semaphore') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2474 | self.sched.reconfigure(self.config) |
| 2475 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2476 | self.waitUntilSettled() |
| 2477 | tenant = self.sched.abide.tenants.get('openstack') |
| 2478 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2479 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2480 | |
| 2481 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2482 | self.assertFalse('test-semaphore' in |
| 2483 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2484 | |
| 2485 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2486 | self.waitUntilSettled() |
| 2487 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2488 | self.assertTrue('test-semaphore' in |
| 2489 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2490 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2491 | # reconfigure without layout change |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2492 | self.sched.reconfigure(self.config) |
| 2493 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2494 | tenant = self.sched.abide.tenants.get('openstack') |
| 2495 | |
| 2496 | # semaphore still must be held |
| 2497 | self.assertTrue('test-semaphore' in |
| 2498 | tenant.semaphore_handler.semaphores) |
| 2499 | |
| 2500 | self.updateConfigLayout('layout-semaphore-reconfiguration') |
| 2501 | self.sched.reconfigure(self.config) |
| 2502 | self.waitUntilSettled() |
| 2503 | tenant = self.sched.abide.tenants.get('openstack') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2504 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2505 | self.executor_server.release('project-test1') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2506 | self.waitUntilSettled() |
| 2507 | |
| 2508 | # There should be no builds anymore |
| 2509 | self.assertEqual(len(self.builds), 0) |
| 2510 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 2511 | # The semaphore should be released |
| 2512 | self.assertFalse('test-semaphore' in |
| 2513 | tenant.semaphore_handler.semaphores) |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2514 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2515 | def test_live_reconfiguration(self): |
| 2516 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2517 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2518 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2519 | A.addApproval('code-review', 2) |
| 2520 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2521 | self.waitUntilSettled() |
| 2522 | |
| 2523 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2524 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2525 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2526 | self.executor_server.hold_jobs_in_build = False |
| 2527 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2528 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2529 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2530 | 'SUCCESS') |
| 2531 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2532 | 'SUCCESS') |
| 2533 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2534 | 'SUCCESS') |
| 2535 | self.assertEqual(A.data['status'], 'MERGED') |
| 2536 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2537 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2538 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2539 | def test_live_reconfiguration_merge_conflict(self): |
| 2540 | # A real-world bug: a change in a gate queue has a merge |
| 2541 | # conflict and a job is added to its project while it's |
| 2542 | # sitting in the queue. The job gets added to the change and |
| 2543 | # enqueued and the change gets stuck. |
| 2544 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2545 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2546 | |
| 2547 | # This change is fine. It's here to stop the queue long |
| 2548 | # enough for the next change to be subject to the |
| 2549 | # reconfiguration, as well as to provide a conflict for the |
| 2550 | # next change. This change will succeed and merge. |
| 2551 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2552 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2553 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2554 | |
| 2555 | # This change will be in merge conflict. During the |
| 2556 | # reconfiguration, we will add a job. We want to make sure |
| 2557 | # that doesn't cause it to get stuck. |
| 2558 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2559 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2560 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2561 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2562 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2563 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2564 | |
| 2565 | self.waitUntilSettled() |
| 2566 | |
| 2567 | # No jobs have run yet |
| 2568 | self.assertEqual(A.data['status'], 'NEW') |
| 2569 | self.assertEqual(A.reported, 1) |
| 2570 | self.assertEqual(B.data['status'], 'NEW') |
| 2571 | self.assertEqual(B.reported, 1) |
| 2572 | self.assertEqual(len(self.history), 0) |
| 2573 | |
| 2574 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2575 | self.updateConfigLayout( |
| 2576 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2577 | self.sched.reconfigure(self.config) |
| 2578 | self.waitUntilSettled() |
| 2579 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2580 | self.executor_server.hold_jobs_in_build = False |
| 2581 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2582 | self.waitUntilSettled() |
| 2583 | |
| 2584 | self.assertEqual(A.data['status'], 'MERGED') |
| 2585 | self.assertEqual(A.reported, 2) |
| 2586 | self.assertEqual(B.data['status'], 'NEW') |
| 2587 | self.assertEqual(B.reported, 2) |
| 2588 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2589 | 'SUCCESS') |
| 2590 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2591 | 'SUCCESS') |
| 2592 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2593 | 'SUCCESS') |
| 2594 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2595 | 'SUCCESS') |
| 2596 | self.assertEqual(len(self.history), 4) |
| 2597 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2598 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2599 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2600 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2601 | # that tests a job added to a job tree with a failed root does |
| 2602 | # not run. |
| 2603 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2604 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2605 | |
| 2606 | # This change is fine. It's here to stop the queue long |
| 2607 | # enough for the next change to be subject to the |
| 2608 | # reconfiguration. This change will succeed and merge. |
| 2609 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2610 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2611 | A.addApproval('code-review', 2) |
| 2612 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2613 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2614 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2615 | self.waitUntilSettled() |
| 2616 | |
| 2617 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2618 | self.executor_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2619 | B.addApproval('code-review', 2) |
| 2620 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2621 | self.waitUntilSettled() |
| 2622 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2623 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2624 | self.waitUntilSettled() |
| 2625 | |
| 2626 | # Both -merge jobs have run, but no others. |
| 2627 | self.assertEqual(A.data['status'], 'NEW') |
| 2628 | self.assertEqual(A.reported, 1) |
| 2629 | self.assertEqual(B.data['status'], 'NEW') |
| 2630 | self.assertEqual(B.reported, 1) |
| 2631 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2632 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2633 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2634 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2635 | self.assertEqual(len(self.history), 2) |
| 2636 | |
| 2637 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2638 | self.updateConfigLayout( |
| 2639 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2640 | self.sched.reconfigure(self.config) |
| 2641 | self.waitUntilSettled() |
| 2642 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2643 | self.executor_server.hold_jobs_in_build = False |
| 2644 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2645 | self.waitUntilSettled() |
| 2646 | |
| 2647 | self.assertEqual(A.data['status'], 'MERGED') |
| 2648 | self.assertEqual(A.reported, 2) |
| 2649 | self.assertEqual(B.data['status'], 'NEW') |
| 2650 | self.assertEqual(B.reported, 2) |
| 2651 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2652 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2653 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2654 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2655 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2656 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2657 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2658 | self.assertEqual(len(self.history), 5) |
| 2659 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2660 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2661 | def test_live_reconfiguration_failed_job(self): |
| 2662 | # Test that a change with a removed failing job does not |
| 2663 | # disrupt reconfiguration. If a change has a failed job and |
| 2664 | # that job is removed during a reconfiguration, we observed a |
| 2665 | # bug where the code to re-set build statuses would run on |
| 2666 | # that build and raise an exception because the job no longer |
| 2667 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2668 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2669 | |
| 2670 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2671 | |
| 2672 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2673 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2674 | |
| 2675 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2676 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2677 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2678 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2679 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2680 | self.waitUntilSettled() |
| 2681 | |
| 2682 | self.assertEqual(A.data['status'], 'NEW') |
| 2683 | self.assertEqual(A.reported, 0) |
| 2684 | |
| 2685 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2686 | 'SUCCESS') |
| 2687 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2688 | 'FAILURE') |
| 2689 | self.assertEqual(len(self.history), 2) |
| 2690 | |
| 2691 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2692 | self.updateConfigLayout( |
| 2693 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2694 | self.sched.reconfigure(self.config) |
| 2695 | self.waitUntilSettled() |
| 2696 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2697 | self.executor_server.hold_jobs_in_build = False |
| 2698 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2699 | self.waitUntilSettled() |
| 2700 | |
| 2701 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2702 | 'SUCCESS') |
| 2703 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2704 | 'SUCCESS') |
| 2705 | self.assertEqual(len(self.history), 4) |
| 2706 | |
| 2707 | self.assertEqual(A.data['status'], 'NEW') |
| 2708 | self.assertEqual(A.reported, 1) |
| 2709 | self.assertIn('Build succeeded', A.messages[0]) |
| 2710 | # Ensure the removed job was not included in the report. |
| 2711 | self.assertNotIn('project-test1', A.messages[0]) |
| 2712 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2713 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2714 | def test_live_reconfiguration_shared_queue(self): |
| 2715 | # Test that a change with a failing job which was removed from |
| 2716 | # this project but otherwise still exists in the system does |
| 2717 | # not disrupt reconfiguration. |
| 2718 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2719 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2720 | |
| 2721 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2722 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2723 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2724 | |
| 2725 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2726 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2727 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2728 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2729 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2730 | self.waitUntilSettled() |
| 2731 | |
| 2732 | self.assertEqual(A.data['status'], 'NEW') |
| 2733 | self.assertEqual(A.reported, 0) |
| 2734 | |
| 2735 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2736 | 'SUCCESS') |
| 2737 | self.assertEqual(self.getJobFromHistory( |
| 2738 | 'project1-project2-integration').result, 'FAILURE') |
| 2739 | self.assertEqual(len(self.history), 2) |
| 2740 | |
| 2741 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2742 | self.updateConfigLayout( |
| 2743 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2744 | self.sched.reconfigure(self.config) |
| 2745 | self.waitUntilSettled() |
| 2746 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2747 | self.executor_server.hold_jobs_in_build = False |
| 2748 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2749 | self.waitUntilSettled() |
| 2750 | |
| 2751 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2752 | 'SUCCESS') |
| 2753 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2754 | 'SUCCESS') |
| 2755 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2756 | 'SUCCESS') |
| 2757 | self.assertEqual(self.getJobFromHistory( |
| 2758 | 'project1-project2-integration').result, 'FAILURE') |
| 2759 | self.assertEqual(len(self.history), 4) |
| 2760 | |
| 2761 | self.assertEqual(A.data['status'], 'NEW') |
| 2762 | self.assertEqual(A.reported, 1) |
| 2763 | self.assertIn('Build succeeded', A.messages[0]) |
| 2764 | # Ensure the removed job was not included in the report. |
| 2765 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2766 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2767 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2768 | def test_double_live_reconfiguration_shared_queue(self): |
| 2769 | # This was a real-world regression. A change is added to |
| 2770 | # gate; a reconfigure happens, a second change which depends |
| 2771 | # on the first is added, and a second reconfiguration happens. |
| 2772 | # Ensure that both changes merge. |
| 2773 | |
| 2774 | # A failure may indicate incorrect caching or cleaning up of |
| 2775 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2776 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2777 | |
| 2778 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2779 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2780 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2781 | A.addApproval('code-review', 2) |
| 2782 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2783 | |
| 2784 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2785 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2786 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2787 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2788 | self.waitUntilSettled() |
| 2789 | |
| 2790 | # Reconfigure (with only one change in the pipeline). |
| 2791 | self.sched.reconfigure(self.config) |
| 2792 | self.waitUntilSettled() |
| 2793 | |
| 2794 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2795 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2796 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2797 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2798 | self.waitUntilSettled() |
| 2799 | |
| 2800 | # Reconfigure (with both in the pipeline). |
| 2801 | self.sched.reconfigure(self.config) |
| 2802 | self.waitUntilSettled() |
| 2803 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2804 | self.executor_server.hold_jobs_in_build = False |
| 2805 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2806 | self.waitUntilSettled() |
| 2807 | |
| 2808 | self.assertEqual(len(self.history), 8) |
| 2809 | |
| 2810 | self.assertEqual(A.data['status'], 'MERGED') |
| 2811 | self.assertEqual(A.reported, 2) |
| 2812 | self.assertEqual(B.data['status'], 'MERGED') |
| 2813 | self.assertEqual(B.reported, 2) |
| 2814 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2815 | def test_live_reconfiguration_del_project(self): |
| 2816 | # Test project deletion from layout |
| 2817 | # while changes are enqueued |
| 2818 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2819 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2820 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2821 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2822 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2823 | |
| 2824 | # A Depends-On: B |
| 2825 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2826 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2827 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2828 | |
| 2829 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2830 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2831 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2832 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2833 | self.waitUntilSettled() |
| 2834 | self.assertEqual(len(self.builds), 5) |
| 2835 | |
| 2836 | # This layout defines only org/project, not org/project1 |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2837 | self.commitLayoutUpdate('common-config', |
| 2838 | 'layout-live-reconfiguration-del-project') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2839 | self.sched.reconfigure(self.config) |
| 2840 | self.waitUntilSettled() |
| 2841 | |
| 2842 | # Builds for C aborted, builds for A succeed, |
| 2843 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2844 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2845 | self.assertEqual(job_c.changes, '3,1') |
| 2846 | self.assertEqual(job_c.result, 'ABORTED') |
| 2847 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2848 | self.executor_server.hold_jobs_in_build = False |
| 2849 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2850 | self.waitUntilSettled() |
| 2851 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2852 | self.assertEqual( |
| 2853 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2854 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2855 | |
| 2856 | self.assertEqual(A.data['status'], 'NEW') |
| 2857 | self.assertEqual(B.data['status'], 'NEW') |
| 2858 | self.assertEqual(C.data['status'], 'NEW') |
| 2859 | self.assertEqual(A.reported, 1) |
| 2860 | self.assertEqual(B.reported, 0) |
| 2861 | self.assertEqual(C.reported, 0) |
| 2862 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2863 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2864 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2865 | self.assertIn('Build succeeded', A.messages[0]) |
| 2866 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2867 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2868 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2869 | self.updateConfigLayout( |
| 2870 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2871 | self.sched.reconfigure(self.config) |
| 2872 | |
| 2873 | self.init_repo("org/new-project") |
| 2874 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2875 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2876 | A.addApproval('code-review', 2) |
| 2877 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2878 | self.waitUntilSettled() |
| 2879 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2880 | 'SUCCESS') |
| 2881 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2882 | 'SUCCESS') |
| 2883 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2884 | 'SUCCESS') |
| 2885 | self.assertEqual(A.data['status'], 'MERGED') |
| 2886 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2887 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2888 | def test_repo_deleted(self): |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 2889 | self.updateConfigLayout('layout-repo-deleted', ['org/delete-project']) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2890 | self.sched.reconfigure(self.config) |
| 2891 | |
| 2892 | self.init_repo("org/delete-project") |
| 2893 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2894 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2895 | A.addApproval('code-review', 2) |
| 2896 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2897 | self.waitUntilSettled() |
| 2898 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2899 | 'SUCCESS') |
| 2900 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2901 | 'SUCCESS') |
| 2902 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2903 | 'SUCCESS') |
| 2904 | self.assertEqual(A.data['status'], 'MERGED') |
| 2905 | self.assertEqual(A.reported, 2) |
| 2906 | |
| 2907 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2908 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2909 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2910 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2911 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2912 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2913 | |
| 2914 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2915 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2916 | B.addApproval('code-review', 2) |
| 2917 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [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(B.data['status'], 'MERGED') |
| 2926 | self.assertEqual(B.reported, 2) |
| 2927 | |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2928 | def test_tags(self): |
| 2929 | "Test job tags" |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2930 | self.updateConfigLayout('layout-tags') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2931 | self.sched.reconfigure(self.config) |
| 2932 | |
| 2933 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2934 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2935 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2936 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2937 | self.waitUntilSettled() |
| 2938 | |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2939 | self.assertEqual(len(self.history), 8) |
| 2940 | |
| 2941 | results = {self.getJobFromHistory('merge', |
| 2942 | project='org/project1').uuid: 'extratag merge', |
| 2943 | self.getJobFromHistory('merge', |
| 2944 | project='org/project2').uuid: 'merge'} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2945 | |
| 2946 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2947 | self.assertEqual(results.get(build.uuid, ''), |
| 2948 | build.parameters['vars']['zuul'].get('tags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2949 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2950 | def test_timer(self): |
| 2951 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2952 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2953 | self.updateConfigLayout('layout-timer') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2954 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2955 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2956 | # The pipeline triggers every second, so we should have seen |
| 2957 | # several by now. |
| 2958 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2959 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2960 | |
| 2961 | self.assertEqual(len(self.builds), 2) |
| 2962 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2963 | port = self.webapp.server.socket.getsockname()[1] |
| 2964 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2965 | req = urllib.request.Request( |
| 2966 | "http://localhost:%s/openstack/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2967 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2968 | data = f.read() |
| 2969 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2970 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2971 | # Stop queuing timer triggered jobs so that the assertions |
| 2972 | # below don't race against more jobs being queued. |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2973 | self.commitLayoutUpdate('layout-timer', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2974 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2975 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2976 | self.waitUntilSettled() |
| 2977 | |
| 2978 | self.assertEqual(self.getJobFromHistory( |
| 2979 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2980 | self.assertEqual(self.getJobFromHistory( |
| 2981 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2982 | |
| 2983 | data = json.loads(data) |
| 2984 | status_jobs = set() |
| 2985 | for p in data['pipelines']: |
| 2986 | for q in p['change_queues']: |
| 2987 | for head in q['heads']: |
| 2988 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2989 | for job in change['jobs']: |
| 2990 | status_jobs.add(job['name']) |
| 2991 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2992 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2993 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2994 | def test_idle(self): |
| 2995 | "Test that frequent periodic jobs work" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2996 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2997 | self.updateConfigLayout('layout-idle') |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2998 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2999 | for x in range(1, 3): |
| 3000 | # Test that timer triggers periodic jobs even across |
| 3001 | # layout config reloads. |
| 3002 | # Start timer trigger |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3003 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3004 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3005 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3006 | # The pipeline triggers every second, so we should have seen |
| 3007 | # several by now. |
| 3008 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3009 | |
| 3010 | # Stop queuing timer triggered jobs so that the assertions |
| 3011 | # below don't race against more jobs being queued. |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3012 | before = self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3013 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3014 | self.waitUntilSettled() |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3015 | self.assertEqual(len(self.builds), 2, |
| 3016 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3017 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3018 | self.waitUntilSettled() |
| 3019 | self.assertEqual(len(self.builds), 0) |
| 3020 | self.assertEqual(len(self.history), x * 2) |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3021 | # Revert back to layout-idle |
| 3022 | repo = git.Repo(os.path.join(self.test_root, |
| 3023 | 'upstream', |
| 3024 | 'layout-idle')) |
| 3025 | repo.git.reset('--hard', before) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3026 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3027 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 3028 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3029 | self.sched.reconfigure(self.config) |
| 3030 | |
| 3031 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3032 | self.waitUntilSettled() |
| 3033 | |
| 3034 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3035 | self.waitUntilSettled() |
| 3036 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3037 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3038 | |
| 3039 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3040 | # work on the knowledge of what the first message should be as |
| 3041 | # it is only configured to go to SMTP. |
| 3042 | |
| 3043 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3044 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3045 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3046 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3047 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3048 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3049 | |
| 3050 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3051 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3052 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3053 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3054 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3055 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3056 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3057 | def test_timer_smtp(self): |
| 3058 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3059 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 3060 | self.updateConfigLayout('layout-timer-smtp') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3061 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3062 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3063 | # The pipeline triggers every second, so we should have seen |
| 3064 | # several by now. |
| 3065 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3066 | self.waitUntilSettled() |
| 3067 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3068 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3069 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3070 | self.waitUntilSettled() |
| 3071 | self.assertEqual(len(self.history), 2) |
| 3072 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3073 | self.assertEqual(self.getJobFromHistory( |
| 3074 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3075 | self.assertEqual(self.getJobFromHistory( |
| 3076 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3077 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3078 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3079 | |
| 3080 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3081 | # work on the knowledge of what the first message should be as |
| 3082 | # it is only configured to go to SMTP. |
| 3083 | |
| 3084 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3085 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3086 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3087 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3088 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3089 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3090 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3091 | # Stop queuing timer triggered jobs and let any that may have |
| 3092 | # queued through so that end of test assertions pass. |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 3093 | self.commitLayoutUpdate('layout-timer-smtp', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3094 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3095 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3096 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3097 | self.waitUntilSettled() |
| 3098 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3099 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3100 | def test_timer_sshkey(self): |
| 3101 | "Test that a periodic job can setup SSH key authentication" |
| 3102 | self.worker.hold_jobs_in_build = True |
| 3103 | self.config.set('zuul', 'layout_config', |
| 3104 | 'tests/fixtures/layout-timer.yaml') |
| 3105 | self.sched.reconfigure(self.config) |
| 3106 | self.registerJobs() |
| 3107 | |
| 3108 | # The pipeline triggers every second, so we should have seen |
| 3109 | # several by now. |
| 3110 | time.sleep(5) |
| 3111 | self.waitUntilSettled() |
| 3112 | |
| 3113 | self.assertEqual(len(self.builds), 2) |
| 3114 | |
| 3115 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3116 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3117 | with open(ssh_wrapper) as f: |
| 3118 | ssh_wrapper_content = f.read() |
| 3119 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3120 | # In the unit tests Merger runs in the same process, |
| 3121 | # so we see its' environment variables |
| 3122 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3123 | |
| 3124 | self.worker.release('.*') |
| 3125 | self.waitUntilSettled() |
| 3126 | self.assertEqual(len(self.history), 2) |
| 3127 | |
| 3128 | self.assertEqual(self.getJobFromHistory( |
| 3129 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3130 | self.assertEqual(self.getJobFromHistory( |
| 3131 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3132 | |
| 3133 | # Stop queuing timer triggered jobs and let any that may have |
| 3134 | # queued through so that end of test assertions pass. |
| 3135 | self.config.set('zuul', 'layout_config', |
| 3136 | 'tests/fixtures/layout-no-timer.yaml') |
| 3137 | self.sched.reconfigure(self.config) |
| 3138 | self.registerJobs() |
| 3139 | self.waitUntilSettled() |
| 3140 | self.worker.release('.*') |
| 3141 | self.waitUntilSettled() |
| 3142 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3143 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3144 | "Test that the RPC client can enqueue a change" |
| 3145 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3146 | A.addApproval('code-review', 2) |
| 3147 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3148 | |
| 3149 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3150 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3151 | r = client.enqueue(tenant='tenant-one', |
| 3152 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3153 | project='org/project', |
| 3154 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3155 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3156 | self.waitUntilSettled() |
| 3157 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3158 | 'SUCCESS') |
| 3159 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3160 | 'SUCCESS') |
| 3161 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3162 | 'SUCCESS') |
| 3163 | self.assertEqual(A.data['status'], 'MERGED') |
| 3164 | self.assertEqual(A.reported, 2) |
| 3165 | self.assertEqual(r, True) |
| 3166 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3167 | def test_client_enqueue_ref(self): |
| 3168 | "Test that the RPC client can enqueue a ref" |
| 3169 | |
| 3170 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3171 | self.gearman_server.port) |
| 3172 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3173 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3174 | pipeline='post', |
| 3175 | project='org/project', |
| 3176 | trigger='gerrit', |
| 3177 | ref='master', |
| 3178 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3179 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3180 | self.waitUntilSettled() |
| 3181 | job_names = [x.name for x in self.history] |
| 3182 | self.assertEqual(len(self.history), 1) |
| 3183 | self.assertIn('project-post', job_names) |
| 3184 | self.assertEqual(r, True) |
| 3185 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3186 | def test_client_enqueue_negative(self): |
| 3187 | "Test that the RPC client returns errors" |
| 3188 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3189 | self.gearman_server.port) |
| 3190 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3191 | "Invalid tenant"): |
| 3192 | r = client.enqueue(tenant='tenant-foo', |
| 3193 | pipeline='gate', |
| 3194 | project='org/project', |
| 3195 | trigger='gerrit', |
| 3196 | change='1,1') |
| 3197 | client.shutdown() |
| 3198 | self.assertEqual(r, False) |
| 3199 | |
| 3200 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3201 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3202 | r = client.enqueue(tenant='tenant-one', |
| 3203 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3204 | project='project-does-not-exist', |
| 3205 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3206 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3207 | client.shutdown() |
| 3208 | self.assertEqual(r, False) |
| 3209 | |
| 3210 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3211 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3212 | r = client.enqueue(tenant='tenant-one', |
| 3213 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3214 | project='org/project', |
| 3215 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3216 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3217 | client.shutdown() |
| 3218 | self.assertEqual(r, False) |
| 3219 | |
| 3220 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3221 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3222 | r = client.enqueue(tenant='tenant-one', |
| 3223 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3224 | project='org/project', |
| 3225 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3226 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3227 | client.shutdown() |
| 3228 | self.assertEqual(r, False) |
| 3229 | |
| 3230 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3231 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3232 | r = client.enqueue(tenant='tenant-one', |
| 3233 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3234 | project='org/project', |
| 3235 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3236 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3237 | client.shutdown() |
| 3238 | self.assertEqual(r, False) |
| 3239 | |
| 3240 | self.waitUntilSettled() |
| 3241 | self.assertEqual(len(self.history), 0) |
| 3242 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3243 | |
| 3244 | def test_client_promote(self): |
| 3245 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3246 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3247 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3248 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3249 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3250 | A.addApproval('code-review', 2) |
| 3251 | B.addApproval('code-review', 2) |
| 3252 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3253 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3254 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3255 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3256 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3257 | |
| 3258 | self.waitUntilSettled() |
| 3259 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3260 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3261 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3262 | enqueue_times = {} |
| 3263 | for item in items: |
| 3264 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3265 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3266 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3267 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3268 | r = client.promote(tenant='tenant-one', |
| 3269 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3270 | change_ids=['2,1', '3,1']) |
| 3271 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3272 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3273 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3274 | for item in items: |
| 3275 | self.assertEqual( |
| 3276 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3277 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3278 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3279 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3280 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3281 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3282 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3283 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3284 | self.waitUntilSettled() |
| 3285 | |
| 3286 | self.assertEqual(len(self.builds), 6) |
| 3287 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3288 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3289 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3290 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3291 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3292 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3293 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3294 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3295 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3296 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3297 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3298 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3299 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3300 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3301 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3302 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3303 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3304 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3305 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3306 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3307 | self.waitUntilSettled() |
| 3308 | |
| 3309 | self.assertEqual(A.data['status'], 'MERGED') |
| 3310 | self.assertEqual(A.reported, 2) |
| 3311 | self.assertEqual(B.data['status'], 'MERGED') |
| 3312 | self.assertEqual(B.reported, 2) |
| 3313 | self.assertEqual(C.data['status'], 'MERGED') |
| 3314 | self.assertEqual(C.reported, 2) |
| 3315 | |
| 3316 | client.shutdown() |
| 3317 | self.assertEqual(r, True) |
| 3318 | |
| 3319 | def test_client_promote_dependent(self): |
| 3320 | "Test that the RPC client can promote a dependent change" |
| 3321 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3322 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3323 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3324 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3325 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3326 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3327 | |
| 3328 | C.setDependsOn(B, 1) |
| 3329 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3330 | A.addApproval('code-review', 2) |
| 3331 | B.addApproval('code-review', 2) |
| 3332 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3333 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3334 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3335 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3336 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3337 | |
| 3338 | self.waitUntilSettled() |
| 3339 | |
| 3340 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3341 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3342 | r = client.promote(tenant='tenant-one', |
| 3343 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3344 | change_ids=['3,1']) |
| 3345 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3346 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3347 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3348 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3349 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3350 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3351 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3352 | self.waitUntilSettled() |
| 3353 | |
| 3354 | self.assertEqual(len(self.builds), 6) |
| 3355 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3356 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3357 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3358 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3359 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3360 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3361 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3362 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3363 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3364 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3365 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3366 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3367 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3368 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3369 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3370 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3371 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3372 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3373 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3374 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3375 | self.waitUntilSettled() |
| 3376 | |
| 3377 | self.assertEqual(A.data['status'], 'MERGED') |
| 3378 | self.assertEqual(A.reported, 2) |
| 3379 | self.assertEqual(B.data['status'], 'MERGED') |
| 3380 | self.assertEqual(B.reported, 2) |
| 3381 | self.assertEqual(C.data['status'], 'MERGED') |
| 3382 | self.assertEqual(C.reported, 2) |
| 3383 | |
| 3384 | client.shutdown() |
| 3385 | self.assertEqual(r, True) |
| 3386 | |
| 3387 | def test_client_promote_negative(self): |
| 3388 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3389 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3390 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3391 | A.addApproval('code-review', 2) |
| 3392 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3393 | self.waitUntilSettled() |
| 3394 | |
| 3395 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3396 | self.gearman_server.port) |
| 3397 | |
| 3398 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3399 | r = client.promote(tenant='tenant-one', |
| 3400 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3401 | change_ids=['2,1', '3,1']) |
| 3402 | client.shutdown() |
| 3403 | self.assertEqual(r, False) |
| 3404 | |
| 3405 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3406 | r = client.promote(tenant='tenant-one', |
| 3407 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3408 | change_ids=['4,1']) |
| 3409 | client.shutdown() |
| 3410 | self.assertEqual(r, False) |
| 3411 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3412 | self.executor_server.hold_jobs_in_build = False |
| 3413 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3414 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3415 | |
| 3416 | def test_queue_rate_limiting(self): |
| 3417 | "Test that DependentPipelines are rate limited with dep across window" |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3418 | self.updateConfigLayout('layout-rate-limit') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3419 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3420 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3421 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3422 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3423 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3424 | |
| 3425 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3426 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3427 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3428 | A.addApproval('code-review', 2) |
| 3429 | B.addApproval('code-review', 2) |
| 3430 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3431 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3432 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3433 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3434 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3435 | self.waitUntilSettled() |
| 3436 | |
| 3437 | # Only A and B will have their merge jobs queued because |
| 3438 | # window is 2. |
| 3439 | self.assertEqual(len(self.builds), 2) |
| 3440 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3441 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3442 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3443 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3444 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3445 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3446 | self.waitUntilSettled() |
| 3447 | |
| 3448 | # Only A and B will have their test jobs queued because |
| 3449 | # window is 2. |
| 3450 | self.assertEqual(len(self.builds), 4) |
| 3451 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3452 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3453 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3454 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3455 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3456 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3457 | self.waitUntilSettled() |
| 3458 | |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3459 | tenant = self.sched.abide.tenants.get('openstack') |
| 3460 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3461 | # A failed so window is reduced by 1 to 1. |
| 3462 | self.assertEqual(queue.window, 1) |
| 3463 | self.assertEqual(queue.window_floor, 1) |
| 3464 | self.assertEqual(A.data['status'], 'NEW') |
| 3465 | |
| 3466 | # Gate is reset and only B's merge job is queued because |
| 3467 | # window shrunk to 1. |
| 3468 | self.assertEqual(len(self.builds), 1) |
| 3469 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3470 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3471 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3472 | self.waitUntilSettled() |
| 3473 | |
| 3474 | # Only B's test jobs are queued because window is still 1. |
| 3475 | self.assertEqual(len(self.builds), 2) |
| 3476 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3477 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3478 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3479 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3480 | self.waitUntilSettled() |
| 3481 | |
| 3482 | # B was successfully merged so window is increased to 2. |
| 3483 | self.assertEqual(queue.window, 2) |
| 3484 | self.assertEqual(queue.window_floor, 1) |
| 3485 | self.assertEqual(B.data['status'], 'MERGED') |
| 3486 | |
| 3487 | # Only C is left and its merge job is queued. |
| 3488 | self.assertEqual(len(self.builds), 1) |
| 3489 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3490 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3491 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3492 | self.waitUntilSettled() |
| 3493 | |
| 3494 | # After successful merge job the test jobs for C are queued. |
| 3495 | self.assertEqual(len(self.builds), 2) |
| 3496 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3497 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3498 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3499 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3500 | self.waitUntilSettled() |
| 3501 | |
| 3502 | # C successfully merged so window is bumped to 3. |
| 3503 | self.assertEqual(queue.window, 3) |
| 3504 | self.assertEqual(queue.window_floor, 1) |
| 3505 | self.assertEqual(C.data['status'], 'MERGED') |
| 3506 | |
| 3507 | def test_queue_rate_limiting_dependent(self): |
| 3508 | "Test that DependentPipelines are rate limited with dep in window" |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3509 | self.updateConfigLayout('layout-rate-limit') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3510 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3511 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3512 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3513 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3514 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3515 | |
| 3516 | B.setDependsOn(A, 1) |
| 3517 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3518 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3519 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3520 | A.addApproval('code-review', 2) |
| 3521 | B.addApproval('code-review', 2) |
| 3522 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3523 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3524 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3525 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3526 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3527 | self.waitUntilSettled() |
| 3528 | |
| 3529 | # Only A and B will have their merge jobs queued because |
| 3530 | # window is 2. |
| 3531 | self.assertEqual(len(self.builds), 2) |
| 3532 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3533 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3534 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3535 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3536 | |
| 3537 | # Only A and B will have their test jobs queued because |
| 3538 | # window is 2. |
| 3539 | self.assertEqual(len(self.builds), 4) |
| 3540 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3541 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3542 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3543 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3544 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3545 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3546 | self.waitUntilSettled() |
| 3547 | |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3548 | tenant = self.sched.abide.tenants.get('openstack') |
| 3549 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3550 | # A failed so window is reduced by 1 to 1. |
| 3551 | self.assertEqual(queue.window, 1) |
| 3552 | self.assertEqual(queue.window_floor, 1) |
| 3553 | self.assertEqual(A.data['status'], 'NEW') |
| 3554 | self.assertEqual(B.data['status'], 'NEW') |
| 3555 | |
| 3556 | # Gate is reset and only C's merge job is queued because |
| 3557 | # window shrunk to 1 and A and B were dequeued. |
| 3558 | self.assertEqual(len(self.builds), 1) |
| 3559 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3560 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3561 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3562 | |
| 3563 | # Only C's test jobs are queued because window is still 1. |
| 3564 | self.assertEqual(len(self.builds), 2) |
| 3565 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3566 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3567 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3568 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3569 | self.waitUntilSettled() |
| 3570 | |
| 3571 | # C was successfully merged so window is increased to 2. |
| 3572 | self.assertEqual(queue.window, 2) |
| 3573 | self.assertEqual(queue.window_floor, 1) |
| 3574 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3575 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3576 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3577 | def test_worker_update_metadata(self): |
| 3578 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3579 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3580 | |
| 3581 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3582 | A.addApproval('code-review', 2) |
| 3583 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3584 | self.waitUntilSettled() |
| 3585 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3586 | self.assertEqual(len(self.executor.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3587 | |
| 3588 | self.log.debug('Current builds:') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3589 | self.log.debug(self.executor.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3590 | |
| 3591 | start = time.time() |
| 3592 | while True: |
| 3593 | if time.time() - start > 10: |
| 3594 | raise Exception("Timeout waiting for gearman server to report " |
| 3595 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3596 | build = self.executor.builds.values()[0] |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3597 | if build.worker.name == "My Worker": |
| 3598 | break |
| 3599 | else: |
| 3600 | time.sleep(0) |
| 3601 | |
| 3602 | self.log.debug(build) |
| 3603 | self.assertEqual("My Worker", build.worker.name) |
| 3604 | self.assertEqual("localhost", build.worker.hostname) |
| 3605 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3606 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3607 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3608 | self.assertEqual("v1.1", build.worker.version) |
| 3609 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3610 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3611 | self.executor_server.hold_jobs_in_build = False |
| 3612 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3613 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3614 | |
| 3615 | def test_footer_message(self): |
| 3616 | "Test a pipeline's footer message is correctly added to the report." |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3617 | self.updateConfigLayout('layout-footer-message') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3618 | self.sched.reconfigure(self.config) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3619 | |
| 3620 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3621 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3622 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3623 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3624 | self.waitUntilSettled() |
| 3625 | |
| 3626 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3627 | B.addApproval('code-review', 2) |
| 3628 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3629 | self.waitUntilSettled() |
| 3630 | |
| 3631 | self.assertEqual(2, len(self.smtp_messages)) |
| 3632 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3633 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3634 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3635 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3636 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3637 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3638 | For CI problems and help debugging, contact ci@example.org""" |
| 3639 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3640 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3641 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3642 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3643 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3644 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3645 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3646 | def test_merge_failure_reporters(self): |
| 3647 | """Check that the config is set up correctly""" |
| 3648 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3649 | self.updateConfigLayout( |
| 3650 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3651 | self.sched.reconfigure(self.config) |
| 3652 | self.registerJobs() |
| 3653 | |
| 3654 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3655 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3656 | "dependencies was unable to be automatically merged with the " |
| 3657 | "current state of its repository. Please rebase the change and " |
| 3658 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3659 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3660 | self.assertEqual( |
| 3661 | "The merge failed! For more information...", |
| 3662 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3663 | |
| 3664 | self.assertEqual( |
| 3665 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3666 | self.assertEqual( |
| 3667 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3668 | |
| 3669 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3670 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3671 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3672 | |
| 3673 | self.assertTrue( |
| 3674 | ( |
| 3675 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3676 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3677 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3678 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3679 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3680 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3681 | ) or ( |
| 3682 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3683 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3684 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3685 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3686 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3687 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3688 | ) |
| 3689 | ) |
| 3690 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3691 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3692 | def test_merge_failure_reports(self): |
| 3693 | """Check that when a change fails to merge the correct message is sent |
| 3694 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3695 | self.updateConfigLayout( |
| 3696 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3697 | self.sched.reconfigure(self.config) |
| 3698 | self.registerJobs() |
| 3699 | |
| 3700 | # Check a test failure isn't reported to SMTP |
| 3701 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3702 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3703 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3704 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3705 | self.waitUntilSettled() |
| 3706 | |
| 3707 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3708 | self.assertEqual(0, len(self.smtp_messages)) |
| 3709 | |
| 3710 | # Check a merge failure is reported to SMTP |
| 3711 | # B should be merged, but C will conflict with B |
| 3712 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3713 | B.addPatchset(['conflict']) |
| 3714 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3715 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3716 | B.addApproval('code-review', 2) |
| 3717 | C.addApproval('code-review', 2) |
| 3718 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3719 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3720 | self.waitUntilSettled() |
| 3721 | |
| 3722 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3723 | self.assertEqual(1, len(self.smtp_messages)) |
| 3724 | self.assertEqual('The merge failed! For more information...', |
| 3725 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3726 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3727 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3728 | def test_default_merge_failure_reports(self): |
| 3729 | """Check that the default merge failure reports are correct.""" |
| 3730 | |
| 3731 | # A should report success, B should report merge failure. |
| 3732 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3733 | A.addPatchset(['conflict']) |
| 3734 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3735 | B.addPatchset(['conflict']) |
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) |
| 3738 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3739 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3740 | self.waitUntilSettled() |
| 3741 | |
| 3742 | self.assertEqual(3, len(self.history)) # A jobs |
| 3743 | self.assertEqual(A.reported, 2) |
| 3744 | self.assertEqual(B.reported, 2) |
| 3745 | self.assertEqual(A.data['status'], 'MERGED') |
| 3746 | self.assertEqual(B.data['status'], 'NEW') |
| 3747 | self.assertIn('Build succeeded', A.messages[1]) |
| 3748 | self.assertIn('Merge Failed', B.messages[1]) |
| 3749 | self.assertIn('automatically merged', B.messages[1]) |
| 3750 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3751 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3752 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3753 | def test_client_get_running_jobs(self): |
| 3754 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3755 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3756 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3757 | A.addApproval('code-review', 2) |
| 3758 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3759 | self.waitUntilSettled() |
| 3760 | |
| 3761 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3762 | self.gearman_server.port) |
| 3763 | |
| 3764 | # Wait for gearman server to send the initial workData back to zuul |
| 3765 | start = time.time() |
| 3766 | while True: |
| 3767 | if time.time() - start > 10: |
| 3768 | raise Exception("Timeout waiting for gearman server to report " |
| 3769 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3770 | build = self.executor_client.builds.values()[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3771 | if build.worker.name == "My Worker": |
| 3772 | break |
| 3773 | else: |
| 3774 | time.sleep(0) |
| 3775 | |
| 3776 | running_items = client.get_running_jobs() |
| 3777 | |
| 3778 | self.assertEqual(1, len(running_items)) |
| 3779 | running_item = running_items[0] |
| 3780 | self.assertEqual([], running_item['failing_reasons']) |
| 3781 | self.assertEqual([], running_item['items_behind']) |
| 3782 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3783 | self.assertEqual(None, running_item['item_ahead']) |
| 3784 | self.assertEqual('org/project', running_item['project']) |
| 3785 | self.assertEqual(None, running_item['remaining_time']) |
| 3786 | self.assertEqual(True, running_item['active']) |
| 3787 | self.assertEqual('1,1', running_item['id']) |
| 3788 | |
| 3789 | self.assertEqual(3, len(running_item['jobs'])) |
| 3790 | for job in running_item['jobs']: |
| 3791 | if job['name'] == 'project-merge': |
| 3792 | self.assertEqual('project-merge', job['name']) |
| 3793 | self.assertEqual('gate', job['pipeline']) |
| 3794 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3795 | self.assertEqual('https://server/job/project-merge/0/', |
| 3796 | job['url']) |
| 3797 | self.assertEqual(7, len(job['worker'])) |
| 3798 | self.assertEqual(False, job['canceled']) |
| 3799 | self.assertEqual(True, job['voting']) |
| 3800 | self.assertEqual(None, job['result']) |
| 3801 | self.assertEqual('gate', job['pipeline']) |
| 3802 | break |
| 3803 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3804 | self.executor_server.hold_jobs_in_build = False |
| 3805 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3806 | self.waitUntilSettled() |
| 3807 | |
| 3808 | running_items = client.get_running_jobs() |
| 3809 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3810 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3811 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3812 | def test_nonvoting_pipeline(self): |
| 3813 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3814 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3815 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3816 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3817 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3818 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3819 | |
| 3820 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3821 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3822 | self.assertEqual( |
| 3823 | self.getJobFromHistory('experimental-project-test').result, |
| 3824 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3825 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3826 | |
| 3827 | def test_crd_gate(self): |
| 3828 | "Test cross-repo dependencies" |
| 3829 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3830 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3831 | A.addApproval('code-review', 2) |
| 3832 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3833 | |
| 3834 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3835 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3836 | AM2.setMerged() |
| 3837 | AM1.setMerged() |
| 3838 | |
| 3839 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3840 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3841 | BM2.setMerged() |
| 3842 | BM1.setMerged() |
| 3843 | |
| 3844 | # A -> AM1 -> AM2 |
| 3845 | # B -> BM1 -> BM2 |
| 3846 | # A Depends-On: B |
| 3847 | # M2 is here to make sure it is never queried. If it is, it |
| 3848 | # means zuul is walking down the entire history of merged |
| 3849 | # changes. |
| 3850 | |
| 3851 | B.setDependsOn(BM1, 1) |
| 3852 | BM1.setDependsOn(BM2, 1) |
| 3853 | |
| 3854 | A.setDependsOn(AM1, 1) |
| 3855 | AM1.setDependsOn(AM2, 1) |
| 3856 | |
| 3857 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3858 | A.subject, B.data['id']) |
| 3859 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3860 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3861 | self.waitUntilSettled() |
| 3862 | |
| 3863 | self.assertEqual(A.data['status'], 'NEW') |
| 3864 | self.assertEqual(B.data['status'], 'NEW') |
| 3865 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3866 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3867 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3868 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3869 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3870 | B.addApproval('approved', 1) |
| 3871 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3872 | self.waitUntilSettled() |
| 3873 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3874 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3875 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3876 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3877 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3878 | self.executor_server.hold_jobs_in_build = False |
| 3879 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3880 | self.waitUntilSettled() |
| 3881 | |
| 3882 | self.assertEqual(AM2.queried, 0) |
| 3883 | self.assertEqual(BM2.queried, 0) |
| 3884 | self.assertEqual(A.data['status'], 'MERGED') |
| 3885 | self.assertEqual(B.data['status'], 'MERGED') |
| 3886 | self.assertEqual(A.reported, 2) |
| 3887 | self.assertEqual(B.reported, 2) |
| 3888 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3889 | changes = self.getJobFromHistory( |
| 3890 | 'project-merge', 'org/project1').changes |
| 3891 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3892 | |
| 3893 | def test_crd_branch(self): |
| 3894 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3895 | |
| 3896 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3897 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3898 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3899 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3900 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3901 | A.addApproval('code-review', 2) |
| 3902 | B.addApproval('code-review', 2) |
| 3903 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3904 | |
| 3905 | # A Depends-On: B+C |
| 3906 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3907 | A.subject, B.data['id']) |
| 3908 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3909 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3910 | B.addApproval('approved', 1) |
| 3911 | C.addApproval('approved', 1) |
| 3912 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3913 | self.waitUntilSettled() |
| 3914 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3915 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3916 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3917 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3918 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3919 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3920 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3921 | self.executor_server.hold_jobs_in_build = False |
| 3922 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3923 | self.waitUntilSettled() |
| 3924 | |
| 3925 | self.assertEqual(A.data['status'], 'MERGED') |
| 3926 | self.assertEqual(B.data['status'], 'MERGED') |
| 3927 | self.assertEqual(C.data['status'], 'MERGED') |
| 3928 | self.assertEqual(A.reported, 2) |
| 3929 | self.assertEqual(B.reported, 2) |
| 3930 | self.assertEqual(C.reported, 2) |
| 3931 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3932 | changes = self.getJobFromHistory( |
| 3933 | 'project-merge', 'org/project1').changes |
| 3934 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3935 | |
| 3936 | def test_crd_multiline(self): |
| 3937 | "Test multiple depends-on lines in commit" |
| 3938 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3939 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3940 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3941 | A.addApproval('code-review', 2) |
| 3942 | B.addApproval('code-review', 2) |
| 3943 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3944 | |
| 3945 | # A Depends-On: B+C |
| 3946 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3947 | A.subject, B.data['id'], C.data['id']) |
| 3948 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3949 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3950 | B.addApproval('approved', 1) |
| 3951 | C.addApproval('approved', 1) |
| 3952 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3953 | self.waitUntilSettled() |
| 3954 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3955 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3956 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3957 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3958 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3959 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3960 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3961 | self.executor_server.hold_jobs_in_build = False |
| 3962 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3963 | self.waitUntilSettled() |
| 3964 | |
| 3965 | self.assertEqual(A.data['status'], 'MERGED') |
| 3966 | self.assertEqual(B.data['status'], 'MERGED') |
| 3967 | self.assertEqual(C.data['status'], 'MERGED') |
| 3968 | self.assertEqual(A.reported, 2) |
| 3969 | self.assertEqual(B.reported, 2) |
| 3970 | self.assertEqual(C.reported, 2) |
| 3971 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3972 | changes = self.getJobFromHistory( |
| 3973 | 'project-merge', 'org/project1').changes |
| 3974 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3975 | |
| 3976 | def test_crd_unshared_gate(self): |
| 3977 | "Test cross-repo dependencies in unshared gate queues" |
| 3978 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3979 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3980 | A.addApproval('code-review', 2) |
| 3981 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3982 | |
| 3983 | # A Depends-On: B |
| 3984 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3985 | A.subject, B.data['id']) |
| 3986 | |
| 3987 | # A and B do not share a queue, make sure that A is unable to |
| 3988 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3989 | B.addApproval('approved', 1) |
| 3990 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3991 | self.waitUntilSettled() |
| 3992 | |
| 3993 | self.assertEqual(A.data['status'], 'NEW') |
| 3994 | self.assertEqual(B.data['status'], 'NEW') |
| 3995 | self.assertEqual(A.reported, 0) |
| 3996 | self.assertEqual(B.reported, 0) |
| 3997 | self.assertEqual(len(self.history), 0) |
| 3998 | |
| 3999 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4000 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4001 | self.waitUntilSettled() |
| 4002 | |
| 4003 | self.assertEqual(B.data['status'], 'MERGED') |
| 4004 | self.assertEqual(B.reported, 2) |
| 4005 | |
| 4006 | # Now that B is merged, A should be able to be enqueued and |
| 4007 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4008 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4009 | self.waitUntilSettled() |
| 4010 | |
| 4011 | self.assertEqual(A.data['status'], 'MERGED') |
| 4012 | self.assertEqual(A.reported, 2) |
| 4013 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4014 | def test_crd_gate_reverse(self): |
| 4015 | "Test reverse cross-repo dependencies" |
| 4016 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4017 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4018 | A.addApproval('code-review', 2) |
| 4019 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4020 | |
| 4021 | # A Depends-On: B |
| 4022 | |
| 4023 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4024 | A.subject, B.data['id']) |
| 4025 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4026 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4027 | self.waitUntilSettled() |
| 4028 | |
| 4029 | self.assertEqual(A.data['status'], 'NEW') |
| 4030 | self.assertEqual(B.data['status'], 'NEW') |
| 4031 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4032 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4033 | A.addApproval('approved', 1) |
| 4034 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4035 | self.waitUntilSettled() |
| 4036 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4037 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4038 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4039 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4040 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4041 | self.executor_server.hold_jobs_in_build = False |
| 4042 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4043 | self.waitUntilSettled() |
| 4044 | |
| 4045 | self.assertEqual(A.data['status'], 'MERGED') |
| 4046 | self.assertEqual(B.data['status'], 'MERGED') |
| 4047 | self.assertEqual(A.reported, 2) |
| 4048 | self.assertEqual(B.reported, 2) |
| 4049 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4050 | changes = self.getJobFromHistory( |
| 4051 | 'project-merge', 'org/project1').changes |
| 4052 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4053 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4054 | def test_crd_cycle(self): |
| 4055 | "Test cross-repo dependency cycles" |
| 4056 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4057 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4058 | A.addApproval('code-review', 2) |
| 4059 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4060 | |
| 4061 | # A -> B -> A (via commit-depends) |
| 4062 | |
| 4063 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4064 | A.subject, B.data['id']) |
| 4065 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4066 | B.subject, A.data['id']) |
| 4067 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4068 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4069 | self.waitUntilSettled() |
| 4070 | |
| 4071 | self.assertEqual(A.reported, 0) |
| 4072 | self.assertEqual(B.reported, 0) |
| 4073 | self.assertEqual(A.data['status'], 'NEW') |
| 4074 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4075 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4076 | def test_crd_gate_unknown(self): |
| 4077 | "Test unknown projects in dependent pipeline" |
| 4078 | self.init_repo("org/unknown") |
| 4079 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4080 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4081 | A.addApproval('code-review', 2) |
| 4082 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4083 | |
| 4084 | # A Depends-On: B |
| 4085 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4086 | A.subject, B.data['id']) |
| 4087 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4088 | B.addApproval('approved', 1) |
| 4089 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4090 | self.waitUntilSettled() |
| 4091 | |
| 4092 | # Unknown projects cannot share a queue with any other |
| 4093 | # since they don't have common jobs with any other (they have no jobs). |
| 4094 | # Changes which depend on unknown project changes |
| 4095 | # should not be processed in dependent pipeline |
| 4096 | self.assertEqual(A.data['status'], 'NEW') |
| 4097 | self.assertEqual(B.data['status'], 'NEW') |
| 4098 | self.assertEqual(A.reported, 0) |
| 4099 | self.assertEqual(B.reported, 0) |
| 4100 | self.assertEqual(len(self.history), 0) |
| 4101 | |
| 4102 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4103 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4104 | B.setMerged() |
| 4105 | self.waitUntilSettled() |
| 4106 | self.assertEqual(len(self.history), 0) |
| 4107 | |
| 4108 | # Now that B is merged, A should be able to be enqueued and |
| 4109 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4110 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4111 | self.waitUntilSettled() |
| 4112 | |
| 4113 | self.assertEqual(A.data['status'], 'MERGED') |
| 4114 | self.assertEqual(A.reported, 2) |
| 4115 | self.assertEqual(B.data['status'], 'MERGED') |
| 4116 | self.assertEqual(B.reported, 0) |
| 4117 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4118 | def test_crd_check(self): |
| 4119 | "Test cross-repo dependencies in independent pipelines" |
| 4120 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4121 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4122 | self.gearman_server.hold_jobs_in_queue = True |
| 4123 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4124 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4125 | |
| 4126 | # A Depends-On: B |
| 4127 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4128 | A.subject, B.data['id']) |
| 4129 | |
| 4130 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4131 | self.waitUntilSettled() |
| 4132 | |
| 4133 | queue = self.gearman_server.getQueue() |
| 4134 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 4135 | self.gearman_server.hold_jobs_in_queue = False |
| 4136 | self.gearman_server.release() |
| 4137 | self.waitUntilSettled() |
| 4138 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4139 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4140 | self.waitUntilSettled() |
| 4141 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4142 | path = os.path.join(self.builds[0].jobdir.src_root, "org/project1") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4143 | repo = git.Repo(path) |
| 4144 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4145 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4146 | correct_messages = [ |
| 4147 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4148 | self.assertEqual(repo_messages, correct_messages) |
| 4149 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4150 | path = os.path.join(self.builds[0].jobdir.src_root, "org/project2") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4151 | repo = git.Repo(path) |
| 4152 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4153 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4154 | correct_messages = [ |
| 4155 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4156 | self.assertEqual(repo_messages, correct_messages) |
| 4157 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4158 | self.executor_server.hold_jobs_in_build = False |
| 4159 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4160 | self.waitUntilSettled() |
| 4161 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4162 | self.assertEqual(A.data['status'], 'NEW') |
| 4163 | self.assertEqual(B.data['status'], 'NEW') |
| 4164 | self.assertEqual(A.reported, 1) |
| 4165 | self.assertEqual(B.reported, 0) |
| 4166 | |
| 4167 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4168 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4169 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4170 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4171 | def test_crd_check_git_depends(self): |
| 4172 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4173 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4174 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4175 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4176 | |
| 4177 | # Add two git-dependent changes and make sure they both report |
| 4178 | # success. |
| 4179 | B.setDependsOn(A, 1) |
| 4180 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4181 | self.waitUntilSettled() |
| 4182 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4183 | self.waitUntilSettled() |
| 4184 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4185 | self.orderedRelease() |
| 4186 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4187 | self.waitUntilSettled() |
| 4188 | |
| 4189 | self.assertEqual(A.data['status'], 'NEW') |
| 4190 | self.assertEqual(B.data['status'], 'NEW') |
| 4191 | self.assertEqual(A.reported, 1) |
| 4192 | self.assertEqual(B.reported, 1) |
| 4193 | |
| 4194 | self.assertEqual(self.history[0].changes, '1,1') |
| 4195 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4196 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4197 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4198 | |
| 4199 | self.assertIn('Build succeeded', A.messages[0]) |
| 4200 | self.assertIn('Build succeeded', B.messages[0]) |
| 4201 | |
| 4202 | def test_crd_check_duplicate(self): |
| 4203 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4204 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4205 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4206 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4207 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4208 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4209 | |
| 4210 | # Add two git-dependent changes... |
| 4211 | B.setDependsOn(A, 1) |
| 4212 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4213 | self.waitUntilSettled() |
| 4214 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4215 | |
| 4216 | # ...make sure the live one is not duplicated... |
| 4217 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4218 | self.waitUntilSettled() |
| 4219 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4220 | |
| 4221 | # ...but the non-live one is able to be. |
| 4222 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4223 | self.waitUntilSettled() |
| 4224 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4225 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4226 | # Release jobs in order to avoid races with change A jobs |
| 4227 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4228 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4229 | self.executor_server.hold_jobs_in_build = False |
| 4230 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4231 | self.waitUntilSettled() |
| 4232 | |
| 4233 | self.assertEqual(A.data['status'], 'NEW') |
| 4234 | self.assertEqual(B.data['status'], 'NEW') |
| 4235 | self.assertEqual(A.reported, 1) |
| 4236 | self.assertEqual(B.reported, 1) |
| 4237 | |
| 4238 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4239 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4240 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4241 | |
| 4242 | self.assertIn('Build succeeded', A.messages[0]) |
| 4243 | self.assertIn('Build succeeded', B.messages[0]) |
| 4244 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4245 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4246 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4247 | |
| 4248 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4249 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4250 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4251 | |
| 4252 | # A Depends-On: B |
| 4253 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4254 | A.subject, B.data['id']) |
| 4255 | |
| 4256 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4257 | self.waitUntilSettled() |
| 4258 | |
| 4259 | self.sched.reconfigure(self.config) |
| 4260 | |
| 4261 | # Make sure the items still share a change queue, and the |
| 4262 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4263 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4264 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4265 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4266 | first_item = queue.queue[0] |
| 4267 | for item in queue.queue: |
| 4268 | self.assertEqual(item.queue, first_item.queue) |
| 4269 | self.assertFalse(first_item.live) |
| 4270 | self.assertTrue(queue.queue[1].live) |
| 4271 | |
| 4272 | self.gearman_server.hold_jobs_in_queue = False |
| 4273 | self.gearman_server.release() |
| 4274 | self.waitUntilSettled() |
| 4275 | |
| 4276 | self.assertEqual(A.data['status'], 'NEW') |
| 4277 | self.assertEqual(B.data['status'], 'NEW') |
| 4278 | self.assertEqual(A.reported, 1) |
| 4279 | self.assertEqual(B.reported, 0) |
| 4280 | |
| 4281 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4282 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4283 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4284 | def test_crd_check_reconfiguration(self): |
| 4285 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4286 | |
| 4287 | def test_crd_undefined_project(self): |
| 4288 | """Test that undefined projects in dependencies are handled for |
| 4289 | independent pipelines""" |
| 4290 | # It's a hack for fake gerrit, |
| 4291 | # as it implies repo creation upon the creation of any change |
| 4292 | self.init_repo("org/unknown") |
| 4293 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4294 | |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4295 | def test_crd_check_ignore_dependencies(self): |
| 4296 | "Test cross-repo dependencies can be ignored" |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4297 | self.updateConfigLayout('layout-ignore-dependencies') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4298 | self.sched.reconfigure(self.config) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4299 | |
| 4300 | self.gearman_server.hold_jobs_in_queue = True |
| 4301 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4302 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4303 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4304 | |
| 4305 | # A Depends-On: B |
| 4306 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4307 | A.subject, B.data['id']) |
| 4308 | # C git-depends on B |
| 4309 | C.setDependsOn(B, 1) |
| 4310 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4311 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4312 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4313 | self.waitUntilSettled() |
| 4314 | |
| 4315 | # Make sure none of the items share a change queue, and all |
| 4316 | # are live. |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4317 | tenant = self.sched.abide.tenants.get('openstack') |
| 4318 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4319 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4320 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4321 | for item in check_pipeline.getAllItems(): |
| 4322 | self.assertTrue(item.live) |
| 4323 | |
| 4324 | self.gearman_server.hold_jobs_in_queue = False |
| 4325 | self.gearman_server.release() |
| 4326 | self.waitUntilSettled() |
| 4327 | |
| 4328 | self.assertEqual(A.data['status'], 'NEW') |
| 4329 | self.assertEqual(B.data['status'], 'NEW') |
| 4330 | self.assertEqual(C.data['status'], 'NEW') |
| 4331 | self.assertEqual(A.reported, 1) |
| 4332 | self.assertEqual(B.reported, 1) |
| 4333 | self.assertEqual(C.reported, 1) |
| 4334 | |
| 4335 | # Each job should have tested exactly one change |
| 4336 | for job in self.history: |
| 4337 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4338 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame^] | 4339 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4340 | def test_crd_check_transitive(self): |
| 4341 | "Test transitive cross-repo dependencies" |
| 4342 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4343 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4344 | # and C,2 (not C,1 which would indicate stale data in the |
| 4345 | # cache for B). |
| 4346 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4347 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4348 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4349 | |
| 4350 | # A Depends-On: B |
| 4351 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4352 | A.subject, B.data['id']) |
| 4353 | |
| 4354 | # B Depends-On: C |
| 4355 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4356 | B.subject, C.data['id']) |
| 4357 | |
| 4358 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4359 | self.waitUntilSettled() |
| 4360 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4361 | |
| 4362 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4363 | self.waitUntilSettled() |
| 4364 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4365 | |
| 4366 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4367 | self.waitUntilSettled() |
| 4368 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4369 | |
| 4370 | C.addPatchset() |
| 4371 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4372 | self.waitUntilSettled() |
| 4373 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4374 | |
| 4375 | A.addPatchset() |
| 4376 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4377 | self.waitUntilSettled() |
| 4378 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4379 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4380 | def test_crd_check_unknown(self): |
| 4381 | "Test unknown projects in independent pipeline" |
| 4382 | self.init_repo("org/unknown") |
| 4383 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4384 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4385 | # A Depends-On: B |
| 4386 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4387 | A.subject, B.data['id']) |
| 4388 | |
| 4389 | # Make sure zuul has seen an event on B. |
| 4390 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4391 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4392 | self.waitUntilSettled() |
| 4393 | |
| 4394 | self.assertEqual(A.data['status'], 'NEW') |
| 4395 | self.assertEqual(A.reported, 1) |
| 4396 | self.assertEqual(B.data['status'], 'NEW') |
| 4397 | self.assertEqual(B.reported, 0) |
| 4398 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4399 | def test_crd_cycle_join(self): |
| 4400 | "Test an updated change creates a cycle" |
| 4401 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4402 | |
| 4403 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4404 | self.waitUntilSettled() |
| 4405 | |
| 4406 | # Create B->A |
| 4407 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4408 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4409 | B.subject, A.data['id']) |
| 4410 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4411 | self.waitUntilSettled() |
| 4412 | |
| 4413 | # Update A to add A->B (a cycle). |
| 4414 | A.addPatchset() |
| 4415 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4416 | A.subject, B.data['id']) |
| 4417 | # Normally we would submit the patchset-created event for |
| 4418 | # processing here, however, we have no way of noting whether |
| 4419 | # the dependency cycle detection correctly raised an |
| 4420 | # exception, so instead, we reach into the source driver and |
| 4421 | # call the method that would ultimately be called by the event |
| 4422 | # processing. |
| 4423 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4424 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 4425 | (trusted, project) = tenant.getProject('org/project') |
| 4426 | source = project.source |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4427 | |
| 4428 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4429 | # it easier for users to create events for testing. |
| 4430 | event = zuul.model.TriggerEvent() |
| 4431 | event.trigger_name = 'gerrit' |
| 4432 | event.change_number = '1' |
| 4433 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4434 | with testtools.ExpectedException( |
| 4435 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4436 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4437 | self.log.debug("Got expected dependency cycle exception") |
| 4438 | |
| 4439 | # Now if we update B to remove the depends-on, everything |
| 4440 | # should be okay. B; A->B |
| 4441 | |
| 4442 | B.addPatchset() |
| 4443 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4444 | |
| 4445 | source.getChange(event, True) |
| 4446 | event.change_number = '2' |
| 4447 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4448 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4449 | def test_disable_at(self): |
| 4450 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4451 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4452 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4453 | self.sched.reconfigure(self.config) |
| 4454 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4455 | tenant = self.sched.abide.tenants.get('openstack') |
| 4456 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4457 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4458 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4459 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4460 | |
| 4461 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4462 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4463 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4464 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4465 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4466 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4467 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4468 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4469 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4470 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4471 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4472 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4473 | self.executor_server.failJob('project-test1', A) |
| 4474 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4475 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4476 | self.executor_server.failJob('project-test1', D) |
| 4477 | self.executor_server.failJob('project-test1', E) |
| 4478 | self.executor_server.failJob('project-test1', F) |
| 4479 | self.executor_server.failJob('project-test1', G) |
| 4480 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4481 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4482 | self.executor_server.failJob('project-test1', J) |
| 4483 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4484 | |
| 4485 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4486 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4487 | self.waitUntilSettled() |
| 4488 | |
| 4489 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4490 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4491 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4492 | |
| 4493 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4494 | self.waitUntilSettled() |
| 4495 | |
| 4496 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4497 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4498 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4499 | |
| 4500 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4501 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4502 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4503 | self.waitUntilSettled() |
| 4504 | |
| 4505 | # We should be disabled now |
| 4506 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4507 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4508 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4509 | |
| 4510 | # We need to wait between each of these patches to make sure the |
| 4511 | # smtp messages come back in an expected order |
| 4512 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4513 | self.waitUntilSettled() |
| 4514 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4515 | self.waitUntilSettled() |
| 4516 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4517 | self.waitUntilSettled() |
| 4518 | |
| 4519 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4520 | # leaving a message on each change |
| 4521 | self.assertEqual(1, len(A.messages)) |
| 4522 | self.assertIn('Build failed.', A.messages[0]) |
| 4523 | self.assertEqual(1, len(B.messages)) |
| 4524 | self.assertIn('Build failed.', B.messages[0]) |
| 4525 | self.assertEqual(1, len(C.messages)) |
| 4526 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4527 | self.assertEqual(1, len(D.messages)) |
| 4528 | self.assertIn('Build failed.', D.messages[0]) |
| 4529 | self.assertEqual(1, len(E.messages)) |
| 4530 | self.assertIn('Build failed.', E.messages[0]) |
| 4531 | self.assertEqual(1, len(F.messages)) |
| 4532 | self.assertIn('Build failed.', F.messages[0]) |
| 4533 | |
| 4534 | # The last 3 (GHI) would have only reported via smtp. |
| 4535 | self.assertEqual(3, len(self.smtp_messages)) |
| 4536 | self.assertEqual(0, len(G.messages)) |
| 4537 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4538 | self.assertIn( |
| 4539 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4540 | self.assertEqual(0, len(H.messages)) |
| 4541 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4542 | self.assertIn( |
| 4543 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4544 | self.assertEqual(0, len(I.messages)) |
| 4545 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4546 | self.assertIn( |
| 4547 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4548 | |
| 4549 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4550 | # comes out of disabled |
| 4551 | self.sched.reconfigure(self.config) |
| 4552 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4553 | tenant = self.sched.abide.tenants.get('openstack') |
| 4554 | |
| 4555 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4556 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4557 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4558 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4559 | |
| 4560 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4561 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4562 | self.waitUntilSettled() |
| 4563 | |
| 4564 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4565 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4566 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4567 | |
| 4568 | # J and K went back to gerrit |
| 4569 | self.assertEqual(1, len(J.messages)) |
| 4570 | self.assertIn('Build failed.', J.messages[0]) |
| 4571 | self.assertEqual(1, len(K.messages)) |
| 4572 | self.assertIn('Build failed.', K.messages[0]) |
| 4573 | # No more messages reported via smtp |
| 4574 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4575 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4576 | @simple_layout('layouts/one-job-project.yaml') |
| 4577 | def test_one_job_project(self): |
| 4578 | "Test that queueing works with one job" |
| 4579 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4580 | 'master', 'A') |
| 4581 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4582 | 'master', 'B') |
| 4583 | A.addApproval('code-review', 2) |
| 4584 | B.addApproval('code-review', 2) |
| 4585 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4586 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4587 | self.waitUntilSettled() |
| 4588 | |
| 4589 | self.assertEqual(A.data['status'], 'MERGED') |
| 4590 | self.assertEqual(A.reported, 2) |
| 4591 | self.assertEqual(B.data['status'], 'MERGED') |
| 4592 | self.assertEqual(B.reported, 2) |
| 4593 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4594 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4595 | "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] | 4596 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4597 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4598 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4599 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4600 | self.waitUntilSettled() |
| 4601 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4602 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4603 | self.waitUntilSettled() |
| 4604 | |
| 4605 | self.assertEqual(len(self.builds), 2) |
| 4606 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4607 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4608 | self.waitUntilSettled() |
| 4609 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4610 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4611 | self.assertEqual(len(self.builds), 1, |
| 4612 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4613 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4614 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4615 | self.waitUntilSettled() |
| 4616 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4617 | self.executor_server.hold_jobs_in_build = False |
| 4618 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4619 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4620 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4621 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4622 | self.assertEqual(A.reported, 1) |
| 4623 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4624 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4625 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4626 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4627 | |
| 4628 | self.fake_nodepool.paused = True |
| 4629 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4630 | A.addApproval('code-review', 2) |
| 4631 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4632 | self.waitUntilSettled() |
| 4633 | |
| 4634 | self.zk.client.stop() |
| 4635 | self.zk.client.start() |
| 4636 | self.fake_nodepool.paused = False |
| 4637 | self.waitUntilSettled() |
| 4638 | |
| 4639 | self.assertEqual(A.data['status'], 'MERGED') |
| 4640 | self.assertEqual(A.reported, 2) |
| 4641 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4642 | def test_nodepool_failure(self): |
| 4643 | "Test that jobs are reported after a nodepool failure" |
| 4644 | |
| 4645 | self.fake_nodepool.paused = True |
| 4646 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4647 | A.addApproval('code-review', 2) |
| 4648 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4649 | self.waitUntilSettled() |
| 4650 | |
| 4651 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4652 | self.fake_nodepool.addFailRequest(req) |
| 4653 | |
| 4654 | self.fake_nodepool.paused = False |
| 4655 | self.waitUntilSettled() |
| 4656 | |
| 4657 | self.assertEqual(A.data['status'], 'NEW') |
| 4658 | self.assertEqual(A.reported, 2) |
| 4659 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4660 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4661 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4662 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4663 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4664 | class TestExecutor(ZuulTestCase): |
| 4665 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4666 | |
| 4667 | def assertFinalState(self): |
| 4668 | # In this test, we expect to shut down in a non-final state, |
| 4669 | # so skip these checks. |
| 4670 | pass |
| 4671 | |
| 4672 | def assertCleanShutdown(self): |
| 4673 | self.log.debug("Assert clean shutdown") |
| 4674 | |
| 4675 | # After shutdown, make sure no jobs are running |
| 4676 | self.assertEqual({}, self.executor_server.job_workers) |
| 4677 | |
| 4678 | # Make sure that git.Repo objects have been garbage collected. |
| 4679 | repos = [] |
| 4680 | gc.collect() |
| 4681 | for obj in gc.get_objects(): |
| 4682 | if isinstance(obj, git.Repo): |
| 4683 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4684 | repos.append(obj) |
| 4685 | self.assertEqual(len(repos), 0) |
| 4686 | |
| 4687 | def test_executor_shutdown(self): |
| 4688 | "Test that the executor can shut down with jobs running" |
| 4689 | |
| 4690 | self.executor_server.hold_jobs_in_build = True |
| 4691 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4692 | A.addApproval('code-review', 2) |
| 4693 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4694 | self.waitUntilSettled() |
| 4695 | |
| 4696 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4697 | class TestDependencyGraph(ZuulTestCase): |
| 4698 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4699 | |
| 4700 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4701 | "Test a job in a dependency graph is queued only once" |
| 4702 | # Job dependencies, starting with A |
| 4703 | # A |
| 4704 | # / \ |
| 4705 | # B C |
| 4706 | # / \ / \ |
| 4707 | # D F E |
| 4708 | # | |
| 4709 | # G |
| 4710 | |
| 4711 | self.executor_server.hold_jobs_in_build = True |
| 4712 | change = self.fake_gerrit.addFakeChange( |
| 4713 | 'org/project', 'master', 'change') |
| 4714 | change.addApproval('code-review', 2) |
| 4715 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4716 | |
| 4717 | self.waitUntilSettled() |
| 4718 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4719 | |
| 4720 | self.executor_server.release('A') |
| 4721 | self.waitUntilSettled() |
| 4722 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4723 | |
| 4724 | self.executor_server.release('B') |
| 4725 | self.waitUntilSettled() |
| 4726 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4727 | |
| 4728 | self.executor_server.release('D') |
| 4729 | self.waitUntilSettled() |
| 4730 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4731 | |
| 4732 | self.executor_server.release('C') |
| 4733 | self.waitUntilSettled() |
| 4734 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4735 | |
| 4736 | self.executor_server.release('F') |
| 4737 | self.waitUntilSettled() |
| 4738 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4739 | |
| 4740 | self.executor_server.release('G') |
| 4741 | self.waitUntilSettled() |
| 4742 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4743 | |
| 4744 | self.executor_server.release('E') |
| 4745 | self.waitUntilSettled() |
| 4746 | self.assertEqual(len(self.builds), 0) |
| 4747 | |
| 4748 | self.executor_server.hold_jobs_in_build = False |
| 4749 | self.executor_server.release() |
| 4750 | self.waitUntilSettled() |
| 4751 | |
| 4752 | self.assertEqual(len(self.builds), 0) |
| 4753 | self.assertEqual(len(self.history), 7) |
| 4754 | |
| 4755 | self.assertEqual(change.data['status'], 'MERGED') |
| 4756 | self.assertEqual(change.reported, 2) |
| 4757 | |
| 4758 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4759 | "Test that a job waits till all dependencies are successful" |
| 4760 | # Job dependencies, starting with A |
| 4761 | # A |
| 4762 | # / \ |
| 4763 | # B C* |
| 4764 | # / \ / \ |
| 4765 | # D F E |
| 4766 | # | |
| 4767 | # G |
| 4768 | |
| 4769 | self.executor_server.hold_jobs_in_build = True |
| 4770 | change = self.fake_gerrit.addFakeChange( |
| 4771 | 'org/project', 'master', 'change') |
| 4772 | change.addApproval('code-review', 2) |
| 4773 | |
| 4774 | self.executor_server.failJob('C', change) |
| 4775 | |
| 4776 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4777 | |
| 4778 | self.waitUntilSettled() |
| 4779 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4780 | |
| 4781 | self.executor_server.release('A') |
| 4782 | self.waitUntilSettled() |
| 4783 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4784 | |
| 4785 | self.executor_server.release('B') |
| 4786 | self.waitUntilSettled() |
| 4787 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4788 | |
| 4789 | self.executor_server.release('D') |
| 4790 | self.waitUntilSettled() |
| 4791 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4792 | |
| 4793 | self.executor_server.release('C') |
| 4794 | self.waitUntilSettled() |
| 4795 | self.assertEqual(len(self.builds), 0) |
| 4796 | |
| 4797 | self.executor_server.hold_jobs_in_build = False |
| 4798 | self.executor_server.release() |
| 4799 | self.waitUntilSettled() |
| 4800 | |
| 4801 | self.assertEqual(len(self.builds), 0) |
| 4802 | self.assertEqual(len(self.history), 4) |
| 4803 | |
| 4804 | self.assertEqual(change.data['status'], 'NEW') |
| 4805 | self.assertEqual(change.reported, 2) |
| 4806 | |
| 4807 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4808 | class TestDuplicatePipeline(ZuulTestCase): |
| 4809 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4810 | |
| 4811 | def test_duplicate_pipelines(self): |
| 4812 | "Test that a change matching multiple pipelines works" |
| 4813 | |
| 4814 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4815 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4816 | self.waitUntilSettled() |
| 4817 | |
| 4818 | self.assertHistory([ |
| 4819 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4820 | pipeline='dup1'), |
| 4821 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4822 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4823 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4824 | |
| 4825 | self.assertEqual(len(A.messages), 2) |
| 4826 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4827 | if 'dup1' in A.messages[0]: |
| 4828 | self.assertIn('dup1', A.messages[0]) |
| 4829 | self.assertNotIn('dup2', A.messages[0]) |
| 4830 | self.assertIn('project-test1', A.messages[0]) |
| 4831 | self.assertIn('dup2', A.messages[1]) |
| 4832 | self.assertNotIn('dup1', A.messages[1]) |
| 4833 | self.assertIn('project-test1', A.messages[1]) |
| 4834 | else: |
| 4835 | self.assertIn('dup1', A.messages[1]) |
| 4836 | self.assertNotIn('dup2', A.messages[1]) |
| 4837 | self.assertIn('project-test1', A.messages[1]) |
| 4838 | self.assertIn('dup2', A.messages[0]) |
| 4839 | self.assertNotIn('dup1', A.messages[0]) |
| 4840 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4841 | |
| 4842 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4843 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4844 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4845 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4846 | def test_job_from_templates_executed(self): |
| 4847 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4848 | |
| 4849 | A = self.fake_gerrit.addFakeChange( |
| 4850 | 'org/templated-project', 'master', 'A') |
| 4851 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4852 | self.waitUntilSettled() |
| 4853 | |
| 4854 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4855 | 'SUCCESS') |
| 4856 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4857 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4858 | |
| 4859 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4860 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4861 | |
| 4862 | A = self.fake_gerrit.addFakeChange( |
| 4863 | 'org/layered-project', 'master', 'A') |
| 4864 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4865 | self.waitUntilSettled() |
| 4866 | |
| 4867 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4868 | 'SUCCESS') |
| 4869 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4870 | 'SUCCESS') |
| 4871 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4872 | ).result, 'SUCCESS') |
| 4873 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4874 | ).result, 'SUCCESS') |
| 4875 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4876 | ).result, 'SUCCESS') |
| 4877 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4878 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4879 | |
| 4880 | |
| 4881 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4882 | tenant_config_file = 'config/success-url/main.yaml' |
| 4883 | |
| 4884 | def test_success_url(self): |
| 4885 | "Ensure bad build params are ignored" |
| 4886 | self.sched.reconfigure(self.config) |
| 4887 | self.init_repo('org/docs') |
| 4888 | |
| 4889 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4890 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4891 | self.waitUntilSettled() |
| 4892 | |
| 4893 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4894 | self.assertEqual(len(self.history), 2) |
| 4895 | |
| 4896 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4897 | for build in self.history: |
| 4898 | if build.name == 'docs-draft-test': |
| 4899 | uuid = build.uuid[:7] |
| 4900 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4901 | |
| 4902 | # Two msgs: 'Starting...' + results |
| 4903 | self.assertEqual(len(self.smtp_messages), 2) |
| 4904 | body = self.smtp_messages[1]['body'].splitlines() |
| 4905 | self.assertEqual('Build succeeded.', body[0]) |
| 4906 | |
| 4907 | self.assertIn( |
| 4908 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4909 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4910 | body[2]) |
| 4911 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4912 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4913 | self.assertIn( |
| 4914 | '- docs-draft-test2 https://server/job', |
| 4915 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4916 | |
| 4917 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4918 | class TestSchedulerMerges(ZuulTestCase): |
| 4919 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4920 | |
| 4921 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4922 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4923 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4924 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4925 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4926 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4927 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4928 | A.addApproval('code-review', 2) |
| 4929 | B.addApproval('code-review', 2) |
| 4930 | C.addApproval('code-review', 2) |
| 4931 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4932 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4933 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4934 | self.waitUntilSettled() |
| 4935 | |
| 4936 | build = self.builds[-1] |
| 4937 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4938 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4939 | path = os.path.join(build.jobdir.src_root, project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4940 | repo = git.Repo(path) |
| 4941 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4942 | repo_messages.reverse() |
| 4943 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4944 | self.executor_server.hold_jobs_in_build = False |
| 4945 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4946 | self.waitUntilSettled() |
| 4947 | |
| 4948 | return repo_messages |
| 4949 | |
| 4950 | def _test_merge(self, mode): |
| 4951 | us_path = os.path.join( |
| 4952 | self.upstream_root, 'org/project-%s' % mode) |
| 4953 | expected_messages = [ |
| 4954 | 'initial commit', |
| 4955 | 'add content from fixture', |
| 4956 | # the intermediate commits order is nondeterministic |
| 4957 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4958 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4959 | ] |
| 4960 | result = self._test_project_merge_mode(mode) |
| 4961 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4962 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4963 | |
| 4964 | def test_project_merge_mode_merge(self): |
| 4965 | self._test_merge('merge') |
| 4966 | |
| 4967 | def test_project_merge_mode_merge_resolve(self): |
| 4968 | self._test_merge('merge-resolve') |
| 4969 | |
| 4970 | def test_project_merge_mode_cherrypick(self): |
| 4971 | expected_messages = [ |
| 4972 | 'initial commit', |
| 4973 | 'add content from fixture', |
| 4974 | 'A-1', |
| 4975 | 'B-1', |
| 4976 | 'C-1'] |
| 4977 | result = self._test_project_merge_mode('cherry-pick') |
| 4978 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4979 | |
| 4980 | def test_merge_branch(self): |
| 4981 | "Test that the right commits are on alternate branches" |
| 4982 | self.create_branch('org/project-merge-branches', 'mp') |
| 4983 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4984 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4985 | A = self.fake_gerrit.addFakeChange( |
| 4986 | 'org/project-merge-branches', 'mp', 'A') |
| 4987 | B = self.fake_gerrit.addFakeChange( |
| 4988 | 'org/project-merge-branches', 'mp', 'B') |
| 4989 | C = self.fake_gerrit.addFakeChange( |
| 4990 | 'org/project-merge-branches', 'mp', 'C') |
| 4991 | A.addApproval('code-review', 2) |
| 4992 | B.addApproval('code-review', 2) |
| 4993 | C.addApproval('code-review', 2) |
| 4994 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4995 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4996 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4997 | self.waitUntilSettled() |
| 4998 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4999 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5000 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5001 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5002 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5003 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5004 | self.waitUntilSettled() |
| 5005 | |
| 5006 | build = self.builds[-1] |
| 5007 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 5008 | ref = self.getParameter(build, 'ZUUL_REF') |
| 5009 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5010 | build.jobdir.src_root, 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5011 | repo = git.Repo(path) |
| 5012 | |
| 5013 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 5014 | repo_messages.reverse() |
| 5015 | correct_messages = [ |
| 5016 | 'initial commit', |
| 5017 | 'add content from fixture', |
| 5018 | 'mp commit', |
| 5019 | 'A-1', 'B-1', 'C-1'] |
| 5020 | self.assertEqual(repo_messages, correct_messages) |
| 5021 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5022 | self.executor_server.hold_jobs_in_build = False |
| 5023 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5024 | self.waitUntilSettled() |
| 5025 | |
| 5026 | def test_merge_multi_branch(self): |
| 5027 | "Test that dependent changes on multiple branches are merged" |
| 5028 | self.create_branch('org/project-merge-branches', 'mp') |
| 5029 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5030 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5031 | A = self.fake_gerrit.addFakeChange( |
| 5032 | 'org/project-merge-branches', 'master', 'A') |
| 5033 | B = self.fake_gerrit.addFakeChange( |
| 5034 | 'org/project-merge-branches', 'mp', 'B') |
| 5035 | C = self.fake_gerrit.addFakeChange( |
| 5036 | 'org/project-merge-branches', 'master', 'C') |
| 5037 | A.addApproval('code-review', 2) |
| 5038 | B.addApproval('code-review', 2) |
| 5039 | C.addApproval('code-review', 2) |
| 5040 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5041 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5042 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5043 | self.waitUntilSettled() |
| 5044 | |
| 5045 | job_A = None |
| 5046 | for job in self.builds: |
| 5047 | if 'project-merge' in job.name: |
| 5048 | job_A = job |
| 5049 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 5050 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 5051 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 5052 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 5053 | |
| 5054 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5055 | job_A.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5056 | repo = git.Repo(path) |
| 5057 | repo_messages = [c.message.strip() |
| 5058 | for c in repo.iter_commits(ref_A)] |
| 5059 | repo_messages.reverse() |
| 5060 | correct_messages = [ |
| 5061 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5062 | self.assertEqual(repo_messages, correct_messages) |
| 5063 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5064 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5065 | self.waitUntilSettled() |
| 5066 | |
| 5067 | job_B = None |
| 5068 | for job in self.builds: |
| 5069 | if 'project-merge' in job.name: |
| 5070 | job_B = job |
| 5071 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 5072 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 5073 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 5074 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 5075 | |
| 5076 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5077 | job_B.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5078 | repo = git.Repo(path) |
| 5079 | repo_messages = [c.message.strip() |
| 5080 | for c in repo.iter_commits(ref_B)] |
| 5081 | repo_messages.reverse() |
| 5082 | correct_messages = [ |
| 5083 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5084 | self.assertEqual(repo_messages, correct_messages) |
| 5085 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5086 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5087 | self.waitUntilSettled() |
| 5088 | |
| 5089 | job_C = None |
| 5090 | for job in self.builds: |
| 5091 | if 'project-merge' in job.name: |
| 5092 | job_C = job |
| 5093 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 5094 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 5095 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 5096 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
| 5097 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 5098 | job_C.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5099 | repo = git.Repo(path) |
| 5100 | repo_messages = [c.message.strip() |
| 5101 | for c in repo.iter_commits(ref_C)] |
| 5102 | |
| 5103 | repo_messages.reverse() |
| 5104 | correct_messages = [ |
| 5105 | 'initial commit', 'add content from fixture', |
| 5106 | 'A-1', 'C-1'] |
| 5107 | # Ensure the right commits are in the history for this ref |
| 5108 | self.assertEqual(repo_messages, correct_messages) |
| 5109 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5110 | self.executor_server.hold_jobs_in_build = False |
| 5111 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5112 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5113 | |
| 5114 | |
| 5115 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5116 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5117 | |
| 5118 | def test_semaphore_tenant_isolation(self): |
| 5119 | "Test semaphores in multiple tenants" |
| 5120 | |
| 5121 | self.waitUntilSettled() |
| 5122 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5123 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5124 | |
| 5125 | self.executor_server.hold_jobs_in_build = True |
| 5126 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5127 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5128 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5129 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5130 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5131 | self.assertFalse('test-semaphore' in |
| 5132 | tenant_one.semaphore_handler.semaphores) |
| 5133 | self.assertFalse('test-semaphore' in |
| 5134 | tenant_two.semaphore_handler.semaphores) |
| 5135 | |
| 5136 | # add patches to project1 of tenant-one |
| 5137 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5138 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5139 | self.waitUntilSettled() |
| 5140 | |
| 5141 | # one build of project1-test1 must run |
| 5142 | # semaphore of tenant-one must be acquired once |
| 5143 | # semaphore of tenant-two must not be acquired |
| 5144 | self.assertEqual(len(self.builds), 1) |
| 5145 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5146 | self.assertTrue('test-semaphore' in |
| 5147 | tenant_one.semaphore_handler.semaphores) |
| 5148 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5149 | 'test-semaphore', [])), 1) |
| 5150 | self.assertFalse('test-semaphore' in |
| 5151 | tenant_two.semaphore_handler.semaphores) |
| 5152 | |
| 5153 | # add patches to project2 of tenant-two |
| 5154 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5155 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5156 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5157 | self.waitUntilSettled() |
| 5158 | |
| 5159 | # one build of project1-test1 must run |
| 5160 | # two builds of project2-test1 must run |
| 5161 | # semaphore of tenant-one must be acquired once |
| 5162 | # semaphore of tenant-two must be acquired twice |
| 5163 | self.assertEqual(len(self.builds), 3) |
| 5164 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5165 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5166 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 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', [])), 2) |
| 5175 | |
| 5176 | self.executor_server.release('project1-test1') |
| 5177 | self.waitUntilSettled() |
| 5178 | |
| 5179 | # one build of project1-test1 must run |
| 5180 | # two builds of project2-test1 must run |
| 5181 | # semaphore of tenant-one must be acquired once |
| 5182 | # semaphore of tenant-two must be acquired twice |
| 5183 | self.assertEqual(len(self.builds), 3) |
| 5184 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5185 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5186 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5187 | self.assertTrue('test-semaphore' in |
| 5188 | tenant_one.semaphore_handler.semaphores) |
| 5189 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5190 | 'test-semaphore', [])), 1) |
| 5191 | self.assertTrue('test-semaphore' in |
| 5192 | tenant_two.semaphore_handler.semaphores) |
| 5193 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5194 | 'test-semaphore', [])), 2) |
| 5195 | |
| 5196 | self.executor_server.release('project2-test1') |
| 5197 | self.waitUntilSettled() |
| 5198 | |
| 5199 | # one build of project1-test1 must run |
| 5200 | # one build of project2-test1 must run |
| 5201 | # semaphore of tenant-one must be acquired once |
| 5202 | # semaphore of tenant-two must be acquired once |
| 5203 | self.assertEqual(len(self.builds), 2) |
| 5204 | self.assertTrue('test-semaphore' in |
| 5205 | tenant_one.semaphore_handler.semaphores) |
| 5206 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5207 | 'test-semaphore', [])), 1) |
| 5208 | self.assertTrue('test-semaphore' in |
| 5209 | tenant_two.semaphore_handler.semaphores) |
| 5210 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5211 | 'test-semaphore', [])), 1) |
| 5212 | |
| 5213 | self.executor_server.hold_jobs_in_build = False |
| 5214 | self.executor_server.release() |
| 5215 | |
| 5216 | self.waitUntilSettled() |
| 5217 | |
| 5218 | # no build must run |
| 5219 | # semaphore of tenant-one must not be acquired |
| 5220 | # semaphore of tenant-two must not be acquired |
| 5221 | self.assertEqual(len(self.builds), 0) |
| 5222 | self.assertFalse('test-semaphore' in |
| 5223 | tenant_one.semaphore_handler.semaphores) |
| 5224 | self.assertFalse('test-semaphore' in |
| 5225 | tenant_two.semaphore_handler.semaphores) |
| 5226 | |
| 5227 | self.assertEqual(A.reported, 1) |
| 5228 | self.assertEqual(B.reported, 1) |
| 5229 | |
| 5230 | |
| 5231 | class TestSemaphoreInRepo(ZuulTestCase): |
| 5232 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5233 | |
| 5234 | def test_semaphore_in_repo(self): |
| 5235 | "Test semaphores in repo config" |
| 5236 | |
| 5237 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5238 | # max value should not be evaluated dynamically but must be updated |
| 5239 | # after the change lands. |
| 5240 | |
| 5241 | self.waitUntilSettled() |
| 5242 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5243 | |
| 5244 | in_repo_conf = textwrap.dedent( |
| 5245 | """ |
| 5246 | - job: |
| 5247 | name: project-test2 |
| 5248 | semaphore: test-semaphore |
| 5249 | |
| 5250 | - project: |
| 5251 | name: org/project |
| 5252 | tenant-one-gate: |
| 5253 | jobs: |
| 5254 | - project-test2 |
| 5255 | |
| 5256 | # the max value in dynamic layout must be ignored |
| 5257 | - semaphore: |
| 5258 | name: test-semaphore |
| 5259 | max: 2 |
| 5260 | """) |
| 5261 | |
| 5262 | in_repo_playbook = textwrap.dedent( |
| 5263 | """ |
| 5264 | - hosts: all |
| 5265 | tasks: [] |
| 5266 | """) |
| 5267 | |
| 5268 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5269 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5270 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5271 | files=file_dict) |
| 5272 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5273 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5274 | B.setDependsOn(A, 1) |
| 5275 | C.setDependsOn(A, 1) |
| 5276 | |
| 5277 | self.executor_server.hold_jobs_in_build = True |
| 5278 | |
| 5279 | A.addApproval('code-review', 2) |
| 5280 | B.addApproval('code-review', 2) |
| 5281 | C.addApproval('code-review', 2) |
| 5282 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5283 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5284 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5285 | self.waitUntilSettled() |
| 5286 | |
| 5287 | # check that the layout in a queue item still has max value of 1 |
| 5288 | # for test-semaphore |
| 5289 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5290 | queue = None |
| 5291 | for queue_candidate in pipeline.queues: |
| 5292 | if queue_candidate.name == 'org/project': |
| 5293 | queue = queue_candidate |
| 5294 | break |
| 5295 | queue_item = queue.queue[0] |
| 5296 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5297 | dynamic_test_semaphore = \ |
| 5298 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5299 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5300 | |
| 5301 | # one build must be in queue, one semaphores acquired |
| 5302 | self.assertEqual(len(self.builds), 1) |
| 5303 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5304 | self.assertTrue('test-semaphore' in |
| 5305 | tenant.semaphore_handler.semaphores) |
| 5306 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5307 | 'test-semaphore', [])), 1) |
| 5308 | |
| 5309 | self.executor_server.release('project-test2') |
| 5310 | self.waitUntilSettled() |
| 5311 | |
| 5312 | # change A must be merged |
| 5313 | self.assertEqual(A.data['status'], 'MERGED') |
| 5314 | self.assertEqual(A.reported, 2) |
| 5315 | |
| 5316 | # send change-merged event as the gerrit mock doesn't send it |
| 5317 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5318 | self.waitUntilSettled() |
| 5319 | |
| 5320 | # now that change A was merged, the new semaphore max must be effective |
| 5321 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5322 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5323 | |
| 5324 | # two builds must be in queue, two semaphores acquired |
| 5325 | self.assertEqual(len(self.builds), 2) |
| 5326 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5327 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5328 | self.assertTrue('test-semaphore' in |
| 5329 | tenant.semaphore_handler.semaphores) |
| 5330 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5331 | 'test-semaphore', [])), 2) |
| 5332 | |
| 5333 | self.executor_server.release('project-test2') |
| 5334 | self.waitUntilSettled() |
| 5335 | |
| 5336 | self.assertEqual(len(self.builds), 0) |
| 5337 | self.assertFalse('test-semaphore' in |
| 5338 | tenant.semaphore_handler.semaphores) |
| 5339 | |
| 5340 | self.executor_server.hold_jobs_in_build = False |
| 5341 | self.executor_server.release() |
| 5342 | |
| 5343 | self.waitUntilSettled() |
| 5344 | self.assertEqual(len(self.builds), 0) |
| 5345 | |
| 5346 | self.assertEqual(A.reported, 2) |
| 5347 | self.assertEqual(B.reported, 2) |
| 5348 | self.assertEqual(C.reported, 2) |