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 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 42 | def test_jobs_launched(self): |
| 43 | "Test that jobs are launched 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') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 59 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 60 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 61 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 62 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 63 | value='1|g') |
| 64 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 65 | kind='ms') |
| 66 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 67 | value='1|c') |
| 68 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 69 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 70 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 71 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 72 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 73 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 74 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 75 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 76 | for build in self.builds: |
| 77 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 78 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 79 | def test_initial_pipeline_gauges(self): |
| 80 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 81 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 82 | value='0|g') |
| 83 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 84 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 85 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 86 | def test_job_branch(self): |
| 87 | "Test the correct variant of a job runs on a branch" |
| 88 | self.create_branch('org/project', 'stable') |
| 89 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 90 | A.addApproval('code-review', 2) |
| 91 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 92 | self.waitUntilSettled() |
| 93 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 94 | 'SUCCESS') |
| 95 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 96 | 'SUCCESS') |
| 97 | self.assertEqual(A.data['status'], 'MERGED') |
| 98 | self.assertEqual(A.reported, 2, |
| 99 | "A should report start and success") |
| 100 | self.assertIn('gate', A.messages[1], |
| 101 | "A should transit gate") |
| 102 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 103 | 'image2') |
| 104 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 105 | def test_parallel_changes(self): |
| 106 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 107 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 108 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 109 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 110 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 111 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 112 | A.addApproval('code-review', 2) |
| 113 | B.addApproval('code-review', 2) |
| 114 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 115 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 116 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 117 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 118 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 119 | |
| 120 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 121 | self.assertEqual(len(self.builds), 1) |
| 122 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 123 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 124 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 125 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 126 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 127 | self.assertEqual(len(self.builds), 3) |
| 128 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 129 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 130 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 131 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 132 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 133 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 134 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 135 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 136 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 137 | self.assertEqual(len(self.builds), 5) |
| 138 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 139 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 140 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 141 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 142 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 143 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 144 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 145 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 146 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 147 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 148 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 149 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 150 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 151 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 152 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 153 | self.assertEqual(len(self.builds), 6) |
| 154 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 155 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 156 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 157 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 158 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 159 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 160 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 161 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 162 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 163 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 164 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 165 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 167 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 168 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 169 | self.launch_server.hold_jobs_in_build = False |
| 170 | self.launch_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 171 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 172 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 173 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 174 | self.assertEqual(len(self.history), 9) |
| 175 | self.assertEqual(A.data['status'], 'MERGED') |
| 176 | self.assertEqual(B.data['status'], 'MERGED') |
| 177 | self.assertEqual(C.data['status'], 'MERGED') |
| 178 | self.assertEqual(A.reported, 2) |
| 179 | self.assertEqual(B.reported, 2) |
| 180 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 181 | |
| 182 | def test_failed_changes(self): |
| 183 | "Test that a change behind a failed change is retested" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 184 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 185 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 186 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 187 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 188 | A.addApproval('code-review', 2) |
| 189 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 190 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 191 | self.launch_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 192 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 193 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 194 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 195 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 196 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 197 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 198 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 199 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 200 | # A/project-merge is complete |
| 201 | self.assertBuilds([ |
| 202 | dict(name='project-test1', changes='1,1'), |
| 203 | dict(name='project-test2', changes='1,1'), |
| 204 | dict(name='project-merge', changes='1,1 2,1'), |
| 205 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 206 | |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 207 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 208 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 209 | # A/project-merge is complete |
| 210 | # B/project-merge is complete |
| 211 | self.assertBuilds([ |
| 212 | dict(name='project-test1', changes='1,1'), |
| 213 | dict(name='project-test2', changes='1,1'), |
| 214 | dict(name='project-test1', changes='1,1 2,1'), |
| 215 | dict(name='project-test2', changes='1,1 2,1'), |
| 216 | ]) |
| 217 | |
| 218 | # Release project-test1 for A which will fail. This will |
| 219 | # abort both running B jobs and relaunch project-merge for B. |
| 220 | self.builds[0].release() |
| 221 | self.waitUntilSettled() |
| 222 | |
| 223 | self.orderedRelease() |
| 224 | self.assertHistory([ |
| 225 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 226 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 227 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 228 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 229 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 230 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 231 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 232 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 233 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 234 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 235 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 236 | self.assertEqual(A.data['status'], 'NEW') |
| 237 | self.assertEqual(B.data['status'], 'MERGED') |
| 238 | self.assertEqual(A.reported, 2) |
| 239 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 240 | |
| 241 | def test_independent_queues(self): |
| 242 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 243 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 244 | self.launch_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 245 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 246 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 247 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 248 | A.addApproval('code-review', 2) |
| 249 | B.addApproval('code-review', 2) |
| 250 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 251 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 252 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 253 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 254 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 255 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 256 | self.waitUntilSettled() |
| 257 | |
| 258 | # 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] | 259 | self.assertBuilds([ |
| 260 | dict(name='project-merge', changes='1,1'), |
| 261 | dict(name='project-merge', changes='2,1'), |
| 262 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 263 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 264 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 265 | self.builds[0].release() |
| 266 | self.waitUntilSettled() |
| 267 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 268 | self.waitUntilSettled() |
| 269 | # Release the merge job for project2 which is behind project1 |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 270 | self.launch_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 271 | self.waitUntilSettled() |
| 272 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 273 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 274 | self.assertBuilds([ |
| 275 | dict(name='project-test1', changes='1,1'), |
| 276 | dict(name='project-test2', changes='1,1'), |
| 277 | dict(name='project-test1', changes='2,1'), |
| 278 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 279 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 280 | dict(name='project-test1', changes='2,1 3,1'), |
| 281 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 282 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 283 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 284 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 285 | self.orderedRelease() |
| 286 | self.assertHistory([ |
| 287 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 288 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 289 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 290 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 291 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 292 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 293 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 294 | dict( |
| 295 | name='project1-project2-integration', |
| 296 | result='SUCCESS', |
| 297 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 298 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 299 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 300 | dict(name='project1-project2-integration', |
| 301 | result='SUCCESS', |
| 302 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 303 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 304 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 305 | self.assertEqual(A.data['status'], 'MERGED') |
| 306 | self.assertEqual(B.data['status'], 'MERGED') |
| 307 | self.assertEqual(C.data['status'], 'MERGED') |
| 308 | self.assertEqual(A.reported, 2) |
| 309 | self.assertEqual(B.reported, 2) |
| 310 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 311 | |
| 312 | def test_failed_change_at_head(self): |
| 313 | "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] | 314 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 315 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 316 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 317 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 318 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 319 | A.addApproval('code-review', 2) |
| 320 | B.addApproval('code-review', 2) |
| 321 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 322 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 323 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 324 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 325 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 326 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 327 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 328 | |
| 329 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 330 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 331 | self.assertBuilds([ |
| 332 | dict(name='project-merge', changes='1,1'), |
| 333 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 334 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 335 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 336 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 337 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 338 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 339 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 340 | self.waitUntilSettled() |
| 341 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 342 | self.assertBuilds([ |
| 343 | dict(name='project-test1', changes='1,1'), |
| 344 | dict(name='project-test2', changes='1,1'), |
| 345 | dict(name='project-test1', changes='1,1 2,1'), |
| 346 | dict(name='project-test2', changes='1,1 2,1'), |
| 347 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 348 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 349 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 350 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 351 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 352 | self.waitUntilSettled() |
| 353 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 354 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 355 | self.assertBuilds([ |
| 356 | dict(name='project-test2', changes='1,1'), |
| 357 | dict(name='project-merge', changes='2,1'), |
| 358 | ]) |
| 359 | # Unordered history comparison because the aborts can finish |
| 360 | # in any order. |
| 361 | self.assertHistory([ |
| 362 | dict(name='project-merge', result='SUCCESS', |
| 363 | changes='1,1'), |
| 364 | dict(name='project-merge', result='SUCCESS', |
| 365 | changes='1,1 2,1'), |
| 366 | dict(name='project-merge', result='SUCCESS', |
| 367 | changes='1,1 2,1 3,1'), |
| 368 | dict(name='project-test1', result='FAILURE', |
| 369 | changes='1,1'), |
| 370 | dict(name='project-test1', result='ABORTED', |
| 371 | changes='1,1 2,1'), |
| 372 | dict(name='project-test2', result='ABORTED', |
| 373 | changes='1,1 2,1'), |
| 374 | dict(name='project-test1', result='ABORTED', |
| 375 | changes='1,1 2,1 3,1'), |
| 376 | dict(name='project-test2', result='ABORTED', |
| 377 | changes='1,1 2,1 3,1'), |
| 378 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 379 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 380 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 381 | self.waitUntilSettled() |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 382 | self.launch_server.release('.*-merge') |
| 383 | self.waitUntilSettled() |
| 384 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 385 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 386 | self.assertBuilds([]) |
| 387 | self.assertHistory([ |
| 388 | dict(name='project-merge', result='SUCCESS', |
| 389 | changes='1,1'), |
| 390 | dict(name='project-merge', result='SUCCESS', |
| 391 | changes='1,1 2,1'), |
| 392 | dict(name='project-merge', result='SUCCESS', |
| 393 | changes='1,1 2,1 3,1'), |
| 394 | dict(name='project-test1', result='FAILURE', |
| 395 | changes='1,1'), |
| 396 | dict(name='project-test1', result='ABORTED', |
| 397 | changes='1,1 2,1'), |
| 398 | dict(name='project-test2', result='ABORTED', |
| 399 | changes='1,1 2,1'), |
| 400 | dict(name='project-test1', result='ABORTED', |
| 401 | changes='1,1 2,1 3,1'), |
| 402 | dict(name='project-test2', result='ABORTED', |
| 403 | changes='1,1 2,1 3,1'), |
| 404 | dict(name='project-merge', result='SUCCESS', |
| 405 | changes='2,1'), |
| 406 | dict(name='project-merge', result='SUCCESS', |
| 407 | changes='2,1 3,1'), |
| 408 | dict(name='project-test2', result='SUCCESS', |
| 409 | changes='1,1'), |
| 410 | dict(name='project-test1', result='SUCCESS', |
| 411 | changes='2,1'), |
| 412 | dict(name='project-test2', result='SUCCESS', |
| 413 | changes='2,1'), |
| 414 | dict(name='project-test1', result='SUCCESS', |
| 415 | changes='2,1 3,1'), |
| 416 | dict(name='project-test2', result='SUCCESS', |
| 417 | changes='2,1 3,1'), |
| 418 | ], ordered=False) |
| 419 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 420 | self.assertEqual(A.data['status'], 'NEW') |
| 421 | self.assertEqual(B.data['status'], 'MERGED') |
| 422 | self.assertEqual(C.data['status'], 'MERGED') |
| 423 | self.assertEqual(A.reported, 2) |
| 424 | self.assertEqual(B.reported, 2) |
| 425 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 426 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 427 | def test_failed_change_in_middle(self): |
| 428 | "Test a failed change in the middle of the queue" |
| 429 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 430 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 431 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 432 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 433 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 434 | A.addApproval('code-review', 2) |
| 435 | B.addApproval('code-review', 2) |
| 436 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 437 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 438 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 439 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 440 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 441 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 442 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 443 | |
| 444 | self.waitUntilSettled() |
| 445 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 446 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 447 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 448 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 449 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 450 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 451 | self.waitUntilSettled() |
| 452 | |
| 453 | self.assertEqual(len(self.builds), 6) |
| 454 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 455 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 456 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 457 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 458 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 459 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 460 | |
| 461 | self.release(self.builds[2]) |
| 462 | self.waitUntilSettled() |
| 463 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 464 | # project-test1 and project-test2 for A |
| 465 | # project-test2 for B |
| 466 | # project-merge for C (without B) |
| 467 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 468 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 469 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 470 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 471 | self.waitUntilSettled() |
| 472 | |
| 473 | # project-test1 and project-test2 for A |
| 474 | # project-test2 for B |
| 475 | # project-test1 and project-test2 for C |
| 476 | self.assertEqual(len(self.builds), 5) |
| 477 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 478 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 479 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 480 | builds = items[0].current_build_set.getBuilds() |
| 481 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 482 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 483 | builds = items[1].current_build_set.getBuilds() |
| 484 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 485 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 486 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 487 | builds = items[2].current_build_set.getBuilds() |
| 488 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 489 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 490 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 491 | self.launch_server.hold_jobs_in_build = False |
| 492 | self.launch_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 493 | self.waitUntilSettled() |
| 494 | |
| 495 | self.assertEqual(len(self.builds), 0) |
| 496 | self.assertEqual(len(self.history), 12) |
| 497 | self.assertEqual(A.data['status'], 'MERGED') |
| 498 | self.assertEqual(B.data['status'], 'NEW') |
| 499 | self.assertEqual(C.data['status'], 'MERGED') |
| 500 | self.assertEqual(A.reported, 2) |
| 501 | self.assertEqual(B.reported, 2) |
| 502 | self.assertEqual(C.reported, 2) |
| 503 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 504 | def test_failed_change_at_head_with_queue(self): |
| 505 | "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] | 506 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 507 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 508 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 509 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 510 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 511 | A.addApproval('code-review', 2) |
| 512 | B.addApproval('code-review', 2) |
| 513 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 514 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 515 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 516 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 517 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 518 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 519 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 520 | |
| 521 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 522 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 523 | self.assertEqual(len(self.builds), 0) |
| 524 | self.assertEqual(len(queue), 1) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 525 | self.assertEqual(queue[0].name, 'launcher:launch') |
| 526 | job_args = json.loads(queue[0].arguments) |
| 527 | self.assertEqual(job_args['job'], 'project-merge') |
| 528 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 529 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 530 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 531 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 532 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 533 | self.waitUntilSettled() |
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 | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 536 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 537 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 538 | self.assertEqual(len(self.builds), 0) |
| 539 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 540 | |
| 541 | self.assertEqual( |
| 542 | json.loads(queue[0].arguments)['job'], 'project-test1') |
| 543 | self.assertEqual( |
| 544 | json.loads(queue[1].arguments)['job'], 'project-test2') |
| 545 | self.assertEqual( |
| 546 | json.loads(queue[2].arguments)['job'], 'project-test1') |
| 547 | self.assertEqual( |
| 548 | json.loads(queue[3].arguments)['job'], 'project-test2') |
| 549 | self.assertEqual( |
| 550 | json.loads(queue[4].arguments)['job'], 'project-test1') |
| 551 | self.assertEqual( |
| 552 | json.loads(queue[5].arguments)['job'], 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 553 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 554 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 555 | self.waitUntilSettled() |
| 556 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 557 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 558 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 559 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 560 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 561 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 562 | self.gearman_server.hold_jobs_in_queue = False |
| 563 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 564 | self.waitUntilSettled() |
| 565 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 566 | self.assertEqual(len(self.builds), 0) |
| 567 | self.assertEqual(len(self.history), 11) |
| 568 | self.assertEqual(A.data['status'], 'NEW') |
| 569 | self.assertEqual(B.data['status'], 'MERGED') |
| 570 | self.assertEqual(C.data['status'], 'MERGED') |
| 571 | self.assertEqual(A.reported, 2) |
| 572 | self.assertEqual(B.reported, 2) |
| 573 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 574 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 575 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 576 | def _test_time_database(self, iteration): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 577 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 578 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 579 | A.addApproval('code-review', 2) |
| 580 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 581 | self.waitUntilSettled() |
| 582 | time.sleep(2) |
| 583 | |
| 584 | data = json.loads(self.sched.formatStatusJSON()) |
| 585 | found_job = None |
| 586 | for pipeline in data['pipelines']: |
| 587 | if pipeline['name'] != 'gate': |
| 588 | continue |
| 589 | for queue in pipeline['change_queues']: |
| 590 | for head in queue['heads']: |
| 591 | for item in head: |
| 592 | for job in item['jobs']: |
| 593 | if job['name'] == 'project-merge': |
| 594 | found_job = job |
| 595 | break |
| 596 | |
| 597 | self.assertIsNotNone(found_job) |
| 598 | if iteration == 1: |
| 599 | self.assertIsNotNone(found_job['estimated_time']) |
| 600 | self.assertIsNone(found_job['remaining_time']) |
| 601 | else: |
| 602 | self.assertIsNotNone(found_job['estimated_time']) |
| 603 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 604 | self.assertIsNotNone(found_job['remaining_time']) |
| 605 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 606 | self.launch_server.hold_jobs_in_build = False |
| 607 | self.launch_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 608 | self.waitUntilSettled() |
| 609 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 610 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 611 | def test_time_database(self): |
| 612 | "Test the time database" |
| 613 | |
| 614 | self._test_time_database(1) |
| 615 | self._test_time_database(2) |
| 616 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 617 | def test_two_failed_changes_at_head(self): |
| 618 | "Test that changes are reparented correctly if 2 fail at head" |
| 619 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 620 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 621 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 622 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 623 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 624 | A.addApproval('code-review', 2) |
| 625 | B.addApproval('code-review', 2) |
| 626 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 627 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 628 | self.launch_server.failJob('project-test1', A) |
| 629 | self.launch_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 630 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 631 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 632 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 633 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 634 | self.waitUntilSettled() |
| 635 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 636 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 637 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 638 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 639 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 640 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 641 | self.waitUntilSettled() |
| 642 | |
| 643 | self.assertEqual(len(self.builds), 6) |
| 644 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 645 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 646 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 647 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 648 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 649 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 650 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 651 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 652 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 653 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 654 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 655 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 656 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 657 | |
| 658 | # Fail change B first |
| 659 | self.release(self.builds[2]) |
| 660 | self.waitUntilSettled() |
| 661 | |
| 662 | # restart of C after B failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 663 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 664 | self.waitUntilSettled() |
| 665 | |
| 666 | self.assertEqual(len(self.builds), 5) |
| 667 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 668 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 669 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 670 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 671 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 672 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 673 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 674 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 675 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 676 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 677 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 678 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 679 | |
| 680 | # Finish running all passing jobs for change A |
| 681 | self.release(self.builds[1]) |
| 682 | self.waitUntilSettled() |
| 683 | # Fail and report change A |
| 684 | self.release(self.builds[0]) |
| 685 | self.waitUntilSettled() |
| 686 | |
| 687 | # restart of B,C after A failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 688 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 689 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 690 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 691 | self.waitUntilSettled() |
| 692 | |
| 693 | self.assertEqual(len(self.builds), 4) |
| 694 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 695 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 696 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 697 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 698 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 699 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 700 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 701 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 702 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 703 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 704 | # After A failed and B and C restarted, B should be back in |
| 705 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 706 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 707 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 708 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 709 | self.launch_server.hold_jobs_in_build = False |
| 710 | self.launch_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 711 | self.waitUntilSettled() |
| 712 | |
| 713 | self.assertEqual(len(self.builds), 0) |
| 714 | self.assertEqual(len(self.history), 21) |
| 715 | self.assertEqual(A.data['status'], 'NEW') |
| 716 | self.assertEqual(B.data['status'], 'NEW') |
| 717 | self.assertEqual(C.data['status'], 'MERGED') |
| 718 | self.assertEqual(A.reported, 2) |
| 719 | self.assertEqual(B.reported, 2) |
| 720 | self.assertEqual(C.reported, 2) |
| 721 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 722 | def test_patch_order(self): |
| 723 | "Test that dependent patches are tested in the right order" |
| 724 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 725 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 726 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 727 | A.addApproval('code-review', 2) |
| 728 | B.addApproval('code-review', 2) |
| 729 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 730 | |
| 731 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 732 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 733 | M2.setMerged() |
| 734 | M1.setMerged() |
| 735 | |
| 736 | # C -> B -> A -> M1 -> M2 |
| 737 | # M2 is here to make sure it is never queried. If it is, it |
| 738 | # means zuul is walking down the entire history of merged |
| 739 | # changes. |
| 740 | |
| 741 | C.setDependsOn(B, 1) |
| 742 | B.setDependsOn(A, 1) |
| 743 | A.setDependsOn(M1, 1) |
| 744 | M1.setDependsOn(M2, 1) |
| 745 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 746 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 747 | |
| 748 | self.waitUntilSettled() |
| 749 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 750 | self.assertEqual(A.data['status'], 'NEW') |
| 751 | self.assertEqual(B.data['status'], 'NEW') |
| 752 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 753 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 754 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 755 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 756 | |
| 757 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 758 | self.assertEqual(M2.queried, 0) |
| 759 | self.assertEqual(A.data['status'], 'MERGED') |
| 760 | self.assertEqual(B.data['status'], 'MERGED') |
| 761 | self.assertEqual(C.data['status'], 'MERGED') |
| 762 | self.assertEqual(A.reported, 2) |
| 763 | self.assertEqual(B.reported, 2) |
| 764 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 765 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 766 | def test_needed_changes_enqueue(self): |
| 767 | "Test that a needed change is enqueued ahead" |
| 768 | # A Given a git tree like this, if we enqueue |
| 769 | # / \ change C, we should walk up and down the tree |
| 770 | # B G and enqueue changes in the order ABCDEFG. |
| 771 | # /|\ This is also the order that you would get if |
| 772 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 773 | # / the ordering is stable across re-enqueue events. |
| 774 | # D |
| 775 | |
| 776 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 777 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 778 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 779 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 780 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 781 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 782 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 783 | B.setDependsOn(A, 1) |
| 784 | C.setDependsOn(B, 1) |
| 785 | D.setDependsOn(C, 1) |
| 786 | E.setDependsOn(B, 1) |
| 787 | F.setDependsOn(B, 1) |
| 788 | G.setDependsOn(A, 1) |
| 789 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 790 | A.addApproval('code-review', 2) |
| 791 | B.addApproval('code-review', 2) |
| 792 | C.addApproval('code-review', 2) |
| 793 | D.addApproval('code-review', 2) |
| 794 | E.addApproval('code-review', 2) |
| 795 | F.addApproval('code-review', 2) |
| 796 | G.addApproval('code-review', 2) |
| 797 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 798 | |
| 799 | self.waitUntilSettled() |
| 800 | |
| 801 | self.assertEqual(A.data['status'], 'NEW') |
| 802 | self.assertEqual(B.data['status'], 'NEW') |
| 803 | self.assertEqual(C.data['status'], 'NEW') |
| 804 | self.assertEqual(D.data['status'], 'NEW') |
| 805 | self.assertEqual(E.data['status'], 'NEW') |
| 806 | self.assertEqual(F.data['status'], 'NEW') |
| 807 | self.assertEqual(G.data['status'], 'NEW') |
| 808 | |
| 809 | # We're about to add approvals to changes without adding the |
| 810 | # triggering events to Zuul, so that we can be sure that it is |
| 811 | # enqueing the changes based on dependencies, not because of |
| 812 | # triggering events. Since it will have the changes cached |
| 813 | # already (without approvals), we need to clear the cache |
| 814 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 815 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 816 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 817 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 818 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 819 | A.addApproval('approved', 1) |
| 820 | B.addApproval('approved', 1) |
| 821 | D.addApproval('approved', 1) |
| 822 | E.addApproval('approved', 1) |
| 823 | F.addApproval('approved', 1) |
| 824 | G.addApproval('approved', 1) |
| 825 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 826 | |
| 827 | for x in range(8): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 828 | self.launch_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 829 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 830 | self.launch_server.hold_jobs_in_build = False |
| 831 | self.launch_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 832 | self.waitUntilSettled() |
| 833 | |
| 834 | self.assertEqual(A.data['status'], 'MERGED') |
| 835 | self.assertEqual(B.data['status'], 'MERGED') |
| 836 | self.assertEqual(C.data['status'], 'MERGED') |
| 837 | self.assertEqual(D.data['status'], 'MERGED') |
| 838 | self.assertEqual(E.data['status'], 'MERGED') |
| 839 | self.assertEqual(F.data['status'], 'MERGED') |
| 840 | self.assertEqual(G.data['status'], 'MERGED') |
| 841 | self.assertEqual(A.reported, 2) |
| 842 | self.assertEqual(B.reported, 2) |
| 843 | self.assertEqual(C.reported, 2) |
| 844 | self.assertEqual(D.reported, 2) |
| 845 | self.assertEqual(E.reported, 2) |
| 846 | self.assertEqual(F.reported, 2) |
| 847 | self.assertEqual(G.reported, 2) |
| 848 | self.assertEqual(self.history[6].changes, |
| 849 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 850 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 851 | def test_source_cache(self): |
| 852 | "Test that the source cache operates correctly" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 853 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 854 | |
| 855 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 856 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 857 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 858 | A.addApproval('code-review', 2) |
| 859 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 860 | |
| 861 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 862 | M1.setMerged() |
| 863 | |
| 864 | B.setDependsOn(A, 1) |
| 865 | A.setDependsOn(M1, 1) |
| 866 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 867 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 868 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 869 | |
| 870 | self.waitUntilSettled() |
| 871 | |
| 872 | for build in self.builds: |
| 873 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 874 | build.release() |
| 875 | self.waitUntilSettled() |
| 876 | for build in self.builds: |
| 877 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 878 | build.release() |
| 879 | self.waitUntilSettled() |
| 880 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 881 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 882 | self.waitUntilSettled() |
| 883 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 884 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 885 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 886 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 887 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 888 | self.launch_server.hold_jobs_in_build = False |
| 889 | self.launch_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 890 | self.waitUntilSettled() |
| 891 | |
| 892 | self.assertEqual(A.data['status'], 'MERGED') |
| 893 | self.assertEqual(B.data['status'], 'MERGED') |
| 894 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 895 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 896 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 897 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 898 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 899 | # TODO: move to test_gerrit (this is a unit test!) |
| 900 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 901 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 902 | source = tenant.layout.pipelines['gate'].source |
| 903 | |
| 904 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 905 | # it easier for users to create events for testing. |
| 906 | event = zuul.model.TriggerEvent() |
| 907 | event.trigger_name = 'gerrit' |
| 908 | event.change_number = '1' |
| 909 | event.patch_number = '2' |
| 910 | |
| 911 | a = source.getChange(event) |
| 912 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 913 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 914 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 915 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 916 | a = source.getChange(event, refresh=True) |
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('approved', 1) |
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.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 922 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 923 | @skip("Disabled for early v3 development") |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 924 | def test_build_configuration_conflict(self): |
| 925 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 926 | |
| 927 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 928 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 929 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 930 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 931 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 932 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 933 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 934 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 935 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 936 | A.addApproval('code-review', 2) |
| 937 | B.addApproval('code-review', 2) |
| 938 | C.addApproval('code-review', 2) |
| 939 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 940 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 941 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 942 | self.waitUntilSettled() |
| 943 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 944 | self.assertEqual(A.reported, 1) |
| 945 | self.assertEqual(B.reported, 1) |
| 946 | self.assertEqual(C.reported, 1) |
| 947 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 948 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 949 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 950 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 951 | self.waitUntilSettled() |
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 | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 954 | |
| 955 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 956 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 957 | self.gearman_server.hold_jobs_in_queue = False |
| 958 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 959 | self.waitUntilSettled() |
| 960 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 961 | self.assertEqual(A.data['status'], 'MERGED') |
| 962 | self.assertEqual(B.data['status'], 'NEW') |
| 963 | self.assertEqual(C.data['status'], 'MERGED') |
| 964 | self.assertEqual(A.reported, 2) |
| 965 | self.assertEqual(B.reported, 2) |
| 966 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 967 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 968 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 969 | def test_post(self): |
| 970 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 971 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 972 | e = { |
| 973 | "type": "ref-updated", |
| 974 | "submitter": { |
| 975 | "name": "User Name", |
| 976 | }, |
| 977 | "refUpdate": { |
| 978 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 979 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 980 | "refName": "master", |
| 981 | "project": "org/project", |
| 982 | } |
| 983 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 984 | self.fake_gerrit.addEvent(e) |
| 985 | self.waitUntilSettled() |
| 986 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 987 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 988 | self.assertEqual(len(self.history), 1) |
| 989 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 990 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 991 | def test_post_ignore_deletes(self): |
| 992 | "Test that deleting refs does not trigger post jobs" |
| 993 | |
| 994 | e = { |
| 995 | "type": "ref-updated", |
| 996 | "submitter": { |
| 997 | "name": "User Name", |
| 998 | }, |
| 999 | "refUpdate": { |
| 1000 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1001 | "newRev": "0000000000000000000000000000000000000000", |
| 1002 | "refName": "master", |
| 1003 | "project": "org/project", |
| 1004 | } |
| 1005 | } |
| 1006 | self.fake_gerrit.addEvent(e) |
| 1007 | self.waitUntilSettled() |
| 1008 | |
| 1009 | job_names = [x.name for x in self.history] |
| 1010 | self.assertEqual(len(self.history), 0) |
| 1011 | self.assertNotIn('project-post', job_names) |
| 1012 | |
| 1013 | def test_post_ignore_deletes_negative(self): |
| 1014 | "Test that deleting refs does trigger post jobs" |
| 1015 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1016 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1017 | self.sched.reconfigure(self.config) |
| 1018 | |
| 1019 | e = { |
| 1020 | "type": "ref-updated", |
| 1021 | "submitter": { |
| 1022 | "name": "User Name", |
| 1023 | }, |
| 1024 | "refUpdate": { |
| 1025 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1026 | "newRev": "0000000000000000000000000000000000000000", |
| 1027 | "refName": "master", |
| 1028 | "project": "org/project", |
| 1029 | } |
| 1030 | } |
| 1031 | self.fake_gerrit.addEvent(e) |
| 1032 | self.waitUntilSettled() |
| 1033 | |
| 1034 | job_names = [x.name for x in self.history] |
| 1035 | self.assertEqual(len(self.history), 1) |
| 1036 | self.assertIn('project-post', job_names) |
| 1037 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1038 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1039 | def test_build_configuration_branch_interaction(self): |
| 1040 | "Test that switching between branches works" |
| 1041 | self.test_build_configuration() |
| 1042 | self.test_build_configuration_branch() |
| 1043 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1044 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1045 | repo = git.Repo(path) |
| 1046 | repo.heads.master.commit = repo.commit('init') |
| 1047 | self.test_build_configuration() |
| 1048 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1049 | def test_dependent_changes_dequeue(self): |
| 1050 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1051 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1052 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1053 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1054 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1055 | A.addApproval('code-review', 2) |
| 1056 | B.addApproval('code-review', 2) |
| 1057 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1058 | |
| 1059 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1060 | M1.setMerged() |
| 1061 | |
| 1062 | # C -> B -> A -> M1 |
| 1063 | |
| 1064 | C.setDependsOn(B, 1) |
| 1065 | B.setDependsOn(A, 1) |
| 1066 | A.setDependsOn(M1, 1) |
| 1067 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1068 | self.launch_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1069 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1070 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1071 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1072 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1073 | |
| 1074 | self.waitUntilSettled() |
| 1075 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1076 | self.assertEqual(A.data['status'], 'NEW') |
| 1077 | self.assertEqual(A.reported, 2) |
| 1078 | self.assertEqual(B.data['status'], 'NEW') |
| 1079 | self.assertEqual(B.reported, 2) |
| 1080 | self.assertEqual(C.data['status'], 'NEW') |
| 1081 | self.assertEqual(C.reported, 2) |
| 1082 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1083 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1084 | def test_failing_dependent_changes(self): |
| 1085 | "Test that failing dependent patches are taken out of stream" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1086 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1087 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1088 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1089 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1090 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1091 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1092 | A.addApproval('code-review', 2) |
| 1093 | B.addApproval('code-review', 2) |
| 1094 | C.addApproval('code-review', 2) |
| 1095 | D.addApproval('code-review', 2) |
| 1096 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1097 | |
| 1098 | # E, D -> C -> B, A |
| 1099 | |
| 1100 | D.setDependsOn(C, 1) |
| 1101 | C.setDependsOn(B, 1) |
| 1102 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1103 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1104 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1105 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1106 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1107 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1108 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1109 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1110 | |
| 1111 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1112 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1113 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1114 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1115 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1116 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1117 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1118 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1119 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1120 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1121 | self.waitUntilSettled() |
| 1122 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1123 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1124 | for build in self.builds: |
| 1125 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1126 | build.release() |
| 1127 | self.waitUntilSettled() |
| 1128 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1129 | self.launch_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1130 | self.waitUntilSettled() |
| 1131 | |
| 1132 | self.assertEqual(A.data['status'], 'MERGED') |
| 1133 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1134 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1135 | self.assertEqual(B.data['status'], 'NEW') |
| 1136 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1137 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1138 | self.assertEqual(C.data['status'], 'NEW') |
| 1139 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1140 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1141 | self.assertEqual(D.data['status'], 'NEW') |
| 1142 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1143 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1144 | self.assertEqual(E.data['status'], 'MERGED') |
| 1145 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1146 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1147 | self.assertEqual(len(self.history), 18) |
| 1148 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1149 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1150 | "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] | 1151 | # If it's dequeued more than once, we should see extra |
| 1152 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1153 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1154 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1155 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1156 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1157 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1158 | A.addApproval('code-review', 2) |
| 1159 | B.addApproval('code-review', 2) |
| 1160 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1161 | |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1162 | self.launch_server.failJob('project-test1', A) |
| 1163 | self.launch_server.failJob('project-test2', A) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1164 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1165 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1166 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1167 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1168 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1169 | |
| 1170 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1171 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1172 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1173 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1174 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1175 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1176 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1177 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1178 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1179 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1180 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1181 | self.waitUntilSettled() |
| 1182 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1183 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1184 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1185 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1186 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1187 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1188 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1189 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1190 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1191 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1192 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1193 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1194 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1195 | self.waitUntilSettled() |
| 1196 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1197 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1198 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1199 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1200 | self.launch_server.hold_jobs_in_build = False |
| 1201 | self.launch_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1202 | self.waitUntilSettled() |
| 1203 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1204 | self.assertEqual(len(self.builds), 0) |
| 1205 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1206 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1207 | self.assertEqual(A.data['status'], 'NEW') |
| 1208 | self.assertEqual(B.data['status'], 'MERGED') |
| 1209 | self.assertEqual(C.data['status'], 'MERGED') |
| 1210 | self.assertEqual(A.reported, 2) |
| 1211 | self.assertEqual(B.reported, 2) |
| 1212 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1213 | |
| 1214 | def test_nonvoting_job(self): |
| 1215 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1216 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1217 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1218 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1219 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1220 | self.launch_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1221 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1222 | |
| 1223 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1224 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1225 | self.assertEqual(A.data['status'], 'MERGED') |
| 1226 | self.assertEqual(A.reported, 2) |
| 1227 | self.assertEqual( |
| 1228 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1229 | 'SUCCESS') |
| 1230 | self.assertEqual( |
| 1231 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1232 | 'SUCCESS') |
| 1233 | self.assertEqual( |
| 1234 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1235 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1236 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1237 | for build in self.builds: |
| 1238 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1239 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1240 | def test_check_queue_success(self): |
| 1241 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1242 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1243 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1244 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1245 | |
| 1246 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1247 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1248 | self.assertEqual(A.data['status'], 'NEW') |
| 1249 | self.assertEqual(A.reported, 1) |
| 1250 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1251 | 'SUCCESS') |
| 1252 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1253 | 'SUCCESS') |
| 1254 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1255 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1256 | |
| 1257 | def test_check_queue_failure(self): |
| 1258 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1259 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1260 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1261 | self.launch_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1262 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1263 | |
| 1264 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1265 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1266 | self.assertEqual(A.data['status'], 'NEW') |
| 1267 | self.assertEqual(A.reported, 1) |
| 1268 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1269 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1270 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1271 | 'SUCCESS') |
| 1272 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1273 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1274 | |
| 1275 | def test_dependent_behind_dequeue(self): |
| 1276 | "test that dependent changes behind dequeued changes work" |
| 1277 | # This complicated test is a reproduction of a real life bug |
| 1278 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1279 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1280 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1281 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1282 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1283 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1284 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1285 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1286 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1287 | D.setDependsOn(C, 1) |
| 1288 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1289 | A.addApproval('code-review', 2) |
| 1290 | B.addApproval('code-review', 2) |
| 1291 | C.addApproval('code-review', 2) |
| 1292 | D.addApproval('code-review', 2) |
| 1293 | E.addApproval('code-review', 2) |
| 1294 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1295 | |
| 1296 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1297 | |
| 1298 | # Change object re-use in the gerrit trigger is hidden if |
| 1299 | # changes are added in quick succession; waiting makes it more |
| 1300 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1301 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1302 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1303 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1304 | self.waitUntilSettled() |
| 1305 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1306 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1307 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1308 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1309 | self.waitUntilSettled() |
| 1310 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1311 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1312 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1313 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1314 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1315 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1316 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1317 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1318 | self.waitUntilSettled() |
| 1319 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1320 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1321 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1322 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1323 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1324 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1325 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1326 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1327 | self.waitUntilSettled() |
| 1328 | |
| 1329 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1330 | |
| 1331 | # Grab pointers to the jobs we want to release before |
| 1332 | # releasing any, because list indexes may change as |
| 1333 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1334 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1335 | a.release() |
| 1336 | b.release() |
| 1337 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1338 | self.waitUntilSettled() |
| 1339 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1340 | self.launch_server.hold_jobs_in_build = False |
| 1341 | self.launch_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1342 | self.waitUntilSettled() |
| 1343 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1344 | self.assertEqual(A.data['status'], 'NEW') |
| 1345 | self.assertEqual(B.data['status'], 'MERGED') |
| 1346 | self.assertEqual(C.data['status'], 'MERGED') |
| 1347 | self.assertEqual(D.data['status'], 'MERGED') |
| 1348 | self.assertEqual(E.data['status'], 'MERGED') |
| 1349 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1350 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1351 | self.assertEqual(A.reported, 2) |
| 1352 | self.assertEqual(B.reported, 2) |
| 1353 | self.assertEqual(C.reported, 2) |
| 1354 | self.assertEqual(D.reported, 2) |
| 1355 | self.assertEqual(E.reported, 2) |
| 1356 | self.assertEqual(F.reported, 2) |
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(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1359 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1360 | |
| 1361 | def test_merger_repack(self): |
| 1362 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1363 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1364 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1365 | A.addApproval('code-review', 2) |
| 1366 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1367 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1368 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1369 | 'SUCCESS') |
| 1370 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1371 | 'SUCCESS') |
| 1372 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1373 | 'SUCCESS') |
| 1374 | self.assertEqual(A.data['status'], 'MERGED') |
| 1375 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1376 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1377 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1378 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1379 | path = os.path.join(self.git_root, "org/project") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1380 | print(repack_repo(path)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1381 | |
| 1382 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1383 | A.addApproval('code-review', 2) |
| 1384 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1385 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1386 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1387 | 'SUCCESS') |
| 1388 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1389 | 'SUCCESS') |
| 1390 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1391 | 'SUCCESS') |
| 1392 | self.assertEqual(A.data['status'], 'MERGED') |
| 1393 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1394 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1395 | def test_merger_repack_large_change(self): |
| 1396 | "Test that the merger works with large changes after a repack" |
| 1397 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1398 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1399 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1400 | url = self.fake_gerrit.getGitUrl( |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1401 | tenant.layout.project_configs.get('org/project1')) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1402 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1403 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1404 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1405 | path = os.path.join(self.upstream_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1406 | print(repack_repo(path)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1407 | path = os.path.join(self.git_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1408 | print(repack_repo(path)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1409 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1410 | A.addApproval('code-review', 2) |
| 1411 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1412 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1413 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1414 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1415 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1416 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1417 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1418 | 'SUCCESS') |
| 1419 | self.assertEqual(A.data['status'], 'MERGED') |
| 1420 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1421 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1422 | def test_new_patchset_dequeues_old(self): |
| 1423 | "Test that a new patchset causes the old to be dequeued" |
| 1424 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1425 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1426 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1427 | M.setMerged() |
| 1428 | |
| 1429 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1430 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1431 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1432 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1433 | A.addApproval('code-review', 2) |
| 1434 | B.addApproval('code-review', 2) |
| 1435 | C.addApproval('code-review', 2) |
| 1436 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1437 | |
| 1438 | C.setDependsOn(B, 1) |
| 1439 | B.setDependsOn(A, 1) |
| 1440 | A.setDependsOn(M, 1) |
| 1441 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1442 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1443 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1444 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1445 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1446 | self.waitUntilSettled() |
| 1447 | |
| 1448 | B.addPatchset() |
| 1449 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1450 | self.waitUntilSettled() |
| 1451 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1452 | self.launch_server.hold_jobs_in_build = False |
| 1453 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1454 | self.waitUntilSettled() |
| 1455 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1456 | self.assertEqual(A.data['status'], 'MERGED') |
| 1457 | self.assertEqual(A.reported, 2) |
| 1458 | self.assertEqual(B.data['status'], 'NEW') |
| 1459 | self.assertEqual(B.reported, 2) |
| 1460 | self.assertEqual(C.data['status'], 'NEW') |
| 1461 | self.assertEqual(C.reported, 2) |
| 1462 | self.assertEqual(D.data['status'], 'MERGED') |
| 1463 | self.assertEqual(D.reported, 2) |
| 1464 | 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] | 1465 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1466 | def test_new_patchset_check(self): |
| 1467 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1468 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1469 | self.launch_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1470 | |
| 1471 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1472 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1473 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1474 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1475 | |
| 1476 | # Add two git-dependent changes |
| 1477 | B.setDependsOn(A, 1) |
| 1478 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1479 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1480 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1481 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1482 | |
| 1483 | # A live item, and a non-live/live pair |
| 1484 | items = check_pipeline.getAllItems() |
| 1485 | self.assertEqual(len(items), 3) |
| 1486 | |
| 1487 | self.assertEqual(items[0].change.number, '1') |
| 1488 | self.assertEqual(items[0].change.patchset, '1') |
| 1489 | self.assertFalse(items[0].live) |
| 1490 | |
| 1491 | self.assertEqual(items[1].change.number, '2') |
| 1492 | self.assertEqual(items[1].change.patchset, '1') |
| 1493 | self.assertTrue(items[1].live) |
| 1494 | |
| 1495 | self.assertEqual(items[2].change.number, '1') |
| 1496 | self.assertEqual(items[2].change.patchset, '1') |
| 1497 | self.assertTrue(items[2].live) |
| 1498 | |
| 1499 | # Add a new patchset to A |
| 1500 | A.addPatchset() |
| 1501 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1502 | self.waitUntilSettled() |
| 1503 | |
| 1504 | # The live copy of A,1 should be gone, but the non-live and B |
| 1505 | # should continue, and we should have a new A,2 |
| 1506 | items = check_pipeline.getAllItems() |
| 1507 | self.assertEqual(len(items), 3) |
| 1508 | |
| 1509 | self.assertEqual(items[0].change.number, '1') |
| 1510 | self.assertEqual(items[0].change.patchset, '1') |
| 1511 | self.assertFalse(items[0].live) |
| 1512 | |
| 1513 | self.assertEqual(items[1].change.number, '2') |
| 1514 | self.assertEqual(items[1].change.patchset, '1') |
| 1515 | self.assertTrue(items[1].live) |
| 1516 | |
| 1517 | self.assertEqual(items[2].change.number, '1') |
| 1518 | self.assertEqual(items[2].change.patchset, '2') |
| 1519 | self.assertTrue(items[2].live) |
| 1520 | |
| 1521 | # Add a new patchset to B |
| 1522 | B.addPatchset() |
| 1523 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1524 | self.waitUntilSettled() |
| 1525 | |
| 1526 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1527 | # but we should have a new B,2 (still based on A,1) |
| 1528 | items = check_pipeline.getAllItems() |
| 1529 | self.assertEqual(len(items), 3) |
| 1530 | |
| 1531 | self.assertEqual(items[0].change.number, '1') |
| 1532 | self.assertEqual(items[0].change.patchset, '2') |
| 1533 | self.assertTrue(items[0].live) |
| 1534 | |
| 1535 | self.assertEqual(items[1].change.number, '1') |
| 1536 | self.assertEqual(items[1].change.patchset, '1') |
| 1537 | self.assertFalse(items[1].live) |
| 1538 | |
| 1539 | self.assertEqual(items[2].change.number, '2') |
| 1540 | self.assertEqual(items[2].change.patchset, '2') |
| 1541 | self.assertTrue(items[2].live) |
| 1542 | |
| 1543 | self.builds[0].release() |
| 1544 | self.waitUntilSettled() |
| 1545 | self.builds[0].release() |
| 1546 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1547 | self.launch_server.hold_jobs_in_build = False |
| 1548 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1549 | self.waitUntilSettled() |
| 1550 | |
| 1551 | self.assertEqual(A.reported, 1) |
| 1552 | self.assertEqual(B.reported, 1) |
| 1553 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1554 | self.assertEqual(self.history[0].changes, '1,1') |
| 1555 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1556 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1557 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1558 | self.assertEqual(self.history[2].changes, '1,2') |
| 1559 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1560 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1561 | |
| 1562 | def test_abandoned_gate(self): |
| 1563 | "Test that an abandoned change is dequeued from gate" |
| 1564 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1565 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1566 | |
| 1567 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1568 | A.addApproval('code-review', 2) |
| 1569 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1570 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1571 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1572 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1573 | |
| 1574 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1575 | self.waitUntilSettled() |
| 1576 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1577 | self.launch_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1578 | self.waitUntilSettled() |
| 1579 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1580 | self.assertBuilds([]) |
| 1581 | self.assertHistory([ |
| 1582 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1583 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1584 | self.assertEqual(A.reported, 1, |
| 1585 | "Abandoned gate change should report only start") |
| 1586 | |
| 1587 | def test_abandoned_check(self): |
| 1588 | "Test that an abandoned change is dequeued from check" |
| 1589 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1590 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1591 | |
| 1592 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1593 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1594 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1595 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1596 | |
| 1597 | # Add two git-dependent changes |
| 1598 | B.setDependsOn(A, 1) |
| 1599 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1600 | self.waitUntilSettled() |
| 1601 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1602 | self.waitUntilSettled() |
| 1603 | # A live item, and a non-live/live pair |
| 1604 | items = check_pipeline.getAllItems() |
| 1605 | self.assertEqual(len(items), 3) |
| 1606 | |
| 1607 | self.assertEqual(items[0].change.number, '1') |
| 1608 | self.assertFalse(items[0].live) |
| 1609 | |
| 1610 | self.assertEqual(items[1].change.number, '2') |
| 1611 | self.assertTrue(items[1].live) |
| 1612 | |
| 1613 | self.assertEqual(items[2].change.number, '1') |
| 1614 | self.assertTrue(items[2].live) |
| 1615 | |
| 1616 | # Abandon A |
| 1617 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1618 | self.waitUntilSettled() |
| 1619 | |
| 1620 | # The live copy of A should be gone, but the non-live and B |
| 1621 | # should continue |
| 1622 | items = check_pipeline.getAllItems() |
| 1623 | self.assertEqual(len(items), 2) |
| 1624 | |
| 1625 | self.assertEqual(items[0].change.number, '1') |
| 1626 | self.assertFalse(items[0].live) |
| 1627 | |
| 1628 | self.assertEqual(items[1].change.number, '2') |
| 1629 | self.assertTrue(items[1].live) |
| 1630 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1631 | self.launch_server.hold_jobs_in_build = False |
| 1632 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1633 | self.waitUntilSettled() |
| 1634 | |
| 1635 | self.assertEqual(len(self.history), 4) |
| 1636 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1637 | 'Build should have been aborted') |
| 1638 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1639 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1640 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1641 | @skip("Disabled for early v3 development") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1642 | def test_abandoned_not_timer(self): |
| 1643 | "Test that an abandoned change does not cancel timer jobs" |
| 1644 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1645 | self.launch_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1646 | |
| 1647 | # Start timer trigger - also org/project |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1648 | self.updateConfigLayout( |
| 1649 | 'tests/fixtures/layout-idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1650 | self.sched.reconfigure(self.config) |
| 1651 | self.registerJobs() |
| 1652 | # The pipeline triggers every second, so we should have seen |
| 1653 | # several by now. |
| 1654 | time.sleep(5) |
| 1655 | self.waitUntilSettled() |
| 1656 | # Stop queuing timer triggered jobs so that the assertions |
| 1657 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1658 | self.updateConfigLayout( |
| 1659 | 'tests/fixtures/layout-no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1660 | self.sched.reconfigure(self.config) |
| 1661 | self.registerJobs() |
| 1662 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1663 | |
| 1664 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1665 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1666 | self.waitUntilSettled() |
| 1667 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1668 | |
| 1669 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1670 | self.waitUntilSettled() |
| 1671 | |
| 1672 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1673 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1674 | self.launch_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1675 | self.waitUntilSettled() |
| 1676 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1677 | def test_zuul_url_return(self): |
| 1678 | "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] | 1679 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1680 | self.launch_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1681 | |
| 1682 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1683 | A.addApproval('code-review', 2) |
| 1684 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1685 | self.waitUntilSettled() |
| 1686 | |
| 1687 | self.assertEqual(len(self.builds), 1) |
| 1688 | for build in self.builds: |
| 1689 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1690 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1691 | self.launch_server.hold_jobs_in_build = False |
| 1692 | self.launch_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1693 | self.waitUntilSettled() |
| 1694 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1695 | def test_new_patchset_dequeues_old_on_head(self): |
| 1696 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1697 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1698 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1699 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1700 | M.setMerged() |
| 1701 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1702 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1703 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1704 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1705 | A.addApproval('code-review', 2) |
| 1706 | B.addApproval('code-review', 2) |
| 1707 | C.addApproval('code-review', 2) |
| 1708 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1709 | |
| 1710 | C.setDependsOn(B, 1) |
| 1711 | B.setDependsOn(A, 1) |
| 1712 | A.setDependsOn(M, 1) |
| 1713 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1714 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1715 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1716 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1717 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1718 | self.waitUntilSettled() |
| 1719 | |
| 1720 | A.addPatchset() |
| 1721 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1722 | self.waitUntilSettled() |
| 1723 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1724 | self.launch_server.hold_jobs_in_build = False |
| 1725 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1726 | self.waitUntilSettled() |
| 1727 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1728 | self.assertEqual(A.data['status'], 'NEW') |
| 1729 | self.assertEqual(A.reported, 2) |
| 1730 | self.assertEqual(B.data['status'], 'NEW') |
| 1731 | self.assertEqual(B.reported, 2) |
| 1732 | self.assertEqual(C.data['status'], 'NEW') |
| 1733 | self.assertEqual(C.reported, 2) |
| 1734 | self.assertEqual(D.data['status'], 'MERGED') |
| 1735 | self.assertEqual(D.reported, 2) |
| 1736 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1737 | |
| 1738 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1739 | "Test that a new patchset causes only the old to be dequeued" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1740 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1741 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1742 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1743 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1744 | A.addApproval('code-review', 2) |
| 1745 | B.addApproval('code-review', 2) |
| 1746 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1747 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1748 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1749 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1750 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1751 | self.waitUntilSettled() |
| 1752 | |
| 1753 | B.addPatchset() |
| 1754 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1755 | self.waitUntilSettled() |
| 1756 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1757 | self.launch_server.hold_jobs_in_build = False |
| 1758 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1759 | self.waitUntilSettled() |
| 1760 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1761 | self.assertEqual(A.data['status'], 'MERGED') |
| 1762 | self.assertEqual(A.reported, 2) |
| 1763 | self.assertEqual(B.data['status'], 'NEW') |
| 1764 | self.assertEqual(B.reported, 2) |
| 1765 | self.assertEqual(C.data['status'], 'MERGED') |
| 1766 | self.assertEqual(C.reported, 2) |
| 1767 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1768 | |
| 1769 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1770 | "Test that a new patchset causes the old to be dequeued (independent)" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1771 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1772 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1773 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1774 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1775 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1776 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1777 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1778 | self.waitUntilSettled() |
| 1779 | |
| 1780 | B.addPatchset() |
| 1781 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1782 | self.waitUntilSettled() |
| 1783 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1784 | self.launch_server.hold_jobs_in_build = False |
| 1785 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1786 | self.waitUntilSettled() |
| 1787 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1788 | self.assertEqual(A.data['status'], 'NEW') |
| 1789 | self.assertEqual(A.reported, 1) |
| 1790 | self.assertEqual(B.data['status'], 'NEW') |
| 1791 | self.assertEqual(B.reported, 1) |
| 1792 | self.assertEqual(C.data['status'], 'NEW') |
| 1793 | self.assertEqual(C.reported, 1) |
| 1794 | self.assertEqual(len(self.history), 10) |
| 1795 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1796 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1797 | def test_noop_job(self): |
| 1798 | "Test that the internal noop job works" |
| 1799 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1800 | A.addApproval('code-review', 2) |
| 1801 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1802 | self.waitUntilSettled() |
| 1803 | |
| 1804 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1805 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1806 | self.assertEqual(len(self.history), 0) |
| 1807 | self.assertEqual(A.data['status'], 'MERGED') |
| 1808 | self.assertEqual(A.reported, 2) |
| 1809 | |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1810 | def test_no_job_project(self): |
| 1811 | "Test that reports with no jobs don't get sent" |
| 1812 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1813 | 'master', 'A') |
| 1814 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1815 | self.waitUntilSettled() |
| 1816 | |
| 1817 | # Change wasn't reported to |
| 1818 | self.assertEqual(A.reported, False) |
| 1819 | |
| 1820 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1821 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1822 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1823 | items = check_pipeline.getAllItems() |
| 1824 | self.assertEqual(len(items), 0) |
| 1825 | |
| 1826 | self.assertEqual(len(self.history), 0) |
| 1827 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1828 | def test_zuul_refs(self): |
| 1829 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1830 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1831 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1832 | M1.setMerged() |
| 1833 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1834 | M2.setMerged() |
| 1835 | |
| 1836 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1837 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1838 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1839 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1840 | A.addApproval('code-review', 2) |
| 1841 | B.addApproval('code-review', 2) |
| 1842 | C.addApproval('code-review', 2) |
| 1843 | D.addApproval('code-review', 2) |
| 1844 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1845 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1846 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1847 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1848 | |
| 1849 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1850 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1851 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1852 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1853 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1854 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1855 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1856 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1857 | self.waitUntilSettled() |
| 1858 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1859 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1860 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1861 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1862 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1863 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1864 | a_build = x |
| 1865 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1866 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1867 | b_build = x |
| 1868 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1869 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1870 | c_build = x |
| 1871 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1872 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1873 | d_build = x |
| 1874 | if a_build and b_build and c_build and d_build: |
| 1875 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1876 | |
| 1877 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1878 | self.assertIsNotNone(a_zref) |
| 1879 | self.assertIsNotNone(b_zref) |
| 1880 | self.assertIsNotNone(c_zref) |
| 1881 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1882 | |
| 1883 | # And they should all be different |
| 1884 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1885 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1886 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1887 | # should have a, not b, and should not be in project2 |
| 1888 | self.assertTrue(a_build.hasChanges(A)) |
| 1889 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1890 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1891 | # should have a and b, and should not be in project2 |
| 1892 | self.assertTrue(b_build.hasChanges(A, B)) |
| 1893 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1894 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1895 | # should have a and b in 1, c in 2 |
| 1896 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 1897 | self.assertFalse(c_build.hasChanges(D)) |
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 and b in 1, c and d in 2 |
| 1900 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1901 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1902 | self.launch_server.hold_jobs_in_build = False |
| 1903 | self.launch_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1904 | self.waitUntilSettled() |
| 1905 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1906 | self.assertEqual(A.data['status'], 'MERGED') |
| 1907 | self.assertEqual(A.reported, 2) |
| 1908 | self.assertEqual(B.data['status'], 'MERGED') |
| 1909 | self.assertEqual(B.reported, 2) |
| 1910 | self.assertEqual(C.data['status'], 'MERGED') |
| 1911 | self.assertEqual(C.reported, 2) |
| 1912 | self.assertEqual(D.data['status'], 'MERGED') |
| 1913 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1914 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1915 | def test_rerun_on_error(self): |
| 1916 | "Test that if a worker fails to run a job, it is run again" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1917 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1918 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1919 | A.addApproval('code-review', 2) |
| 1920 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1921 | self.waitUntilSettled() |
| 1922 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 1923 | self.builds[0].requeue = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1924 | self.launch_server.hold_jobs_in_build = False |
| 1925 | self.launch_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1926 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 1927 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1928 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 1929 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1930 | def test_statsd(self): |
| 1931 | "Test each of the statsd methods used in the scheduler" |
| 1932 | import extras |
| 1933 | statsd = extras.try_import('statsd.statsd') |
| 1934 | statsd.incr('test-incr') |
| 1935 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1936 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1937 | self.assertReportedStat('test-incr', '1|c') |
| 1938 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1939 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1940 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1941 | @skip("Disabled for early v3 development") |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1942 | def test_stuck_job_cleanup(self): |
| 1943 | "Test that pending jobs are cleaned up if removed from layout" |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1944 | # This job won't be registered at startup because it is not in |
| 1945 | # the standard layout, but we need it to already be registerd |
| 1946 | # for when we reconfigure, as that is when Zuul will attempt |
| 1947 | # to run the new job. |
| 1948 | self.worker.registerFunction('build:gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1949 | self.gearman_server.hold_jobs_in_queue = True |
| 1950 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1951 | A.addApproval('code-review', 2) |
| 1952 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1953 | self.waitUntilSettled() |
| 1954 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 1955 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1956 | self.updateConfigLayout( |
| 1957 | 'tests/fixtures/layout-no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1958 | self.sched.reconfigure(self.config) |
| 1959 | self.waitUntilSettled() |
| 1960 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1961 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1962 | self.waitUntilSettled() |
| 1963 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1964 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1965 | |
| 1966 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1967 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1968 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 1969 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 1970 | def test_file_head(self): |
| 1971 | # This is a regression test for an observed bug. A change |
| 1972 | # with a file named "HEAD" in the root directory of the repo |
| 1973 | # was processed by a merger. It then was unable to reset the |
| 1974 | # repo because of: |
| 1975 | # GitCommandError: 'git reset --hard HEAD' returned |
| 1976 | # with exit code 128 |
| 1977 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 1978 | # and filename |
| 1979 | # Use '--' to separate filenames from revisions' |
| 1980 | |
| 1981 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 1982 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 1983 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1984 | |
| 1985 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1986 | self.waitUntilSettled() |
| 1987 | |
| 1988 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1989 | self.waitUntilSettled() |
| 1990 | |
| 1991 | self.assertIn('Build succeeded', A.messages[0]) |
| 1992 | self.assertIn('Build succeeded', B.messages[0]) |
| 1993 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1994 | def test_file_jobs(self): |
| 1995 | "Test that file jobs run only when appropriate" |
| 1996 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 1997 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1998 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1999 | A.addApproval('code-review', 2) |
| 2000 | B.addApproval('code-review', 2) |
| 2001 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2002 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2003 | self.waitUntilSettled() |
| 2004 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2005 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2006 | if x.name == 'project-testfile'] |
| 2007 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2008 | self.assertEqual(len(testfile_jobs), 1) |
| 2009 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2010 | self.assertEqual(A.data['status'], 'MERGED') |
| 2011 | self.assertEqual(A.reported, 2) |
| 2012 | self.assertEqual(B.data['status'], 'MERGED') |
| 2013 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2014 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2015 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2016 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2017 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2018 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2019 | |
| 2020 | if should_skip: |
| 2021 | files = {'ignoreme': 'ignored\n'} |
| 2022 | else: |
| 2023 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2024 | |
| 2025 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2026 | 'master', |
| 2027 | 'test irrelevant-files', |
| 2028 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2029 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2030 | self.waitUntilSettled() |
| 2031 | |
| 2032 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2033 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2034 | |
| 2035 | if should_skip: |
| 2036 | self.assertEqual([], tested_change_ids) |
| 2037 | else: |
| 2038 | self.assertIn(change.data['number'], tested_change_ids) |
| 2039 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2040 | def test_irrelevant_files_match_skips_job(self): |
| 2041 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2042 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2043 | def test_irrelevant_files_no_match_runs_job(self): |
| 2044 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2045 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2046 | def test_inherited_jobs_keep_matchers(self): |
| 2047 | self.updateConfigLayout('layout-inheritance') |
| 2048 | self.sched.reconfigure(self.config) |
| 2049 | |
| 2050 | files = {'ignoreme': 'ignored\n'} |
| 2051 | |
| 2052 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2053 | 'master', |
| 2054 | 'test irrelevant-files', |
| 2055 | files=files) |
| 2056 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2057 | self.waitUntilSettled() |
| 2058 | |
| 2059 | run_jobs = set([build.name for build in self.history]) |
| 2060 | |
| 2061 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2062 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2063 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2064 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2065 | def test_test_config(self): |
| 2066 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2067 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2068 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2069 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2070 | @skip("Disabled for early v3 development") |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2071 | def test_queue_names(self): |
| 2072 | "Test shared change queue names" |
| 2073 | project1 = self.sched.layout.projects['org/project1'] |
| 2074 | project2 = self.sched.layout.projects['org/project2'] |
| 2075 | q1 = self.sched.layout.pipelines['gate'].getQueue(project1) |
| 2076 | q2 = self.sched.layout.pipelines['gate'].getQueue(project2) |
| 2077 | self.assertEqual(q1.name, 'integration') |
| 2078 | self.assertEqual(q2.name, 'integration') |
| 2079 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2080 | self.updateConfigLayout( |
| 2081 | 'tests/fixtures/layout-bad-queue.yaml') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2082 | with testtools.ExpectedException( |
| 2083 | Exception, "More than one name assigned to change queue"): |
| 2084 | self.sched.reconfigure(self.config) |
| 2085 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2086 | def test_queue_precedence(self): |
| 2087 | "Test that queue precedence works" |
| 2088 | |
| 2089 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2090 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2091 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2092 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2093 | A.addApproval('code-review', 2) |
| 2094 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2095 | |
| 2096 | self.waitUntilSettled() |
| 2097 | self.gearman_server.hold_jobs_in_queue = False |
| 2098 | self.gearman_server.release() |
| 2099 | self.waitUntilSettled() |
| 2100 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2101 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2102 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2103 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2104 | self.waitUntilSettled() |
| 2105 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2106 | self.log.debug(self.history) |
| 2107 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2108 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2109 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2110 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2111 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2112 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2113 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2114 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2115 | "Test that we can retrieve JSON status info" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2116 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2117 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2118 | A.addApproval('code-review', 2) |
| 2119 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2120 | self.waitUntilSettled() |
| 2121 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2122 | self.launch_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2123 | self.waitUntilSettled() |
| 2124 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2125 | port = self.webapp.server.socket.getsockname()[1] |
| 2126 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2127 | req = urllib.request.Request( |
| 2128 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2129 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2130 | headers = f.info() |
| 2131 | self.assertIn('Content-Length', headers) |
| 2132 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2133 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2134 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2135 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2136 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2137 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2138 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2139 | data = f.read() |
| 2140 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2141 | self.launch_server.hold_jobs_in_build = False |
| 2142 | self.launch_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2143 | self.waitUntilSettled() |
| 2144 | |
| 2145 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2146 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2147 | for p in data['pipelines']: |
| 2148 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2149 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2150 | self.assertEqual(q['window'], 20) |
| 2151 | else: |
| 2152 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2153 | for head in q['heads']: |
| 2154 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2155 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2156 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2157 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2158 | status_jobs.append(job) |
| 2159 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2160 | self.assertEqual('https://server/job/project-merge/0/', |
| 2161 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2162 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2163 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2164 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2165 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2166 | status_jobs[1]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2167 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2168 | status_jobs[1]['report_url']) |
| 2169 | |
| 2170 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2171 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2172 | status_jobs[2]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2173 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2174 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2175 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2176 | @skip("Disabled for early v3 development") |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2177 | def test_merging_queues(self): |
| 2178 | "Test that transitively-connected change queues are merged" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2179 | self.updateConfigLayout( |
| 2180 | 'tests/fixtures/layout-merge-queues.yaml') |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2181 | self.sched.reconfigure(self.config) |
| 2182 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 2183 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2184 | def test_mutex(self): |
| 2185 | "Test job mutexes" |
Adam Gandelman | ea9ac9b | 2017-02-03 16:59:58 -0800 | [diff] [blame] | 2186 | self.updateConfigLayout('layout-mutex') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2187 | self.sched.reconfigure(self.config) |
| 2188 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2189 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2190 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2191 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2192 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2193 | |
| 2194 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2195 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2196 | self.waitUntilSettled() |
| 2197 | self.assertEqual(len(self.builds), 3) |
| 2198 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2199 | self.assertEqual(self.builds[1].name, 'mutex-one') |
| 2200 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2201 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2202 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2203 | self.waitUntilSettled() |
| 2204 | |
| 2205 | self.assertEqual(len(self.builds), 3) |
| 2206 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2207 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2208 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2209 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2210 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2211 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2212 | self.waitUntilSettled() |
| 2213 | |
| 2214 | self.assertEqual(len(self.builds), 3) |
| 2215 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2216 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2217 | self.assertEqual(self.builds[2].name, 'mutex-one') |
| 2218 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2219 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2220 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2221 | self.waitUntilSettled() |
| 2222 | |
| 2223 | self.assertEqual(len(self.builds), 3) |
| 2224 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2225 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2226 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2227 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2228 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2229 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2230 | self.waitUntilSettled() |
| 2231 | |
| 2232 | self.assertEqual(len(self.builds), 2) |
| 2233 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2234 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2235 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2236 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2237 | self.launch_server.hold_jobs_in_build = False |
| 2238 | self.launch_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2239 | |
| 2240 | self.waitUntilSettled() |
| 2241 | self.assertEqual(len(self.builds), 0) |
| 2242 | |
| 2243 | self.assertEqual(A.reported, 1) |
| 2244 | self.assertEqual(B.reported, 1) |
| 2245 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2246 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2247 | @skip("Disabled for early v3 development") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2248 | def test_node_label(self): |
| 2249 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2250 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2251 | |
| 2252 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2253 | A.addApproval('code-review', 2) |
| 2254 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2255 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2256 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2257 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2258 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2259 | 'debian') |
| 2260 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2261 | |
| 2262 | def test_live_reconfiguration(self): |
| 2263 | "Test that live reconfiguration works" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2264 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2265 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2266 | A.addApproval('code-review', 2) |
| 2267 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2268 | self.waitUntilSettled() |
| 2269 | |
| 2270 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2271 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2272 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2273 | self.launch_server.hold_jobs_in_build = False |
| 2274 | self.launch_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2275 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2276 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2277 | 'SUCCESS') |
| 2278 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2279 | 'SUCCESS') |
| 2280 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2281 | 'SUCCESS') |
| 2282 | self.assertEqual(A.data['status'], 'MERGED') |
| 2283 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2284 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2285 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2286 | def test_live_reconfiguration_merge_conflict(self): |
| 2287 | # A real-world bug: a change in a gate queue has a merge |
| 2288 | # conflict and a job is added to its project while it's |
| 2289 | # sitting in the queue. The job gets added to the change and |
| 2290 | # enqueued and the change gets stuck. |
| 2291 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2292 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2293 | |
| 2294 | # This change is fine. It's here to stop the queue long |
| 2295 | # enough for the next change to be subject to the |
| 2296 | # reconfiguration, as well as to provide a conflict for the |
| 2297 | # next change. This change will succeed and merge. |
| 2298 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2299 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2300 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2301 | |
| 2302 | # This change will be in merge conflict. During the |
| 2303 | # reconfiguration, we will add a job. We want to make sure |
| 2304 | # that doesn't cause it to get stuck. |
| 2305 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2306 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2307 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2308 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2309 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2310 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2311 | |
| 2312 | self.waitUntilSettled() |
| 2313 | |
| 2314 | # No jobs have run yet |
| 2315 | self.assertEqual(A.data['status'], 'NEW') |
| 2316 | self.assertEqual(A.reported, 1) |
| 2317 | self.assertEqual(B.data['status'], 'NEW') |
| 2318 | self.assertEqual(B.reported, 1) |
| 2319 | self.assertEqual(len(self.history), 0) |
| 2320 | |
| 2321 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2322 | self.updateConfigLayout( |
| 2323 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2324 | self.sched.reconfigure(self.config) |
| 2325 | self.waitUntilSettled() |
| 2326 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2327 | self.launch_server.hold_jobs_in_build = False |
| 2328 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2329 | self.waitUntilSettled() |
| 2330 | |
| 2331 | self.assertEqual(A.data['status'], 'MERGED') |
| 2332 | self.assertEqual(A.reported, 2) |
| 2333 | self.assertEqual(B.data['status'], 'NEW') |
| 2334 | self.assertEqual(B.reported, 2) |
| 2335 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2336 | 'SUCCESS') |
| 2337 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2338 | 'SUCCESS') |
| 2339 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2340 | 'SUCCESS') |
| 2341 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2342 | 'SUCCESS') |
| 2343 | self.assertEqual(len(self.history), 4) |
| 2344 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2345 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2346 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2347 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2348 | # that tests a job added to a job tree with a failed root does |
| 2349 | # not run. |
| 2350 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2351 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2352 | |
| 2353 | # This change is fine. It's here to stop the queue long |
| 2354 | # enough for the next change to be subject to the |
| 2355 | # reconfiguration. This change will succeed and merge. |
| 2356 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2357 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2358 | A.addApproval('code-review', 2) |
| 2359 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2360 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2361 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2362 | self.waitUntilSettled() |
| 2363 | |
| 2364 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2365 | self.launch_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2366 | B.addApproval('code-review', 2) |
| 2367 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2368 | self.waitUntilSettled() |
| 2369 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2370 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2371 | self.waitUntilSettled() |
| 2372 | |
| 2373 | # Both -merge jobs have run, but no others. |
| 2374 | self.assertEqual(A.data['status'], 'NEW') |
| 2375 | self.assertEqual(A.reported, 1) |
| 2376 | self.assertEqual(B.data['status'], 'NEW') |
| 2377 | self.assertEqual(B.reported, 1) |
| 2378 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2379 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2380 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2381 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2382 | self.assertEqual(len(self.history), 2) |
| 2383 | |
| 2384 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2385 | self.updateConfigLayout( |
| 2386 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2387 | self.sched.reconfigure(self.config) |
| 2388 | self.waitUntilSettled() |
| 2389 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2390 | self.launch_server.hold_jobs_in_build = False |
| 2391 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2392 | self.waitUntilSettled() |
| 2393 | |
| 2394 | self.assertEqual(A.data['status'], 'MERGED') |
| 2395 | self.assertEqual(A.reported, 2) |
| 2396 | self.assertEqual(B.data['status'], 'NEW') |
| 2397 | self.assertEqual(B.reported, 2) |
| 2398 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2399 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2400 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2401 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2402 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2403 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2404 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2405 | self.assertEqual(len(self.history), 5) |
| 2406 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2407 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2408 | def test_live_reconfiguration_failed_job(self): |
| 2409 | # Test that a change with a removed failing job does not |
| 2410 | # disrupt reconfiguration. If a change has a failed job and |
| 2411 | # that job is removed during a reconfiguration, we observed a |
| 2412 | # bug where the code to re-set build statuses would run on |
| 2413 | # that build and raise an exception because the job no longer |
| 2414 | # existed. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2415 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2416 | |
| 2417 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2418 | |
| 2419 | # This change will fail and later be removed by the reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2420 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2421 | |
| 2422 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2423 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2424 | self.launch_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2425 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2426 | self.launch_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2427 | self.waitUntilSettled() |
| 2428 | |
| 2429 | self.assertEqual(A.data['status'], 'NEW') |
| 2430 | self.assertEqual(A.reported, 0) |
| 2431 | |
| 2432 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2433 | 'SUCCESS') |
| 2434 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2435 | 'FAILURE') |
| 2436 | self.assertEqual(len(self.history), 2) |
| 2437 | |
| 2438 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2439 | self.updateConfigLayout( |
| 2440 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2441 | self.sched.reconfigure(self.config) |
| 2442 | self.waitUntilSettled() |
| 2443 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2444 | self.launch_server.hold_jobs_in_build = False |
| 2445 | self.launch_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2446 | self.waitUntilSettled() |
| 2447 | |
| 2448 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2449 | 'SUCCESS') |
| 2450 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2451 | 'SUCCESS') |
| 2452 | self.assertEqual(len(self.history), 4) |
| 2453 | |
| 2454 | self.assertEqual(A.data['status'], 'NEW') |
| 2455 | self.assertEqual(A.reported, 1) |
| 2456 | self.assertIn('Build succeeded', A.messages[0]) |
| 2457 | # Ensure the removed job was not included in the report. |
| 2458 | self.assertNotIn('project-test1', A.messages[0]) |
| 2459 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2460 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2461 | def test_live_reconfiguration_shared_queue(self): |
| 2462 | # Test that a change with a failing job which was removed from |
| 2463 | # this project but otherwise still exists in the system does |
| 2464 | # not disrupt reconfiguration. |
| 2465 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2466 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2467 | |
| 2468 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2469 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2470 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2471 | |
| 2472 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2473 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2474 | self.launch_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2475 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2476 | self.launch_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2477 | self.waitUntilSettled() |
| 2478 | |
| 2479 | self.assertEqual(A.data['status'], 'NEW') |
| 2480 | self.assertEqual(A.reported, 0) |
| 2481 | |
| 2482 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2483 | 'SUCCESS') |
| 2484 | self.assertEqual(self.getJobFromHistory( |
| 2485 | 'project1-project2-integration').result, 'FAILURE') |
| 2486 | self.assertEqual(len(self.history), 2) |
| 2487 | |
| 2488 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2489 | self.updateConfigLayout( |
| 2490 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2491 | self.sched.reconfigure(self.config) |
| 2492 | self.waitUntilSettled() |
| 2493 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2494 | self.launch_server.hold_jobs_in_build = False |
| 2495 | self.launch_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2496 | self.waitUntilSettled() |
| 2497 | |
| 2498 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2499 | 'SUCCESS') |
| 2500 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2501 | 'SUCCESS') |
| 2502 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2503 | 'SUCCESS') |
| 2504 | self.assertEqual(self.getJobFromHistory( |
| 2505 | 'project1-project2-integration').result, 'FAILURE') |
| 2506 | self.assertEqual(len(self.history), 4) |
| 2507 | |
| 2508 | self.assertEqual(A.data['status'], 'NEW') |
| 2509 | self.assertEqual(A.reported, 1) |
| 2510 | self.assertIn('Build succeeded', A.messages[0]) |
| 2511 | # Ensure the removed job was not included in the report. |
| 2512 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2513 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2514 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2515 | def test_double_live_reconfiguration_shared_queue(self): |
| 2516 | # This was a real-world regression. A change is added to |
| 2517 | # gate; a reconfigure happens, a second change which depends |
| 2518 | # on the first is added, and a second reconfiguration happens. |
| 2519 | # Ensure that both changes merge. |
| 2520 | |
| 2521 | # A failure may indicate incorrect caching or cleaning up of |
| 2522 | # references during a reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2523 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2524 | |
| 2525 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2526 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2527 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2528 | A.addApproval('code-review', 2) |
| 2529 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2530 | |
| 2531 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2532 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2533 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2534 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2535 | self.waitUntilSettled() |
| 2536 | |
| 2537 | # Reconfigure (with only one change in the pipeline). |
| 2538 | self.sched.reconfigure(self.config) |
| 2539 | self.waitUntilSettled() |
| 2540 | |
| 2541 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2542 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2543 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2544 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2545 | self.waitUntilSettled() |
| 2546 | |
| 2547 | # Reconfigure (with both in the pipeline). |
| 2548 | self.sched.reconfigure(self.config) |
| 2549 | self.waitUntilSettled() |
| 2550 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2551 | self.launch_server.hold_jobs_in_build = False |
| 2552 | self.launch_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2553 | self.waitUntilSettled() |
| 2554 | |
| 2555 | self.assertEqual(len(self.history), 8) |
| 2556 | |
| 2557 | self.assertEqual(A.data['status'], 'MERGED') |
| 2558 | self.assertEqual(A.reported, 2) |
| 2559 | self.assertEqual(B.data['status'], 'MERGED') |
| 2560 | self.assertEqual(B.reported, 2) |
| 2561 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2562 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2563 | def test_live_reconfiguration_del_project(self): |
| 2564 | # Test project deletion from layout |
| 2565 | # while changes are enqueued |
| 2566 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2567 | self.launch_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2568 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2569 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2570 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2571 | |
| 2572 | # A Depends-On: B |
| 2573 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2574 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2575 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2576 | |
| 2577 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2578 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2579 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2580 | self.launch_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2581 | self.waitUntilSettled() |
| 2582 | self.assertEqual(len(self.builds), 5) |
| 2583 | |
| 2584 | # This layout defines only org/project, not org/project1 |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2585 | self.updateConfigLayout( |
| 2586 | 'tests/fixtures/layout-live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2587 | self.sched.reconfigure(self.config) |
| 2588 | self.waitUntilSettled() |
| 2589 | |
| 2590 | # Builds for C aborted, builds for A succeed, |
| 2591 | # and have change B applied ahead |
| 2592 | job_c = self.getJobFromHistory('project1-test1') |
| 2593 | self.assertEqual(job_c.changes, '3,1') |
| 2594 | self.assertEqual(job_c.result, 'ABORTED') |
| 2595 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2596 | self.launch_server.hold_jobs_in_build = False |
| 2597 | self.launch_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2598 | self.waitUntilSettled() |
| 2599 | |
| 2600 | self.assertEqual(self.getJobFromHistory('project-test1').changes, |
| 2601 | '2,1 1,1') |
| 2602 | |
| 2603 | self.assertEqual(A.data['status'], 'NEW') |
| 2604 | self.assertEqual(B.data['status'], 'NEW') |
| 2605 | self.assertEqual(C.data['status'], 'NEW') |
| 2606 | self.assertEqual(A.reported, 1) |
| 2607 | self.assertEqual(B.reported, 0) |
| 2608 | self.assertEqual(C.reported, 0) |
| 2609 | |
| 2610 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 2611 | self.assertIn('Build succeeded', A.messages[0]) |
| 2612 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2613 | @skip("Disabled for early v3 development") |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2614 | def test_live_reconfiguration_functions(self): |
| 2615 | "Test live reconfiguration with a custom function" |
| 2616 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2617 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2618 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2619 | A.addApproval('code-review', 2) |
| 2620 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2621 | self.waitUntilSettled() |
| 2622 | |
| 2623 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2624 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2625 | 'debian') |
| 2626 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2627 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2628 | self.updateConfigLayout( |
| 2629 | 'tests/fixtures/layout-live-reconfiguration-functions.yaml') |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2630 | self.sched.reconfigure(self.config) |
| 2631 | self.worker.build_history = [] |
| 2632 | |
| 2633 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2634 | B.addApproval('code-review', 2) |
| 2635 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2636 | self.waitUntilSettled() |
| 2637 | |
| 2638 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2639 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2640 | 'wheezy') |
| 2641 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2642 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2643 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2644 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2645 | self.updateConfigLayout( |
| 2646 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2647 | self.sched.reconfigure(self.config) |
| 2648 | |
| 2649 | self.init_repo("org/new-project") |
| 2650 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2651 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2652 | A.addApproval('code-review', 2) |
| 2653 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2654 | self.waitUntilSettled() |
| 2655 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2656 | 'SUCCESS') |
| 2657 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2658 | 'SUCCESS') |
| 2659 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2660 | 'SUCCESS') |
| 2661 | self.assertEqual(A.data['status'], 'MERGED') |
| 2662 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2663 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2664 | def test_repo_deleted(self): |
Paul Belanger | 66e9596 | 2016-11-11 12:11:06 -0500 | [diff] [blame] | 2665 | self.updateConfigLayout('layout-repo-deleted') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2666 | self.sched.reconfigure(self.config) |
| 2667 | |
| 2668 | self.init_repo("org/delete-project") |
| 2669 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2670 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2671 | A.addApproval('code-review', 2) |
| 2672 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2673 | self.waitUntilSettled() |
| 2674 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2675 | 'SUCCESS') |
| 2676 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2677 | 'SUCCESS') |
| 2678 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2679 | 'SUCCESS') |
| 2680 | self.assertEqual(A.data['status'], 'MERGED') |
| 2681 | self.assertEqual(A.reported, 2) |
| 2682 | |
| 2683 | # Delete org/new-project zuul repo. Should be recloned. |
| 2684 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 2685 | |
| 2686 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2687 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2688 | B.addApproval('code-review', 2) |
| 2689 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2690 | self.waitUntilSettled() |
| 2691 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2692 | 'SUCCESS') |
| 2693 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2694 | 'SUCCESS') |
| 2695 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2696 | 'SUCCESS') |
| 2697 | self.assertEqual(B.data['status'], 'MERGED') |
| 2698 | self.assertEqual(B.reported, 2) |
| 2699 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2700 | @skip("Disabled for early v3 development") |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2701 | def test_tags(self): |
| 2702 | "Test job tags" |
| 2703 | self.config.set('zuul', 'layout_config', |
| 2704 | 'tests/fixtures/layout-tags.yaml') |
| 2705 | self.sched.reconfigure(self.config) |
| 2706 | |
| 2707 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2708 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2709 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2710 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2711 | self.waitUntilSettled() |
| 2712 | |
| 2713 | results = {'project1-merge': 'extratag merge project1', |
| 2714 | 'project2-merge': 'merge'} |
| 2715 | |
| 2716 | for build in self.history: |
| 2717 | self.assertEqual(results.get(build.name, ''), |
| 2718 | build.parameters.get('BUILD_TAGS')) |
| 2719 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2720 | @skip("Disabled for early v3 development") |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2721 | def test_timer(self): |
| 2722 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2723 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2724 | self.updateConfigLayout( |
| 2725 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2726 | self.sched.reconfigure(self.config) |
| 2727 | self.registerJobs() |
| 2728 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2729 | # The pipeline triggers every second, so we should have seen |
| 2730 | # several by now. |
| 2731 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2732 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2733 | |
| 2734 | self.assertEqual(len(self.builds), 2) |
| 2735 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2736 | port = self.webapp.server.socket.getsockname()[1] |
| 2737 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2738 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 2739 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2740 | data = f.read() |
| 2741 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2742 | self.launch_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2743 | # Stop queuing timer triggered jobs so that the assertions |
| 2744 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2745 | self.updateConfigLayout( |
| 2746 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2747 | self.sched.reconfigure(self.config) |
| 2748 | self.registerJobs() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2749 | self.launch_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2750 | self.waitUntilSettled() |
| 2751 | |
| 2752 | self.assertEqual(self.getJobFromHistory( |
| 2753 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2754 | self.assertEqual(self.getJobFromHistory( |
| 2755 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2756 | |
| 2757 | data = json.loads(data) |
| 2758 | status_jobs = set() |
| 2759 | for p in data['pipelines']: |
| 2760 | for q in p['change_queues']: |
| 2761 | for head in q['heads']: |
| 2762 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 2763 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2764 | for job in change['jobs']: |
| 2765 | status_jobs.add(job['name']) |
| 2766 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2767 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2768 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2769 | @skip("Disabled for early v3 development") |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2770 | def test_idle(self): |
| 2771 | "Test that frequent periodic jobs work" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2772 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2773 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2774 | for x in range(1, 3): |
| 2775 | # Test that timer triggers periodic jobs even across |
| 2776 | # layout config reloads. |
| 2777 | # Start timer trigger |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2778 | self.updateConfigLayout( |
| 2779 | 'tests/fixtures/layout-idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2780 | self.sched.reconfigure(self.config) |
| 2781 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2782 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2783 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2784 | # The pipeline triggers every second, so we should have seen |
| 2785 | # several by now. |
| 2786 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2787 | |
| 2788 | # Stop queuing timer triggered jobs so that the assertions |
| 2789 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2790 | self.updateConfigLayout( |
| 2791 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2792 | self.sched.reconfigure(self.config) |
| 2793 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2794 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2795 | |
| 2796 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2797 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2798 | self.waitUntilSettled() |
| 2799 | self.assertEqual(len(self.builds), 0) |
| 2800 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2801 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2802 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 2803 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2804 | self.sched.reconfigure(self.config) |
| 2805 | |
| 2806 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2807 | self.waitUntilSettled() |
| 2808 | |
| 2809 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2810 | self.waitUntilSettled() |
| 2811 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2812 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2813 | |
| 2814 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2815 | # work on the knowledge of what the first message should be as |
| 2816 | # it is only configured to go to SMTP. |
| 2817 | |
| 2818 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2819 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2820 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2821 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2822 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2823 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2824 | |
| 2825 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2826 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2827 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2828 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2829 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2830 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2831 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2832 | @skip("Disabled for early v3 development") |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2833 | def test_timer_smtp(self): |
| 2834 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2835 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2836 | self.updateConfigLayout( |
| 2837 | 'tests/fixtures/layout-timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2838 | self.sched.reconfigure(self.config) |
| 2839 | self.registerJobs() |
| 2840 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2841 | # The pipeline triggers every second, so we should have seen |
| 2842 | # several by now. |
| 2843 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2844 | self.waitUntilSettled() |
| 2845 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2846 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2847 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2848 | self.waitUntilSettled() |
| 2849 | self.assertEqual(len(self.history), 2) |
| 2850 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2851 | self.assertEqual(self.getJobFromHistory( |
| 2852 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2853 | self.assertEqual(self.getJobFromHistory( |
| 2854 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2855 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2856 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2857 | |
| 2858 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2859 | # work on the knowledge of what the first message should be as |
| 2860 | # it is only configured to go to SMTP. |
| 2861 | |
| 2862 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2863 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2864 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2865 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2866 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2867 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2868 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2869 | # Stop queuing timer triggered jobs and let any that may have |
| 2870 | # queued through so that end of test assertions pass. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2871 | self.updateConfigLayout( |
| 2872 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2873 | self.sched.reconfigure(self.config) |
| 2874 | self.registerJobs() |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 2875 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2876 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2877 | self.waitUntilSettled() |
| 2878 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2879 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2880 | "Test that the RPC client can enqueue a change" |
| 2881 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2882 | A.addApproval('code-review', 2) |
| 2883 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2884 | |
| 2885 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2886 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2887 | r = client.enqueue(tenant='tenant-one', |
| 2888 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2889 | project='org/project', |
| 2890 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2891 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2892 | self.waitUntilSettled() |
| 2893 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2894 | 'SUCCESS') |
| 2895 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2896 | 'SUCCESS') |
| 2897 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2898 | 'SUCCESS') |
| 2899 | self.assertEqual(A.data['status'], 'MERGED') |
| 2900 | self.assertEqual(A.reported, 2) |
| 2901 | self.assertEqual(r, True) |
| 2902 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2903 | @skip("Disabled for early v3 development") |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2904 | def test_client_enqueue_ref(self): |
| 2905 | "Test that the RPC client can enqueue a ref" |
| 2906 | |
| 2907 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2908 | self.gearman_server.port) |
| 2909 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2910 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2911 | pipeline='post', |
| 2912 | project='org/project', |
| 2913 | trigger='gerrit', |
| 2914 | ref='master', |
| 2915 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 2916 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 2917 | self.waitUntilSettled() |
| 2918 | job_names = [x.name for x in self.history] |
| 2919 | self.assertEqual(len(self.history), 1) |
| 2920 | self.assertIn('project-post', job_names) |
| 2921 | self.assertEqual(r, True) |
| 2922 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2923 | def test_client_enqueue_negative(self): |
| 2924 | "Test that the RPC client returns errors" |
| 2925 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2926 | self.gearman_server.port) |
| 2927 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2928 | "Invalid tenant"): |
| 2929 | r = client.enqueue(tenant='tenant-foo', |
| 2930 | pipeline='gate', |
| 2931 | project='org/project', |
| 2932 | trigger='gerrit', |
| 2933 | change='1,1') |
| 2934 | client.shutdown() |
| 2935 | self.assertEqual(r, False) |
| 2936 | |
| 2937 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2938 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2939 | r = client.enqueue(tenant='tenant-one', |
| 2940 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2941 | project='project-does-not-exist', |
| 2942 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2943 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2944 | client.shutdown() |
| 2945 | self.assertEqual(r, False) |
| 2946 | |
| 2947 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2948 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2949 | r = client.enqueue(tenant='tenant-one', |
| 2950 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2951 | project='org/project', |
| 2952 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2953 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2954 | client.shutdown() |
| 2955 | self.assertEqual(r, False) |
| 2956 | |
| 2957 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2958 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2959 | r = client.enqueue(tenant='tenant-one', |
| 2960 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2961 | project='org/project', |
| 2962 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2963 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2964 | client.shutdown() |
| 2965 | self.assertEqual(r, False) |
| 2966 | |
| 2967 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2968 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2969 | r = client.enqueue(tenant='tenant-one', |
| 2970 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2971 | project='org/project', |
| 2972 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2973 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2974 | client.shutdown() |
| 2975 | self.assertEqual(r, False) |
| 2976 | |
| 2977 | self.waitUntilSettled() |
| 2978 | self.assertEqual(len(self.history), 0) |
| 2979 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2980 | |
| 2981 | def test_client_promote(self): |
| 2982 | "Test that the RPC client can promote a change" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2983 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2984 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2985 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2986 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2987 | A.addApproval('code-review', 2) |
| 2988 | B.addApproval('code-review', 2) |
| 2989 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2990 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2991 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2992 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 2993 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2994 | |
| 2995 | self.waitUntilSettled() |
| 2996 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2997 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2998 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 2999 | enqueue_times = {} |
| 3000 | for item in items: |
| 3001 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3002 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3003 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3004 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3005 | r = client.promote(tenant='tenant-one', |
| 3006 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3007 | change_ids=['2,1', '3,1']) |
| 3008 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3009 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3010 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3011 | for item in items: |
| 3012 | self.assertEqual( |
| 3013 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3014 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3015 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3016 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3017 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3018 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3019 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3020 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3021 | self.waitUntilSettled() |
| 3022 | |
| 3023 | self.assertEqual(len(self.builds), 6) |
| 3024 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3025 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3026 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3027 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3028 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3029 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3030 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3031 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3032 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3033 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3034 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3035 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3036 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3037 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3038 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3039 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3040 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3041 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3042 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3043 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3044 | self.waitUntilSettled() |
| 3045 | |
| 3046 | self.assertEqual(A.data['status'], 'MERGED') |
| 3047 | self.assertEqual(A.reported, 2) |
| 3048 | self.assertEqual(B.data['status'], 'MERGED') |
| 3049 | self.assertEqual(B.reported, 2) |
| 3050 | self.assertEqual(C.data['status'], 'MERGED') |
| 3051 | self.assertEqual(C.reported, 2) |
| 3052 | |
| 3053 | client.shutdown() |
| 3054 | self.assertEqual(r, True) |
| 3055 | |
| 3056 | def test_client_promote_dependent(self): |
| 3057 | "Test that the RPC client can promote a dependent change" |
| 3058 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3059 | # A -> C (depends on B) -> B |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3060 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3061 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3062 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3063 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3064 | |
| 3065 | C.setDependsOn(B, 1) |
| 3066 | |
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 | |
| 3077 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3078 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3079 | r = client.promote(tenant='tenant-one', |
| 3080 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3081 | change_ids=['3,1']) |
| 3082 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3083 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3084 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3085 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3086 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3087 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3088 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3089 | self.waitUntilSettled() |
| 3090 | |
| 3091 | self.assertEqual(len(self.builds), 6) |
| 3092 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3093 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3094 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3095 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3096 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3097 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3098 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3099 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3100 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3101 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3102 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3103 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3104 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3105 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3106 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3107 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3108 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3109 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3110 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3111 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3112 | self.waitUntilSettled() |
| 3113 | |
| 3114 | self.assertEqual(A.data['status'], 'MERGED') |
| 3115 | self.assertEqual(A.reported, 2) |
| 3116 | self.assertEqual(B.data['status'], 'MERGED') |
| 3117 | self.assertEqual(B.reported, 2) |
| 3118 | self.assertEqual(C.data['status'], 'MERGED') |
| 3119 | self.assertEqual(C.reported, 2) |
| 3120 | |
| 3121 | client.shutdown() |
| 3122 | self.assertEqual(r, True) |
| 3123 | |
| 3124 | def test_client_promote_negative(self): |
| 3125 | "Test that the RPC client returns errors for promotion" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3126 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3127 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3128 | A.addApproval('code-review', 2) |
| 3129 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3130 | self.waitUntilSettled() |
| 3131 | |
| 3132 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3133 | self.gearman_server.port) |
| 3134 | |
| 3135 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3136 | r = client.promote(tenant='tenant-one', |
| 3137 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3138 | change_ids=['2,1', '3,1']) |
| 3139 | client.shutdown() |
| 3140 | self.assertEqual(r, False) |
| 3141 | |
| 3142 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3143 | r = client.promote(tenant='tenant-one', |
| 3144 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3145 | change_ids=['4,1']) |
| 3146 | client.shutdown() |
| 3147 | self.assertEqual(r, False) |
| 3148 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3149 | self.launch_server.hold_jobs_in_build = False |
| 3150 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3151 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3152 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3153 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3154 | def test_queue_rate_limiting(self): |
| 3155 | "Test that DependentPipelines are rate limited with dep across window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3156 | self.updateConfigLayout( |
| 3157 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3158 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3159 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3160 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3161 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3162 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3163 | |
| 3164 | C.setDependsOn(B, 1) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3165 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3166 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3167 | A.addApproval('code-review', 2) |
| 3168 | B.addApproval('code-review', 2) |
| 3169 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3170 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3171 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3172 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3173 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3174 | self.waitUntilSettled() |
| 3175 | |
| 3176 | # Only A and B will have their merge jobs queued because |
| 3177 | # window is 2. |
| 3178 | self.assertEqual(len(self.builds), 2) |
| 3179 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3180 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3181 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3182 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3183 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3184 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3185 | self.waitUntilSettled() |
| 3186 | |
| 3187 | # Only A and B will have their test jobs queued because |
| 3188 | # window is 2. |
| 3189 | self.assertEqual(len(self.builds), 4) |
| 3190 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3191 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3192 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3193 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3194 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3195 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3196 | self.waitUntilSettled() |
| 3197 | |
| 3198 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3199 | # A failed so window is reduced by 1 to 1. |
| 3200 | self.assertEqual(queue.window, 1) |
| 3201 | self.assertEqual(queue.window_floor, 1) |
| 3202 | self.assertEqual(A.data['status'], 'NEW') |
| 3203 | |
| 3204 | # Gate is reset and only B's merge job is queued because |
| 3205 | # window shrunk to 1. |
| 3206 | self.assertEqual(len(self.builds), 1) |
| 3207 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3208 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3209 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3210 | self.waitUntilSettled() |
| 3211 | |
| 3212 | # Only B's test jobs are queued because window is still 1. |
| 3213 | self.assertEqual(len(self.builds), 2) |
| 3214 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3215 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3216 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3217 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3218 | self.waitUntilSettled() |
| 3219 | |
| 3220 | # B was successfully merged so window is increased to 2. |
| 3221 | self.assertEqual(queue.window, 2) |
| 3222 | self.assertEqual(queue.window_floor, 1) |
| 3223 | self.assertEqual(B.data['status'], 'MERGED') |
| 3224 | |
| 3225 | # Only C is left and its merge job is queued. |
| 3226 | self.assertEqual(len(self.builds), 1) |
| 3227 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3228 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3229 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3230 | self.waitUntilSettled() |
| 3231 | |
| 3232 | # After successful merge job the test jobs for C are queued. |
| 3233 | self.assertEqual(len(self.builds), 2) |
| 3234 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3235 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3236 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3237 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3238 | self.waitUntilSettled() |
| 3239 | |
| 3240 | # C successfully merged so window is bumped to 3. |
| 3241 | self.assertEqual(queue.window, 3) |
| 3242 | self.assertEqual(queue.window_floor, 1) |
| 3243 | self.assertEqual(C.data['status'], 'MERGED') |
| 3244 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3245 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3246 | def test_queue_rate_limiting_dependent(self): |
| 3247 | "Test that DependentPipelines are rate limited with dep in window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3248 | self.updateConfigLayout( |
| 3249 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3250 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3251 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3252 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3253 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3254 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3255 | |
| 3256 | B.setDependsOn(A, 1) |
| 3257 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3258 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3259 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3260 | A.addApproval('code-review', 2) |
| 3261 | B.addApproval('code-review', 2) |
| 3262 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3263 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3264 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3265 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3266 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3267 | self.waitUntilSettled() |
| 3268 | |
| 3269 | # Only A and B will have their merge jobs queued because |
| 3270 | # window is 2. |
| 3271 | self.assertEqual(len(self.builds), 2) |
| 3272 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3273 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3274 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3275 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3276 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3277 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3278 | self.waitUntilSettled() |
| 3279 | |
| 3280 | # Only A and B will have their test jobs queued because |
| 3281 | # window is 2. |
| 3282 | self.assertEqual(len(self.builds), 4) |
| 3283 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3284 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3285 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3286 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3287 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3288 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3289 | self.waitUntilSettled() |
| 3290 | |
| 3291 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3292 | # A failed so window is reduced by 1 to 1. |
| 3293 | self.assertEqual(queue.window, 1) |
| 3294 | self.assertEqual(queue.window_floor, 1) |
| 3295 | self.assertEqual(A.data['status'], 'NEW') |
| 3296 | self.assertEqual(B.data['status'], 'NEW') |
| 3297 | |
| 3298 | # Gate is reset and only C's merge job is queued because |
| 3299 | # window shrunk to 1 and A and B were dequeued. |
| 3300 | self.assertEqual(len(self.builds), 1) |
| 3301 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3302 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3303 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3304 | self.waitUntilSettled() |
| 3305 | |
| 3306 | # Only C's test jobs are queued because window is still 1. |
| 3307 | self.assertEqual(len(self.builds), 2) |
| 3308 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3309 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3310 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3311 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3312 | self.waitUntilSettled() |
| 3313 | |
| 3314 | # C was successfully merged so window is increased to 2. |
| 3315 | self.assertEqual(queue.window, 2) |
| 3316 | self.assertEqual(queue.window_floor, 1) |
| 3317 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3318 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3319 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3320 | def test_worker_update_metadata(self): |
| 3321 | "Test if a worker can send back metadata about itself" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3322 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3323 | |
| 3324 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3325 | A.addApproval('code-review', 2) |
| 3326 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3327 | self.waitUntilSettled() |
| 3328 | |
| 3329 | self.assertEqual(len(self.launcher.builds), 1) |
| 3330 | |
| 3331 | self.log.debug('Current builds:') |
| 3332 | self.log.debug(self.launcher.builds) |
| 3333 | |
| 3334 | start = time.time() |
| 3335 | while True: |
| 3336 | if time.time() - start > 10: |
| 3337 | raise Exception("Timeout waiting for gearman server to report " |
| 3338 | + "back to the client") |
| 3339 | build = self.launcher.builds.values()[0] |
| 3340 | if build.worker.name == "My Worker": |
| 3341 | break |
| 3342 | else: |
| 3343 | time.sleep(0) |
| 3344 | |
| 3345 | self.log.debug(build) |
| 3346 | self.assertEqual("My Worker", build.worker.name) |
| 3347 | self.assertEqual("localhost", build.worker.hostname) |
| 3348 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3349 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3350 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3351 | self.assertEqual("v1.1", build.worker.version) |
| 3352 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3353 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3354 | self.launch_server.hold_jobs_in_build = False |
| 3355 | self.launch_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3356 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3357 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3358 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3359 | def test_footer_message(self): |
| 3360 | "Test a pipeline's footer message is correctly added to the report." |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3361 | self.updateConfigLayout( |
| 3362 | 'tests/fixtures/layout-footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3363 | self.sched.reconfigure(self.config) |
| 3364 | self.registerJobs() |
| 3365 | |
| 3366 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3367 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3368 | self.launch_server.failJob('test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3369 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3370 | self.waitUntilSettled() |
| 3371 | |
| 3372 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3373 | B.addApproval('code-review', 2) |
| 3374 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3375 | self.waitUntilSettled() |
| 3376 | |
| 3377 | self.assertEqual(2, len(self.smtp_messages)) |
| 3378 | |
| 3379 | failure_body = """\ |
| 3380 | Build failed. For information on how to proceed, see \ |
| 3381 | http://wiki.example.org/Test_Failures |
| 3382 | |
| 3383 | - test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s |
| 3384 | - test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s |
| 3385 | |
| 3386 | For CI problems and help debugging, contact ci@example.org""" |
| 3387 | |
| 3388 | success_body = """\ |
| 3389 | Build succeeded. |
| 3390 | |
| 3391 | - test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s |
| 3392 | - test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s |
| 3393 | |
| 3394 | For CI problems and help debugging, contact ci@example.org""" |
| 3395 | |
| 3396 | self.assertEqual(failure_body, self.smtp_messages[0]['body']) |
| 3397 | self.assertEqual(success_body, self.smtp_messages[1]['body']) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [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 | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3400 | def test_merge_failure_reporters(self): |
| 3401 | """Check that the config is set up correctly""" |
| 3402 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3403 | self.updateConfigLayout( |
| 3404 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3405 | self.sched.reconfigure(self.config) |
| 3406 | self.registerJobs() |
| 3407 | |
| 3408 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3409 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3410 | "dependencies was unable to be automatically merged with the " |
| 3411 | "current state of its repository. Please rebase the change and " |
| 3412 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3413 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3414 | self.assertEqual( |
| 3415 | "The merge failed! For more information...", |
| 3416 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3417 | |
| 3418 | self.assertEqual( |
| 3419 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3420 | self.assertEqual( |
| 3421 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3422 | |
| 3423 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3424 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3425 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3426 | |
| 3427 | self.assertTrue( |
| 3428 | ( |
| 3429 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3430 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3431 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3432 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3433 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3434 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3435 | ) or ( |
| 3436 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3437 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3438 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3439 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3440 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3441 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3442 | ) |
| 3443 | ) |
| 3444 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3445 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3446 | def test_merge_failure_reports(self): |
| 3447 | """Check that when a change fails to merge the correct message is sent |
| 3448 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3449 | self.updateConfigLayout( |
| 3450 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3451 | self.sched.reconfigure(self.config) |
| 3452 | self.registerJobs() |
| 3453 | |
| 3454 | # Check a test failure isn't reported to SMTP |
| 3455 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3456 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3457 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3458 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3459 | self.waitUntilSettled() |
| 3460 | |
| 3461 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3462 | self.assertEqual(0, len(self.smtp_messages)) |
| 3463 | |
| 3464 | # Check a merge failure is reported to SMTP |
| 3465 | # B should be merged, but C will conflict with B |
| 3466 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3467 | B.addPatchset(['conflict']) |
| 3468 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3469 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3470 | B.addApproval('code-review', 2) |
| 3471 | C.addApproval('code-review', 2) |
| 3472 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3473 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3474 | self.waitUntilSettled() |
| 3475 | |
| 3476 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3477 | self.assertEqual(1, len(self.smtp_messages)) |
| 3478 | self.assertEqual('The merge failed! For more information...', |
| 3479 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3480 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3481 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3482 | def test_default_merge_failure_reports(self): |
| 3483 | """Check that the default merge failure reports are correct.""" |
| 3484 | |
| 3485 | # A should report success, B should report merge failure. |
| 3486 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3487 | A.addPatchset(['conflict']) |
| 3488 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3489 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3490 | A.addApproval('code-review', 2) |
| 3491 | B.addApproval('code-review', 2) |
| 3492 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3493 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3494 | self.waitUntilSettled() |
| 3495 | |
| 3496 | self.assertEqual(3, len(self.history)) # A jobs |
| 3497 | self.assertEqual(A.reported, 2) |
| 3498 | self.assertEqual(B.reported, 2) |
| 3499 | self.assertEqual(A.data['status'], 'MERGED') |
| 3500 | self.assertEqual(B.data['status'], 'NEW') |
| 3501 | self.assertIn('Build succeeded', A.messages[1]) |
| 3502 | self.assertIn('Merge Failed', B.messages[1]) |
| 3503 | self.assertIn('automatically merged', B.messages[1]) |
| 3504 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3505 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3506 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3507 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3508 | def test_swift_instructions(self): |
| 3509 | "Test that the correct swift instructions are sent to the workers" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3510 | self.updateConfigLayout( |
| 3511 | 'tests/fixtures/layout-swift.yaml') |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3512 | self.sched.reconfigure(self.config) |
| 3513 | self.registerJobs() |
| 3514 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3515 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3516 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3517 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3518 | A.addApproval('code-review', 2) |
| 3519 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3520 | self.waitUntilSettled() |
| 3521 | |
| 3522 | self.assertEqual( |
| 3523 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3524 | "gate/test-merge/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3525 | self.builds[0].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3526 | self.assertEqual(5, |
| 3527 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3528 | split('\n'))) |
| 3529 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3530 | |
| 3531 | self.assertEqual( |
| 3532 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3533 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3534 | self.builds[1].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3535 | self.assertEqual(5, |
| 3536 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3537 | split('\n'))) |
| 3538 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3539 | |
| 3540 | self.assertEqual( |
| 3541 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3542 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3543 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3544 | self.assertEqual(5, |
| 3545 | len(self.builds[1]. |
| 3546 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3547 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3548 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3549 | self.launch_server.hold_jobs_in_build = False |
| 3550 | self.launch_server.release() |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3551 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3552 | |
| 3553 | def test_client_get_running_jobs(self): |
| 3554 | "Test that the RPC client can get a list of running jobs" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3555 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3556 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3557 | A.addApproval('code-review', 2) |
| 3558 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3559 | self.waitUntilSettled() |
| 3560 | |
| 3561 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3562 | self.gearman_server.port) |
| 3563 | |
| 3564 | # Wait for gearman server to send the initial workData back to zuul |
| 3565 | start = time.time() |
| 3566 | while True: |
| 3567 | if time.time() - start > 10: |
| 3568 | raise Exception("Timeout waiting for gearman server to report " |
| 3569 | + "back to the client") |
Clint Byrum | 78a6977 | 2016-12-05 10:52:07 -0800 | [diff] [blame] | 3570 | build = self.launch_client.builds.values()[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3571 | if build.worker.name == "My Worker": |
| 3572 | break |
| 3573 | else: |
| 3574 | time.sleep(0) |
| 3575 | |
| 3576 | running_items = client.get_running_jobs() |
| 3577 | |
| 3578 | self.assertEqual(1, len(running_items)) |
| 3579 | running_item = running_items[0] |
| 3580 | self.assertEqual([], running_item['failing_reasons']) |
| 3581 | self.assertEqual([], running_item['items_behind']) |
| 3582 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3583 | self.assertEqual(None, running_item['item_ahead']) |
| 3584 | self.assertEqual('org/project', running_item['project']) |
| 3585 | self.assertEqual(None, running_item['remaining_time']) |
| 3586 | self.assertEqual(True, running_item['active']) |
| 3587 | self.assertEqual('1,1', running_item['id']) |
| 3588 | |
| 3589 | self.assertEqual(3, len(running_item['jobs'])) |
| 3590 | for job in running_item['jobs']: |
| 3591 | if job['name'] == 'project-merge': |
| 3592 | self.assertEqual('project-merge', job['name']) |
| 3593 | self.assertEqual('gate', job['pipeline']) |
| 3594 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3595 | self.assertEqual('https://server/job/project-merge/0/', |
| 3596 | job['url']) |
| 3597 | self.assertEqual(7, len(job['worker'])) |
| 3598 | self.assertEqual(False, job['canceled']) |
| 3599 | self.assertEqual(True, job['voting']) |
| 3600 | self.assertEqual(None, job['result']) |
| 3601 | self.assertEqual('gate', job['pipeline']) |
| 3602 | break |
| 3603 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3604 | self.launch_server.hold_jobs_in_build = False |
| 3605 | self.launch_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3606 | self.waitUntilSettled() |
| 3607 | |
| 3608 | running_items = client.get_running_jobs() |
| 3609 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3610 | |
| 3611 | def test_nonvoting_pipeline(self): |
| 3612 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3613 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3614 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3615 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3616 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3617 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3618 | |
| 3619 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3620 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3621 | self.assertEqual( |
| 3622 | self.getJobFromHistory('experimental-project-test').result, |
| 3623 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3624 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3625 | |
| 3626 | def test_crd_gate(self): |
| 3627 | "Test cross-repo dependencies" |
| 3628 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3629 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3630 | A.addApproval('code-review', 2) |
| 3631 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3632 | |
| 3633 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3634 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3635 | AM2.setMerged() |
| 3636 | AM1.setMerged() |
| 3637 | |
| 3638 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3639 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3640 | BM2.setMerged() |
| 3641 | BM1.setMerged() |
| 3642 | |
| 3643 | # A -> AM1 -> AM2 |
| 3644 | # B -> BM1 -> BM2 |
| 3645 | # A Depends-On: B |
| 3646 | # M2 is here to make sure it is never queried. If it is, it |
| 3647 | # means zuul is walking down the entire history of merged |
| 3648 | # changes. |
| 3649 | |
| 3650 | B.setDependsOn(BM1, 1) |
| 3651 | BM1.setDependsOn(BM2, 1) |
| 3652 | |
| 3653 | A.setDependsOn(AM1, 1) |
| 3654 | AM1.setDependsOn(AM2, 1) |
| 3655 | |
| 3656 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3657 | A.subject, B.data['id']) |
| 3658 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3659 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3660 | self.waitUntilSettled() |
| 3661 | |
| 3662 | self.assertEqual(A.data['status'], 'NEW') |
| 3663 | self.assertEqual(B.data['status'], 'NEW') |
| 3664 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3665 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3666 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3667 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3668 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3669 | B.addApproval('approved', 1) |
| 3670 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3671 | self.waitUntilSettled() |
| 3672 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3673 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3674 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3675 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3676 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3677 | self.launch_server.hold_jobs_in_build = False |
| 3678 | self.launch_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3679 | self.waitUntilSettled() |
| 3680 | |
| 3681 | self.assertEqual(AM2.queried, 0) |
| 3682 | self.assertEqual(BM2.queried, 0) |
| 3683 | self.assertEqual(A.data['status'], 'MERGED') |
| 3684 | self.assertEqual(B.data['status'], 'MERGED') |
| 3685 | self.assertEqual(A.reported, 2) |
| 3686 | self.assertEqual(B.reported, 2) |
| 3687 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3688 | changes = self.getJobFromHistory( |
| 3689 | 'project-merge', 'org/project1').changes |
| 3690 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3691 | |
| 3692 | def test_crd_branch(self): |
| 3693 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3694 | |
| 3695 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3696 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3697 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3698 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3699 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3700 | A.addApproval('code-review', 2) |
| 3701 | B.addApproval('code-review', 2) |
| 3702 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3703 | |
| 3704 | # A Depends-On: B+C |
| 3705 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3706 | A.subject, B.data['id']) |
| 3707 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3708 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3709 | B.addApproval('approved', 1) |
| 3710 | C.addApproval('approved', 1) |
| 3711 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3712 | self.waitUntilSettled() |
| 3713 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3714 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3715 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3716 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3717 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3718 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3719 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3720 | self.launch_server.hold_jobs_in_build = False |
| 3721 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3722 | self.waitUntilSettled() |
| 3723 | |
| 3724 | self.assertEqual(A.data['status'], 'MERGED') |
| 3725 | self.assertEqual(B.data['status'], 'MERGED') |
| 3726 | self.assertEqual(C.data['status'], 'MERGED') |
| 3727 | self.assertEqual(A.reported, 2) |
| 3728 | self.assertEqual(B.reported, 2) |
| 3729 | self.assertEqual(C.reported, 2) |
| 3730 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3731 | changes = self.getJobFromHistory( |
| 3732 | 'project-merge', 'org/project1').changes |
| 3733 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3734 | |
| 3735 | def test_crd_multiline(self): |
| 3736 | "Test multiple depends-on lines in commit" |
| 3737 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3738 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3739 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3740 | A.addApproval('code-review', 2) |
| 3741 | B.addApproval('code-review', 2) |
| 3742 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3743 | |
| 3744 | # A Depends-On: B+C |
| 3745 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3746 | A.subject, B.data['id'], C.data['id']) |
| 3747 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3748 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3749 | B.addApproval('approved', 1) |
| 3750 | C.addApproval('approved', 1) |
| 3751 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3752 | self.waitUntilSettled() |
| 3753 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3754 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3755 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3756 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3757 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3758 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3759 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3760 | self.launch_server.hold_jobs_in_build = False |
| 3761 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3762 | self.waitUntilSettled() |
| 3763 | |
| 3764 | self.assertEqual(A.data['status'], 'MERGED') |
| 3765 | self.assertEqual(B.data['status'], 'MERGED') |
| 3766 | self.assertEqual(C.data['status'], 'MERGED') |
| 3767 | self.assertEqual(A.reported, 2) |
| 3768 | self.assertEqual(B.reported, 2) |
| 3769 | self.assertEqual(C.reported, 2) |
| 3770 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3771 | changes = self.getJobFromHistory( |
| 3772 | 'project-merge', 'org/project1').changes |
| 3773 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3774 | |
| 3775 | def test_crd_unshared_gate(self): |
| 3776 | "Test cross-repo dependencies in unshared gate queues" |
| 3777 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3778 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3779 | A.addApproval('code-review', 2) |
| 3780 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3781 | |
| 3782 | # A Depends-On: B |
| 3783 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3784 | A.subject, B.data['id']) |
| 3785 | |
| 3786 | # A and B do not share a queue, make sure that A is unable to |
| 3787 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3788 | B.addApproval('approved', 1) |
| 3789 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3790 | self.waitUntilSettled() |
| 3791 | |
| 3792 | self.assertEqual(A.data['status'], 'NEW') |
| 3793 | self.assertEqual(B.data['status'], 'NEW') |
| 3794 | self.assertEqual(A.reported, 0) |
| 3795 | self.assertEqual(B.reported, 0) |
| 3796 | self.assertEqual(len(self.history), 0) |
| 3797 | |
| 3798 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3799 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3800 | self.waitUntilSettled() |
| 3801 | |
| 3802 | self.assertEqual(B.data['status'], 'MERGED') |
| 3803 | self.assertEqual(B.reported, 2) |
| 3804 | |
| 3805 | # Now that B is merged, A should be able to be enqueued and |
| 3806 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3807 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3808 | self.waitUntilSettled() |
| 3809 | |
| 3810 | self.assertEqual(A.data['status'], 'MERGED') |
| 3811 | self.assertEqual(A.reported, 2) |
| 3812 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3813 | def test_crd_gate_reverse(self): |
| 3814 | "Test reverse cross-repo dependencies" |
| 3815 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3816 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3817 | A.addApproval('code-review', 2) |
| 3818 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3819 | |
| 3820 | # A Depends-On: B |
| 3821 | |
| 3822 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3823 | A.subject, B.data['id']) |
| 3824 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3825 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3826 | self.waitUntilSettled() |
| 3827 | |
| 3828 | self.assertEqual(A.data['status'], 'NEW') |
| 3829 | self.assertEqual(B.data['status'], 'NEW') |
| 3830 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3831 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3832 | A.addApproval('approved', 1) |
| 3833 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3834 | self.waitUntilSettled() |
| 3835 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3836 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3837 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3838 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3839 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3840 | self.launch_server.hold_jobs_in_build = False |
| 3841 | self.launch_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3842 | self.waitUntilSettled() |
| 3843 | |
| 3844 | self.assertEqual(A.data['status'], 'MERGED') |
| 3845 | self.assertEqual(B.data['status'], 'MERGED') |
| 3846 | self.assertEqual(A.reported, 2) |
| 3847 | self.assertEqual(B.reported, 2) |
| 3848 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3849 | changes = self.getJobFromHistory( |
| 3850 | 'project-merge', 'org/project1').changes |
| 3851 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3852 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3853 | def test_crd_cycle(self): |
| 3854 | "Test cross-repo dependency cycles" |
| 3855 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3856 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3857 | A.addApproval('code-review', 2) |
| 3858 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3859 | |
| 3860 | # A -> B -> A (via commit-depends) |
| 3861 | |
| 3862 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3863 | A.subject, B.data['id']) |
| 3864 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3865 | B.subject, A.data['id']) |
| 3866 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3867 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3868 | self.waitUntilSettled() |
| 3869 | |
| 3870 | self.assertEqual(A.reported, 0) |
| 3871 | self.assertEqual(B.reported, 0) |
| 3872 | self.assertEqual(A.data['status'], 'NEW') |
| 3873 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3874 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3875 | def test_crd_gate_unknown(self): |
| 3876 | "Test unknown projects in dependent pipeline" |
| 3877 | self.init_repo("org/unknown") |
| 3878 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3879 | B = self.fake_gerrit.addFakeChange('org/unknown', '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) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3882 | |
| 3883 | # A Depends-On: B |
| 3884 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3885 | A.subject, B.data['id']) |
| 3886 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3887 | B.addApproval('approved', 1) |
| 3888 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3889 | self.waitUntilSettled() |
| 3890 | |
| 3891 | # Unknown projects cannot share a queue with any other |
| 3892 | # since they don't have common jobs with any other (they have no jobs). |
| 3893 | # Changes which depend on unknown project changes |
| 3894 | # should not be processed in dependent pipeline |
| 3895 | self.assertEqual(A.data['status'], 'NEW') |
| 3896 | self.assertEqual(B.data['status'], 'NEW') |
| 3897 | self.assertEqual(A.reported, 0) |
| 3898 | self.assertEqual(B.reported, 0) |
| 3899 | self.assertEqual(len(self.history), 0) |
| 3900 | |
| 3901 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3902 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3903 | B.setMerged() |
| 3904 | self.waitUntilSettled() |
| 3905 | self.assertEqual(len(self.history), 0) |
| 3906 | |
| 3907 | # Now that B is merged, A should be able to be enqueued and |
| 3908 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3909 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3910 | self.waitUntilSettled() |
| 3911 | |
| 3912 | self.assertEqual(A.data['status'], 'MERGED') |
| 3913 | self.assertEqual(A.reported, 2) |
| 3914 | self.assertEqual(B.data['status'], 'MERGED') |
| 3915 | self.assertEqual(B.reported, 0) |
| 3916 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3917 | def test_crd_check(self): |
| 3918 | "Test cross-repo dependencies in independent pipelines" |
| 3919 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3920 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3921 | self.gearman_server.hold_jobs_in_queue = True |
| 3922 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3923 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3924 | |
| 3925 | # A Depends-On: B |
| 3926 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3927 | A.subject, B.data['id']) |
| 3928 | |
| 3929 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3930 | self.waitUntilSettled() |
| 3931 | |
| 3932 | queue = self.gearman_server.getQueue() |
| 3933 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 3934 | self.gearman_server.hold_jobs_in_queue = False |
| 3935 | self.gearman_server.release() |
| 3936 | self.waitUntilSettled() |
| 3937 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3938 | self.launch_server.release('.*-merge') |
| 3939 | self.waitUntilSettled() |
| 3940 | |
| 3941 | path = os.path.join(self.builds[0].jobdir.git_root, "org/project1") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3942 | repo = git.Repo(path) |
| 3943 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 3944 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3945 | correct_messages = [ |
| 3946 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3947 | self.assertEqual(repo_messages, correct_messages) |
| 3948 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3949 | path = os.path.join(self.builds[0].jobdir.git_root, "org/project2") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3950 | repo = git.Repo(path) |
| 3951 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 3952 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3953 | correct_messages = [ |
| 3954 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3955 | self.assertEqual(repo_messages, correct_messages) |
| 3956 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3957 | self.launch_server.hold_jobs_in_build = False |
| 3958 | self.launch_server.release() |
| 3959 | self.waitUntilSettled() |
| 3960 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3961 | self.assertEqual(A.data['status'], 'NEW') |
| 3962 | self.assertEqual(B.data['status'], 'NEW') |
| 3963 | self.assertEqual(A.reported, 1) |
| 3964 | self.assertEqual(B.reported, 0) |
| 3965 | |
| 3966 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3967 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3968 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3969 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3970 | def test_crd_check_git_depends(self): |
| 3971 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 3972 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3973 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3974 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3975 | |
| 3976 | # Add two git-dependent changes and make sure they both report |
| 3977 | # success. |
| 3978 | B.setDependsOn(A, 1) |
| 3979 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3980 | self.waitUntilSettled() |
| 3981 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3982 | self.waitUntilSettled() |
| 3983 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 3984 | self.orderedRelease() |
| 3985 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3986 | self.waitUntilSettled() |
| 3987 | |
| 3988 | self.assertEqual(A.data['status'], 'NEW') |
| 3989 | self.assertEqual(B.data['status'], 'NEW') |
| 3990 | self.assertEqual(A.reported, 1) |
| 3991 | self.assertEqual(B.reported, 1) |
| 3992 | |
| 3993 | self.assertEqual(self.history[0].changes, '1,1') |
| 3994 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3995 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3996 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3997 | |
| 3998 | self.assertIn('Build succeeded', A.messages[0]) |
| 3999 | self.assertIn('Build succeeded', B.messages[0]) |
| 4000 | |
| 4001 | def test_crd_check_duplicate(self): |
| 4002 | "Test duplicate check in independent pipelines" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4003 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4004 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4005 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4006 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4007 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4008 | |
| 4009 | # Add two git-dependent changes... |
| 4010 | B.setDependsOn(A, 1) |
| 4011 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4012 | self.waitUntilSettled() |
| 4013 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4014 | |
| 4015 | # ...make sure the live one is not duplicated... |
| 4016 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4017 | self.waitUntilSettled() |
| 4018 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4019 | |
| 4020 | # ...but the non-live one is able to be. |
| 4021 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4022 | self.waitUntilSettled() |
| 4023 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4024 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4025 | # Release jobs in order to avoid races with change A jobs |
| 4026 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4027 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4028 | self.launch_server.hold_jobs_in_build = False |
| 4029 | self.launch_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4030 | self.waitUntilSettled() |
| 4031 | |
| 4032 | self.assertEqual(A.data['status'], 'NEW') |
| 4033 | self.assertEqual(B.data['status'], 'NEW') |
| 4034 | self.assertEqual(A.reported, 1) |
| 4035 | self.assertEqual(B.reported, 1) |
| 4036 | |
| 4037 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4038 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4039 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4040 | |
| 4041 | self.assertIn('Build succeeded', A.messages[0]) |
| 4042 | self.assertIn('Build succeeded', B.messages[0]) |
| 4043 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4044 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4045 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4046 | |
| 4047 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4048 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4049 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4050 | |
| 4051 | # A Depends-On: B |
| 4052 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4053 | A.subject, B.data['id']) |
| 4054 | |
| 4055 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4056 | self.waitUntilSettled() |
| 4057 | |
| 4058 | self.sched.reconfigure(self.config) |
| 4059 | |
| 4060 | # Make sure the items still share a change queue, and the |
| 4061 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4062 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4063 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4064 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4065 | first_item = queue.queue[0] |
| 4066 | for item in queue.queue: |
| 4067 | self.assertEqual(item.queue, first_item.queue) |
| 4068 | self.assertFalse(first_item.live) |
| 4069 | self.assertTrue(queue.queue[1].live) |
| 4070 | |
| 4071 | self.gearman_server.hold_jobs_in_queue = False |
| 4072 | self.gearman_server.release() |
| 4073 | self.waitUntilSettled() |
| 4074 | |
| 4075 | self.assertEqual(A.data['status'], 'NEW') |
| 4076 | self.assertEqual(B.data['status'], 'NEW') |
| 4077 | self.assertEqual(A.reported, 1) |
| 4078 | self.assertEqual(B.reported, 0) |
| 4079 | |
| 4080 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4081 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4082 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4083 | def test_crd_check_reconfiguration(self): |
| 4084 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4085 | |
| 4086 | def test_crd_undefined_project(self): |
| 4087 | """Test that undefined projects in dependencies are handled for |
| 4088 | independent pipelines""" |
| 4089 | # It's a hack for fake gerrit, |
| 4090 | # as it implies repo creation upon the creation of any change |
| 4091 | self.init_repo("org/unknown") |
| 4092 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4093 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4094 | @skip("Disabled for early v3 development") |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4095 | def test_crd_check_ignore_dependencies(self): |
| 4096 | "Test cross-repo dependencies can be ignored" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4097 | self.updateConfigLayout( |
| 4098 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4099 | self.sched.reconfigure(self.config) |
| 4100 | self.registerJobs() |
| 4101 | |
| 4102 | self.gearman_server.hold_jobs_in_queue = True |
| 4103 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4104 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4105 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4106 | |
| 4107 | # A Depends-On: B |
| 4108 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4109 | A.subject, B.data['id']) |
| 4110 | # C git-depends on B |
| 4111 | C.setDependsOn(B, 1) |
| 4112 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4113 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4114 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4115 | self.waitUntilSettled() |
| 4116 | |
| 4117 | # Make sure none of the items share a change queue, and all |
| 4118 | # are live. |
| 4119 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4120 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4121 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4122 | for item in check_pipeline.getAllItems(): |
| 4123 | self.assertTrue(item.live) |
| 4124 | |
| 4125 | self.gearman_server.hold_jobs_in_queue = False |
| 4126 | self.gearman_server.release() |
| 4127 | self.waitUntilSettled() |
| 4128 | |
| 4129 | self.assertEqual(A.data['status'], 'NEW') |
| 4130 | self.assertEqual(B.data['status'], 'NEW') |
| 4131 | self.assertEqual(C.data['status'], 'NEW') |
| 4132 | self.assertEqual(A.reported, 1) |
| 4133 | self.assertEqual(B.reported, 1) |
| 4134 | self.assertEqual(C.reported, 1) |
| 4135 | |
| 4136 | # Each job should have tested exactly one change |
| 4137 | for job in self.history: |
| 4138 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4139 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4140 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4141 | def test_crd_check_transitive(self): |
| 4142 | "Test transitive cross-repo dependencies" |
| 4143 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4144 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4145 | # and C,2 (not C,1 which would indicate stale data in the |
| 4146 | # cache for B). |
| 4147 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4148 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4149 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4150 | |
| 4151 | # A Depends-On: B |
| 4152 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4153 | A.subject, B.data['id']) |
| 4154 | |
| 4155 | # B Depends-On: C |
| 4156 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4157 | B.subject, C.data['id']) |
| 4158 | |
| 4159 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4160 | self.waitUntilSettled() |
| 4161 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4162 | |
| 4163 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4164 | self.waitUntilSettled() |
| 4165 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4166 | |
| 4167 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4168 | self.waitUntilSettled() |
| 4169 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4170 | |
| 4171 | C.addPatchset() |
| 4172 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4173 | self.waitUntilSettled() |
| 4174 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4175 | |
| 4176 | A.addPatchset() |
| 4177 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4178 | self.waitUntilSettled() |
| 4179 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4180 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4181 | def test_crd_check_unknown(self): |
| 4182 | "Test unknown projects in independent pipeline" |
| 4183 | self.init_repo("org/unknown") |
| 4184 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4185 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4186 | # A Depends-On: B |
| 4187 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4188 | A.subject, B.data['id']) |
| 4189 | |
| 4190 | # Make sure zuul has seen an event on B. |
| 4191 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4192 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4193 | self.waitUntilSettled() |
| 4194 | |
| 4195 | self.assertEqual(A.data['status'], 'NEW') |
| 4196 | self.assertEqual(A.reported, 1) |
| 4197 | self.assertEqual(B.data['status'], 'NEW') |
| 4198 | self.assertEqual(B.reported, 0) |
| 4199 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4200 | def test_crd_cycle_join(self): |
| 4201 | "Test an updated change creates a cycle" |
| 4202 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4203 | |
| 4204 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4205 | self.waitUntilSettled() |
| 4206 | |
| 4207 | # Create B->A |
| 4208 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4209 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4210 | B.subject, A.data['id']) |
| 4211 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4212 | self.waitUntilSettled() |
| 4213 | |
| 4214 | # Update A to add A->B (a cycle). |
| 4215 | A.addPatchset() |
| 4216 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4217 | A.subject, B.data['id']) |
| 4218 | # Normally we would submit the patchset-created event for |
| 4219 | # processing here, however, we have no way of noting whether |
| 4220 | # the dependency cycle detection correctly raised an |
| 4221 | # exception, so instead, we reach into the source driver and |
| 4222 | # call the method that would ultimately be called by the event |
| 4223 | # processing. |
| 4224 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4225 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4226 | source = tenant.layout.pipelines['gate'].source |
| 4227 | |
| 4228 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4229 | # it easier for users to create events for testing. |
| 4230 | event = zuul.model.TriggerEvent() |
| 4231 | event.trigger_name = 'gerrit' |
| 4232 | event.change_number = '1' |
| 4233 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4234 | with testtools.ExpectedException( |
| 4235 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4236 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4237 | self.log.debug("Got expected dependency cycle exception") |
| 4238 | |
| 4239 | # Now if we update B to remove the depends-on, everything |
| 4240 | # should be okay. B; A->B |
| 4241 | |
| 4242 | B.addPatchset() |
| 4243 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4244 | |
| 4245 | source.getChange(event, True) |
| 4246 | event.change_number = '2' |
| 4247 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4248 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4249 | def test_disable_at(self): |
| 4250 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4251 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4252 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4253 | self.sched.reconfigure(self.config) |
| 4254 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4255 | tenant = self.sched.abide.tenants.get('openstack') |
| 4256 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4257 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4258 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4259 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4260 | |
| 4261 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4262 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4263 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4264 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4265 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4266 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4267 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4268 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4269 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4270 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4271 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4272 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4273 | self.launch_server.failJob('project-test1', A) |
| 4274 | self.launch_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4275 | # Let C pass, resetting the counter |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4276 | self.launch_server.failJob('project-test1', D) |
| 4277 | self.launch_server.failJob('project-test1', E) |
| 4278 | self.launch_server.failJob('project-test1', F) |
| 4279 | self.launch_server.failJob('project-test1', G) |
| 4280 | self.launch_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4281 | # I also passes but should only report to the disabled reporters |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4282 | self.launch_server.failJob('project-test1', J) |
| 4283 | self.launch_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4284 | |
| 4285 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4286 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4287 | self.waitUntilSettled() |
| 4288 | |
| 4289 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4290 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4291 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4292 | |
| 4293 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4294 | self.waitUntilSettled() |
| 4295 | |
| 4296 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4297 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4298 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4299 | |
| 4300 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4301 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4302 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4303 | self.waitUntilSettled() |
| 4304 | |
| 4305 | # We should be disabled now |
| 4306 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4307 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4308 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4309 | |
| 4310 | # We need to wait between each of these patches to make sure the |
| 4311 | # smtp messages come back in an expected order |
| 4312 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4313 | self.waitUntilSettled() |
| 4314 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4315 | self.waitUntilSettled() |
| 4316 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4317 | self.waitUntilSettled() |
| 4318 | |
| 4319 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4320 | # leaving a message on each change |
| 4321 | self.assertEqual(1, len(A.messages)) |
| 4322 | self.assertIn('Build failed.', A.messages[0]) |
| 4323 | self.assertEqual(1, len(B.messages)) |
| 4324 | self.assertIn('Build failed.', B.messages[0]) |
| 4325 | self.assertEqual(1, len(C.messages)) |
| 4326 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4327 | self.assertEqual(1, len(D.messages)) |
| 4328 | self.assertIn('Build failed.', D.messages[0]) |
| 4329 | self.assertEqual(1, len(E.messages)) |
| 4330 | self.assertIn('Build failed.', E.messages[0]) |
| 4331 | self.assertEqual(1, len(F.messages)) |
| 4332 | self.assertIn('Build failed.', F.messages[0]) |
| 4333 | |
| 4334 | # The last 3 (GHI) would have only reported via smtp. |
| 4335 | self.assertEqual(3, len(self.smtp_messages)) |
| 4336 | self.assertEqual(0, len(G.messages)) |
| 4337 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4338 | self.assertIn( |
| 4339 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4340 | self.assertEqual(0, len(H.messages)) |
| 4341 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4342 | self.assertIn( |
| 4343 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4344 | self.assertEqual(0, len(I.messages)) |
| 4345 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4346 | self.assertIn( |
| 4347 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4348 | |
| 4349 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4350 | # comes out of disabled |
| 4351 | self.sched.reconfigure(self.config) |
| 4352 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4353 | tenant = self.sched.abide.tenants.get('openstack') |
| 4354 | |
| 4355 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4356 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4357 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4358 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4359 | |
| 4360 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4361 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4362 | self.waitUntilSettled() |
| 4363 | |
| 4364 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4365 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4366 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4367 | |
| 4368 | # J and K went back to gerrit |
| 4369 | self.assertEqual(1, len(J.messages)) |
| 4370 | self.assertIn('Build failed.', J.messages[0]) |
| 4371 | self.assertEqual(1, len(K.messages)) |
| 4372 | self.assertIn('Build failed.', K.messages[0]) |
| 4373 | # No more messages reported via smtp |
| 4374 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4375 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4376 | def test_rerun_on_abort(self): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4377 | "Test that if a launch server fails to run a job, it is run again" |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4378 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4379 | self.launch_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4380 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4381 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4382 | self.waitUntilSettled() |
| 4383 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4384 | self.launch_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4385 | self.waitUntilSettled() |
| 4386 | |
| 4387 | self.assertEqual(len(self.builds), 2) |
| 4388 | self.builds[0].requeue = True |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4389 | self.launch_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4390 | self.waitUntilSettled() |
| 4391 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4392 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4393 | self.assertEqual(len(self.builds), 1, |
| 4394 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4395 | self.builds[0].requeue = True |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4396 | self.launch_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4397 | self.waitUntilSettled() |
| 4398 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4399 | self.launch_server.hold_jobs_in_build = False |
| 4400 | self.launch_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4401 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4402 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4403 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4404 | self.assertEqual(A.reported, 1) |
| 4405 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4406 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4407 | def test_zookeeper_disconnect(self): |
| 4408 | "Test that jobs are launched after a zookeeper disconnect" |
| 4409 | |
| 4410 | self.fake_nodepool.paused = True |
| 4411 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4412 | A.addApproval('code-review', 2) |
| 4413 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4414 | self.waitUntilSettled() |
| 4415 | |
| 4416 | self.zk.client.stop() |
| 4417 | self.zk.client.start() |
| 4418 | self.fake_nodepool.paused = False |
| 4419 | self.waitUntilSettled() |
| 4420 | |
| 4421 | self.assertEqual(A.data['status'], 'MERGED') |
| 4422 | self.assertEqual(A.reported, 2) |
| 4423 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4424 | def test_nodepool_failure(self): |
| 4425 | "Test that jobs are reported after a nodepool failure" |
| 4426 | |
| 4427 | self.fake_nodepool.paused = True |
| 4428 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4429 | A.addApproval('code-review', 2) |
| 4430 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4431 | self.waitUntilSettled() |
| 4432 | |
| 4433 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4434 | self.fake_nodepool.addFailRequest(req) |
| 4435 | |
| 4436 | self.fake_nodepool.paused = False |
| 4437 | self.waitUntilSettled() |
| 4438 | |
| 4439 | self.assertEqual(A.data['status'], 'NEW') |
| 4440 | self.assertEqual(A.reported, 2) |
| 4441 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4442 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4443 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4444 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4445 | |
| 4446 | class TestDuplicatePipeline(ZuulTestCase): |
| 4447 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4448 | |
| 4449 | def test_duplicate_pipelines(self): |
| 4450 | "Test that a change matching multiple pipelines works" |
| 4451 | |
| 4452 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4453 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4454 | self.waitUntilSettled() |
| 4455 | |
| 4456 | self.assertHistory([ |
| 4457 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4458 | pipeline='dup1'), |
| 4459 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4460 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4461 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4462 | |
| 4463 | self.assertEqual(len(A.messages), 2) |
| 4464 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4465 | if 'dup1' in A.messages[0]: |
| 4466 | self.assertIn('dup1', A.messages[0]) |
| 4467 | self.assertNotIn('dup2', A.messages[0]) |
| 4468 | self.assertIn('project-test1', A.messages[0]) |
| 4469 | self.assertIn('dup2', A.messages[1]) |
| 4470 | self.assertNotIn('dup1', A.messages[1]) |
| 4471 | self.assertIn('project-test1', A.messages[1]) |
| 4472 | else: |
| 4473 | self.assertIn('dup1', A.messages[1]) |
| 4474 | self.assertNotIn('dup2', A.messages[1]) |
| 4475 | self.assertIn('project-test1', A.messages[1]) |
| 4476 | self.assertIn('dup2', A.messages[0]) |
| 4477 | self.assertNotIn('dup1', A.messages[0]) |
| 4478 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4479 | |
| 4480 | |
| 4481 | class TestSchedulerOneJobProject(ZuulTestCase): |
| 4482 | tenant_config_file = 'config/one-job-project/main.yaml' |
| 4483 | |
| 4484 | def test_one_job_project(self): |
| 4485 | "Test that queueing works with one job" |
| 4486 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4487 | 'master', 'A') |
| 4488 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4489 | 'master', 'B') |
| 4490 | A.addApproval('code-review', 2) |
| 4491 | B.addApproval('code-review', 2) |
| 4492 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4493 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4494 | self.waitUntilSettled() |
| 4495 | |
| 4496 | self.assertEqual(A.data['status'], 'MERGED') |
| 4497 | self.assertEqual(A.reported, 2) |
| 4498 | self.assertEqual(B.data['status'], 'MERGED') |
| 4499 | self.assertEqual(B.reported, 2) |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4500 | |
| 4501 | |
| 4502 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4503 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4504 | |
| 4505 | def test_job_from_templates_launched(self): |
| 4506 | "Test whether a job generated via a template can be launched" |
| 4507 | |
| 4508 | A = self.fake_gerrit.addFakeChange( |
| 4509 | 'org/templated-project', 'master', 'A') |
| 4510 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4511 | self.waitUntilSettled() |
| 4512 | |
| 4513 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4514 | 'SUCCESS') |
| 4515 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4516 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4517 | |
| 4518 | def test_layered_templates(self): |
| 4519 | "Test whether a job generated via a template can be launched" |
| 4520 | |
| 4521 | A = self.fake_gerrit.addFakeChange( |
| 4522 | 'org/layered-project', 'master', 'A') |
| 4523 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4524 | self.waitUntilSettled() |
| 4525 | |
| 4526 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4527 | 'SUCCESS') |
| 4528 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4529 | 'SUCCESS') |
| 4530 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4531 | ).result, 'SUCCESS') |
| 4532 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4533 | ).result, 'SUCCESS') |
| 4534 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4535 | ).result, 'SUCCESS') |
| 4536 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4537 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4538 | |
| 4539 | |
| 4540 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4541 | tenant_config_file = 'config/success-url/main.yaml' |
| 4542 | |
| 4543 | def test_success_url(self): |
| 4544 | "Ensure bad build params are ignored" |
| 4545 | self.sched.reconfigure(self.config) |
| 4546 | self.init_repo('org/docs') |
| 4547 | |
| 4548 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4549 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4550 | self.waitUntilSettled() |
| 4551 | |
| 4552 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4553 | self.assertEqual(len(self.history), 2) |
| 4554 | |
| 4555 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4556 | for build in self.history: |
| 4557 | if build.name == 'docs-draft-test': |
| 4558 | uuid = build.uuid[:7] |
| 4559 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4560 | |
| 4561 | # Two msgs: 'Starting...' + results |
| 4562 | self.assertEqual(len(self.smtp_messages), 2) |
| 4563 | body = self.smtp_messages[1]['body'].splitlines() |
| 4564 | self.assertEqual('Build succeeded.', body[0]) |
| 4565 | |
| 4566 | self.assertIn( |
| 4567 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4568 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4569 | body[2]) |
| 4570 | |
| 4571 | # NOTE: This default URL is currently hard-coded in launcher/server.py |
| 4572 | self.assertIn( |
| 4573 | '- docs-draft-test2 https://server/job', |
| 4574 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4575 | |
| 4576 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4577 | class TestSchedulerMerges(ZuulTestCase): |
| 4578 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4579 | |
| 4580 | def _test_project_merge_mode(self, mode): |
| 4581 | self.launch_server.keep_jobdir = False |
| 4582 | project = 'org/project-%s' % mode |
| 4583 | self.launch_server.hold_jobs_in_build = True |
| 4584 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4585 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4586 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4587 | A.addApproval('code-review', 2) |
| 4588 | B.addApproval('code-review', 2) |
| 4589 | C.addApproval('code-review', 2) |
| 4590 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4591 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4592 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4593 | self.waitUntilSettled() |
| 4594 | |
| 4595 | build = self.builds[-1] |
| 4596 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4597 | |
| 4598 | path = os.path.join(build.jobdir.git_root, project) |
| 4599 | repo = git.Repo(path) |
| 4600 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4601 | repo_messages.reverse() |
| 4602 | |
| 4603 | self.launch_server.hold_jobs_in_build = False |
| 4604 | self.launch_server.release() |
| 4605 | self.waitUntilSettled() |
| 4606 | |
| 4607 | return repo_messages |
| 4608 | |
| 4609 | def _test_merge(self, mode): |
| 4610 | us_path = os.path.join( |
| 4611 | self.upstream_root, 'org/project-%s' % mode) |
| 4612 | expected_messages = [ |
| 4613 | 'initial commit', |
| 4614 | 'add content from fixture', |
| 4615 | # the intermediate commits order is nondeterministic |
| 4616 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4617 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4618 | ] |
| 4619 | result = self._test_project_merge_mode(mode) |
| 4620 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4621 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4622 | |
| 4623 | def test_project_merge_mode_merge(self): |
| 4624 | self._test_merge('merge') |
| 4625 | |
| 4626 | def test_project_merge_mode_merge_resolve(self): |
| 4627 | self._test_merge('merge-resolve') |
| 4628 | |
| 4629 | def test_project_merge_mode_cherrypick(self): |
| 4630 | expected_messages = [ |
| 4631 | 'initial commit', |
| 4632 | 'add content from fixture', |
| 4633 | 'A-1', |
| 4634 | 'B-1', |
| 4635 | 'C-1'] |
| 4636 | result = self._test_project_merge_mode('cherry-pick') |
| 4637 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4638 | |
| 4639 | def test_merge_branch(self): |
| 4640 | "Test that the right commits are on alternate branches" |
| 4641 | self.create_branch('org/project-merge-branches', 'mp') |
| 4642 | |
| 4643 | self.launch_server.hold_jobs_in_build = True |
| 4644 | A = self.fake_gerrit.addFakeChange( |
| 4645 | 'org/project-merge-branches', 'mp', 'A') |
| 4646 | B = self.fake_gerrit.addFakeChange( |
| 4647 | 'org/project-merge-branches', 'mp', 'B') |
| 4648 | C = self.fake_gerrit.addFakeChange( |
| 4649 | 'org/project-merge-branches', 'mp', 'C') |
| 4650 | A.addApproval('code-review', 2) |
| 4651 | B.addApproval('code-review', 2) |
| 4652 | C.addApproval('code-review', 2) |
| 4653 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4654 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4655 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4656 | self.waitUntilSettled() |
| 4657 | |
| 4658 | self.launch_server.release('.*-merge') |
| 4659 | self.waitUntilSettled() |
| 4660 | self.launch_server.release('.*-merge') |
| 4661 | self.waitUntilSettled() |
| 4662 | self.launch_server.release('.*-merge') |
| 4663 | self.waitUntilSettled() |
| 4664 | |
| 4665 | build = self.builds[-1] |
| 4666 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 4667 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4668 | path = os.path.join( |
| 4669 | build.jobdir.git_root, 'org/project-merge-branches') |
| 4670 | repo = git.Repo(path) |
| 4671 | |
| 4672 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4673 | repo_messages.reverse() |
| 4674 | correct_messages = [ |
| 4675 | 'initial commit', |
| 4676 | 'add content from fixture', |
| 4677 | 'mp commit', |
| 4678 | 'A-1', 'B-1', 'C-1'] |
| 4679 | self.assertEqual(repo_messages, correct_messages) |
| 4680 | |
| 4681 | self.launch_server.hold_jobs_in_build = False |
| 4682 | self.launch_server.release() |
| 4683 | self.waitUntilSettled() |
| 4684 | |
| 4685 | def test_merge_multi_branch(self): |
| 4686 | "Test that dependent changes on multiple branches are merged" |
| 4687 | self.create_branch('org/project-merge-branches', 'mp') |
| 4688 | |
| 4689 | self.launch_server.hold_jobs_in_build = True |
| 4690 | A = self.fake_gerrit.addFakeChange( |
| 4691 | 'org/project-merge-branches', 'master', 'A') |
| 4692 | B = self.fake_gerrit.addFakeChange( |
| 4693 | 'org/project-merge-branches', 'mp', 'B') |
| 4694 | C = self.fake_gerrit.addFakeChange( |
| 4695 | 'org/project-merge-branches', 'master', 'C') |
| 4696 | A.addApproval('code-review', 2) |
| 4697 | B.addApproval('code-review', 2) |
| 4698 | C.addApproval('code-review', 2) |
| 4699 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4700 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4701 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4702 | self.waitUntilSettled() |
| 4703 | |
| 4704 | job_A = None |
| 4705 | for job in self.builds: |
| 4706 | if 'project-merge' in job.name: |
| 4707 | job_A = job |
| 4708 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 4709 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 4710 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 4711 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 4712 | |
| 4713 | path = os.path.join( |
| 4714 | job_A.jobdir.git_root, "org/project-merge-branches") |
| 4715 | repo = git.Repo(path) |
| 4716 | repo_messages = [c.message.strip() |
| 4717 | for c in repo.iter_commits(ref_A)] |
| 4718 | repo_messages.reverse() |
| 4719 | correct_messages = [ |
| 4720 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4721 | self.assertEqual(repo_messages, correct_messages) |
| 4722 | |
| 4723 | self.launch_server.release('.*-merge') |
| 4724 | self.waitUntilSettled() |
| 4725 | |
| 4726 | job_B = None |
| 4727 | for job in self.builds: |
| 4728 | if 'project-merge' in job.name: |
| 4729 | job_B = job |
| 4730 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 4731 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 4732 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 4733 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 4734 | |
| 4735 | path = os.path.join( |
| 4736 | job_B.jobdir.git_root, "org/project-merge-branches") |
| 4737 | repo = git.Repo(path) |
| 4738 | repo_messages = [c.message.strip() |
| 4739 | for c in repo.iter_commits(ref_B)] |
| 4740 | repo_messages.reverse() |
| 4741 | correct_messages = [ |
| 4742 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4743 | self.assertEqual(repo_messages, correct_messages) |
| 4744 | |
| 4745 | self.launch_server.release('.*-merge') |
| 4746 | self.waitUntilSettled() |
| 4747 | |
| 4748 | job_C = None |
| 4749 | for job in self.builds: |
| 4750 | if 'project-merge' in job.name: |
| 4751 | job_C = job |
| 4752 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 4753 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 4754 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 4755 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
| 4756 | path = os.path.join( |
| 4757 | job_C.jobdir.git_root, "org/project-merge-branches") |
| 4758 | repo = git.Repo(path) |
| 4759 | repo_messages = [c.message.strip() |
| 4760 | for c in repo.iter_commits(ref_C)] |
| 4761 | |
| 4762 | repo_messages.reverse() |
| 4763 | correct_messages = [ |
| 4764 | 'initial commit', 'add content from fixture', |
| 4765 | 'A-1', 'C-1'] |
| 4766 | # Ensure the right commits are in the history for this ref |
| 4767 | self.assertEqual(repo_messages, correct_messages) |
| 4768 | |
| 4769 | self.launch_server.hold_jobs_in_build = False |
| 4770 | self.launch_server.release() |
| 4771 | self.waitUntilSettled() |