James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 17 | import json |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 18 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 19 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 20 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 21 | import time |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 22 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 23 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 24 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 25 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 27 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 28 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 29 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 30 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 31 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 32 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 33 | from tests.base import ( |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 34 | ZuulTestCase, |
| 35 | repack_repo, |
| 36 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 37 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 38 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 39 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 40 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 41 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 42 | def test_jobs_executed(self): |
| 43 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 44 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 45 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 46 | A.addApproval('code-review', 2) |
| 47 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 48 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 49 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 50 | 'SUCCESS') |
| 51 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 52 | 'SUCCESS') |
| 53 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 54 | 'SUCCESS') |
| 55 | self.assertEqual(A.data['status'], 'MERGED') |
| 56 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 57 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 58 | 'image1') |
Adam Gandelman | eace469 | 2017-02-07 15:18:36 -0800 | [diff] [blame] | 59 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 60 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 61 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 62 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 63 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 64 | value='1|g') |
| 65 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 66 | kind='ms') |
| 67 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 68 | value='1|c') |
| 69 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 70 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 71 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 72 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 73 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 74 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 75 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 76 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 77 | for build in self.builds: |
| 78 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 79 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 80 | def test_initial_pipeline_gauges(self): |
| 81 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 82 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 83 | value='0|g') |
| 84 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 85 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 86 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 87 | def test_job_branch(self): |
| 88 | "Test the correct variant of a job runs on a branch" |
| 89 | self.create_branch('org/project', 'stable') |
| 90 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 91 | A.addApproval('code-review', 2) |
| 92 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 93 | self.waitUntilSettled() |
| 94 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 95 | 'SUCCESS') |
| 96 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 97 | 'SUCCESS') |
| 98 | self.assertEqual(A.data['status'], 'MERGED') |
| 99 | self.assertEqual(A.reported, 2, |
| 100 | "A should report start and success") |
| 101 | self.assertIn('gate', A.messages[1], |
| 102 | "A should transit gate") |
| 103 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 104 | 'image2') |
| 105 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 106 | def test_parallel_changes(self): |
| 107 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 108 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 109 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 110 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 111 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 112 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 113 | A.addApproval('code-review', 2) |
| 114 | B.addApproval('code-review', 2) |
| 115 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 116 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 117 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 118 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 119 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 120 | |
| 121 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 122 | self.assertEqual(len(self.builds), 1) |
| 123 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 124 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 125 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 126 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 127 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 128 | self.assertEqual(len(self.builds), 3) |
| 129 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 130 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 131 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 132 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 133 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 134 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 135 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 136 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 137 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 138 | self.assertEqual(len(self.builds), 5) |
| 139 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 140 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 141 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 142 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 143 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 144 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 145 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 146 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 147 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 148 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 149 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 150 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 151 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 152 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 153 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 154 | self.assertEqual(len(self.builds), 6) |
| 155 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 156 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 157 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 158 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 159 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 160 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 161 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 162 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 163 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 164 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 165 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 166 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 167 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 168 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 169 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 170 | self.executor_server.hold_jobs_in_build = False |
| 171 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 172 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 173 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 174 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 175 | self.assertEqual(len(self.history), 9) |
| 176 | self.assertEqual(A.data['status'], 'MERGED') |
| 177 | self.assertEqual(B.data['status'], 'MERGED') |
| 178 | self.assertEqual(C.data['status'], 'MERGED') |
| 179 | self.assertEqual(A.reported, 2) |
| 180 | self.assertEqual(B.reported, 2) |
| 181 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 182 | |
| 183 | def test_failed_changes(self): |
| 184 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 185 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 186 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 187 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 188 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 189 | A.addApproval('code-review', 2) |
| 190 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 191 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 192 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 193 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 194 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 195 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 196 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 197 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 198 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 199 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 200 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 201 | # A/project-merge is complete |
| 202 | self.assertBuilds([ |
| 203 | dict(name='project-test1', changes='1,1'), |
| 204 | dict(name='project-test2', changes='1,1'), |
| 205 | dict(name='project-merge', changes='1,1 2,1'), |
| 206 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 207 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 208 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 209 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 210 | # A/project-merge is complete |
| 211 | # B/project-merge is complete |
| 212 | self.assertBuilds([ |
| 213 | dict(name='project-test1', changes='1,1'), |
| 214 | dict(name='project-test2', changes='1,1'), |
| 215 | dict(name='project-test1', changes='1,1 2,1'), |
| 216 | dict(name='project-test2', changes='1,1 2,1'), |
| 217 | ]) |
| 218 | |
| 219 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 220 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 221 | self.builds[0].release() |
| 222 | self.waitUntilSettled() |
| 223 | |
| 224 | self.orderedRelease() |
| 225 | self.assertHistory([ |
| 226 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 227 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 228 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 229 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 230 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 231 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 232 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 233 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 234 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 235 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 236 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 237 | self.assertEqual(A.data['status'], 'NEW') |
| 238 | self.assertEqual(B.data['status'], 'MERGED') |
| 239 | self.assertEqual(A.reported, 2) |
| 240 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 241 | |
| 242 | def test_independent_queues(self): |
| 243 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 244 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 245 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 246 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 247 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 248 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 249 | A.addApproval('code-review', 2) |
| 250 | B.addApproval('code-review', 2) |
| 251 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 252 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 253 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 254 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 255 | |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 256 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 257 | self.waitUntilSettled() |
| 258 | |
| 259 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 260 | self.waitUntilSettled() |
| 261 | |
| 262 | # 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] | 263 | self.assertBuilds([ |
| 264 | dict(name='project-merge', changes='1,1'), |
| 265 | dict(name='project-merge', changes='2,1'), |
| 266 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 267 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 268 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 269 | self.builds[0].release() |
| 270 | self.waitUntilSettled() |
| 271 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 272 | self.waitUntilSettled() |
| 273 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 274 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 275 | self.waitUntilSettled() |
| 276 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 277 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 278 | self.assertBuilds([ |
| 279 | dict(name='project-test1', changes='1,1'), |
| 280 | dict(name='project-test2', changes='1,1'), |
| 281 | dict(name='project-test1', changes='2,1'), |
| 282 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 283 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 284 | dict(name='project-test1', changes='2,1 3,1'), |
| 285 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 286 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 287 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 288 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 289 | self.orderedRelease() |
| 290 | self.assertHistory([ |
| 291 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 292 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 293 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 294 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 295 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 296 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 297 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 298 | dict( |
| 299 | name='project1-project2-integration', |
| 300 | result='SUCCESS', |
| 301 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 302 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 303 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 304 | dict(name='project1-project2-integration', |
| 305 | result='SUCCESS', |
| 306 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 307 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 308 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 309 | self.assertEqual(A.data['status'], 'MERGED') |
| 310 | self.assertEqual(B.data['status'], 'MERGED') |
| 311 | self.assertEqual(C.data['status'], 'MERGED') |
| 312 | self.assertEqual(A.reported, 2) |
| 313 | self.assertEqual(B.reported, 2) |
| 314 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 315 | |
| 316 | def test_failed_change_at_head(self): |
| 317 | "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] | 318 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 319 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 320 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 321 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 322 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 323 | A.addApproval('code-review', 2) |
| 324 | B.addApproval('code-review', 2) |
| 325 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 326 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 327 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 328 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 329 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 330 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 331 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 332 | |
| 333 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 334 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 335 | self.assertBuilds([ |
| 336 | dict(name='project-merge', changes='1,1'), |
| 337 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 338 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 339 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 340 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 341 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 342 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 343 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 344 | self.waitUntilSettled() |
| 345 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 346 | self.assertBuilds([ |
| 347 | dict(name='project-test1', changes='1,1'), |
| 348 | dict(name='project-test2', changes='1,1'), |
| 349 | dict(name='project-test1', changes='1,1 2,1'), |
| 350 | dict(name='project-test2', changes='1,1 2,1'), |
| 351 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 352 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 353 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 354 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 355 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 356 | self.waitUntilSettled() |
| 357 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 358 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 359 | self.assertBuilds([ |
| 360 | dict(name='project-test2', changes='1,1'), |
| 361 | dict(name='project-merge', changes='2,1'), |
| 362 | ]) |
| 363 | # Unordered history comparison because the aborts can finish |
| 364 | # in any order. |
| 365 | self.assertHistory([ |
| 366 | dict(name='project-merge', result='SUCCESS', |
| 367 | changes='1,1'), |
| 368 | dict(name='project-merge', result='SUCCESS', |
| 369 | changes='1,1 2,1'), |
| 370 | dict(name='project-merge', result='SUCCESS', |
| 371 | changes='1,1 2,1 3,1'), |
| 372 | dict(name='project-test1', result='FAILURE', |
| 373 | changes='1,1'), |
| 374 | dict(name='project-test1', result='ABORTED', |
| 375 | changes='1,1 2,1'), |
| 376 | dict(name='project-test2', result='ABORTED', |
| 377 | changes='1,1 2,1'), |
| 378 | dict(name='project-test1', result='ABORTED', |
| 379 | changes='1,1 2,1 3,1'), |
| 380 | dict(name='project-test2', result='ABORTED', |
| 381 | changes='1,1 2,1 3,1'), |
| 382 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 383 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 384 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 385 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 386 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 387 | self.waitUntilSettled() |
| 388 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 389 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 390 | self.assertBuilds([]) |
| 391 | self.assertHistory([ |
| 392 | dict(name='project-merge', result='SUCCESS', |
| 393 | changes='1,1'), |
| 394 | dict(name='project-merge', result='SUCCESS', |
| 395 | changes='1,1 2,1'), |
| 396 | dict(name='project-merge', result='SUCCESS', |
| 397 | changes='1,1 2,1 3,1'), |
| 398 | dict(name='project-test1', result='FAILURE', |
| 399 | changes='1,1'), |
| 400 | dict(name='project-test1', result='ABORTED', |
| 401 | changes='1,1 2,1'), |
| 402 | dict(name='project-test2', result='ABORTED', |
| 403 | changes='1,1 2,1'), |
| 404 | dict(name='project-test1', result='ABORTED', |
| 405 | changes='1,1 2,1 3,1'), |
| 406 | dict(name='project-test2', result='ABORTED', |
| 407 | changes='1,1 2,1 3,1'), |
| 408 | dict(name='project-merge', result='SUCCESS', |
| 409 | changes='2,1'), |
| 410 | dict(name='project-merge', result='SUCCESS', |
| 411 | changes='2,1 3,1'), |
| 412 | dict(name='project-test2', result='SUCCESS', |
| 413 | changes='1,1'), |
| 414 | dict(name='project-test1', result='SUCCESS', |
| 415 | changes='2,1'), |
| 416 | dict(name='project-test2', result='SUCCESS', |
| 417 | changes='2,1'), |
| 418 | dict(name='project-test1', result='SUCCESS', |
| 419 | changes='2,1 3,1'), |
| 420 | dict(name='project-test2', result='SUCCESS', |
| 421 | changes='2,1 3,1'), |
| 422 | ], ordered=False) |
| 423 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 424 | self.assertEqual(A.data['status'], 'NEW') |
| 425 | self.assertEqual(B.data['status'], 'MERGED') |
| 426 | self.assertEqual(C.data['status'], 'MERGED') |
| 427 | self.assertEqual(A.reported, 2) |
| 428 | self.assertEqual(B.reported, 2) |
| 429 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 430 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 431 | def test_failed_change_in_middle(self): |
| 432 | "Test a failed change in the middle of the queue" |
| 433 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 434 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 435 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 436 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 437 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 438 | A.addApproval('code-review', 2) |
| 439 | B.addApproval('code-review', 2) |
| 440 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 441 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 442 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 443 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 444 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 445 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 446 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 447 | |
| 448 | self.waitUntilSettled() |
| 449 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 450 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 451 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 452 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 453 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 454 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 455 | self.waitUntilSettled() |
| 456 | |
| 457 | self.assertEqual(len(self.builds), 6) |
| 458 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 459 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 460 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 461 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 462 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 463 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 464 | |
| 465 | self.release(self.builds[2]) |
| 466 | self.waitUntilSettled() |
| 467 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 468 | # project-test1 and project-test2 for A |
| 469 | # project-test2 for B |
| 470 | # project-merge for C (without B) |
| 471 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 472 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 473 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 474 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 475 | self.waitUntilSettled() |
| 476 | |
| 477 | # project-test1 and project-test2 for A |
| 478 | # project-test2 for B |
| 479 | # project-test1 and project-test2 for C |
| 480 | self.assertEqual(len(self.builds), 5) |
| 481 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 482 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 483 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 484 | builds = items[0].current_build_set.getBuilds() |
| 485 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 486 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 487 | builds = items[1].current_build_set.getBuilds() |
| 488 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 489 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 490 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 491 | builds = items[2].current_build_set.getBuilds() |
| 492 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 493 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 494 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 495 | self.executor_server.hold_jobs_in_build = False |
| 496 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 497 | self.waitUntilSettled() |
| 498 | |
| 499 | self.assertEqual(len(self.builds), 0) |
| 500 | self.assertEqual(len(self.history), 12) |
| 501 | self.assertEqual(A.data['status'], 'MERGED') |
| 502 | self.assertEqual(B.data['status'], 'NEW') |
| 503 | self.assertEqual(C.data['status'], 'MERGED') |
| 504 | self.assertEqual(A.reported, 2) |
| 505 | self.assertEqual(B.reported, 2) |
| 506 | self.assertEqual(C.reported, 2) |
| 507 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 508 | def test_failed_change_at_head_with_queue(self): |
| 509 | "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] | 510 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 511 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 512 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 513 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 514 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 515 | A.addApproval('code-review', 2) |
| 516 | B.addApproval('code-review', 2) |
| 517 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 518 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 519 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 520 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 521 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 522 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 523 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 524 | |
| 525 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 526 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 527 | self.assertEqual(len(self.builds), 0) |
| 528 | self.assertEqual(len(queue), 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 529 | self.assertEqual(queue[0].name, 'executor:execute') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 530 | job_args = json.loads(queue[0].arguments) |
| 531 | self.assertEqual(job_args['job'], 'project-merge') |
| 532 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 533 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 534 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 535 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 536 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 537 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 538 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 539 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 540 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 541 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 542 | self.assertEqual(len(self.builds), 0) |
| 543 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 544 | |
| 545 | self.assertEqual( |
| 546 | json.loads(queue[0].arguments)['job'], 'project-test1') |
| 547 | self.assertEqual( |
| 548 | json.loads(queue[1].arguments)['job'], 'project-test2') |
| 549 | self.assertEqual( |
| 550 | json.loads(queue[2].arguments)['job'], 'project-test1') |
| 551 | self.assertEqual( |
| 552 | json.loads(queue[3].arguments)['job'], 'project-test2') |
| 553 | self.assertEqual( |
| 554 | json.loads(queue[4].arguments)['job'], 'project-test1') |
| 555 | self.assertEqual( |
| 556 | json.loads(queue[5].arguments)['job'], 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 557 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 558 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 559 | self.waitUntilSettled() |
| 560 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 561 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 562 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 563 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 564 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 565 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 566 | self.gearman_server.hold_jobs_in_queue = False |
| 567 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 568 | self.waitUntilSettled() |
| 569 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 570 | self.assertEqual(len(self.builds), 0) |
| 571 | self.assertEqual(len(self.history), 11) |
| 572 | self.assertEqual(A.data['status'], 'NEW') |
| 573 | self.assertEqual(B.data['status'], 'MERGED') |
| 574 | self.assertEqual(C.data['status'], 'MERGED') |
| 575 | self.assertEqual(A.reported, 2) |
| 576 | self.assertEqual(B.reported, 2) |
| 577 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 578 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 579 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 580 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 581 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 582 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 583 | A.addApproval('code-review', 2) |
| 584 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 585 | self.waitUntilSettled() |
| 586 | time.sleep(2) |
| 587 | |
| 588 | data = json.loads(self.sched.formatStatusJSON()) |
| 589 | found_job = None |
| 590 | for pipeline in data['pipelines']: |
| 591 | if pipeline['name'] != 'gate': |
| 592 | continue |
| 593 | for queue in pipeline['change_queues']: |
| 594 | for head in queue['heads']: |
| 595 | for item in head: |
| 596 | for job in item['jobs']: |
| 597 | if job['name'] == 'project-merge': |
| 598 | found_job = job |
| 599 | break |
| 600 | |
| 601 | self.assertIsNotNone(found_job) |
| 602 | if iteration == 1: |
| 603 | self.assertIsNotNone(found_job['estimated_time']) |
| 604 | self.assertIsNone(found_job['remaining_time']) |
| 605 | else: |
| 606 | self.assertIsNotNone(found_job['estimated_time']) |
| 607 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 608 | self.assertIsNotNone(found_job['remaining_time']) |
| 609 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 610 | self.executor_server.hold_jobs_in_build = False |
| 611 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 612 | self.waitUntilSettled() |
| 613 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 614 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 615 | def test_time_database(self): |
| 616 | "Test the time database" |
| 617 | |
| 618 | self._test_time_database(1) |
| 619 | self._test_time_database(2) |
| 620 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 621 | def test_two_failed_changes_at_head(self): |
| 622 | "Test that changes are reparented correctly if 2 fail at head" |
| 623 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 624 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 625 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 626 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 627 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 628 | A.addApproval('code-review', 2) |
| 629 | B.addApproval('code-review', 2) |
| 630 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 631 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 632 | self.executor_server.failJob('project-test1', A) |
| 633 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 634 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 635 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 636 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 637 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 638 | self.waitUntilSettled() |
| 639 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 640 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 641 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 642 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 643 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 644 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 645 | self.waitUntilSettled() |
| 646 | |
| 647 | self.assertEqual(len(self.builds), 6) |
| 648 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 649 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 650 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 651 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 652 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 653 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 654 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 655 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 656 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 657 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 658 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 659 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 660 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 661 | |
| 662 | # Fail change B first |
| 663 | self.release(self.builds[2]) |
| 664 | self.waitUntilSettled() |
| 665 | |
| 666 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 667 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 668 | self.waitUntilSettled() |
| 669 | |
| 670 | self.assertEqual(len(self.builds), 5) |
| 671 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 672 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 673 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 674 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 675 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 676 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 677 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 678 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 679 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 680 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 681 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 682 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 683 | |
| 684 | # Finish running all passing jobs for change A |
| 685 | self.release(self.builds[1]) |
| 686 | self.waitUntilSettled() |
| 687 | # Fail and report change A |
| 688 | self.release(self.builds[0]) |
| 689 | self.waitUntilSettled() |
| 690 | |
| 691 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 692 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 693 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 694 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 695 | self.waitUntilSettled() |
| 696 | |
| 697 | self.assertEqual(len(self.builds), 4) |
| 698 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 699 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 700 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 701 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 702 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 703 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 704 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 705 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 706 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 707 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 708 | # After A failed and B and C restarted, B should be back in |
| 709 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 710 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 711 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 712 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 713 | self.executor_server.hold_jobs_in_build = False |
| 714 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 715 | self.waitUntilSettled() |
| 716 | |
| 717 | self.assertEqual(len(self.builds), 0) |
| 718 | self.assertEqual(len(self.history), 21) |
| 719 | self.assertEqual(A.data['status'], 'NEW') |
| 720 | self.assertEqual(B.data['status'], 'NEW') |
| 721 | self.assertEqual(C.data['status'], 'MERGED') |
| 722 | self.assertEqual(A.reported, 2) |
| 723 | self.assertEqual(B.reported, 2) |
| 724 | self.assertEqual(C.reported, 2) |
| 725 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 726 | def test_patch_order(self): |
| 727 | "Test that dependent patches are tested in the right order" |
| 728 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 729 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 730 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 731 | A.addApproval('code-review', 2) |
| 732 | B.addApproval('code-review', 2) |
| 733 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 734 | |
| 735 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 736 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 737 | M2.setMerged() |
| 738 | M1.setMerged() |
| 739 | |
| 740 | # C -> B -> A -> M1 -> M2 |
| 741 | # M2 is here to make sure it is never queried. If it is, it |
| 742 | # means zuul is walking down the entire history of merged |
| 743 | # changes. |
| 744 | |
| 745 | C.setDependsOn(B, 1) |
| 746 | B.setDependsOn(A, 1) |
| 747 | A.setDependsOn(M1, 1) |
| 748 | M1.setDependsOn(M2, 1) |
| 749 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 750 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 751 | |
| 752 | self.waitUntilSettled() |
| 753 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 754 | self.assertEqual(A.data['status'], 'NEW') |
| 755 | self.assertEqual(B.data['status'], 'NEW') |
| 756 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 757 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 758 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 759 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 760 | |
| 761 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 762 | self.assertEqual(M2.queried, 0) |
| 763 | self.assertEqual(A.data['status'], 'MERGED') |
| 764 | self.assertEqual(B.data['status'], 'MERGED') |
| 765 | self.assertEqual(C.data['status'], 'MERGED') |
| 766 | self.assertEqual(A.reported, 2) |
| 767 | self.assertEqual(B.reported, 2) |
| 768 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 769 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 770 | def test_needed_changes_enqueue(self): |
| 771 | "Test that a needed change is enqueued ahead" |
| 772 | # A Given a git tree like this, if we enqueue |
| 773 | # / \ change C, we should walk up and down the tree |
| 774 | # B G and enqueue changes in the order ABCDEFG. |
| 775 | # /|\ This is also the order that you would get if |
| 776 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 777 | # / the ordering is stable across re-enqueue events. |
| 778 | # D |
| 779 | |
| 780 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 781 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 782 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 783 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 784 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 785 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 786 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 787 | B.setDependsOn(A, 1) |
| 788 | C.setDependsOn(B, 1) |
| 789 | D.setDependsOn(C, 1) |
| 790 | E.setDependsOn(B, 1) |
| 791 | F.setDependsOn(B, 1) |
| 792 | G.setDependsOn(A, 1) |
| 793 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 794 | A.addApproval('code-review', 2) |
| 795 | B.addApproval('code-review', 2) |
| 796 | C.addApproval('code-review', 2) |
| 797 | D.addApproval('code-review', 2) |
| 798 | E.addApproval('code-review', 2) |
| 799 | F.addApproval('code-review', 2) |
| 800 | G.addApproval('code-review', 2) |
| 801 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 802 | |
| 803 | self.waitUntilSettled() |
| 804 | |
| 805 | self.assertEqual(A.data['status'], 'NEW') |
| 806 | self.assertEqual(B.data['status'], 'NEW') |
| 807 | self.assertEqual(C.data['status'], 'NEW') |
| 808 | self.assertEqual(D.data['status'], 'NEW') |
| 809 | self.assertEqual(E.data['status'], 'NEW') |
| 810 | self.assertEqual(F.data['status'], 'NEW') |
| 811 | self.assertEqual(G.data['status'], 'NEW') |
| 812 | |
| 813 | # We're about to add approvals to changes without adding the |
| 814 | # triggering events to Zuul, so that we can be sure that it is |
| 815 | # enqueing the changes based on dependencies, not because of |
| 816 | # triggering events. Since it will have the changes cached |
| 817 | # already (without approvals), we need to clear the cache |
| 818 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 819 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 820 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 821 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 822 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 823 | A.addApproval('approved', 1) |
| 824 | B.addApproval('approved', 1) |
| 825 | D.addApproval('approved', 1) |
| 826 | E.addApproval('approved', 1) |
| 827 | F.addApproval('approved', 1) |
| 828 | G.addApproval('approved', 1) |
| 829 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 830 | |
| 831 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 832 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 833 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 834 | self.executor_server.hold_jobs_in_build = False |
| 835 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 836 | self.waitUntilSettled() |
| 837 | |
| 838 | self.assertEqual(A.data['status'], 'MERGED') |
| 839 | self.assertEqual(B.data['status'], 'MERGED') |
| 840 | self.assertEqual(C.data['status'], 'MERGED') |
| 841 | self.assertEqual(D.data['status'], 'MERGED') |
| 842 | self.assertEqual(E.data['status'], 'MERGED') |
| 843 | self.assertEqual(F.data['status'], 'MERGED') |
| 844 | self.assertEqual(G.data['status'], 'MERGED') |
| 845 | self.assertEqual(A.reported, 2) |
| 846 | self.assertEqual(B.reported, 2) |
| 847 | self.assertEqual(C.reported, 2) |
| 848 | self.assertEqual(D.reported, 2) |
| 849 | self.assertEqual(E.reported, 2) |
| 850 | self.assertEqual(F.reported, 2) |
| 851 | self.assertEqual(G.reported, 2) |
| 852 | self.assertEqual(self.history[6].changes, |
| 853 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 854 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 855 | def test_source_cache(self): |
| 856 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 857 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 858 | |
| 859 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 860 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 861 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 862 | A.addApproval('code-review', 2) |
| 863 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 864 | |
| 865 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 866 | M1.setMerged() |
| 867 | |
| 868 | B.setDependsOn(A, 1) |
| 869 | A.setDependsOn(M1, 1) |
| 870 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 871 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 872 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 873 | |
| 874 | self.waitUntilSettled() |
| 875 | |
| 876 | for build in self.builds: |
| 877 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 878 | build.release() |
| 879 | self.waitUntilSettled() |
| 880 | for build in self.builds: |
| 881 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 882 | build.release() |
| 883 | self.waitUntilSettled() |
| 884 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 885 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 886 | self.waitUntilSettled() |
| 887 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 888 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 889 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 890 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 891 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 892 | self.executor_server.hold_jobs_in_build = False |
| 893 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 894 | self.waitUntilSettled() |
| 895 | |
| 896 | self.assertEqual(A.data['status'], 'MERGED') |
| 897 | self.assertEqual(B.data['status'], 'MERGED') |
| 898 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 899 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 900 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 901 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 902 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 903 | # TODO: move to test_gerrit (this is a unit test!) |
| 904 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 905 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 906 | source = tenant.layout.pipelines['gate'].source |
| 907 | |
| 908 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 909 | # it easier for users to create events for testing. |
| 910 | event = zuul.model.TriggerEvent() |
| 911 | event.trigger_name = 'gerrit' |
| 912 | event.change_number = '1' |
| 913 | event.patch_number = '2' |
| 914 | |
| 915 | a = source.getChange(event) |
| 916 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 917 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 918 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 919 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 920 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 921 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 922 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 923 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 924 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 925 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 926 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 927 | @skip("Disabled for early v3 development") |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 928 | def test_build_configuration_conflict(self): |
| 929 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 930 | |
| 931 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 932 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 933 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 934 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 935 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 936 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 937 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 938 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 939 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 940 | A.addApproval('code-review', 2) |
| 941 | B.addApproval('code-review', 2) |
| 942 | C.addApproval('code-review', 2) |
| 943 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 944 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 945 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 946 | self.waitUntilSettled() |
| 947 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 948 | self.assertEqual(A.reported, 1) |
| 949 | self.assertEqual(B.reported, 1) |
| 950 | self.assertEqual(C.reported, 1) |
| 951 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 952 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 953 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 954 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 955 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 956 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 957 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 958 | |
| 959 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 960 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 961 | self.gearman_server.hold_jobs_in_queue = False |
| 962 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 963 | self.waitUntilSettled() |
| 964 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 965 | self.assertEqual(A.data['status'], 'MERGED') |
| 966 | self.assertEqual(B.data['status'], 'NEW') |
| 967 | self.assertEqual(C.data['status'], 'MERGED') |
| 968 | self.assertEqual(A.reported, 2) |
| 969 | self.assertEqual(B.reported, 2) |
| 970 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 971 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 972 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 973 | def test_post(self): |
| 974 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 975 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 976 | e = { |
| 977 | "type": "ref-updated", |
| 978 | "submitter": { |
| 979 | "name": "User Name", |
| 980 | }, |
| 981 | "refUpdate": { |
| 982 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 983 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 984 | "refName": "master", |
| 985 | "project": "org/project", |
| 986 | } |
| 987 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 988 | self.fake_gerrit.addEvent(e) |
| 989 | self.waitUntilSettled() |
| 990 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 991 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 992 | self.assertEqual(len(self.history), 1) |
| 993 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 994 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 995 | def test_post_ignore_deletes(self): |
| 996 | "Test that deleting refs does not trigger post jobs" |
| 997 | |
| 998 | e = { |
| 999 | "type": "ref-updated", |
| 1000 | "submitter": { |
| 1001 | "name": "User Name", |
| 1002 | }, |
| 1003 | "refUpdate": { |
| 1004 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1005 | "newRev": "0000000000000000000000000000000000000000", |
| 1006 | "refName": "master", |
| 1007 | "project": "org/project", |
| 1008 | } |
| 1009 | } |
| 1010 | self.fake_gerrit.addEvent(e) |
| 1011 | self.waitUntilSettled() |
| 1012 | |
| 1013 | job_names = [x.name for x in self.history] |
| 1014 | self.assertEqual(len(self.history), 0) |
| 1015 | self.assertNotIn('project-post', job_names) |
| 1016 | |
| 1017 | def test_post_ignore_deletes_negative(self): |
| 1018 | "Test that deleting refs does trigger post jobs" |
| 1019 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1020 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1021 | self.sched.reconfigure(self.config) |
| 1022 | |
| 1023 | e = { |
| 1024 | "type": "ref-updated", |
| 1025 | "submitter": { |
| 1026 | "name": "User Name", |
| 1027 | }, |
| 1028 | "refUpdate": { |
| 1029 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1030 | "newRev": "0000000000000000000000000000000000000000", |
| 1031 | "refName": "master", |
| 1032 | "project": "org/project", |
| 1033 | } |
| 1034 | } |
| 1035 | self.fake_gerrit.addEvent(e) |
| 1036 | self.waitUntilSettled() |
| 1037 | |
| 1038 | job_names = [x.name for x in self.history] |
| 1039 | self.assertEqual(len(self.history), 1) |
| 1040 | self.assertIn('project-post', job_names) |
| 1041 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1042 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1043 | def test_build_configuration_branch_interaction(self): |
| 1044 | "Test that switching between branches works" |
| 1045 | self.test_build_configuration() |
| 1046 | self.test_build_configuration_branch() |
| 1047 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1048 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1049 | repo = git.Repo(path) |
| 1050 | repo.heads.master.commit = repo.commit('init') |
| 1051 | self.test_build_configuration() |
| 1052 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1053 | def test_dependent_changes_dequeue(self): |
| 1054 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1055 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1056 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1057 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1058 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1059 | A.addApproval('code-review', 2) |
| 1060 | B.addApproval('code-review', 2) |
| 1061 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1062 | |
| 1063 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1064 | M1.setMerged() |
| 1065 | |
| 1066 | # C -> B -> A -> M1 |
| 1067 | |
| 1068 | C.setDependsOn(B, 1) |
| 1069 | B.setDependsOn(A, 1) |
| 1070 | A.setDependsOn(M1, 1) |
| 1071 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1072 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1073 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1074 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1075 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1076 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1077 | |
| 1078 | self.waitUntilSettled() |
| 1079 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1080 | self.assertEqual(A.data['status'], 'NEW') |
| 1081 | self.assertEqual(A.reported, 2) |
| 1082 | self.assertEqual(B.data['status'], 'NEW') |
| 1083 | self.assertEqual(B.reported, 2) |
| 1084 | self.assertEqual(C.data['status'], 'NEW') |
| 1085 | self.assertEqual(C.reported, 2) |
| 1086 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1087 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1088 | def test_failing_dependent_changes(self): |
| 1089 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1090 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1091 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1092 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1093 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1094 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1095 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1096 | A.addApproval('code-review', 2) |
| 1097 | B.addApproval('code-review', 2) |
| 1098 | C.addApproval('code-review', 2) |
| 1099 | D.addApproval('code-review', 2) |
| 1100 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1101 | |
| 1102 | # E, D -> C -> B, A |
| 1103 | |
| 1104 | D.setDependsOn(C, 1) |
| 1105 | C.setDependsOn(B, 1) |
| 1106 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1107 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1108 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1109 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1110 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1111 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1112 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1113 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1114 | |
| 1115 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1116 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1117 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1118 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1119 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1120 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1121 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1122 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1123 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1124 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1125 | self.waitUntilSettled() |
| 1126 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1127 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1128 | for build in self.builds: |
| 1129 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1130 | build.release() |
| 1131 | self.waitUntilSettled() |
| 1132 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1133 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1134 | self.waitUntilSettled() |
| 1135 | |
| 1136 | self.assertEqual(A.data['status'], 'MERGED') |
| 1137 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1138 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1139 | self.assertEqual(B.data['status'], 'NEW') |
| 1140 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1141 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1142 | self.assertEqual(C.data['status'], 'NEW') |
| 1143 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1144 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1145 | self.assertEqual(D.data['status'], 'NEW') |
| 1146 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1147 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1148 | self.assertEqual(E.data['status'], 'MERGED') |
| 1149 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1150 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1151 | self.assertEqual(len(self.history), 18) |
| 1152 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1153 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1154 | "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] | 1155 | # If it's dequeued more than once, we should see extra |
| 1156 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1157 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1158 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1159 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1160 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1161 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1162 | A.addApproval('code-review', 2) |
| 1163 | B.addApproval('code-review', 2) |
| 1164 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1165 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1166 | self.executor_server.failJob('project-test1', A) |
| 1167 | self.executor_server.failJob('project-test2', A) |
| 1168 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1169 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1170 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1171 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1172 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1173 | |
| 1174 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1175 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1176 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1177 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1178 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1179 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1180 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1181 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1182 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1183 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1184 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1185 | self.waitUntilSettled() |
| 1186 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1187 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1188 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1189 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1190 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1191 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1192 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1193 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1194 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1195 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1196 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1197 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1198 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1199 | self.waitUntilSettled() |
| 1200 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1201 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1202 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1203 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1204 | self.executor_server.hold_jobs_in_build = False |
| 1205 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1206 | self.waitUntilSettled() |
| 1207 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1208 | self.assertEqual(len(self.builds), 0) |
| 1209 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1210 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1211 | self.assertEqual(A.data['status'], 'NEW') |
| 1212 | self.assertEqual(B.data['status'], 'MERGED') |
| 1213 | self.assertEqual(C.data['status'], 'MERGED') |
| 1214 | self.assertEqual(A.reported, 2) |
| 1215 | self.assertEqual(B.reported, 2) |
| 1216 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1217 | |
| 1218 | def test_nonvoting_job(self): |
| 1219 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1220 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1221 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1222 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1223 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1224 | self.executor_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1225 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1226 | |
| 1227 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1228 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1229 | self.assertEqual(A.data['status'], 'MERGED') |
| 1230 | self.assertEqual(A.reported, 2) |
| 1231 | self.assertEqual( |
| 1232 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1233 | 'SUCCESS') |
| 1234 | self.assertEqual( |
| 1235 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1236 | 'SUCCESS') |
| 1237 | self.assertEqual( |
| 1238 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1239 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1240 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1241 | for build in self.builds: |
| 1242 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1243 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1244 | def test_check_queue_success(self): |
| 1245 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1246 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1247 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1248 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1249 | |
| 1250 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1251 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1252 | self.assertEqual(A.data['status'], 'NEW') |
| 1253 | self.assertEqual(A.reported, 1) |
| 1254 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1255 | 'SUCCESS') |
| 1256 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1257 | 'SUCCESS') |
| 1258 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1259 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1260 | |
| 1261 | def test_check_queue_failure(self): |
| 1262 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1263 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1264 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1265 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1266 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1267 | |
| 1268 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1269 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1270 | self.assertEqual(A.data['status'], 'NEW') |
| 1271 | self.assertEqual(A.reported, 1) |
| 1272 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1273 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1274 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1275 | 'SUCCESS') |
| 1276 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1277 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1278 | |
| 1279 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1280 | # This particular test does a large amount of merges and needs a little |
| 1281 | # more time to complete |
| 1282 | self.wait_timeout = 90 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1283 | "test that dependent changes behind dequeued changes work" |
| 1284 | # This complicated test is a reproduction of a real life bug |
| 1285 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1286 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1287 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1288 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1289 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1290 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1291 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1292 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1293 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1294 | D.setDependsOn(C, 1) |
| 1295 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1296 | A.addApproval('code-review', 2) |
| 1297 | B.addApproval('code-review', 2) |
| 1298 | C.addApproval('code-review', 2) |
| 1299 | D.addApproval('code-review', 2) |
| 1300 | E.addApproval('code-review', 2) |
| 1301 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1302 | |
| 1303 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1304 | |
| 1305 | # Change object re-use in the gerrit trigger is hidden if |
| 1306 | # changes are added in quick succession; waiting makes it more |
| 1307 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1308 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1309 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1310 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1311 | self.waitUntilSettled() |
| 1312 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1313 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1314 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1315 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1316 | self.waitUntilSettled() |
| 1317 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1318 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1319 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1320 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1321 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1322 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1323 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1324 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1325 | self.waitUntilSettled() |
| 1326 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1327 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1328 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1329 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1330 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1331 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1332 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1333 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1334 | self.waitUntilSettled() |
| 1335 | |
| 1336 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1337 | |
| 1338 | # Grab pointers to the jobs we want to release before |
| 1339 | # releasing any, because list indexes may change as |
| 1340 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1341 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1342 | a.release() |
| 1343 | b.release() |
| 1344 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1345 | self.waitUntilSettled() |
| 1346 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1347 | self.executor_server.hold_jobs_in_build = False |
| 1348 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1349 | self.waitUntilSettled() |
| 1350 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1351 | self.assertEqual(A.data['status'], 'NEW') |
| 1352 | self.assertEqual(B.data['status'], 'MERGED') |
| 1353 | self.assertEqual(C.data['status'], 'MERGED') |
| 1354 | self.assertEqual(D.data['status'], 'MERGED') |
| 1355 | self.assertEqual(E.data['status'], 'MERGED') |
| 1356 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1357 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1358 | self.assertEqual(A.reported, 2) |
| 1359 | self.assertEqual(B.reported, 2) |
| 1360 | self.assertEqual(C.reported, 2) |
| 1361 | self.assertEqual(D.reported, 2) |
| 1362 | self.assertEqual(E.reported, 2) |
| 1363 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1364 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1365 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1366 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1367 | |
| 1368 | def test_merger_repack(self): |
| 1369 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1370 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1371 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1372 | A.addApproval('code-review', 2) |
| 1373 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1374 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1375 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1376 | 'SUCCESS') |
| 1377 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1378 | 'SUCCESS') |
| 1379 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1380 | 'SUCCESS') |
| 1381 | self.assertEqual(A.data['status'], 'MERGED') |
| 1382 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1383 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1384 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1385 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1386 | path = os.path.join(self.merger_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1387 | if os.path.exists(path): |
| 1388 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1389 | path = os.path.join(self.executor_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1390 | if os.path.exists(path): |
| 1391 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1392 | |
| 1393 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1394 | A.addApproval('code-review', 2) |
| 1395 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1396 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1397 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1398 | 'SUCCESS') |
| 1399 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1400 | 'SUCCESS') |
| 1401 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1402 | 'SUCCESS') |
| 1403 | self.assertEqual(A.data['status'], 'MERGED') |
| 1404 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1405 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1406 | def test_merger_repack_large_change(self): |
| 1407 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1408 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1409 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1410 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1411 | url = self.fake_gerrit.getGitUrl( |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1412 | tenant.layout.project_configs.get('org/project1')) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1413 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1414 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1415 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1416 | path = os.path.join(self.upstream_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1417 | repack_repo(path) |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1418 | path = os.path.join(self.merger_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1419 | if os.path.exists(path): |
| 1420 | repack_repo(path) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1421 | path = os.path.join(self.executor_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1422 | if os.path.exists(path): |
| 1423 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1424 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1425 | A.addApproval('code-review', 2) |
| 1426 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1427 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1428 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1429 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1430 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1431 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1432 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1433 | 'SUCCESS') |
| 1434 | self.assertEqual(A.data['status'], 'MERGED') |
| 1435 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1436 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1437 | def test_new_patchset_dequeues_old(self): |
| 1438 | "Test that a new patchset causes the old to be dequeued" |
| 1439 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1440 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1441 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1442 | M.setMerged() |
| 1443 | |
| 1444 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1445 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1446 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1447 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1448 | A.addApproval('code-review', 2) |
| 1449 | B.addApproval('code-review', 2) |
| 1450 | C.addApproval('code-review', 2) |
| 1451 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1452 | |
| 1453 | C.setDependsOn(B, 1) |
| 1454 | B.setDependsOn(A, 1) |
| 1455 | A.setDependsOn(M, 1) |
| 1456 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1457 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1458 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1459 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1460 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1461 | self.waitUntilSettled() |
| 1462 | |
| 1463 | B.addPatchset() |
| 1464 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1465 | self.waitUntilSettled() |
| 1466 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1467 | self.executor_server.hold_jobs_in_build = False |
| 1468 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1469 | self.waitUntilSettled() |
| 1470 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1471 | self.assertEqual(A.data['status'], 'MERGED') |
| 1472 | self.assertEqual(A.reported, 2) |
| 1473 | self.assertEqual(B.data['status'], 'NEW') |
| 1474 | self.assertEqual(B.reported, 2) |
| 1475 | self.assertEqual(C.data['status'], 'NEW') |
| 1476 | self.assertEqual(C.reported, 2) |
| 1477 | self.assertEqual(D.data['status'], 'MERGED') |
| 1478 | self.assertEqual(D.reported, 2) |
| 1479 | 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] | 1480 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1481 | def test_new_patchset_check(self): |
| 1482 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1483 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1484 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1485 | |
| 1486 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1487 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1488 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1489 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1490 | |
| 1491 | # Add two git-dependent changes |
| 1492 | B.setDependsOn(A, 1) |
| 1493 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1494 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1495 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1496 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1497 | |
| 1498 | # A live item, and a non-live/live pair |
| 1499 | items = check_pipeline.getAllItems() |
| 1500 | self.assertEqual(len(items), 3) |
| 1501 | |
| 1502 | self.assertEqual(items[0].change.number, '1') |
| 1503 | self.assertEqual(items[0].change.patchset, '1') |
| 1504 | self.assertFalse(items[0].live) |
| 1505 | |
| 1506 | self.assertEqual(items[1].change.number, '2') |
| 1507 | self.assertEqual(items[1].change.patchset, '1') |
| 1508 | self.assertTrue(items[1].live) |
| 1509 | |
| 1510 | self.assertEqual(items[2].change.number, '1') |
| 1511 | self.assertEqual(items[2].change.patchset, '1') |
| 1512 | self.assertTrue(items[2].live) |
| 1513 | |
| 1514 | # Add a new patchset to A |
| 1515 | A.addPatchset() |
| 1516 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1517 | self.waitUntilSettled() |
| 1518 | |
| 1519 | # The live copy of A,1 should be gone, but the non-live and B |
| 1520 | # should continue, and we should have a new A,2 |
| 1521 | items = check_pipeline.getAllItems() |
| 1522 | self.assertEqual(len(items), 3) |
| 1523 | |
| 1524 | self.assertEqual(items[0].change.number, '1') |
| 1525 | self.assertEqual(items[0].change.patchset, '1') |
| 1526 | self.assertFalse(items[0].live) |
| 1527 | |
| 1528 | self.assertEqual(items[1].change.number, '2') |
| 1529 | self.assertEqual(items[1].change.patchset, '1') |
| 1530 | self.assertTrue(items[1].live) |
| 1531 | |
| 1532 | self.assertEqual(items[2].change.number, '1') |
| 1533 | self.assertEqual(items[2].change.patchset, '2') |
| 1534 | self.assertTrue(items[2].live) |
| 1535 | |
| 1536 | # Add a new patchset to B |
| 1537 | B.addPatchset() |
| 1538 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1539 | self.waitUntilSettled() |
| 1540 | |
| 1541 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1542 | # but we should have a new B,2 (still based on A,1) |
| 1543 | items = check_pipeline.getAllItems() |
| 1544 | self.assertEqual(len(items), 3) |
| 1545 | |
| 1546 | self.assertEqual(items[0].change.number, '1') |
| 1547 | self.assertEqual(items[0].change.patchset, '2') |
| 1548 | self.assertTrue(items[0].live) |
| 1549 | |
| 1550 | self.assertEqual(items[1].change.number, '1') |
| 1551 | self.assertEqual(items[1].change.patchset, '1') |
| 1552 | self.assertFalse(items[1].live) |
| 1553 | |
| 1554 | self.assertEqual(items[2].change.number, '2') |
| 1555 | self.assertEqual(items[2].change.patchset, '2') |
| 1556 | self.assertTrue(items[2].live) |
| 1557 | |
| 1558 | self.builds[0].release() |
| 1559 | self.waitUntilSettled() |
| 1560 | self.builds[0].release() |
| 1561 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1562 | self.executor_server.hold_jobs_in_build = False |
| 1563 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1564 | self.waitUntilSettled() |
| 1565 | |
| 1566 | self.assertEqual(A.reported, 1) |
| 1567 | self.assertEqual(B.reported, 1) |
| 1568 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1569 | self.assertEqual(self.history[0].changes, '1,1') |
| 1570 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1571 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1572 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1573 | self.assertEqual(self.history[2].changes, '1,2') |
| 1574 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1575 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1576 | |
| 1577 | def test_abandoned_gate(self): |
| 1578 | "Test that an abandoned change is dequeued from gate" |
| 1579 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1580 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1581 | |
| 1582 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1583 | A.addApproval('code-review', 2) |
| 1584 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1585 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1586 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1587 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1588 | |
| 1589 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1590 | self.waitUntilSettled() |
| 1591 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1592 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1593 | self.waitUntilSettled() |
| 1594 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1595 | self.assertBuilds([]) |
| 1596 | self.assertHistory([ |
| 1597 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1598 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1599 | self.assertEqual(A.reported, 1, |
| 1600 | "Abandoned gate change should report only start") |
| 1601 | |
| 1602 | def test_abandoned_check(self): |
| 1603 | "Test that an abandoned change is dequeued from check" |
| 1604 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1605 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1606 | |
| 1607 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1608 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1609 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1610 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1611 | |
| 1612 | # Add two git-dependent changes |
| 1613 | B.setDependsOn(A, 1) |
| 1614 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1615 | self.waitUntilSettled() |
| 1616 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1617 | self.waitUntilSettled() |
| 1618 | # A live item, and a non-live/live pair |
| 1619 | items = check_pipeline.getAllItems() |
| 1620 | self.assertEqual(len(items), 3) |
| 1621 | |
| 1622 | self.assertEqual(items[0].change.number, '1') |
| 1623 | self.assertFalse(items[0].live) |
| 1624 | |
| 1625 | self.assertEqual(items[1].change.number, '2') |
| 1626 | self.assertTrue(items[1].live) |
| 1627 | |
| 1628 | self.assertEqual(items[2].change.number, '1') |
| 1629 | self.assertTrue(items[2].live) |
| 1630 | |
| 1631 | # Abandon A |
| 1632 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1633 | self.waitUntilSettled() |
| 1634 | |
| 1635 | # The live copy of A should be gone, but the non-live and B |
| 1636 | # should continue |
| 1637 | items = check_pipeline.getAllItems() |
| 1638 | self.assertEqual(len(items), 2) |
| 1639 | |
| 1640 | self.assertEqual(items[0].change.number, '1') |
| 1641 | self.assertFalse(items[0].live) |
| 1642 | |
| 1643 | self.assertEqual(items[1].change.number, '2') |
| 1644 | self.assertTrue(items[1].live) |
| 1645 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1646 | self.executor_server.hold_jobs_in_build = False |
| 1647 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1648 | self.waitUntilSettled() |
| 1649 | |
| 1650 | self.assertEqual(len(self.history), 4) |
| 1651 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1652 | 'Build should have been aborted') |
| 1653 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1654 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1655 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1656 | def test_abandoned_not_timer(self): |
| 1657 | "Test that an abandoned change does not cancel timer jobs" |
| 1658 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1659 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1660 | |
| 1661 | # Start timer trigger - also org/project |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1662 | self.updateConfigLayout('layout-idle') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1663 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1664 | # The pipeline triggers every second, so we should have seen |
| 1665 | # several by now. |
| 1666 | time.sleep(5) |
| 1667 | self.waitUntilSettled() |
| 1668 | # Stop queuing timer triggered jobs so that the assertions |
| 1669 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1670 | # Must be in same repo, so overwrite config with another one |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 1671 | self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1672 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1673 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1674 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1675 | |
| 1676 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1677 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1678 | self.waitUntilSettled() |
| 1679 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1680 | |
| 1681 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1682 | self.waitUntilSettled() |
| 1683 | |
| 1684 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1685 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1686 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1687 | self.waitUntilSettled() |
| 1688 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1689 | def test_zuul_url_return(self): |
| 1690 | "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] | 1691 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1692 | self.executor_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1693 | |
| 1694 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1695 | A.addApproval('code-review', 2) |
| 1696 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1697 | self.waitUntilSettled() |
| 1698 | |
| 1699 | self.assertEqual(len(self.builds), 1) |
| 1700 | for build in self.builds: |
| 1701 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1702 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1703 | self.executor_server.hold_jobs_in_build = False |
| 1704 | self.executor_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1705 | self.waitUntilSettled() |
| 1706 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1707 | def test_new_patchset_dequeues_old_on_head(self): |
| 1708 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1709 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1710 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1711 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1712 | M.setMerged() |
| 1713 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1714 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1715 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1716 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1717 | A.addApproval('code-review', 2) |
| 1718 | B.addApproval('code-review', 2) |
| 1719 | C.addApproval('code-review', 2) |
| 1720 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1721 | |
| 1722 | C.setDependsOn(B, 1) |
| 1723 | B.setDependsOn(A, 1) |
| 1724 | A.setDependsOn(M, 1) |
| 1725 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1726 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1727 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1728 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1729 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1730 | self.waitUntilSettled() |
| 1731 | |
| 1732 | A.addPatchset() |
| 1733 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1734 | self.waitUntilSettled() |
| 1735 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1736 | self.executor_server.hold_jobs_in_build = False |
| 1737 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1738 | self.waitUntilSettled() |
| 1739 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1740 | self.assertEqual(A.data['status'], 'NEW') |
| 1741 | self.assertEqual(A.reported, 2) |
| 1742 | self.assertEqual(B.data['status'], 'NEW') |
| 1743 | self.assertEqual(B.reported, 2) |
| 1744 | self.assertEqual(C.data['status'], 'NEW') |
| 1745 | self.assertEqual(C.reported, 2) |
| 1746 | self.assertEqual(D.data['status'], 'MERGED') |
| 1747 | self.assertEqual(D.reported, 2) |
| 1748 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1749 | |
| 1750 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1751 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1752 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1753 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1754 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1755 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1756 | A.addApproval('code-review', 2) |
| 1757 | B.addApproval('code-review', 2) |
| 1758 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1759 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1760 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1761 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1762 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1763 | self.waitUntilSettled() |
| 1764 | |
| 1765 | B.addPatchset() |
| 1766 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1767 | self.waitUntilSettled() |
| 1768 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1769 | self.executor_server.hold_jobs_in_build = False |
| 1770 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1771 | self.waitUntilSettled() |
| 1772 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1773 | self.assertEqual(A.data['status'], 'MERGED') |
| 1774 | self.assertEqual(A.reported, 2) |
| 1775 | self.assertEqual(B.data['status'], 'NEW') |
| 1776 | self.assertEqual(B.reported, 2) |
| 1777 | self.assertEqual(C.data['status'], 'MERGED') |
| 1778 | self.assertEqual(C.reported, 2) |
| 1779 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1780 | |
| 1781 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1782 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1783 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1784 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1785 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1786 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1787 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1788 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1789 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1790 | self.waitUntilSettled() |
| 1791 | |
| 1792 | B.addPatchset() |
| 1793 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1794 | self.waitUntilSettled() |
| 1795 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1796 | self.executor_server.hold_jobs_in_build = False |
| 1797 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1798 | self.waitUntilSettled() |
| 1799 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1800 | self.assertEqual(A.data['status'], 'NEW') |
| 1801 | self.assertEqual(A.reported, 1) |
| 1802 | self.assertEqual(B.data['status'], 'NEW') |
| 1803 | self.assertEqual(B.reported, 1) |
| 1804 | self.assertEqual(C.data['status'], 'NEW') |
| 1805 | self.assertEqual(C.reported, 1) |
| 1806 | self.assertEqual(len(self.history), 10) |
| 1807 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1808 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1809 | def test_noop_job(self): |
| 1810 | "Test that the internal noop job works" |
| 1811 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1812 | A.addApproval('code-review', 2) |
| 1813 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1814 | self.waitUntilSettled() |
| 1815 | |
| 1816 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1817 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1818 | self.assertEqual(len(self.history), 0) |
| 1819 | self.assertEqual(A.data['status'], 'MERGED') |
| 1820 | self.assertEqual(A.reported, 2) |
| 1821 | |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1822 | def test_no_job_project(self): |
| 1823 | "Test that reports with no jobs don't get sent" |
| 1824 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1825 | 'master', 'A') |
| 1826 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1827 | self.waitUntilSettled() |
| 1828 | |
| 1829 | # Change wasn't reported to |
| 1830 | self.assertEqual(A.reported, False) |
| 1831 | |
| 1832 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1833 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1834 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1835 | items = check_pipeline.getAllItems() |
| 1836 | self.assertEqual(len(items), 0) |
| 1837 | |
| 1838 | self.assertEqual(len(self.history), 0) |
| 1839 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1840 | def test_zuul_refs(self): |
| 1841 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1842 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1843 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1844 | M1.setMerged() |
| 1845 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1846 | M2.setMerged() |
| 1847 | |
| 1848 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1849 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1850 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1851 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1852 | A.addApproval('code-review', 2) |
| 1853 | B.addApproval('code-review', 2) |
| 1854 | C.addApproval('code-review', 2) |
| 1855 | D.addApproval('code-review', 2) |
| 1856 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1857 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1858 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1859 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1860 | |
| 1861 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1862 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1863 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1864 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1865 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1866 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1867 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1868 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1869 | self.waitUntilSettled() |
| 1870 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1871 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1872 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1873 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1874 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1875 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1876 | a_build = x |
| 1877 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1878 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1879 | b_build = x |
| 1880 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1881 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1882 | c_build = x |
| 1883 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1884 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1885 | d_build = x |
| 1886 | if a_build and b_build and c_build and d_build: |
| 1887 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1888 | |
| 1889 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1890 | self.assertIsNotNone(a_zref) |
| 1891 | self.assertIsNotNone(b_zref) |
| 1892 | self.assertIsNotNone(c_zref) |
| 1893 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1894 | |
| 1895 | # And they should all be different |
| 1896 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1897 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1898 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1899 | # should have a, not b, and should not be in project2 |
| 1900 | self.assertTrue(a_build.hasChanges(A)) |
| 1901 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1902 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1903 | # should have a and b, and should not be in project2 |
| 1904 | self.assertTrue(b_build.hasChanges(A, B)) |
| 1905 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1906 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1907 | # should have a and b in 1, c in 2 |
| 1908 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 1909 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1910 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1911 | # should have a and b in 1, c and d in 2 |
| 1912 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1913 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1914 | self.executor_server.hold_jobs_in_build = False |
| 1915 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1916 | self.waitUntilSettled() |
| 1917 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1918 | self.assertEqual(A.data['status'], 'MERGED') |
| 1919 | self.assertEqual(A.reported, 2) |
| 1920 | self.assertEqual(B.data['status'], 'MERGED') |
| 1921 | self.assertEqual(B.reported, 2) |
| 1922 | self.assertEqual(C.data['status'], 'MERGED') |
| 1923 | self.assertEqual(C.reported, 2) |
| 1924 | self.assertEqual(D.data['status'], 'MERGED') |
| 1925 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1926 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1927 | def test_rerun_on_error(self): |
| 1928 | "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] | 1929 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1930 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1931 | A.addApproval('code-review', 2) |
| 1932 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1933 | self.waitUntilSettled() |
| 1934 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 1935 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1936 | self.executor_server.hold_jobs_in_build = False |
| 1937 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1938 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 1939 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1940 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 1941 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1942 | def test_statsd(self): |
| 1943 | "Test each of the statsd methods used in the scheduler" |
| 1944 | import extras |
| 1945 | statsd = extras.try_import('statsd.statsd') |
| 1946 | statsd.incr('test-incr') |
| 1947 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1948 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1949 | self.assertReportedStat('test-incr', '1|c') |
| 1950 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1951 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1952 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1953 | def test_stuck_job_cleanup(self): |
| 1954 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 1955 | |
| 1956 | # 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] | 1957 | self.gearman_server.hold_jobs_in_queue = True |
| 1958 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1959 | A.addApproval('code-review', 2) |
| 1960 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1961 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 1962 | # 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] | 1963 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 1964 | |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 1965 | self.commitLayoutUpdate('common-config', 'layout-no-jobs') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1966 | self.sched.reconfigure(self.config) |
| 1967 | self.waitUntilSettled() |
| 1968 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1969 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1970 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 1971 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1972 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1973 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1974 | |
| 1975 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1976 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1977 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 1978 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 1979 | def test_file_head(self): |
| 1980 | # This is a regression test for an observed bug. A change |
| 1981 | # with a file named "HEAD" in the root directory of the repo |
| 1982 | # was processed by a merger. It then was unable to reset the |
| 1983 | # repo because of: |
| 1984 | # GitCommandError: 'git reset --hard HEAD' returned |
| 1985 | # with exit code 128 |
| 1986 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 1987 | # and filename |
| 1988 | # Use '--' to separate filenames from revisions' |
| 1989 | |
| 1990 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 1991 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 1992 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1993 | |
| 1994 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1995 | self.waitUntilSettled() |
| 1996 | |
| 1997 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1998 | self.waitUntilSettled() |
| 1999 | |
| 2000 | self.assertIn('Build succeeded', A.messages[0]) |
| 2001 | self.assertIn('Build succeeded', B.messages[0]) |
| 2002 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2003 | def test_file_jobs(self): |
| 2004 | "Test that file jobs run only when appropriate" |
| 2005 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2006 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2007 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2008 | A.addApproval('code-review', 2) |
| 2009 | B.addApproval('code-review', 2) |
| 2010 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2011 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2012 | self.waitUntilSettled() |
| 2013 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2014 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2015 | if x.name == 'project-testfile'] |
| 2016 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2017 | self.assertEqual(len(testfile_jobs), 1) |
| 2018 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2019 | self.assertEqual(A.data['status'], 'MERGED') |
| 2020 | self.assertEqual(A.reported, 2) |
| 2021 | self.assertEqual(B.data['status'], 'MERGED') |
| 2022 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2023 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2024 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2025 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2026 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2027 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2028 | |
| 2029 | if should_skip: |
| 2030 | files = {'ignoreme': 'ignored\n'} |
| 2031 | else: |
| 2032 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2033 | |
| 2034 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2035 | 'master', |
| 2036 | 'test irrelevant-files', |
| 2037 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2038 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2039 | self.waitUntilSettled() |
| 2040 | |
| 2041 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2042 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2043 | |
| 2044 | if should_skip: |
| 2045 | self.assertEqual([], tested_change_ids) |
| 2046 | else: |
| 2047 | self.assertIn(change.data['number'], tested_change_ids) |
| 2048 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2049 | def test_irrelevant_files_match_skips_job(self): |
| 2050 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2051 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2052 | def test_irrelevant_files_no_match_runs_job(self): |
| 2053 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2054 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2055 | def test_inherited_jobs_keep_matchers(self): |
| 2056 | self.updateConfigLayout('layout-inheritance') |
| 2057 | self.sched.reconfigure(self.config) |
| 2058 | |
| 2059 | files = {'ignoreme': 'ignored\n'} |
| 2060 | |
| 2061 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2062 | 'master', |
| 2063 | 'test irrelevant-files', |
| 2064 | files=files) |
| 2065 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2066 | self.waitUntilSettled() |
| 2067 | |
| 2068 | run_jobs = set([build.name for build in self.history]) |
| 2069 | |
| 2070 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2071 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2072 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2073 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2074 | def test_test_config(self): |
| 2075 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2076 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2077 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2078 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2079 | def test_queue_names(self): |
| 2080 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2081 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2082 | source = tenant.layout.pipelines['gate'].source |
| 2083 | project1 = source.getProject('org/project1') |
| 2084 | project2 = source.getProject('org/project2') |
| 2085 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2086 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2087 | self.assertEqual(q1.name, 'integrated') |
| 2088 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2089 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2090 | def test_queue_precedence(self): |
| 2091 | "Test that queue precedence works" |
| 2092 | |
| 2093 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2094 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2095 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2096 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2097 | A.addApproval('code-review', 2) |
| 2098 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2099 | |
| 2100 | self.waitUntilSettled() |
| 2101 | self.gearman_server.hold_jobs_in_queue = False |
| 2102 | self.gearman_server.release() |
| 2103 | self.waitUntilSettled() |
| 2104 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2105 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2106 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2107 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2108 | self.waitUntilSettled() |
| 2109 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2110 | self.log.debug(self.history) |
| 2111 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2112 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2113 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2114 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2115 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2116 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2117 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2118 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2119 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2120 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2121 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2122 | A.addApproval('code-review', 2) |
| 2123 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2124 | self.waitUntilSettled() |
| 2125 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2126 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2127 | self.waitUntilSettled() |
| 2128 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2129 | port = self.webapp.server.socket.getsockname()[1] |
| 2130 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2131 | req = urllib.request.Request( |
| 2132 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2133 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2134 | headers = f.info() |
| 2135 | self.assertIn('Content-Length', headers) |
| 2136 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2137 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2138 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2139 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2140 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2141 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2142 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2143 | data = f.read() |
| 2144 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2145 | self.executor_server.hold_jobs_in_build = False |
| 2146 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2147 | self.waitUntilSettled() |
| 2148 | |
| 2149 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2150 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2151 | for p in data['pipelines']: |
| 2152 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2153 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2154 | self.assertEqual(q['window'], 20) |
| 2155 | else: |
| 2156 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2157 | for head in q['heads']: |
| 2158 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2159 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2160 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2161 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2162 | status_jobs.append(job) |
| 2163 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2164 | self.assertEqual('https://server/job/project-merge/0/', |
| 2165 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2166 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2167 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2168 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2169 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2170 | status_jobs[1]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2171 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2172 | status_jobs[1]['report_url']) |
| 2173 | |
| 2174 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2175 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2176 | status_jobs[2]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2177 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2178 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2179 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2180 | def test_mutex(self): |
| 2181 | "Test job mutexes" |
Adam Gandelman | ea9ac9b | 2017-02-03 16:59:58 -0800 | [diff] [blame] | 2182 | self.updateConfigLayout('layout-mutex') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2183 | self.sched.reconfigure(self.config) |
| 2184 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2185 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2186 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2187 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2188 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2189 | |
| 2190 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2191 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2192 | self.waitUntilSettled() |
| 2193 | self.assertEqual(len(self.builds), 3) |
| 2194 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2195 | self.assertEqual(self.builds[1].name, 'mutex-one') |
| 2196 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2197 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2198 | self.executor_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2199 | self.waitUntilSettled() |
| 2200 | |
| 2201 | self.assertEqual(len(self.builds), 3) |
| 2202 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2203 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2204 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2205 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2206 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2207 | self.executor_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2208 | self.waitUntilSettled() |
| 2209 | |
| 2210 | self.assertEqual(len(self.builds), 3) |
| 2211 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2212 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2213 | self.assertEqual(self.builds[2].name, 'mutex-one') |
| 2214 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2215 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2216 | self.executor_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2217 | self.waitUntilSettled() |
| 2218 | |
| 2219 | self.assertEqual(len(self.builds), 3) |
| 2220 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2221 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2222 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2223 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2224 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2225 | self.executor_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2226 | self.waitUntilSettled() |
| 2227 | |
| 2228 | self.assertEqual(len(self.builds), 2) |
| 2229 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2230 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2231 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2232 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2233 | self.executor_server.hold_jobs_in_build = False |
| 2234 | self.executor_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2235 | |
| 2236 | self.waitUntilSettled() |
| 2237 | self.assertEqual(len(self.builds), 0) |
| 2238 | |
| 2239 | self.assertEqual(A.reported, 1) |
| 2240 | self.assertEqual(B.reported, 1) |
| 2241 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2242 | |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2243 | def test_mutex_abandon(self): |
| 2244 | "Test abandon with job mutexes" |
| 2245 | self.updateConfigLayout('layout-mutex') |
| 2246 | self.sched.reconfigure(self.config) |
| 2247 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2248 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2249 | |
| 2250 | tenant = self.sched.abide.tenants.get('openstack') |
| 2251 | check_pipeline = tenant.layout.pipelines['check'] |
| 2252 | |
| 2253 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2254 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2255 | |
| 2256 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2257 | self.waitUntilSettled() |
| 2258 | |
| 2259 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2260 | |
| 2261 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2262 | self.waitUntilSettled() |
| 2263 | |
| 2264 | # The check pipeline should be empty |
| 2265 | items = check_pipeline.getAllItems() |
| 2266 | self.assertEqual(len(items), 0) |
| 2267 | |
| 2268 | # The mutex should be released |
| 2269 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2270 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2271 | self.executor_server.hold_jobs_in_build = False |
| 2272 | self.executor_server.release() |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2273 | self.waitUntilSettled() |
| 2274 | |
| 2275 | def test_mutex_reconfigure(self): |
| 2276 | "Test reconfigure with job mutexes" |
| 2277 | self.updateConfigLayout('layout-mutex') |
| 2278 | self.sched.reconfigure(self.config) |
| 2279 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2280 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2281 | |
| 2282 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2283 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2284 | |
| 2285 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2286 | self.waitUntilSettled() |
| 2287 | |
| 2288 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2289 | |
| 2290 | self.updateConfigLayout('layout-mutex-reconfiguration') |
| 2291 | self.sched.reconfigure(self.config) |
| 2292 | self.waitUntilSettled() |
| 2293 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2294 | self.executor_server.release('project-test1') |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2295 | self.waitUntilSettled() |
| 2296 | |
| 2297 | # There should be no builds anymore |
| 2298 | self.assertEqual(len(self.builds), 0) |
| 2299 | |
| 2300 | # The mutex should be released |
| 2301 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2302 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2303 | def test_live_reconfiguration(self): |
| 2304 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2305 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2306 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2307 | A.addApproval('code-review', 2) |
| 2308 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2309 | self.waitUntilSettled() |
| 2310 | |
| 2311 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2312 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2313 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2314 | self.executor_server.hold_jobs_in_build = False |
| 2315 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2316 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2317 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2318 | 'SUCCESS') |
| 2319 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2320 | 'SUCCESS') |
| 2321 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2322 | 'SUCCESS') |
| 2323 | self.assertEqual(A.data['status'], 'MERGED') |
| 2324 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2325 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2326 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2327 | def test_live_reconfiguration_merge_conflict(self): |
| 2328 | # A real-world bug: a change in a gate queue has a merge |
| 2329 | # conflict and a job is added to its project while it's |
| 2330 | # sitting in the queue. The job gets added to the change and |
| 2331 | # enqueued and the change gets stuck. |
| 2332 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2333 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2334 | |
| 2335 | # This change is fine. It's here to stop the queue long |
| 2336 | # enough for the next change to be subject to the |
| 2337 | # reconfiguration, as well as to provide a conflict for the |
| 2338 | # next change. This change will succeed and merge. |
| 2339 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2340 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2341 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2342 | |
| 2343 | # This change will be in merge conflict. During the |
| 2344 | # reconfiguration, we will add a job. We want to make sure |
| 2345 | # that doesn't cause it to get stuck. |
| 2346 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2347 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2348 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2349 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2350 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2351 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2352 | |
| 2353 | self.waitUntilSettled() |
| 2354 | |
| 2355 | # No jobs have run yet |
| 2356 | self.assertEqual(A.data['status'], 'NEW') |
| 2357 | self.assertEqual(A.reported, 1) |
| 2358 | self.assertEqual(B.data['status'], 'NEW') |
| 2359 | self.assertEqual(B.reported, 1) |
| 2360 | self.assertEqual(len(self.history), 0) |
| 2361 | |
| 2362 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2363 | self.updateConfigLayout( |
| 2364 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2365 | self.sched.reconfigure(self.config) |
| 2366 | self.waitUntilSettled() |
| 2367 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2368 | self.executor_server.hold_jobs_in_build = False |
| 2369 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2370 | self.waitUntilSettled() |
| 2371 | |
| 2372 | self.assertEqual(A.data['status'], 'MERGED') |
| 2373 | self.assertEqual(A.reported, 2) |
| 2374 | self.assertEqual(B.data['status'], 'NEW') |
| 2375 | self.assertEqual(B.reported, 2) |
| 2376 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2377 | 'SUCCESS') |
| 2378 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2379 | 'SUCCESS') |
| 2380 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2381 | 'SUCCESS') |
| 2382 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2383 | 'SUCCESS') |
| 2384 | self.assertEqual(len(self.history), 4) |
| 2385 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2386 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2387 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2388 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2389 | # that tests a job added to a job tree with a failed root does |
| 2390 | # not run. |
| 2391 | self.worker.registerFunction('build:project-test3') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2392 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2393 | |
| 2394 | # This change is fine. It's here to stop the queue long |
| 2395 | # enough for the next change to be subject to the |
| 2396 | # reconfiguration. This change will succeed and merge. |
| 2397 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2398 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2399 | A.addApproval('code-review', 2) |
| 2400 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2401 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2402 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2403 | self.waitUntilSettled() |
| 2404 | |
| 2405 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2406 | self.executor_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2407 | B.addApproval('code-review', 2) |
| 2408 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2409 | self.waitUntilSettled() |
| 2410 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2411 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2412 | self.waitUntilSettled() |
| 2413 | |
| 2414 | # Both -merge jobs have run, but no others. |
| 2415 | self.assertEqual(A.data['status'], 'NEW') |
| 2416 | self.assertEqual(A.reported, 1) |
| 2417 | self.assertEqual(B.data['status'], 'NEW') |
| 2418 | self.assertEqual(B.reported, 1) |
| 2419 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2420 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2421 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2422 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2423 | self.assertEqual(len(self.history), 2) |
| 2424 | |
| 2425 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2426 | self.updateConfigLayout( |
| 2427 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2428 | self.sched.reconfigure(self.config) |
| 2429 | self.waitUntilSettled() |
| 2430 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2431 | self.executor_server.hold_jobs_in_build = False |
| 2432 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2433 | self.waitUntilSettled() |
| 2434 | |
| 2435 | self.assertEqual(A.data['status'], 'MERGED') |
| 2436 | self.assertEqual(A.reported, 2) |
| 2437 | self.assertEqual(B.data['status'], 'NEW') |
| 2438 | self.assertEqual(B.reported, 2) |
| 2439 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2440 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2441 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2442 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2443 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2444 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2445 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2446 | self.assertEqual(len(self.history), 5) |
| 2447 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2448 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2449 | def test_live_reconfiguration_failed_job(self): |
| 2450 | # Test that a change with a removed failing job does not |
| 2451 | # disrupt reconfiguration. If a change has a failed job and |
| 2452 | # that job is removed during a reconfiguration, we observed a |
| 2453 | # bug where the code to re-set build statuses would run on |
| 2454 | # that build and raise an exception because the job no longer |
| 2455 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2456 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2457 | |
| 2458 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2459 | |
| 2460 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2461 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2462 | |
| 2463 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2464 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2465 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2466 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2467 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2468 | self.waitUntilSettled() |
| 2469 | |
| 2470 | self.assertEqual(A.data['status'], 'NEW') |
| 2471 | self.assertEqual(A.reported, 0) |
| 2472 | |
| 2473 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2474 | 'SUCCESS') |
| 2475 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2476 | 'FAILURE') |
| 2477 | self.assertEqual(len(self.history), 2) |
| 2478 | |
| 2479 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2480 | self.updateConfigLayout( |
| 2481 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2482 | self.sched.reconfigure(self.config) |
| 2483 | self.waitUntilSettled() |
| 2484 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2485 | self.executor_server.hold_jobs_in_build = False |
| 2486 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2487 | self.waitUntilSettled() |
| 2488 | |
| 2489 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2490 | 'SUCCESS') |
| 2491 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2492 | 'SUCCESS') |
| 2493 | self.assertEqual(len(self.history), 4) |
| 2494 | |
| 2495 | self.assertEqual(A.data['status'], 'NEW') |
| 2496 | self.assertEqual(A.reported, 1) |
| 2497 | self.assertIn('Build succeeded', A.messages[0]) |
| 2498 | # Ensure the removed job was not included in the report. |
| 2499 | self.assertNotIn('project-test1', A.messages[0]) |
| 2500 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2501 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2502 | def test_live_reconfiguration_shared_queue(self): |
| 2503 | # Test that a change with a failing job which was removed from |
| 2504 | # this project but otherwise still exists in the system does |
| 2505 | # not disrupt reconfiguration. |
| 2506 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2507 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2508 | |
| 2509 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2510 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2511 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2512 | |
| 2513 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2514 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2515 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2516 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2517 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2518 | self.waitUntilSettled() |
| 2519 | |
| 2520 | self.assertEqual(A.data['status'], 'NEW') |
| 2521 | self.assertEqual(A.reported, 0) |
| 2522 | |
| 2523 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2524 | 'SUCCESS') |
| 2525 | self.assertEqual(self.getJobFromHistory( |
| 2526 | 'project1-project2-integration').result, 'FAILURE') |
| 2527 | self.assertEqual(len(self.history), 2) |
| 2528 | |
| 2529 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2530 | self.updateConfigLayout( |
| 2531 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2532 | self.sched.reconfigure(self.config) |
| 2533 | self.waitUntilSettled() |
| 2534 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2535 | self.executor_server.hold_jobs_in_build = False |
| 2536 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2537 | self.waitUntilSettled() |
| 2538 | |
| 2539 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2540 | 'SUCCESS') |
| 2541 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2542 | 'SUCCESS') |
| 2543 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2544 | 'SUCCESS') |
| 2545 | self.assertEqual(self.getJobFromHistory( |
| 2546 | 'project1-project2-integration').result, 'FAILURE') |
| 2547 | self.assertEqual(len(self.history), 4) |
| 2548 | |
| 2549 | self.assertEqual(A.data['status'], 'NEW') |
| 2550 | self.assertEqual(A.reported, 1) |
| 2551 | self.assertIn('Build succeeded', A.messages[0]) |
| 2552 | # Ensure the removed job was not included in the report. |
| 2553 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2554 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2555 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2556 | def test_double_live_reconfiguration_shared_queue(self): |
| 2557 | # This was a real-world regression. A change is added to |
| 2558 | # gate; a reconfigure happens, a second change which depends |
| 2559 | # on the first is added, and a second reconfiguration happens. |
| 2560 | # Ensure that both changes merge. |
| 2561 | |
| 2562 | # A failure may indicate incorrect caching or cleaning up of |
| 2563 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2564 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2565 | |
| 2566 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2567 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2568 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2569 | A.addApproval('code-review', 2) |
| 2570 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2571 | |
| 2572 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2573 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2574 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2575 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2576 | self.waitUntilSettled() |
| 2577 | |
| 2578 | # Reconfigure (with only one change in the pipeline). |
| 2579 | self.sched.reconfigure(self.config) |
| 2580 | self.waitUntilSettled() |
| 2581 | |
| 2582 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2583 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2584 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2585 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2586 | self.waitUntilSettled() |
| 2587 | |
| 2588 | # Reconfigure (with both in the pipeline). |
| 2589 | self.sched.reconfigure(self.config) |
| 2590 | self.waitUntilSettled() |
| 2591 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2592 | self.executor_server.hold_jobs_in_build = False |
| 2593 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2594 | self.waitUntilSettled() |
| 2595 | |
| 2596 | self.assertEqual(len(self.history), 8) |
| 2597 | |
| 2598 | self.assertEqual(A.data['status'], 'MERGED') |
| 2599 | self.assertEqual(A.reported, 2) |
| 2600 | self.assertEqual(B.data['status'], 'MERGED') |
| 2601 | self.assertEqual(B.reported, 2) |
| 2602 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2603 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2604 | def test_live_reconfiguration_del_project(self): |
| 2605 | # Test project deletion from layout |
| 2606 | # while changes are enqueued |
| 2607 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2608 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2609 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2610 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2611 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2612 | |
| 2613 | # A Depends-On: B |
| 2614 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2615 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2616 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2617 | |
| 2618 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2619 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2620 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2621 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2622 | self.waitUntilSettled() |
| 2623 | self.assertEqual(len(self.builds), 5) |
| 2624 | |
| 2625 | # This layout defines only org/project, not org/project1 |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2626 | self.updateConfigLayout( |
| 2627 | 'tests/fixtures/layout-live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2628 | self.sched.reconfigure(self.config) |
| 2629 | self.waitUntilSettled() |
| 2630 | |
| 2631 | # Builds for C aborted, builds for A succeed, |
| 2632 | # and have change B applied ahead |
| 2633 | job_c = self.getJobFromHistory('project1-test1') |
| 2634 | self.assertEqual(job_c.changes, '3,1') |
| 2635 | self.assertEqual(job_c.result, 'ABORTED') |
| 2636 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2637 | self.executor_server.hold_jobs_in_build = False |
| 2638 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2639 | self.waitUntilSettled() |
| 2640 | |
| 2641 | self.assertEqual(self.getJobFromHistory('project-test1').changes, |
| 2642 | '2,1 1,1') |
| 2643 | |
| 2644 | self.assertEqual(A.data['status'], 'NEW') |
| 2645 | self.assertEqual(B.data['status'], 'NEW') |
| 2646 | self.assertEqual(C.data['status'], 'NEW') |
| 2647 | self.assertEqual(A.reported, 1) |
| 2648 | self.assertEqual(B.reported, 0) |
| 2649 | self.assertEqual(C.reported, 0) |
| 2650 | |
| 2651 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 2652 | self.assertIn('Build succeeded', A.messages[0]) |
| 2653 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2654 | @skip("Disabled for early v3 development") |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2655 | def test_live_reconfiguration_functions(self): |
| 2656 | "Test live reconfiguration with a custom function" |
| 2657 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2658 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2659 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2660 | A.addApproval('code-review', 2) |
| 2661 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2662 | self.waitUntilSettled() |
| 2663 | |
| 2664 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2665 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2666 | 'debian') |
| 2667 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2668 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2669 | self.updateConfigLayout( |
| 2670 | 'tests/fixtures/layout-live-reconfiguration-functions.yaml') |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2671 | self.sched.reconfigure(self.config) |
| 2672 | self.worker.build_history = [] |
| 2673 | |
| 2674 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2675 | B.addApproval('code-review', 2) |
| 2676 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2677 | self.waitUntilSettled() |
| 2678 | |
| 2679 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2680 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2681 | 'wheezy') |
| 2682 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2683 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2684 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2685 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2686 | self.updateConfigLayout( |
| 2687 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2688 | self.sched.reconfigure(self.config) |
| 2689 | |
| 2690 | self.init_repo("org/new-project") |
| 2691 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2692 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2693 | A.addApproval('code-review', 2) |
| 2694 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2695 | self.waitUntilSettled() |
| 2696 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2697 | 'SUCCESS') |
| 2698 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2699 | 'SUCCESS') |
| 2700 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2701 | 'SUCCESS') |
| 2702 | self.assertEqual(A.data['status'], 'MERGED') |
| 2703 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2704 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2705 | def test_repo_deleted(self): |
Paul Belanger | 66e9596 | 2016-11-11 12:11:06 -0500 | [diff] [blame] | 2706 | self.updateConfigLayout('layout-repo-deleted') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2707 | self.sched.reconfigure(self.config) |
| 2708 | |
| 2709 | self.init_repo("org/delete-project") |
| 2710 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2711 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2712 | A.addApproval('code-review', 2) |
| 2713 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2714 | self.waitUntilSettled() |
| 2715 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2716 | 'SUCCESS') |
| 2717 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2718 | 'SUCCESS') |
| 2719 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2720 | 'SUCCESS') |
| 2721 | self.assertEqual(A.data['status'], 'MERGED') |
| 2722 | self.assertEqual(A.reported, 2) |
| 2723 | |
| 2724 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2725 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2726 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2727 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2728 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2729 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2730 | |
| 2731 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2732 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2733 | B.addApproval('code-review', 2) |
| 2734 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2735 | self.waitUntilSettled() |
| 2736 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2737 | 'SUCCESS') |
| 2738 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2739 | 'SUCCESS') |
| 2740 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2741 | 'SUCCESS') |
| 2742 | self.assertEqual(B.data['status'], 'MERGED') |
| 2743 | self.assertEqual(B.reported, 2) |
| 2744 | |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2745 | def test_tags(self): |
| 2746 | "Test job tags" |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2747 | self.updateConfigLayout('layout-tags') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2748 | self.sched.reconfigure(self.config) |
| 2749 | |
| 2750 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2751 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2752 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2753 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2754 | self.waitUntilSettled() |
| 2755 | |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2756 | self.assertEqual(len(self.history), 8) |
| 2757 | |
| 2758 | results = {self.getJobFromHistory('merge', |
| 2759 | project='org/project1').uuid: 'extratag merge', |
| 2760 | self.getJobFromHistory('merge', |
| 2761 | project='org/project2').uuid: 'merge'} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2762 | |
| 2763 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2764 | self.assertEqual(results.get(build.uuid, ''), |
| 2765 | build.parameters['vars']['zuul'].get('tags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2766 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2767 | def test_timer(self): |
| 2768 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2769 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2770 | self.updateConfigLayout('layout-timer') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2771 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2772 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2773 | # The pipeline triggers every second, so we should have seen |
| 2774 | # several by now. |
| 2775 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2776 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2777 | |
| 2778 | self.assertEqual(len(self.builds), 2) |
| 2779 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2780 | port = self.webapp.server.socket.getsockname()[1] |
| 2781 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2782 | req = urllib.request.Request( |
| 2783 | "http://localhost:%s/openstack/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2784 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2785 | data = f.read() |
| 2786 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2787 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2788 | # Stop queuing timer triggered jobs so that the assertions |
| 2789 | # below don't race against more jobs being queued. |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2790 | self.commitLayoutUpdate('layout-timer', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2791 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2792 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2793 | self.waitUntilSettled() |
| 2794 | |
| 2795 | self.assertEqual(self.getJobFromHistory( |
| 2796 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2797 | self.assertEqual(self.getJobFromHistory( |
| 2798 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2799 | |
| 2800 | data = json.loads(data) |
| 2801 | status_jobs = set() |
| 2802 | for p in data['pipelines']: |
| 2803 | for q in p['change_queues']: |
| 2804 | for head in q['heads']: |
| 2805 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2806 | for job in change['jobs']: |
| 2807 | status_jobs.add(job['name']) |
| 2808 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2809 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2810 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2811 | def test_idle(self): |
| 2812 | "Test that frequent periodic jobs work" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2813 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2814 | self.updateConfigLayout('layout-idle') |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2815 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2816 | for x in range(1, 3): |
| 2817 | # Test that timer triggers periodic jobs even across |
| 2818 | # layout config reloads. |
| 2819 | # Start timer trigger |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2820 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2821 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2822 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2823 | # The pipeline triggers every second, so we should have seen |
| 2824 | # several by now. |
| 2825 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2826 | |
| 2827 | # Stop queuing timer triggered jobs so that the assertions |
| 2828 | # below don't race against more jobs being queued. |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2829 | before = self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2830 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2831 | self.waitUntilSettled() |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2832 | self.assertEqual(len(self.builds), 2, |
| 2833 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2834 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2835 | self.waitUntilSettled() |
| 2836 | self.assertEqual(len(self.builds), 0) |
| 2837 | self.assertEqual(len(self.history), x * 2) |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2838 | # Revert back to layout-idle |
| 2839 | repo = git.Repo(os.path.join(self.test_root, |
| 2840 | 'upstream', |
| 2841 | 'layout-idle')) |
| 2842 | repo.git.reset('--hard', before) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2843 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2844 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 2845 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2846 | self.sched.reconfigure(self.config) |
| 2847 | |
| 2848 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2849 | self.waitUntilSettled() |
| 2850 | |
| 2851 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2852 | self.waitUntilSettled() |
| 2853 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2854 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2855 | |
| 2856 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2857 | # work on the knowledge of what the first message should be as |
| 2858 | # it is only configured to go to SMTP. |
| 2859 | |
| 2860 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2861 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2862 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2863 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2864 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2865 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2866 | |
| 2867 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2868 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2869 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2870 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2871 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2872 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2873 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2874 | def test_timer_smtp(self): |
| 2875 | "Test that a periodic job is triggered" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2876 | self.executor_server.hold_jobs_in_build = True |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 2877 | self.updateConfigLayout('layout-timer-smtp') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2878 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2879 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2880 | # The pipeline triggers every second, so we should have seen |
| 2881 | # several by now. |
| 2882 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2883 | self.waitUntilSettled() |
| 2884 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2885 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2886 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2887 | self.waitUntilSettled() |
| 2888 | self.assertEqual(len(self.history), 2) |
| 2889 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2890 | self.assertEqual(self.getJobFromHistory( |
| 2891 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2892 | self.assertEqual(self.getJobFromHistory( |
| 2893 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2894 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2895 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2896 | |
| 2897 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2898 | # work on the knowledge of what the first message should be as |
| 2899 | # it is only configured to go to SMTP. |
| 2900 | |
| 2901 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2902 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2903 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2904 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2905 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2906 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2907 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2908 | # Stop queuing timer triggered jobs and let any that may have |
| 2909 | # queued through so that end of test assertions pass. |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 2910 | self.commitLayoutUpdate('layout-timer-smtp', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2911 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 2912 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2913 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2914 | self.waitUntilSettled() |
| 2915 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 2916 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 2917 | def test_timer_sshkey(self): |
| 2918 | "Test that a periodic job can setup SSH key authentication" |
| 2919 | self.worker.hold_jobs_in_build = True |
| 2920 | self.config.set('zuul', 'layout_config', |
| 2921 | 'tests/fixtures/layout-timer.yaml') |
| 2922 | self.sched.reconfigure(self.config) |
| 2923 | self.registerJobs() |
| 2924 | |
| 2925 | # The pipeline triggers every second, so we should have seen |
| 2926 | # several by now. |
| 2927 | time.sleep(5) |
| 2928 | self.waitUntilSettled() |
| 2929 | |
| 2930 | self.assertEqual(len(self.builds), 2) |
| 2931 | |
| 2932 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 2933 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 2934 | with open(ssh_wrapper) as f: |
| 2935 | ssh_wrapper_content = f.read() |
| 2936 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 2937 | # In the unit tests Merger runs in the same process, |
| 2938 | # so we see its' environment variables |
| 2939 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 2940 | |
| 2941 | self.worker.release('.*') |
| 2942 | self.waitUntilSettled() |
| 2943 | self.assertEqual(len(self.history), 2) |
| 2944 | |
| 2945 | self.assertEqual(self.getJobFromHistory( |
| 2946 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2947 | self.assertEqual(self.getJobFromHistory( |
| 2948 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2949 | |
| 2950 | # Stop queuing timer triggered jobs and let any that may have |
| 2951 | # queued through so that end of test assertions pass. |
| 2952 | self.config.set('zuul', 'layout_config', |
| 2953 | 'tests/fixtures/layout-no-timer.yaml') |
| 2954 | self.sched.reconfigure(self.config) |
| 2955 | self.registerJobs() |
| 2956 | self.waitUntilSettled() |
| 2957 | self.worker.release('.*') |
| 2958 | self.waitUntilSettled() |
| 2959 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2960 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2961 | "Test that the RPC client can enqueue a change" |
| 2962 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2963 | A.addApproval('code-review', 2) |
| 2964 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2965 | |
| 2966 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2967 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2968 | r = client.enqueue(tenant='tenant-one', |
| 2969 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2970 | project='org/project', |
| 2971 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2972 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2973 | self.waitUntilSettled() |
| 2974 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2975 | 'SUCCESS') |
| 2976 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2977 | 'SUCCESS') |
| 2978 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2979 | 'SUCCESS') |
| 2980 | self.assertEqual(A.data['status'], 'MERGED') |
| 2981 | self.assertEqual(A.reported, 2) |
| 2982 | self.assertEqual(r, True) |
| 2983 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2984 | def test_client_enqueue_ref(self): |
| 2985 | "Test that the RPC client can enqueue a ref" |
| 2986 | |
| 2987 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2988 | self.gearman_server.port) |
| 2989 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2990 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2991 | pipeline='post', |
| 2992 | project='org/project', |
| 2993 | trigger='gerrit', |
| 2994 | ref='master', |
| 2995 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 2996 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 2997 | self.waitUntilSettled() |
| 2998 | job_names = [x.name for x in self.history] |
| 2999 | self.assertEqual(len(self.history), 1) |
| 3000 | self.assertIn('project-post', job_names) |
| 3001 | self.assertEqual(r, True) |
| 3002 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3003 | def test_client_enqueue_negative(self): |
| 3004 | "Test that the RPC client returns errors" |
| 3005 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3006 | self.gearman_server.port) |
| 3007 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3008 | "Invalid tenant"): |
| 3009 | r = client.enqueue(tenant='tenant-foo', |
| 3010 | pipeline='gate', |
| 3011 | project='org/project', |
| 3012 | trigger='gerrit', |
| 3013 | change='1,1') |
| 3014 | client.shutdown() |
| 3015 | self.assertEqual(r, False) |
| 3016 | |
| 3017 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3018 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3019 | r = client.enqueue(tenant='tenant-one', |
| 3020 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3021 | project='project-does-not-exist', |
| 3022 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3023 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3024 | client.shutdown() |
| 3025 | self.assertEqual(r, False) |
| 3026 | |
| 3027 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3028 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3029 | r = client.enqueue(tenant='tenant-one', |
| 3030 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3031 | project='org/project', |
| 3032 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3033 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3034 | client.shutdown() |
| 3035 | self.assertEqual(r, False) |
| 3036 | |
| 3037 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3038 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3039 | r = client.enqueue(tenant='tenant-one', |
| 3040 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3041 | project='org/project', |
| 3042 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3043 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3044 | client.shutdown() |
| 3045 | self.assertEqual(r, False) |
| 3046 | |
| 3047 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3048 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3049 | r = client.enqueue(tenant='tenant-one', |
| 3050 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3051 | project='org/project', |
| 3052 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3053 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3054 | client.shutdown() |
| 3055 | self.assertEqual(r, False) |
| 3056 | |
| 3057 | self.waitUntilSettled() |
| 3058 | self.assertEqual(len(self.history), 0) |
| 3059 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3060 | |
| 3061 | def test_client_promote(self): |
| 3062 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3063 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3064 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3065 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3066 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3067 | A.addApproval('code-review', 2) |
| 3068 | B.addApproval('code-review', 2) |
| 3069 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3070 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3071 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3072 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3073 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3074 | |
| 3075 | self.waitUntilSettled() |
| 3076 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3077 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3078 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3079 | enqueue_times = {} |
| 3080 | for item in items: |
| 3081 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3082 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3083 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3084 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3085 | r = client.promote(tenant='tenant-one', |
| 3086 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3087 | change_ids=['2,1', '3,1']) |
| 3088 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3089 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3090 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3091 | for item in items: |
| 3092 | self.assertEqual( |
| 3093 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3094 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3095 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3096 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3097 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3098 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3099 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3100 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3101 | self.waitUntilSettled() |
| 3102 | |
| 3103 | self.assertEqual(len(self.builds), 6) |
| 3104 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3105 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3106 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3107 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3108 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3109 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3110 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3111 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3112 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3113 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3114 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3115 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3116 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3117 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3118 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3119 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3120 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3121 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3122 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3123 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3124 | self.waitUntilSettled() |
| 3125 | |
| 3126 | self.assertEqual(A.data['status'], 'MERGED') |
| 3127 | self.assertEqual(A.reported, 2) |
| 3128 | self.assertEqual(B.data['status'], 'MERGED') |
| 3129 | self.assertEqual(B.reported, 2) |
| 3130 | self.assertEqual(C.data['status'], 'MERGED') |
| 3131 | self.assertEqual(C.reported, 2) |
| 3132 | |
| 3133 | client.shutdown() |
| 3134 | self.assertEqual(r, True) |
| 3135 | |
| 3136 | def test_client_promote_dependent(self): |
| 3137 | "Test that the RPC client can promote a dependent change" |
| 3138 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3139 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3140 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3141 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3142 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3143 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3144 | |
| 3145 | C.setDependsOn(B, 1) |
| 3146 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3147 | A.addApproval('code-review', 2) |
| 3148 | B.addApproval('code-review', 2) |
| 3149 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3150 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3151 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3152 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3153 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3154 | |
| 3155 | self.waitUntilSettled() |
| 3156 | |
| 3157 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3158 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3159 | r = client.promote(tenant='tenant-one', |
| 3160 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3161 | change_ids=['3,1']) |
| 3162 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3163 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3164 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3165 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3166 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3167 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3168 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3169 | self.waitUntilSettled() |
| 3170 | |
| 3171 | self.assertEqual(len(self.builds), 6) |
| 3172 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3173 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3174 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3175 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3176 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3177 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3178 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3179 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3180 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3181 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3182 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3183 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3184 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3185 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3186 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3187 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3188 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3189 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3190 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3191 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3192 | self.waitUntilSettled() |
| 3193 | |
| 3194 | self.assertEqual(A.data['status'], 'MERGED') |
| 3195 | self.assertEqual(A.reported, 2) |
| 3196 | self.assertEqual(B.data['status'], 'MERGED') |
| 3197 | self.assertEqual(B.reported, 2) |
| 3198 | self.assertEqual(C.data['status'], 'MERGED') |
| 3199 | self.assertEqual(C.reported, 2) |
| 3200 | |
| 3201 | client.shutdown() |
| 3202 | self.assertEqual(r, True) |
| 3203 | |
| 3204 | def test_client_promote_negative(self): |
| 3205 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3206 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3207 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3208 | A.addApproval('code-review', 2) |
| 3209 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3210 | self.waitUntilSettled() |
| 3211 | |
| 3212 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3213 | self.gearman_server.port) |
| 3214 | |
| 3215 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3216 | r = client.promote(tenant='tenant-one', |
| 3217 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3218 | change_ids=['2,1', '3,1']) |
| 3219 | client.shutdown() |
| 3220 | self.assertEqual(r, False) |
| 3221 | |
| 3222 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3223 | r = client.promote(tenant='tenant-one', |
| 3224 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3225 | change_ids=['4,1']) |
| 3226 | client.shutdown() |
| 3227 | self.assertEqual(r, False) |
| 3228 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3229 | self.executor_server.hold_jobs_in_build = False |
| 3230 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3231 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3232 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3233 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3234 | def test_queue_rate_limiting(self): |
| 3235 | "Test that DependentPipelines are rate limited with dep across window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3236 | self.updateConfigLayout( |
| 3237 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3238 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3239 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3240 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3241 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3242 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3243 | |
| 3244 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3245 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3246 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3247 | A.addApproval('code-review', 2) |
| 3248 | B.addApproval('code-review', 2) |
| 3249 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3250 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3251 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3252 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3253 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3254 | self.waitUntilSettled() |
| 3255 | |
| 3256 | # Only A and B will have their merge jobs queued because |
| 3257 | # window is 2. |
| 3258 | self.assertEqual(len(self.builds), 2) |
| 3259 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3260 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3261 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3262 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3263 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3264 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3265 | self.waitUntilSettled() |
| 3266 | |
| 3267 | # Only A and B will have their test jobs queued because |
| 3268 | # window is 2. |
| 3269 | self.assertEqual(len(self.builds), 4) |
| 3270 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3271 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3272 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3273 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3274 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3275 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3276 | self.waitUntilSettled() |
| 3277 | |
| 3278 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3279 | # A failed so window is reduced by 1 to 1. |
| 3280 | self.assertEqual(queue.window, 1) |
| 3281 | self.assertEqual(queue.window_floor, 1) |
| 3282 | self.assertEqual(A.data['status'], 'NEW') |
| 3283 | |
| 3284 | # Gate is reset and only B's merge job is queued because |
| 3285 | # window shrunk to 1. |
| 3286 | self.assertEqual(len(self.builds), 1) |
| 3287 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3288 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3289 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3290 | self.waitUntilSettled() |
| 3291 | |
| 3292 | # Only B's test jobs are queued because window is still 1. |
| 3293 | self.assertEqual(len(self.builds), 2) |
| 3294 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3295 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3296 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3297 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3298 | self.waitUntilSettled() |
| 3299 | |
| 3300 | # B was successfully merged so window is increased to 2. |
| 3301 | self.assertEqual(queue.window, 2) |
| 3302 | self.assertEqual(queue.window_floor, 1) |
| 3303 | self.assertEqual(B.data['status'], 'MERGED') |
| 3304 | |
| 3305 | # Only C is left and its merge job is queued. |
| 3306 | self.assertEqual(len(self.builds), 1) |
| 3307 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3308 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3309 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3310 | self.waitUntilSettled() |
| 3311 | |
| 3312 | # After successful merge job the test jobs for C are queued. |
| 3313 | self.assertEqual(len(self.builds), 2) |
| 3314 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3315 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3316 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3317 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3318 | self.waitUntilSettled() |
| 3319 | |
| 3320 | # C successfully merged so window is bumped to 3. |
| 3321 | self.assertEqual(queue.window, 3) |
| 3322 | self.assertEqual(queue.window_floor, 1) |
| 3323 | self.assertEqual(C.data['status'], 'MERGED') |
| 3324 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3325 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3326 | def test_queue_rate_limiting_dependent(self): |
| 3327 | "Test that DependentPipelines are rate limited with dep in window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3328 | self.updateConfigLayout( |
| 3329 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3330 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3331 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3332 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3333 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3334 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3335 | |
| 3336 | B.setDependsOn(A, 1) |
| 3337 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3338 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3339 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3340 | A.addApproval('code-review', 2) |
| 3341 | B.addApproval('code-review', 2) |
| 3342 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3343 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3344 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3345 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3346 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3347 | self.waitUntilSettled() |
| 3348 | |
| 3349 | # Only A and B will have their merge jobs queued because |
| 3350 | # window is 2. |
| 3351 | self.assertEqual(len(self.builds), 2) |
| 3352 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3353 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3354 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3355 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3356 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3357 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3358 | self.waitUntilSettled() |
| 3359 | |
| 3360 | # Only A and B will have their test jobs queued because |
| 3361 | # window is 2. |
| 3362 | self.assertEqual(len(self.builds), 4) |
| 3363 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3364 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3365 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3366 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3367 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3368 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3369 | self.waitUntilSettled() |
| 3370 | |
| 3371 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3372 | # A failed so window is reduced by 1 to 1. |
| 3373 | self.assertEqual(queue.window, 1) |
| 3374 | self.assertEqual(queue.window_floor, 1) |
| 3375 | self.assertEqual(A.data['status'], 'NEW') |
| 3376 | self.assertEqual(B.data['status'], 'NEW') |
| 3377 | |
| 3378 | # Gate is reset and only C's merge job is queued because |
| 3379 | # window shrunk to 1 and A and B were dequeued. |
| 3380 | self.assertEqual(len(self.builds), 1) |
| 3381 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3382 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3383 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3384 | self.waitUntilSettled() |
| 3385 | |
| 3386 | # Only C's test jobs are queued because window is still 1. |
| 3387 | self.assertEqual(len(self.builds), 2) |
| 3388 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3389 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3390 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3391 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3392 | self.waitUntilSettled() |
| 3393 | |
| 3394 | # C was successfully merged so window is increased to 2. |
| 3395 | self.assertEqual(queue.window, 2) |
| 3396 | self.assertEqual(queue.window_floor, 1) |
| 3397 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3398 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3399 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3400 | def test_worker_update_metadata(self): |
| 3401 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3402 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3403 | |
| 3404 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3405 | A.addApproval('code-review', 2) |
| 3406 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3407 | self.waitUntilSettled() |
| 3408 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3409 | self.assertEqual(len(self.executor.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3410 | |
| 3411 | self.log.debug('Current builds:') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3412 | self.log.debug(self.executor.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3413 | |
| 3414 | start = time.time() |
| 3415 | while True: |
| 3416 | if time.time() - start > 10: |
| 3417 | raise Exception("Timeout waiting for gearman server to report " |
| 3418 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3419 | build = self.executor.builds.values()[0] |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3420 | if build.worker.name == "My Worker": |
| 3421 | break |
| 3422 | else: |
| 3423 | time.sleep(0) |
| 3424 | |
| 3425 | self.log.debug(build) |
| 3426 | self.assertEqual("My Worker", build.worker.name) |
| 3427 | self.assertEqual("localhost", build.worker.hostname) |
| 3428 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3429 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3430 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3431 | self.assertEqual("v1.1", build.worker.version) |
| 3432 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3433 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3434 | self.executor_server.hold_jobs_in_build = False |
| 3435 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3436 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3437 | |
| 3438 | def test_footer_message(self): |
| 3439 | "Test a pipeline's footer message is correctly added to the report." |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3440 | self.updateConfigLayout('layout-footer-message') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3441 | self.sched.reconfigure(self.config) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3442 | |
| 3443 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3444 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3445 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3446 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3447 | self.waitUntilSettled() |
| 3448 | |
| 3449 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3450 | B.addApproval('code-review', 2) |
| 3451 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3452 | self.waitUntilSettled() |
| 3453 | |
| 3454 | self.assertEqual(2, len(self.smtp_messages)) |
| 3455 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3456 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3457 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3458 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3459 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3460 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3461 | For CI problems and help debugging, contact ci@example.org""" |
| 3462 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3463 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3464 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3465 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3466 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3467 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3468 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3469 | def test_merge_failure_reporters(self): |
| 3470 | """Check that the config is set up correctly""" |
| 3471 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3472 | self.updateConfigLayout( |
| 3473 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3474 | self.sched.reconfigure(self.config) |
| 3475 | self.registerJobs() |
| 3476 | |
| 3477 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3478 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3479 | "dependencies was unable to be automatically merged with the " |
| 3480 | "current state of its repository. Please rebase the change and " |
| 3481 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3482 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3483 | self.assertEqual( |
| 3484 | "The merge failed! For more information...", |
| 3485 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3486 | |
| 3487 | self.assertEqual( |
| 3488 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3489 | self.assertEqual( |
| 3490 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3491 | |
| 3492 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3493 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3494 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3495 | |
| 3496 | self.assertTrue( |
| 3497 | ( |
| 3498 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3499 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3500 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3501 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3502 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3503 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3504 | ) or ( |
| 3505 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3506 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3507 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3508 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3509 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3510 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3511 | ) |
| 3512 | ) |
| 3513 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3514 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3515 | def test_merge_failure_reports(self): |
| 3516 | """Check that when a change fails to merge the correct message is sent |
| 3517 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3518 | self.updateConfigLayout( |
| 3519 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3520 | self.sched.reconfigure(self.config) |
| 3521 | self.registerJobs() |
| 3522 | |
| 3523 | # Check a test failure isn't reported to SMTP |
| 3524 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3525 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3526 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3527 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3528 | self.waitUntilSettled() |
| 3529 | |
| 3530 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3531 | self.assertEqual(0, len(self.smtp_messages)) |
| 3532 | |
| 3533 | # Check a merge failure is reported to SMTP |
| 3534 | # B should be merged, but C will conflict with B |
| 3535 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3536 | B.addPatchset(['conflict']) |
| 3537 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3538 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3539 | B.addApproval('code-review', 2) |
| 3540 | C.addApproval('code-review', 2) |
| 3541 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3542 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3543 | self.waitUntilSettled() |
| 3544 | |
| 3545 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3546 | self.assertEqual(1, len(self.smtp_messages)) |
| 3547 | self.assertEqual('The merge failed! For more information...', |
| 3548 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3549 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3550 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3551 | def test_default_merge_failure_reports(self): |
| 3552 | """Check that the default merge failure reports are correct.""" |
| 3553 | |
| 3554 | # A should report success, B should report merge failure. |
| 3555 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3556 | A.addPatchset(['conflict']) |
| 3557 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3558 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3559 | A.addApproval('code-review', 2) |
| 3560 | B.addApproval('code-review', 2) |
| 3561 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3562 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3563 | self.waitUntilSettled() |
| 3564 | |
| 3565 | self.assertEqual(3, len(self.history)) # A jobs |
| 3566 | self.assertEqual(A.reported, 2) |
| 3567 | self.assertEqual(B.reported, 2) |
| 3568 | self.assertEqual(A.data['status'], 'MERGED') |
| 3569 | self.assertEqual(B.data['status'], 'NEW') |
| 3570 | self.assertIn('Build succeeded', A.messages[1]) |
| 3571 | self.assertIn('Merge Failed', B.messages[1]) |
| 3572 | self.assertIn('automatically merged', B.messages[1]) |
| 3573 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3574 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3575 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3576 | def test_client_get_running_jobs(self): |
| 3577 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3578 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3579 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3580 | A.addApproval('code-review', 2) |
| 3581 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3582 | self.waitUntilSettled() |
| 3583 | |
| 3584 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3585 | self.gearman_server.port) |
| 3586 | |
| 3587 | # Wait for gearman server to send the initial workData back to zuul |
| 3588 | start = time.time() |
| 3589 | while True: |
| 3590 | if time.time() - start > 10: |
| 3591 | raise Exception("Timeout waiting for gearman server to report " |
| 3592 | + "back to the client") |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3593 | build = self.executor_client.builds.values()[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3594 | if build.worker.name == "My Worker": |
| 3595 | break |
| 3596 | else: |
| 3597 | time.sleep(0) |
| 3598 | |
| 3599 | running_items = client.get_running_jobs() |
| 3600 | |
| 3601 | self.assertEqual(1, len(running_items)) |
| 3602 | running_item = running_items[0] |
| 3603 | self.assertEqual([], running_item['failing_reasons']) |
| 3604 | self.assertEqual([], running_item['items_behind']) |
| 3605 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3606 | self.assertEqual(None, running_item['item_ahead']) |
| 3607 | self.assertEqual('org/project', running_item['project']) |
| 3608 | self.assertEqual(None, running_item['remaining_time']) |
| 3609 | self.assertEqual(True, running_item['active']) |
| 3610 | self.assertEqual('1,1', running_item['id']) |
| 3611 | |
| 3612 | self.assertEqual(3, len(running_item['jobs'])) |
| 3613 | for job in running_item['jobs']: |
| 3614 | if job['name'] == 'project-merge': |
| 3615 | self.assertEqual('project-merge', job['name']) |
| 3616 | self.assertEqual('gate', job['pipeline']) |
| 3617 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3618 | self.assertEqual('https://server/job/project-merge/0/', |
| 3619 | job['url']) |
| 3620 | self.assertEqual(7, len(job['worker'])) |
| 3621 | self.assertEqual(False, job['canceled']) |
| 3622 | self.assertEqual(True, job['voting']) |
| 3623 | self.assertEqual(None, job['result']) |
| 3624 | self.assertEqual('gate', job['pipeline']) |
| 3625 | break |
| 3626 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3627 | self.executor_server.hold_jobs_in_build = False |
| 3628 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3629 | self.waitUntilSettled() |
| 3630 | |
| 3631 | running_items = client.get_running_jobs() |
| 3632 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3633 | |
| 3634 | def test_nonvoting_pipeline(self): |
| 3635 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3636 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3637 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3638 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3639 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3640 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3641 | |
| 3642 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3643 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3644 | self.assertEqual( |
| 3645 | self.getJobFromHistory('experimental-project-test').result, |
| 3646 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3647 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3648 | |
| 3649 | def test_crd_gate(self): |
| 3650 | "Test cross-repo dependencies" |
| 3651 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3652 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3653 | A.addApproval('code-review', 2) |
| 3654 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3655 | |
| 3656 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3657 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3658 | AM2.setMerged() |
| 3659 | AM1.setMerged() |
| 3660 | |
| 3661 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3662 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3663 | BM2.setMerged() |
| 3664 | BM1.setMerged() |
| 3665 | |
| 3666 | # A -> AM1 -> AM2 |
| 3667 | # B -> BM1 -> BM2 |
| 3668 | # A Depends-On: B |
| 3669 | # M2 is here to make sure it is never queried. If it is, it |
| 3670 | # means zuul is walking down the entire history of merged |
| 3671 | # changes. |
| 3672 | |
| 3673 | B.setDependsOn(BM1, 1) |
| 3674 | BM1.setDependsOn(BM2, 1) |
| 3675 | |
| 3676 | A.setDependsOn(AM1, 1) |
| 3677 | AM1.setDependsOn(AM2, 1) |
| 3678 | |
| 3679 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3680 | A.subject, B.data['id']) |
| 3681 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3682 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3683 | self.waitUntilSettled() |
| 3684 | |
| 3685 | self.assertEqual(A.data['status'], 'NEW') |
| 3686 | self.assertEqual(B.data['status'], 'NEW') |
| 3687 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3688 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3689 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3690 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3691 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3692 | B.addApproval('approved', 1) |
| 3693 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3694 | self.waitUntilSettled() |
| 3695 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3696 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3697 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3698 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3699 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3700 | self.executor_server.hold_jobs_in_build = False |
| 3701 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3702 | self.waitUntilSettled() |
| 3703 | |
| 3704 | self.assertEqual(AM2.queried, 0) |
| 3705 | self.assertEqual(BM2.queried, 0) |
| 3706 | self.assertEqual(A.data['status'], 'MERGED') |
| 3707 | self.assertEqual(B.data['status'], 'MERGED') |
| 3708 | self.assertEqual(A.reported, 2) |
| 3709 | self.assertEqual(B.reported, 2) |
| 3710 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3711 | changes = self.getJobFromHistory( |
| 3712 | 'project-merge', 'org/project1').changes |
| 3713 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3714 | |
| 3715 | def test_crd_branch(self): |
| 3716 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3717 | |
| 3718 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3719 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3720 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3721 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3722 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3723 | A.addApproval('code-review', 2) |
| 3724 | B.addApproval('code-review', 2) |
| 3725 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3726 | |
| 3727 | # A Depends-On: B+C |
| 3728 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3729 | A.subject, B.data['id']) |
| 3730 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3731 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3732 | B.addApproval('approved', 1) |
| 3733 | C.addApproval('approved', 1) |
| 3734 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3735 | self.waitUntilSettled() |
| 3736 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3737 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3738 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3739 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3740 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3741 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3742 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3743 | self.executor_server.hold_jobs_in_build = False |
| 3744 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3745 | self.waitUntilSettled() |
| 3746 | |
| 3747 | self.assertEqual(A.data['status'], 'MERGED') |
| 3748 | self.assertEqual(B.data['status'], 'MERGED') |
| 3749 | self.assertEqual(C.data['status'], 'MERGED') |
| 3750 | self.assertEqual(A.reported, 2) |
| 3751 | self.assertEqual(B.reported, 2) |
| 3752 | self.assertEqual(C.reported, 2) |
| 3753 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3754 | changes = self.getJobFromHistory( |
| 3755 | 'project-merge', 'org/project1').changes |
| 3756 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3757 | |
| 3758 | def test_crd_multiline(self): |
| 3759 | "Test multiple depends-on lines in commit" |
| 3760 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3761 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3762 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3763 | A.addApproval('code-review', 2) |
| 3764 | B.addApproval('code-review', 2) |
| 3765 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3766 | |
| 3767 | # A Depends-On: B+C |
| 3768 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3769 | A.subject, B.data['id'], C.data['id']) |
| 3770 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3771 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3772 | B.addApproval('approved', 1) |
| 3773 | C.addApproval('approved', 1) |
| 3774 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3775 | self.waitUntilSettled() |
| 3776 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3777 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3778 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3779 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3780 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3781 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3782 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3783 | self.executor_server.hold_jobs_in_build = False |
| 3784 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3785 | self.waitUntilSettled() |
| 3786 | |
| 3787 | self.assertEqual(A.data['status'], 'MERGED') |
| 3788 | self.assertEqual(B.data['status'], 'MERGED') |
| 3789 | self.assertEqual(C.data['status'], 'MERGED') |
| 3790 | self.assertEqual(A.reported, 2) |
| 3791 | self.assertEqual(B.reported, 2) |
| 3792 | self.assertEqual(C.reported, 2) |
| 3793 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3794 | changes = self.getJobFromHistory( |
| 3795 | 'project-merge', 'org/project1').changes |
| 3796 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3797 | |
| 3798 | def test_crd_unshared_gate(self): |
| 3799 | "Test cross-repo dependencies in unshared gate queues" |
| 3800 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3801 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3802 | A.addApproval('code-review', 2) |
| 3803 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3804 | |
| 3805 | # A Depends-On: B |
| 3806 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3807 | A.subject, B.data['id']) |
| 3808 | |
| 3809 | # A and B do not share a queue, make sure that A is unable to |
| 3810 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3811 | B.addApproval('approved', 1) |
| 3812 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3813 | self.waitUntilSettled() |
| 3814 | |
| 3815 | self.assertEqual(A.data['status'], 'NEW') |
| 3816 | self.assertEqual(B.data['status'], 'NEW') |
| 3817 | self.assertEqual(A.reported, 0) |
| 3818 | self.assertEqual(B.reported, 0) |
| 3819 | self.assertEqual(len(self.history), 0) |
| 3820 | |
| 3821 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3822 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3823 | self.waitUntilSettled() |
| 3824 | |
| 3825 | self.assertEqual(B.data['status'], 'MERGED') |
| 3826 | self.assertEqual(B.reported, 2) |
| 3827 | |
| 3828 | # Now that B is merged, A should be able to be enqueued and |
| 3829 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3830 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3831 | self.waitUntilSettled() |
| 3832 | |
| 3833 | self.assertEqual(A.data['status'], 'MERGED') |
| 3834 | self.assertEqual(A.reported, 2) |
| 3835 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3836 | def test_crd_gate_reverse(self): |
| 3837 | "Test reverse cross-repo dependencies" |
| 3838 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3839 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3840 | A.addApproval('code-review', 2) |
| 3841 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3842 | |
| 3843 | # A Depends-On: B |
| 3844 | |
| 3845 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3846 | A.subject, B.data['id']) |
| 3847 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3848 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3849 | self.waitUntilSettled() |
| 3850 | |
| 3851 | self.assertEqual(A.data['status'], 'NEW') |
| 3852 | self.assertEqual(B.data['status'], 'NEW') |
| 3853 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3854 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3855 | A.addApproval('approved', 1) |
| 3856 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3857 | self.waitUntilSettled() |
| 3858 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3859 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3860 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3861 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3862 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3863 | self.executor_server.hold_jobs_in_build = False |
| 3864 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3865 | self.waitUntilSettled() |
| 3866 | |
| 3867 | self.assertEqual(A.data['status'], 'MERGED') |
| 3868 | self.assertEqual(B.data['status'], 'MERGED') |
| 3869 | self.assertEqual(A.reported, 2) |
| 3870 | self.assertEqual(B.reported, 2) |
| 3871 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3872 | changes = self.getJobFromHistory( |
| 3873 | 'project-merge', 'org/project1').changes |
| 3874 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3875 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3876 | def test_crd_cycle(self): |
| 3877 | "Test cross-repo dependency cycles" |
| 3878 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3879 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3880 | A.addApproval('code-review', 2) |
| 3881 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3882 | |
| 3883 | # A -> B -> A (via commit-depends) |
| 3884 | |
| 3885 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3886 | A.subject, B.data['id']) |
| 3887 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3888 | B.subject, A.data['id']) |
| 3889 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3890 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3891 | self.waitUntilSettled() |
| 3892 | |
| 3893 | self.assertEqual(A.reported, 0) |
| 3894 | self.assertEqual(B.reported, 0) |
| 3895 | self.assertEqual(A.data['status'], 'NEW') |
| 3896 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3897 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3898 | def test_crd_gate_unknown(self): |
| 3899 | "Test unknown projects in dependent pipeline" |
| 3900 | self.init_repo("org/unknown") |
| 3901 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3902 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3903 | A.addApproval('code-review', 2) |
| 3904 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3905 | |
| 3906 | # A Depends-On: B |
| 3907 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3908 | A.subject, B.data['id']) |
| 3909 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3910 | B.addApproval('approved', 1) |
| 3911 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3912 | self.waitUntilSettled() |
| 3913 | |
| 3914 | # Unknown projects cannot share a queue with any other |
| 3915 | # since they don't have common jobs with any other (they have no jobs). |
| 3916 | # Changes which depend on unknown project changes |
| 3917 | # should not be processed in dependent pipeline |
| 3918 | self.assertEqual(A.data['status'], 'NEW') |
| 3919 | self.assertEqual(B.data['status'], 'NEW') |
| 3920 | self.assertEqual(A.reported, 0) |
| 3921 | self.assertEqual(B.reported, 0) |
| 3922 | self.assertEqual(len(self.history), 0) |
| 3923 | |
| 3924 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3925 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3926 | B.setMerged() |
| 3927 | self.waitUntilSettled() |
| 3928 | self.assertEqual(len(self.history), 0) |
| 3929 | |
| 3930 | # Now that B is merged, A should be able to be enqueued and |
| 3931 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3932 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3933 | self.waitUntilSettled() |
| 3934 | |
| 3935 | self.assertEqual(A.data['status'], 'MERGED') |
| 3936 | self.assertEqual(A.reported, 2) |
| 3937 | self.assertEqual(B.data['status'], 'MERGED') |
| 3938 | self.assertEqual(B.reported, 0) |
| 3939 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3940 | def test_crd_check(self): |
| 3941 | "Test cross-repo dependencies in independent pipelines" |
| 3942 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3943 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3944 | self.gearman_server.hold_jobs_in_queue = True |
| 3945 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3946 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3947 | |
| 3948 | # A Depends-On: B |
| 3949 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3950 | A.subject, B.data['id']) |
| 3951 | |
| 3952 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3953 | self.waitUntilSettled() |
| 3954 | |
| 3955 | queue = self.gearman_server.getQueue() |
| 3956 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 3957 | self.gearman_server.hold_jobs_in_queue = False |
| 3958 | self.gearman_server.release() |
| 3959 | self.waitUntilSettled() |
| 3960 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3961 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3962 | self.waitUntilSettled() |
| 3963 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 3964 | 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] | 3965 | repo = git.Repo(path) |
| 3966 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 3967 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3968 | correct_messages = [ |
| 3969 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3970 | self.assertEqual(repo_messages, correct_messages) |
| 3971 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 3972 | 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] | 3973 | repo = git.Repo(path) |
| 3974 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 3975 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3976 | correct_messages = [ |
| 3977 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3978 | self.assertEqual(repo_messages, correct_messages) |
| 3979 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3980 | self.executor_server.hold_jobs_in_build = False |
| 3981 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3982 | self.waitUntilSettled() |
| 3983 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3984 | self.assertEqual(A.data['status'], 'NEW') |
| 3985 | self.assertEqual(B.data['status'], 'NEW') |
| 3986 | self.assertEqual(A.reported, 1) |
| 3987 | self.assertEqual(B.reported, 0) |
| 3988 | |
| 3989 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3990 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3991 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3992 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3993 | def test_crd_check_git_depends(self): |
| 3994 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 3995 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3996 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3997 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3998 | |
| 3999 | # Add two git-dependent changes and make sure they both report |
| 4000 | # success. |
| 4001 | B.setDependsOn(A, 1) |
| 4002 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4003 | self.waitUntilSettled() |
| 4004 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4005 | self.waitUntilSettled() |
| 4006 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4007 | self.orderedRelease() |
| 4008 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4009 | self.waitUntilSettled() |
| 4010 | |
| 4011 | self.assertEqual(A.data['status'], 'NEW') |
| 4012 | self.assertEqual(B.data['status'], 'NEW') |
| 4013 | self.assertEqual(A.reported, 1) |
| 4014 | self.assertEqual(B.reported, 1) |
| 4015 | |
| 4016 | self.assertEqual(self.history[0].changes, '1,1') |
| 4017 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4018 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4019 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4020 | |
| 4021 | self.assertIn('Build succeeded', A.messages[0]) |
| 4022 | self.assertIn('Build succeeded', B.messages[0]) |
| 4023 | |
| 4024 | def test_crd_check_duplicate(self): |
| 4025 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4026 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4027 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4028 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4029 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4030 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4031 | |
| 4032 | # Add two git-dependent changes... |
| 4033 | B.setDependsOn(A, 1) |
| 4034 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4035 | self.waitUntilSettled() |
| 4036 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4037 | |
| 4038 | # ...make sure the live one is not duplicated... |
| 4039 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4040 | self.waitUntilSettled() |
| 4041 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4042 | |
| 4043 | # ...but the non-live one is able to be. |
| 4044 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4045 | self.waitUntilSettled() |
| 4046 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4047 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4048 | # Release jobs in order to avoid races with change A jobs |
| 4049 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4050 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4051 | self.executor_server.hold_jobs_in_build = False |
| 4052 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4053 | self.waitUntilSettled() |
| 4054 | |
| 4055 | self.assertEqual(A.data['status'], 'NEW') |
| 4056 | self.assertEqual(B.data['status'], 'NEW') |
| 4057 | self.assertEqual(A.reported, 1) |
| 4058 | self.assertEqual(B.reported, 1) |
| 4059 | |
| 4060 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4061 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4062 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4063 | |
| 4064 | self.assertIn('Build succeeded', A.messages[0]) |
| 4065 | self.assertIn('Build succeeded', B.messages[0]) |
| 4066 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4067 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4068 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4069 | |
| 4070 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4071 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4072 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4073 | |
| 4074 | # A Depends-On: B |
| 4075 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4076 | A.subject, B.data['id']) |
| 4077 | |
| 4078 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4079 | self.waitUntilSettled() |
| 4080 | |
| 4081 | self.sched.reconfigure(self.config) |
| 4082 | |
| 4083 | # Make sure the items still share a change queue, and the |
| 4084 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4085 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4086 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4087 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4088 | first_item = queue.queue[0] |
| 4089 | for item in queue.queue: |
| 4090 | self.assertEqual(item.queue, first_item.queue) |
| 4091 | self.assertFalse(first_item.live) |
| 4092 | self.assertTrue(queue.queue[1].live) |
| 4093 | |
| 4094 | self.gearman_server.hold_jobs_in_queue = False |
| 4095 | self.gearman_server.release() |
| 4096 | self.waitUntilSettled() |
| 4097 | |
| 4098 | self.assertEqual(A.data['status'], 'NEW') |
| 4099 | self.assertEqual(B.data['status'], 'NEW') |
| 4100 | self.assertEqual(A.reported, 1) |
| 4101 | self.assertEqual(B.reported, 0) |
| 4102 | |
| 4103 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4104 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4105 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4106 | def test_crd_check_reconfiguration(self): |
| 4107 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4108 | |
| 4109 | def test_crd_undefined_project(self): |
| 4110 | """Test that undefined projects in dependencies are handled for |
| 4111 | independent pipelines""" |
| 4112 | # It's a hack for fake gerrit, |
| 4113 | # as it implies repo creation upon the creation of any change |
| 4114 | self.init_repo("org/unknown") |
| 4115 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4116 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4117 | @skip("Disabled for early v3 development") |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4118 | def test_crd_check_ignore_dependencies(self): |
| 4119 | "Test cross-repo dependencies can be ignored" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4120 | self.updateConfigLayout( |
| 4121 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4122 | self.sched.reconfigure(self.config) |
| 4123 | self.registerJobs() |
| 4124 | |
| 4125 | self.gearman_server.hold_jobs_in_queue = True |
| 4126 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4127 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4128 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4129 | |
| 4130 | # A Depends-On: B |
| 4131 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4132 | A.subject, B.data['id']) |
| 4133 | # C git-depends on B |
| 4134 | C.setDependsOn(B, 1) |
| 4135 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4136 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4137 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4138 | self.waitUntilSettled() |
| 4139 | |
| 4140 | # Make sure none of the items share a change queue, and all |
| 4141 | # are live. |
| 4142 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4143 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4144 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4145 | for item in check_pipeline.getAllItems(): |
| 4146 | self.assertTrue(item.live) |
| 4147 | |
| 4148 | self.gearman_server.hold_jobs_in_queue = False |
| 4149 | self.gearman_server.release() |
| 4150 | self.waitUntilSettled() |
| 4151 | |
| 4152 | self.assertEqual(A.data['status'], 'NEW') |
| 4153 | self.assertEqual(B.data['status'], 'NEW') |
| 4154 | self.assertEqual(C.data['status'], 'NEW') |
| 4155 | self.assertEqual(A.reported, 1) |
| 4156 | self.assertEqual(B.reported, 1) |
| 4157 | self.assertEqual(C.reported, 1) |
| 4158 | |
| 4159 | # Each job should have tested exactly one change |
| 4160 | for job in self.history: |
| 4161 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4162 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4163 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4164 | def test_crd_check_transitive(self): |
| 4165 | "Test transitive cross-repo dependencies" |
| 4166 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4167 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4168 | # and C,2 (not C,1 which would indicate stale data in the |
| 4169 | # cache for B). |
| 4170 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4171 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4172 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4173 | |
| 4174 | # A Depends-On: B |
| 4175 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4176 | A.subject, B.data['id']) |
| 4177 | |
| 4178 | # B Depends-On: C |
| 4179 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4180 | B.subject, C.data['id']) |
| 4181 | |
| 4182 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4183 | self.waitUntilSettled() |
| 4184 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4185 | |
| 4186 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4187 | self.waitUntilSettled() |
| 4188 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4189 | |
| 4190 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4191 | self.waitUntilSettled() |
| 4192 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4193 | |
| 4194 | C.addPatchset() |
| 4195 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4196 | self.waitUntilSettled() |
| 4197 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4198 | |
| 4199 | A.addPatchset() |
| 4200 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4201 | self.waitUntilSettled() |
| 4202 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4203 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4204 | def test_crd_check_unknown(self): |
| 4205 | "Test unknown projects in independent pipeline" |
| 4206 | self.init_repo("org/unknown") |
| 4207 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4208 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4209 | # A Depends-On: B |
| 4210 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4211 | A.subject, B.data['id']) |
| 4212 | |
| 4213 | # Make sure zuul has seen an event on B. |
| 4214 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4215 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4216 | self.waitUntilSettled() |
| 4217 | |
| 4218 | self.assertEqual(A.data['status'], 'NEW') |
| 4219 | self.assertEqual(A.reported, 1) |
| 4220 | self.assertEqual(B.data['status'], 'NEW') |
| 4221 | self.assertEqual(B.reported, 0) |
| 4222 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4223 | def test_crd_cycle_join(self): |
| 4224 | "Test an updated change creates a cycle" |
| 4225 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4226 | |
| 4227 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4228 | self.waitUntilSettled() |
| 4229 | |
| 4230 | # Create B->A |
| 4231 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4232 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4233 | B.subject, A.data['id']) |
| 4234 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4235 | self.waitUntilSettled() |
| 4236 | |
| 4237 | # Update A to add A->B (a cycle). |
| 4238 | A.addPatchset() |
| 4239 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4240 | A.subject, B.data['id']) |
| 4241 | # Normally we would submit the patchset-created event for |
| 4242 | # processing here, however, we have no way of noting whether |
| 4243 | # the dependency cycle detection correctly raised an |
| 4244 | # exception, so instead, we reach into the source driver and |
| 4245 | # call the method that would ultimately be called by the event |
| 4246 | # processing. |
| 4247 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4248 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4249 | source = tenant.layout.pipelines['gate'].source |
| 4250 | |
| 4251 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4252 | # it easier for users to create events for testing. |
| 4253 | event = zuul.model.TriggerEvent() |
| 4254 | event.trigger_name = 'gerrit' |
| 4255 | event.change_number = '1' |
| 4256 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4257 | with testtools.ExpectedException( |
| 4258 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4259 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4260 | self.log.debug("Got expected dependency cycle exception") |
| 4261 | |
| 4262 | # Now if we update B to remove the depends-on, everything |
| 4263 | # should be okay. B; A->B |
| 4264 | |
| 4265 | B.addPatchset() |
| 4266 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4267 | |
| 4268 | source.getChange(event, True) |
| 4269 | event.change_number = '2' |
| 4270 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4271 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4272 | def test_disable_at(self): |
| 4273 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4274 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4275 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4276 | self.sched.reconfigure(self.config) |
| 4277 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4278 | tenant = self.sched.abide.tenants.get('openstack') |
| 4279 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4280 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4281 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4282 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4283 | |
| 4284 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4285 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4286 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4287 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4288 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4289 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4290 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4291 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4292 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4293 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4294 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4295 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4296 | self.executor_server.failJob('project-test1', A) |
| 4297 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4298 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4299 | self.executor_server.failJob('project-test1', D) |
| 4300 | self.executor_server.failJob('project-test1', E) |
| 4301 | self.executor_server.failJob('project-test1', F) |
| 4302 | self.executor_server.failJob('project-test1', G) |
| 4303 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4304 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4305 | self.executor_server.failJob('project-test1', J) |
| 4306 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4307 | |
| 4308 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4309 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4310 | self.waitUntilSettled() |
| 4311 | |
| 4312 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4313 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4314 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4315 | |
| 4316 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4317 | self.waitUntilSettled() |
| 4318 | |
| 4319 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4320 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4321 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4322 | |
| 4323 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4324 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4325 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4326 | self.waitUntilSettled() |
| 4327 | |
| 4328 | # We should be disabled now |
| 4329 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4330 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4331 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4332 | |
| 4333 | # We need to wait between each of these patches to make sure the |
| 4334 | # smtp messages come back in an expected order |
| 4335 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4336 | self.waitUntilSettled() |
| 4337 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4338 | self.waitUntilSettled() |
| 4339 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4340 | self.waitUntilSettled() |
| 4341 | |
| 4342 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4343 | # leaving a message on each change |
| 4344 | self.assertEqual(1, len(A.messages)) |
| 4345 | self.assertIn('Build failed.', A.messages[0]) |
| 4346 | self.assertEqual(1, len(B.messages)) |
| 4347 | self.assertIn('Build failed.', B.messages[0]) |
| 4348 | self.assertEqual(1, len(C.messages)) |
| 4349 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4350 | self.assertEqual(1, len(D.messages)) |
| 4351 | self.assertIn('Build failed.', D.messages[0]) |
| 4352 | self.assertEqual(1, len(E.messages)) |
| 4353 | self.assertIn('Build failed.', E.messages[0]) |
| 4354 | self.assertEqual(1, len(F.messages)) |
| 4355 | self.assertIn('Build failed.', F.messages[0]) |
| 4356 | |
| 4357 | # The last 3 (GHI) would have only reported via smtp. |
| 4358 | self.assertEqual(3, len(self.smtp_messages)) |
| 4359 | self.assertEqual(0, len(G.messages)) |
| 4360 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4361 | self.assertIn( |
| 4362 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4363 | self.assertEqual(0, len(H.messages)) |
| 4364 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4365 | self.assertIn( |
| 4366 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4367 | self.assertEqual(0, len(I.messages)) |
| 4368 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4369 | self.assertIn( |
| 4370 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4371 | |
| 4372 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4373 | # comes out of disabled |
| 4374 | self.sched.reconfigure(self.config) |
| 4375 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4376 | tenant = self.sched.abide.tenants.get('openstack') |
| 4377 | |
| 4378 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4379 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4380 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4381 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4382 | |
| 4383 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4384 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4385 | self.waitUntilSettled() |
| 4386 | |
| 4387 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4388 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4389 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4390 | |
| 4391 | # J and K went back to gerrit |
| 4392 | self.assertEqual(1, len(J.messages)) |
| 4393 | self.assertIn('Build failed.', J.messages[0]) |
| 4394 | self.assertEqual(1, len(K.messages)) |
| 4395 | self.assertIn('Build failed.', K.messages[0]) |
| 4396 | # No more messages reported via smtp |
| 4397 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4398 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4399 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4400 | "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] | 4401 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4402 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4403 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4404 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4405 | self.waitUntilSettled() |
| 4406 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4407 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4408 | self.waitUntilSettled() |
| 4409 | |
| 4410 | self.assertEqual(len(self.builds), 2) |
| 4411 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4412 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4413 | self.waitUntilSettled() |
| 4414 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4415 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4416 | self.assertEqual(len(self.builds), 1, |
| 4417 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4418 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4419 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4420 | self.waitUntilSettled() |
| 4421 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4422 | self.executor_server.hold_jobs_in_build = False |
| 4423 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4424 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4425 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4426 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4427 | self.assertEqual(A.reported, 1) |
| 4428 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4429 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4430 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4431 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4432 | |
| 4433 | self.fake_nodepool.paused = True |
| 4434 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4435 | A.addApproval('code-review', 2) |
| 4436 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4437 | self.waitUntilSettled() |
| 4438 | |
| 4439 | self.zk.client.stop() |
| 4440 | self.zk.client.start() |
| 4441 | self.fake_nodepool.paused = False |
| 4442 | self.waitUntilSettled() |
| 4443 | |
| 4444 | self.assertEqual(A.data['status'], 'MERGED') |
| 4445 | self.assertEqual(A.reported, 2) |
| 4446 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4447 | def test_nodepool_failure(self): |
| 4448 | "Test that jobs are reported after a nodepool failure" |
| 4449 | |
| 4450 | self.fake_nodepool.paused = True |
| 4451 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4452 | A.addApproval('code-review', 2) |
| 4453 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4454 | self.waitUntilSettled() |
| 4455 | |
| 4456 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4457 | self.fake_nodepool.addFailRequest(req) |
| 4458 | |
| 4459 | self.fake_nodepool.paused = False |
| 4460 | self.waitUntilSettled() |
| 4461 | |
| 4462 | self.assertEqual(A.data['status'], 'NEW') |
| 4463 | self.assertEqual(A.reported, 2) |
| 4464 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4465 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4466 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4467 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4468 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4469 | class TestDependencyGraph(ZuulTestCase): |
| 4470 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4471 | |
| 4472 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4473 | "Test a job in a dependency graph is queued only once" |
| 4474 | # Job dependencies, starting with A |
| 4475 | # A |
| 4476 | # / \ |
| 4477 | # B C |
| 4478 | # / \ / \ |
| 4479 | # D F E |
| 4480 | # | |
| 4481 | # G |
| 4482 | |
| 4483 | self.executor_server.hold_jobs_in_build = True |
| 4484 | change = self.fake_gerrit.addFakeChange( |
| 4485 | 'org/project', 'master', 'change') |
| 4486 | change.addApproval('code-review', 2) |
| 4487 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4488 | |
| 4489 | self.waitUntilSettled() |
| 4490 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4491 | |
| 4492 | self.executor_server.release('A') |
| 4493 | self.waitUntilSettled() |
| 4494 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4495 | |
| 4496 | self.executor_server.release('B') |
| 4497 | self.waitUntilSettled() |
| 4498 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4499 | |
| 4500 | self.executor_server.release('D') |
| 4501 | self.waitUntilSettled() |
| 4502 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4503 | |
| 4504 | self.executor_server.release('C') |
| 4505 | self.waitUntilSettled() |
| 4506 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4507 | |
| 4508 | self.executor_server.release('F') |
| 4509 | self.waitUntilSettled() |
| 4510 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4511 | |
| 4512 | self.executor_server.release('G') |
| 4513 | self.waitUntilSettled() |
| 4514 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4515 | |
| 4516 | self.executor_server.release('E') |
| 4517 | self.waitUntilSettled() |
| 4518 | self.assertEqual(len(self.builds), 0) |
| 4519 | |
| 4520 | self.executor_server.hold_jobs_in_build = False |
| 4521 | self.executor_server.release() |
| 4522 | self.waitUntilSettled() |
| 4523 | |
| 4524 | self.assertEqual(len(self.builds), 0) |
| 4525 | self.assertEqual(len(self.history), 7) |
| 4526 | |
| 4527 | self.assertEqual(change.data['status'], 'MERGED') |
| 4528 | self.assertEqual(change.reported, 2) |
| 4529 | |
| 4530 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4531 | "Test that a job waits till all dependencies are successful" |
| 4532 | # Job dependencies, starting with A |
| 4533 | # A |
| 4534 | # / \ |
| 4535 | # B C* |
| 4536 | # / \ / \ |
| 4537 | # D F E |
| 4538 | # | |
| 4539 | # G |
| 4540 | |
| 4541 | self.executor_server.hold_jobs_in_build = True |
| 4542 | change = self.fake_gerrit.addFakeChange( |
| 4543 | 'org/project', 'master', 'change') |
| 4544 | change.addApproval('code-review', 2) |
| 4545 | |
| 4546 | self.executor_server.failJob('C', change) |
| 4547 | |
| 4548 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4549 | |
| 4550 | self.waitUntilSettled() |
| 4551 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4552 | |
| 4553 | self.executor_server.release('A') |
| 4554 | self.waitUntilSettled() |
| 4555 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4556 | |
| 4557 | self.executor_server.release('B') |
| 4558 | self.waitUntilSettled() |
| 4559 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4560 | |
| 4561 | self.executor_server.release('D') |
| 4562 | self.waitUntilSettled() |
| 4563 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4564 | |
| 4565 | self.executor_server.release('C') |
| 4566 | self.waitUntilSettled() |
| 4567 | self.assertEqual(len(self.builds), 0) |
| 4568 | |
| 4569 | self.executor_server.hold_jobs_in_build = False |
| 4570 | self.executor_server.release() |
| 4571 | self.waitUntilSettled() |
| 4572 | |
| 4573 | self.assertEqual(len(self.builds), 0) |
| 4574 | self.assertEqual(len(self.history), 4) |
| 4575 | |
| 4576 | self.assertEqual(change.data['status'], 'NEW') |
| 4577 | self.assertEqual(change.reported, 2) |
| 4578 | |
| 4579 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4580 | class TestDuplicatePipeline(ZuulTestCase): |
| 4581 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4582 | |
| 4583 | def test_duplicate_pipelines(self): |
| 4584 | "Test that a change matching multiple pipelines works" |
| 4585 | |
| 4586 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4587 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4588 | self.waitUntilSettled() |
| 4589 | |
| 4590 | self.assertHistory([ |
| 4591 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4592 | pipeline='dup1'), |
| 4593 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4594 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4595 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4596 | |
| 4597 | self.assertEqual(len(A.messages), 2) |
| 4598 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4599 | if 'dup1' in A.messages[0]: |
| 4600 | self.assertIn('dup1', A.messages[0]) |
| 4601 | self.assertNotIn('dup2', A.messages[0]) |
| 4602 | self.assertIn('project-test1', A.messages[0]) |
| 4603 | self.assertIn('dup2', A.messages[1]) |
| 4604 | self.assertNotIn('dup1', A.messages[1]) |
| 4605 | self.assertIn('project-test1', A.messages[1]) |
| 4606 | else: |
| 4607 | self.assertIn('dup1', A.messages[1]) |
| 4608 | self.assertNotIn('dup2', A.messages[1]) |
| 4609 | self.assertIn('project-test1', A.messages[1]) |
| 4610 | self.assertIn('dup2', A.messages[0]) |
| 4611 | self.assertNotIn('dup1', A.messages[0]) |
| 4612 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4613 | |
| 4614 | |
| 4615 | class TestSchedulerOneJobProject(ZuulTestCase): |
| 4616 | tenant_config_file = 'config/one-job-project/main.yaml' |
| 4617 | |
| 4618 | def test_one_job_project(self): |
| 4619 | "Test that queueing works with one job" |
| 4620 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4621 | 'master', 'A') |
| 4622 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4623 | 'master', 'B') |
| 4624 | A.addApproval('code-review', 2) |
| 4625 | B.addApproval('code-review', 2) |
| 4626 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4627 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4628 | self.waitUntilSettled() |
| 4629 | |
| 4630 | self.assertEqual(A.data['status'], 'MERGED') |
| 4631 | self.assertEqual(A.reported, 2) |
| 4632 | self.assertEqual(B.data['status'], 'MERGED') |
| 4633 | self.assertEqual(B.reported, 2) |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4634 | |
| 4635 | |
| 4636 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4637 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4638 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4639 | def test_job_from_templates_executed(self): |
| 4640 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4641 | |
| 4642 | A = self.fake_gerrit.addFakeChange( |
| 4643 | 'org/templated-project', 'master', 'A') |
| 4644 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4645 | self.waitUntilSettled() |
| 4646 | |
| 4647 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4648 | 'SUCCESS') |
| 4649 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4650 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4651 | |
| 4652 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4653 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4654 | |
| 4655 | A = self.fake_gerrit.addFakeChange( |
| 4656 | 'org/layered-project', 'master', 'A') |
| 4657 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4658 | self.waitUntilSettled() |
| 4659 | |
| 4660 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4661 | 'SUCCESS') |
| 4662 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4663 | 'SUCCESS') |
| 4664 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4665 | ).result, 'SUCCESS') |
| 4666 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4667 | ).result, 'SUCCESS') |
| 4668 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4669 | ).result, 'SUCCESS') |
| 4670 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4671 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4672 | |
| 4673 | |
| 4674 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4675 | tenant_config_file = 'config/success-url/main.yaml' |
| 4676 | |
| 4677 | def test_success_url(self): |
| 4678 | "Ensure bad build params are ignored" |
| 4679 | self.sched.reconfigure(self.config) |
| 4680 | self.init_repo('org/docs') |
| 4681 | |
| 4682 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4683 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4684 | self.waitUntilSettled() |
| 4685 | |
| 4686 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4687 | self.assertEqual(len(self.history), 2) |
| 4688 | |
| 4689 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4690 | for build in self.history: |
| 4691 | if build.name == 'docs-draft-test': |
| 4692 | uuid = build.uuid[:7] |
| 4693 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4694 | |
| 4695 | # Two msgs: 'Starting...' + results |
| 4696 | self.assertEqual(len(self.smtp_messages), 2) |
| 4697 | body = self.smtp_messages[1]['body'].splitlines() |
| 4698 | self.assertEqual('Build succeeded.', body[0]) |
| 4699 | |
| 4700 | self.assertIn( |
| 4701 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4702 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4703 | body[2]) |
| 4704 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4705 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4706 | self.assertIn( |
| 4707 | '- docs-draft-test2 https://server/job', |
| 4708 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4709 | |
| 4710 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4711 | class TestSchedulerMerges(ZuulTestCase): |
| 4712 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4713 | |
| 4714 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4715 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4716 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4717 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4718 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4719 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4720 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4721 | A.addApproval('code-review', 2) |
| 4722 | B.addApproval('code-review', 2) |
| 4723 | C.addApproval('code-review', 2) |
| 4724 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4725 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4726 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4727 | self.waitUntilSettled() |
| 4728 | |
| 4729 | build = self.builds[-1] |
| 4730 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4731 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4732 | path = os.path.join(build.jobdir.src_root, project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4733 | repo = git.Repo(path) |
| 4734 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4735 | repo_messages.reverse() |
| 4736 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4737 | self.executor_server.hold_jobs_in_build = False |
| 4738 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4739 | self.waitUntilSettled() |
| 4740 | |
| 4741 | return repo_messages |
| 4742 | |
| 4743 | def _test_merge(self, mode): |
| 4744 | us_path = os.path.join( |
| 4745 | self.upstream_root, 'org/project-%s' % mode) |
| 4746 | expected_messages = [ |
| 4747 | 'initial commit', |
| 4748 | 'add content from fixture', |
| 4749 | # the intermediate commits order is nondeterministic |
| 4750 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4751 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4752 | ] |
| 4753 | result = self._test_project_merge_mode(mode) |
| 4754 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4755 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4756 | |
| 4757 | def test_project_merge_mode_merge(self): |
| 4758 | self._test_merge('merge') |
| 4759 | |
| 4760 | def test_project_merge_mode_merge_resolve(self): |
| 4761 | self._test_merge('merge-resolve') |
| 4762 | |
| 4763 | def test_project_merge_mode_cherrypick(self): |
| 4764 | expected_messages = [ |
| 4765 | 'initial commit', |
| 4766 | 'add content from fixture', |
| 4767 | 'A-1', |
| 4768 | 'B-1', |
| 4769 | 'C-1'] |
| 4770 | result = self._test_project_merge_mode('cherry-pick') |
| 4771 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4772 | |
| 4773 | def test_merge_branch(self): |
| 4774 | "Test that the right commits are on alternate branches" |
| 4775 | self.create_branch('org/project-merge-branches', 'mp') |
| 4776 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4777 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4778 | A = self.fake_gerrit.addFakeChange( |
| 4779 | 'org/project-merge-branches', 'mp', 'A') |
| 4780 | B = self.fake_gerrit.addFakeChange( |
| 4781 | 'org/project-merge-branches', 'mp', 'B') |
| 4782 | C = self.fake_gerrit.addFakeChange( |
| 4783 | 'org/project-merge-branches', 'mp', 'C') |
| 4784 | A.addApproval('code-review', 2) |
| 4785 | B.addApproval('code-review', 2) |
| 4786 | C.addApproval('code-review', 2) |
| 4787 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4788 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4789 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4790 | self.waitUntilSettled() |
| 4791 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4792 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4793 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4794 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4795 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4796 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4797 | self.waitUntilSettled() |
| 4798 | |
| 4799 | build = self.builds[-1] |
| 4800 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 4801 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4802 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4803 | build.jobdir.src_root, 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4804 | repo = git.Repo(path) |
| 4805 | |
| 4806 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4807 | repo_messages.reverse() |
| 4808 | correct_messages = [ |
| 4809 | 'initial commit', |
| 4810 | 'add content from fixture', |
| 4811 | 'mp commit', |
| 4812 | 'A-1', 'B-1', 'C-1'] |
| 4813 | self.assertEqual(repo_messages, correct_messages) |
| 4814 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4815 | self.executor_server.hold_jobs_in_build = False |
| 4816 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4817 | self.waitUntilSettled() |
| 4818 | |
| 4819 | def test_merge_multi_branch(self): |
| 4820 | "Test that dependent changes on multiple branches are merged" |
| 4821 | self.create_branch('org/project-merge-branches', 'mp') |
| 4822 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4823 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4824 | A = self.fake_gerrit.addFakeChange( |
| 4825 | 'org/project-merge-branches', 'master', 'A') |
| 4826 | B = self.fake_gerrit.addFakeChange( |
| 4827 | 'org/project-merge-branches', 'mp', 'B') |
| 4828 | C = self.fake_gerrit.addFakeChange( |
| 4829 | 'org/project-merge-branches', 'master', 'C') |
| 4830 | A.addApproval('code-review', 2) |
| 4831 | B.addApproval('code-review', 2) |
| 4832 | C.addApproval('code-review', 2) |
| 4833 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4834 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4835 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4836 | self.waitUntilSettled() |
| 4837 | |
| 4838 | job_A = None |
| 4839 | for job in self.builds: |
| 4840 | if 'project-merge' in job.name: |
| 4841 | job_A = job |
| 4842 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 4843 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 4844 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 4845 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 4846 | |
| 4847 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4848 | job_A.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4849 | repo = git.Repo(path) |
| 4850 | repo_messages = [c.message.strip() |
| 4851 | for c in repo.iter_commits(ref_A)] |
| 4852 | repo_messages.reverse() |
| 4853 | correct_messages = [ |
| 4854 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4855 | self.assertEqual(repo_messages, correct_messages) |
| 4856 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4857 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4858 | self.waitUntilSettled() |
| 4859 | |
| 4860 | job_B = None |
| 4861 | for job in self.builds: |
| 4862 | if 'project-merge' in job.name: |
| 4863 | job_B = job |
| 4864 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 4865 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 4866 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 4867 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 4868 | |
| 4869 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4870 | job_B.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4871 | repo = git.Repo(path) |
| 4872 | repo_messages = [c.message.strip() |
| 4873 | for c in repo.iter_commits(ref_B)] |
| 4874 | repo_messages.reverse() |
| 4875 | correct_messages = [ |
| 4876 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4877 | self.assertEqual(repo_messages, correct_messages) |
| 4878 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4879 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4880 | self.waitUntilSettled() |
| 4881 | |
| 4882 | job_C = None |
| 4883 | for job in self.builds: |
| 4884 | if 'project-merge' in job.name: |
| 4885 | job_C = job |
| 4886 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 4887 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 4888 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 4889 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
| 4890 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4891 | job_C.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4892 | repo = git.Repo(path) |
| 4893 | repo_messages = [c.message.strip() |
| 4894 | for c in repo.iter_commits(ref_C)] |
| 4895 | |
| 4896 | repo_messages.reverse() |
| 4897 | correct_messages = [ |
| 4898 | 'initial commit', 'add content from fixture', |
| 4899 | 'A-1', 'C-1'] |
| 4900 | # Ensure the right commits are in the history for this ref |
| 4901 | self.assertEqual(repo_messages, correct_messages) |
| 4902 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4903 | self.executor_server.hold_jobs_in_build = False |
| 4904 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4905 | self.waitUntilSettled() |